diff options
Diffstat (limited to 'internal/typeutils/astointernal.go')
-rw-r--r-- | internal/typeutils/astointernal.go | 44 |
1 files changed, 43 insertions, 1 deletions
diff --git a/internal/typeutils/astointernal.go b/internal/typeutils/astointernal.go index dcc2674cd..0fee13b13 100644 --- a/internal/typeutils/astointernal.go +++ b/internal/typeutils/astointernal.go @@ -226,7 +226,7 @@ func (c *converter) ASStatusToStatus(statusable Statusable) (*gtsmodel.Status, e return nil, fmt.Errorf("couldn't get status owner from db: %s", err) } status.AccountID = statusOwner.ID - status.GTSAccount = statusOwner + status.GTSAuthorAccount = statusOwner // check if there's a post that this is a reply to inReplyToURI, err := extractInReplyToURI(statusable) @@ -380,6 +380,48 @@ func (c *converter) ASFollowToFollow(followable Followable) (*gtsmodel.Follow, e return follow, nil } +func (c *converter) ASLikeToFave(likeable Likeable) (*gtsmodel.StatusFave, error) { + idProp := likeable.GetJSONLDId() + if idProp == nil || !idProp.IsIRI() { + return nil, errors.New("no id property set on like, or was not an iri") + } + uri := idProp.GetIRI().String() + + origin, err := extractActor(likeable) + if err != nil { + return nil, errors.New("error extracting actor property from like") + } + originAccount := >smodel.Account{} + if err := c.db.GetWhere([]db.Where{{Key: "uri", Value: origin.String()}}, originAccount); err != nil { + return nil, fmt.Errorf("error extracting account with uri %s from the database: %s", origin.String(), err) + } + + target, err := extractObject(likeable) + if err != nil { + return nil, errors.New("error extracting object property from like") + } + + targetStatus := >smodel.Status{} + if err := c.db.GetWhere([]db.Where{{Key: "uri", Value: target.String()}}, targetStatus); err != nil { + return nil, fmt.Errorf("error extracting status with uri %s from the database: %s", target.String(), err) + } + + targetAccount := >smodel.Account{} + if err := c.db.GetByID(targetStatus.AccountID, targetAccount); err != nil { + return nil, fmt.Errorf("error extracting account with id %s from the database: %s", targetStatus.AccountID, err) + } + + return >smodel.StatusFave{ + TargetAccountID: targetAccount.ID, + StatusID: targetStatus.ID, + AccountID: originAccount.ID, + URI: uri, + GTSStatus: targetStatus, + GTSTargetAccount: targetAccount, + GTSFavingAccount: originAccount, + }, nil +} + func isPublic(tos []*url.URL) bool { for _, entry := range tos { if strings.EqualFold(entry.String(), "https://www.w3.org/ns/activitystreams#Public") { |