diff options
author | 2021-07-05 13:23:03 +0200 | |
---|---|---|
committer | 2021-07-05 13:23:03 +0200 | |
commit | d389e7b150df6ecd215c7b661b294ea153ad0103 (patch) | |
tree | 8739e3103cb5130875d903cc7fc72fd9db3b8434 /internal/processing/status/context.go | |
parent | Fix 404 contact (#74) (diff) | |
download | gotosocial-d389e7b150df6ecd215c7b661b294ea153ad0103.tar.xz |
Domain block (#76)
* start work on admin domain blocking
* move stuff around + further work on domain blocks
* move + restructure processor
* prep work for deleting account
* tidy
* go fmt
* formatting
* domain blocking more work
* check domain blocks way earlier on
* progress on delete account
* delete more stuff when an account is gone
* and more...
* domain blocky block block
* get individual domain block, delete a block
Diffstat (limited to 'internal/processing/status/context.go')
-rw-r--r-- | internal/processing/status/context.go | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/internal/processing/status/context.go b/internal/processing/status/context.go new file mode 100644 index 000000000..72b9b5623 --- /dev/null +++ b/internal/processing/status/context.go @@ -0,0 +1,69 @@ +package status + +import ( + "fmt" + "sort" + + apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model" + "github.com/superseriousbusiness/gotosocial/internal/db" + "github.com/superseriousbusiness/gotosocial/internal/gtserror" + "github.com/superseriousbusiness/gotosocial/internal/gtsmodel" +) + +func (p *processor) Context(account *gtsmodel.Account, targetStatusID string) (*apimodel.Context, gtserror.WithCode) { + + context := &apimodel.Context{ + Ancestors: []apimodel.Status{}, + Descendants: []apimodel.Status{}, + } + + targetStatus := >smodel.Status{} + if err := p.db.GetByID(targetStatusID, targetStatus); err != nil { + if _, ok := err.(db.ErrNoEntries); ok { + return nil, gtserror.NewErrorNotFound(err) + } + return nil, gtserror.NewErrorInternalError(err) + } + + visible, err := p.filter.StatusVisible(targetStatus, account) + if err != nil { + return nil, gtserror.NewErrorNotFound(err) + } + if !visible { + return nil, gtserror.NewErrorForbidden(fmt.Errorf("account with id %s does not have permission to view status %s", account.ID, targetStatusID)) + } + + parents, err := p.db.StatusParents(targetStatus) + if err != nil { + return nil, gtserror.NewErrorInternalError(err) + } + + for _, status := range parents { + if v, err := p.filter.StatusVisible(status, account); err == nil && v { + mastoStatus, err := p.tc.StatusToMasto(status, account) + if err == nil { + context.Ancestors = append(context.Ancestors, *mastoStatus) + } + } + } + + sort.Slice(context.Ancestors, func(i int, j int) bool { + return context.Ancestors[i].ID < context.Ancestors[j].ID + }) + + children, err := p.db.StatusChildren(targetStatus) + if err != nil { + return nil, gtserror.NewErrorInternalError(err) + } + + for _, status := range children { + if v, err := p.filter.StatusVisible(status, account); err == nil && v { + mastoStatus, err := p.tc.StatusToMasto(status, account) + if err == nil { + context.Descendants = append(context.Descendants, *mastoStatus) + } + } + } + + return context, nil +} |