diff options
author | 2021-07-11 16:22:21 +0200 | |
---|---|---|
committer | 2021-07-11 16:22:21 +0200 | |
commit | 846057f0d696fded87d105dec1245e9ba32763ce (patch) | |
tree | 9a4914c07bcf189a3eea0a2c091567c56cdf4963 /internal/typeutils/astointernal.go | |
parent | favourites GET implementation (#95) (diff) | |
download | gotosocial-846057f0d696fded87d105dec1245e9ba32763ce.tar.xz |
Block/unblock (#96)
* remote + local block logic, incl. federation
* improve blocking stuff
* fiddle with display of blocked profiles
* go fmt
Diffstat (limited to 'internal/typeutils/astointernal.go')
-rw-r--r-- | internal/typeutils/astointernal.go | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/internal/typeutils/astointernal.go b/internal/typeutils/astointernal.go index dc58346fb..394de6e82 100644 --- a/internal/typeutils/astointernal.go +++ b/internal/typeutils/astointernal.go @@ -426,6 +426,41 @@ func (c *converter) ASLikeToFave(likeable Likeable) (*gtsmodel.StatusFave, error }, nil } +func (c *converter) ASBlockToBlock(blockable Blockable) (*gtsmodel.Block, error) { + idProp := blockable.GetJSONLDId() + if idProp == nil || !idProp.IsIRI() { + return nil, errors.New("ASBlockToBlock: no id property set on block, or was not an iri") + } + uri := idProp.GetIRI().String() + + origin, err := extractActor(blockable) + if err != nil { + return nil, errors.New("ASBlockToBlock: error extracting actor property from block") + } + originAccount := >smodel.Account{} + if err := c.db.GetWhere([]db.Where{{Key: "uri", Value: origin.String()}}, originAccount); err != nil { + return nil, fmt.Errorf("ASBlockToBlock: error extracting account with uri %s from the database: %s", origin.String(), err) + } + + target, err := extractObject(blockable) + if err != nil { + return nil, errors.New("ASBlockToBlock: error extracting object property from block") + } + + targetAccount := >smodel.Account{} + if err := c.db.GetWhere([]db.Where{{Key: "uri", Value: target.String(), CaseInsensitive: true}}, targetAccount); err != nil { + return nil, fmt.Errorf("ASBlockToBlock: error extracting account with uri %s from the database: %s", target.String(), err) + } + + return >smodel.Block{ + AccountID: originAccount.ID, + Account: originAccount, + TargetAccountID: targetAccount.ID, + TargetAccount: targetAccount, + URI: uri, + }, nil +} + func (c *converter) ASAnnounceToStatus(announceable Announceable) (*gtsmodel.Status, bool, error) { status := >smodel.Status{} isNew := true |