mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2026-01-05 23:23:16 -06:00
start moving some database stuff around
This commit is contained in:
parent
ce190d867c
commit
f409f7c65a
43 changed files with 1230 additions and 1223 deletions
|
|
@ -231,7 +231,7 @@ func (c *converter) ASStatusToStatus(statusable ap.Statusable) (*gtsmodel.Status
|
|||
}
|
||||
status.AccountID = statusOwner.ID
|
||||
status.AccountURI = statusOwner.URI
|
||||
status.GTSAuthorAccount = statusOwner
|
||||
status.Account = statusOwner
|
||||
|
||||
// check if there's a post that this is a reply to
|
||||
inReplyToURI := ap.ExtractInReplyToURI(statusable)
|
||||
|
|
@ -247,12 +247,12 @@ func (c *converter) ASStatusToStatus(statusable ap.Statusable) (*gtsmodel.Status
|
|||
// so we can set these fields here and then...
|
||||
status.InReplyToID = inReplyToStatus.ID
|
||||
status.InReplyToAccountID = inReplyToStatus.AccountID
|
||||
status.GTSReplyToStatus = inReplyToStatus
|
||||
status.InReplyTo = inReplyToStatus
|
||||
|
||||
// ... check if we've seen the account already
|
||||
inReplyToAccount := >smodel.Account{}
|
||||
if err := c.db.GetByID(inReplyToStatus.AccountID, inReplyToAccount); err == nil {
|
||||
status.GTSReplyToAccount = inReplyToAccount
|
||||
status.InReplyToAccount = inReplyToAccount
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -421,9 +421,9 @@ func (c *converter) ASLikeToFave(likeable ap.Likeable) (*gtsmodel.StatusFave, er
|
|||
StatusID: targetStatus.ID,
|
||||
AccountID: originAccount.ID,
|
||||
URI: uri,
|
||||
GTSStatus: targetStatus,
|
||||
GTSTargetAccount: targetAccount,
|
||||
GTSFavingAccount: originAccount,
|
||||
Status: targetStatus,
|
||||
TargetAccount: targetAccount,
|
||||
Account: originAccount,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
|
@ -487,7 +487,7 @@ func (c *converter) ASAnnounceToStatus(announceable ap.Announceable) (*gtsmodel.
|
|||
}
|
||||
|
||||
// set the URI on the new status for dereferencing later
|
||||
status.GTSBoostedStatus = >smodel.Status{
|
||||
status.BoostOf = >smodel.Status{
|
||||
URI: boostedStatusURI.String(),
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -74,7 +74,7 @@ func (c *converter) StatusToBoost(s *gtsmodel.Status, boostingAccount *gtsmodel.
|
|||
// attach these here for convenience -- the boosted status/account won't go in the DB
|
||||
// but they're needed in the processor and for the frontend. Since we have them, we can
|
||||
// attach them so we don't need to fetch them again later (save some DB calls)
|
||||
GTSBoostedStatus: s,
|
||||
BoostOf: s,
|
||||
}
|
||||
|
||||
return boostWrapperStatus, nil
|
||||
|
|
|
|||
|
|
@ -330,12 +330,12 @@ func (c *converter) StatusToAS(s *gtsmodel.Status) (vocab.ActivityStreamsNote, e
|
|||
|
||||
// check if author account is already attached to status and attach it if not
|
||||
// if we can't retrieve this, bail here already because we can't attribute the status to anyone
|
||||
if s.GTSAuthorAccount == nil {
|
||||
if s.Account == nil {
|
||||
a := >smodel.Account{}
|
||||
if err := c.db.GetByID(s.AccountID, a); err != nil {
|
||||
return nil, fmt.Errorf("StatusToAS: error retrieving author account from db: %s", err)
|
||||
}
|
||||
s.GTSAuthorAccount = a
|
||||
s.Account = a
|
||||
}
|
||||
|
||||
// create the Note!
|
||||
|
|
@ -361,16 +361,16 @@ func (c *converter) StatusToAS(s *gtsmodel.Status) (vocab.ActivityStreamsNote, e
|
|||
// inReplyTo
|
||||
if s.InReplyToID != "" {
|
||||
// fetch the replied status if we don't have it on hand already
|
||||
if s.GTSReplyToStatus == nil {
|
||||
if s.InReplyTo == nil {
|
||||
rs := >smodel.Status{}
|
||||
if err := c.db.GetByID(s.InReplyToID, rs); err != nil {
|
||||
return nil, fmt.Errorf("StatusToAS: error retrieving replied-to status from db: %s", err)
|
||||
}
|
||||
s.GTSReplyToStatus = rs
|
||||
s.InReplyTo = rs
|
||||
}
|
||||
rURI, err := url.Parse(s.GTSReplyToStatus.URI)
|
||||
rURI, err := url.Parse(s.InReplyTo.URI)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("StatusToAS: error parsing url %s: %s", s.GTSReplyToStatus.URI, err)
|
||||
return nil, fmt.Errorf("StatusToAS: error parsing url %s: %s", s.InReplyTo.URI, err)
|
||||
}
|
||||
|
||||
inReplyToProp := streams.NewActivityStreamsInReplyToProperty()
|
||||
|
|
@ -396,9 +396,9 @@ func (c *converter) StatusToAS(s *gtsmodel.Status) (vocab.ActivityStreamsNote, e
|
|||
}
|
||||
|
||||
// attributedTo
|
||||
authorAccountURI, err := url.Parse(s.GTSAuthorAccount.URI)
|
||||
authorAccountURI, err := url.Parse(s.Account.URI)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("StatusToAS: error parsing url %s: %s", s.GTSAuthorAccount.URI, err)
|
||||
return nil, fmt.Errorf("StatusToAS: error parsing url %s: %s", s.Account.URI, err)
|
||||
}
|
||||
attributedToProp := streams.NewActivityStreamsAttributedToProperty()
|
||||
attributedToProp.AppendIRI(authorAccountURI)
|
||||
|
|
@ -425,9 +425,9 @@ func (c *converter) StatusToAS(s *gtsmodel.Status) (vocab.ActivityStreamsNote, e
|
|||
status.SetActivityStreamsTag(tagProp)
|
||||
|
||||
// parse out some URIs we need here
|
||||
authorFollowersURI, err := url.Parse(s.GTSAuthorAccount.FollowersURI)
|
||||
authorFollowersURI, err := url.Parse(s.Account.FollowersURI)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("StatusToAS: error parsing url %s: %s", s.GTSAuthorAccount.FollowersURI, err)
|
||||
return nil, fmt.Errorf("StatusToAS: error parsing url %s: %s", s.Account.FollowersURI, err)
|
||||
}
|
||||
|
||||
publicURI, err := url.Parse(asPublicURI)
|
||||
|
|
@ -648,30 +648,30 @@ func (c *converter) AttachmentToAS(a *gtsmodel.MediaAttachment) (vocab.ActivityS
|
|||
*/
|
||||
func (c *converter) FaveToAS(f *gtsmodel.StatusFave) (vocab.ActivityStreamsLike, error) {
|
||||
// check if targetStatus is already pinned to this fave, and fetch it if not
|
||||
if f.GTSStatus == nil {
|
||||
if f.Status == nil {
|
||||
s := >smodel.Status{}
|
||||
if err := c.db.GetByID(f.StatusID, s); err != nil {
|
||||
return nil, fmt.Errorf("FaveToAS: error fetching target status from database: %s", err)
|
||||
}
|
||||
f.GTSStatus = s
|
||||
f.Status = s
|
||||
}
|
||||
|
||||
// check if the targetAccount is already pinned to this fave, and fetch it if not
|
||||
if f.GTSTargetAccount == nil {
|
||||
if f.TargetAccount == nil {
|
||||
a := >smodel.Account{}
|
||||
if err := c.db.GetByID(f.TargetAccountID, a); err != nil {
|
||||
return nil, fmt.Errorf("FaveToAS: error fetching target account from database: %s", err)
|
||||
}
|
||||
f.GTSTargetAccount = a
|
||||
f.TargetAccount = a
|
||||
}
|
||||
|
||||
// check if the faving account is already pinned to this fave, and fetch it if not
|
||||
if f.GTSFavingAccount == nil {
|
||||
if f.Account == nil {
|
||||
a := >smodel.Account{}
|
||||
if err := c.db.GetByID(f.AccountID, a); err != nil {
|
||||
return nil, fmt.Errorf("FaveToAS: error fetching faving account from database: %s", err)
|
||||
}
|
||||
f.GTSFavingAccount = a
|
||||
f.Account = a
|
||||
}
|
||||
|
||||
// create the like
|
||||
|
|
@ -679,9 +679,9 @@ func (c *converter) FaveToAS(f *gtsmodel.StatusFave) (vocab.ActivityStreamsLike,
|
|||
|
||||
// set the actor property to the fave-ing account's URI
|
||||
actorProp := streams.NewActivityStreamsActorProperty()
|
||||
actorIRI, err := url.Parse(f.GTSFavingAccount.URI)
|
||||
actorIRI, err := url.Parse(f.Account.URI)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("FaveToAS: error parsing uri %s: %s", f.GTSFavingAccount.URI, err)
|
||||
return nil, fmt.Errorf("FaveToAS: error parsing uri %s: %s", f.Account.URI, err)
|
||||
}
|
||||
actorProp.AppendIRI(actorIRI)
|
||||
like.SetActivityStreamsActor(actorProp)
|
||||
|
|
@ -697,18 +697,18 @@ func (c *converter) FaveToAS(f *gtsmodel.StatusFave) (vocab.ActivityStreamsLike,
|
|||
|
||||
// set the object property to the target status's URI
|
||||
objectProp := streams.NewActivityStreamsObjectProperty()
|
||||
statusIRI, err := url.Parse(f.GTSStatus.URI)
|
||||
statusIRI, err := url.Parse(f.Status.URI)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("FaveToAS: error parsing uri %s: %s", f.GTSStatus.URI, err)
|
||||
return nil, fmt.Errorf("FaveToAS: error parsing uri %s: %s", f.Status.URI, err)
|
||||
}
|
||||
objectProp.AppendIRI(statusIRI)
|
||||
like.SetActivityStreamsObject(objectProp)
|
||||
|
||||
// set the TO property to the target account's IRI
|
||||
toProp := streams.NewActivityStreamsToProperty()
|
||||
toIRI, err := url.Parse(f.GTSTargetAccount.URI)
|
||||
toIRI, err := url.Parse(f.TargetAccount.URI)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("FaveToAS: error parsing uri %s: %s", f.GTSTargetAccount.URI, err)
|
||||
return nil, fmt.Errorf("FaveToAS: error parsing uri %s: %s", f.TargetAccount.URI, err)
|
||||
}
|
||||
toProp.AppendIRI(toIRI)
|
||||
like.SetActivityStreamsTo(toProp)
|
||||
|
|
@ -718,12 +718,12 @@ func (c *converter) FaveToAS(f *gtsmodel.StatusFave) (vocab.ActivityStreamsLike,
|
|||
|
||||
func (c *converter) BoostToAS(boostWrapperStatus *gtsmodel.Status, boostingAccount *gtsmodel.Account, boostedAccount *gtsmodel.Account) (vocab.ActivityStreamsAnnounce, error) {
|
||||
// the boosted status is probably pinned to the boostWrapperStatus but double check to make sure
|
||||
if boostWrapperStatus.GTSBoostedStatus == nil {
|
||||
if boostWrapperStatus.BoostOf == nil {
|
||||
b := >smodel.Status{}
|
||||
if err := c.db.GetByID(boostWrapperStatus.BoostOfID, b); err != nil {
|
||||
return nil, fmt.Errorf("BoostToAS: error getting status with ID %s from the db: %s", boostWrapperStatus.BoostOfID, err)
|
||||
}
|
||||
boostWrapperStatus.GTSBoostedStatus = b
|
||||
boostWrapperStatus.BoostOf = b
|
||||
}
|
||||
|
||||
// create the announce
|
||||
|
|
@ -748,9 +748,9 @@ func (c *converter) BoostToAS(boostWrapperStatus *gtsmodel.Status, boostingAccou
|
|||
announce.SetJSONLDId(idProp)
|
||||
|
||||
// set the object
|
||||
boostedStatusURI, err := url.Parse(boostWrapperStatus.GTSBoostedStatus.URI)
|
||||
boostedStatusURI, err := url.Parse(boostWrapperStatus.BoostOf.URI)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("BoostToAS: error parsing uri %s: %s", boostWrapperStatus.GTSBoostedStatus.URI, err)
|
||||
return nil, fmt.Errorf("BoostToAS: error parsing uri %s: %s", boostWrapperStatus.BoostOf.URI, err)
|
||||
}
|
||||
objectProp := streams.NewActivityStreamsObjectProperty()
|
||||
objectProp.AppendIRI(boostedStatusURI)
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ func (c *converter) AccountToMastoSensitive(a *gtsmodel.Account) (*model.Account
|
|||
|
||||
// check pending follow requests aimed at this account
|
||||
fr := []gtsmodel.FollowRequest{}
|
||||
if err := c.db.GetFollowRequestsForAccountID(a.ID, &fr); err != nil {
|
||||
if err := c.db.GetAccountFollowRequests(a.ID, &fr); err != nil {
|
||||
if _, ok := err.(db.ErrNoEntries); !ok {
|
||||
return nil, fmt.Errorf("error getting follow requests: %s", err)
|
||||
}
|
||||
|
|
@ -64,7 +64,7 @@ func (c *converter) AccountToMastoSensitive(a *gtsmodel.Account) (*model.Account
|
|||
func (c *converter) AccountToMastoPublic(a *gtsmodel.Account) (*model.Account, error) {
|
||||
// count followers
|
||||
followers := []gtsmodel.Follow{}
|
||||
if err := c.db.GetFollowersByAccountID(a.ID, &followers, false); err != nil {
|
||||
if err := c.db.GetAccountFollowers(a.ID, &followers, false); err != nil {
|
||||
if _, ok := err.(db.ErrNoEntries); !ok {
|
||||
return nil, fmt.Errorf("error getting followers: %s", err)
|
||||
}
|
||||
|
|
@ -76,7 +76,7 @@ func (c *converter) AccountToMastoPublic(a *gtsmodel.Account) (*model.Account, e
|
|||
|
||||
// count following
|
||||
following := []gtsmodel.Follow{}
|
||||
if err := c.db.GetFollowingByAccountID(a.ID, &following); err != nil {
|
||||
if err := c.db.GetAccountFollowing(a.ID, &following); err != nil {
|
||||
if _, ok := err.(db.ErrNoEntries); !ok {
|
||||
return nil, fmt.Errorf("error getting following: %s", err)
|
||||
}
|
||||
|
|
@ -87,7 +87,7 @@ func (c *converter) AccountToMastoPublic(a *gtsmodel.Account) (*model.Account, e
|
|||
}
|
||||
|
||||
// count statuses
|
||||
statusesCount, err := c.db.CountStatusesByAccountID(a.ID)
|
||||
statusesCount, err := c.db.GetAccountStatusesCount(a.ID)
|
||||
if err != nil {
|
||||
if _, ok := err.(db.ErrNoEntries); !ok {
|
||||
return nil, fmt.Errorf("error getting last statuses: %s", err)
|
||||
|
|
@ -96,7 +96,7 @@ func (c *converter) AccountToMastoPublic(a *gtsmodel.Account) (*model.Account, e
|
|||
|
||||
// check when the last status was
|
||||
lastStatus := >smodel.Status{}
|
||||
if err := c.db.GetLastStatusForAccountID(a.ID, lastStatus); err != nil {
|
||||
if err := c.db.GetAccountLastStatus(a.ID, lastStatus); err != nil {
|
||||
if _, ok := err.(db.ErrNoEntries); !ok {
|
||||
return nil, fmt.Errorf("error getting last status: %s", err)
|
||||
}
|
||||
|
|
@ -108,7 +108,7 @@ func (c *converter) AccountToMastoPublic(a *gtsmodel.Account) (*model.Account, e
|
|||
|
||||
// build the avatar and header URLs
|
||||
avi := >smodel.MediaAttachment{}
|
||||
if err := c.db.GetAvatarForAccountID(avi, a.ID); err != nil {
|
||||
if err := c.db.GetAccountAvatar(avi, a.ID); err != nil {
|
||||
if _, ok := err.(db.ErrNoEntries); !ok {
|
||||
return nil, fmt.Errorf("error getting avatar: %s", err)
|
||||
}
|
||||
|
|
@ -117,7 +117,7 @@ func (c *converter) AccountToMastoPublic(a *gtsmodel.Account) (*model.Account, e
|
|||
aviURLStatic := avi.Thumbnail.URL
|
||||
|
||||
header := >smodel.MediaAttachment{}
|
||||
if err := c.db.GetHeaderForAccountID(header, a.ID); err != nil {
|
||||
if err := c.db.GetAccountHeader(header, a.ID); err != nil {
|
||||
if _, ok := err.(db.ErrNoEntries); !ok {
|
||||
return nil, fmt.Errorf("error getting header: %s", err)
|
||||
}
|
||||
|
|
@ -320,27 +320,27 @@ func (c *converter) StatusToMasto(s *gtsmodel.Status, requestingAccount *gtsmode
|
|||
var mastoRebloggedStatus *model.Status
|
||||
if s.BoostOfID != "" {
|
||||
// the boosted status might have been set on this struct already so check first before doing db calls
|
||||
if s.GTSBoostedStatus == nil {
|
||||
if s.BoostOf == nil {
|
||||
// it's not set so fetch it from the db
|
||||
bs := >smodel.Status{}
|
||||
if err := c.db.GetByID(s.BoostOfID, bs); err != nil {
|
||||
return nil, fmt.Errorf("error getting boosted status with id %s: %s", s.BoostOfID, err)
|
||||
}
|
||||
s.GTSBoostedStatus = bs
|
||||
s.BoostOf = bs
|
||||
}
|
||||
|
||||
// the boosted account might have been set on this struct already or passed as a param so check first before doing db calls
|
||||
if s.GTSBoostedAccount == nil {
|
||||
if s.BoostOfAccount == nil {
|
||||
// it's not set so fetch it from the db
|
||||
ba := >smodel.Account{}
|
||||
if err := c.db.GetByID(s.GTSBoostedStatus.AccountID, ba); err != nil {
|
||||
return nil, fmt.Errorf("error getting boosted account %s from status with id %s: %s", s.GTSBoostedStatus.AccountID, s.BoostOfID, err)
|
||||
if err := c.db.GetByID(s.BoostOf.AccountID, ba); err != nil {
|
||||
return nil, fmt.Errorf("error getting boosted account %s from status with id %s: %s", s.BoostOf.AccountID, s.BoostOfID, err)
|
||||
}
|
||||
s.GTSBoostedAccount = ba
|
||||
s.GTSBoostedStatus.GTSAuthorAccount = ba
|
||||
s.BoostOfAccount = ba
|
||||
s.BoostOf.Account = ba
|
||||
}
|
||||
|
||||
mastoRebloggedStatus, err = c.StatusToMasto(s.GTSBoostedStatus, requestingAccount)
|
||||
mastoRebloggedStatus, err = c.StatusToMasto(s.BoostOf, requestingAccount)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error converting boosted status to mastotype: %s", err)
|
||||
}
|
||||
|
|
@ -358,15 +358,15 @@ func (c *converter) StatusToMasto(s *gtsmodel.Status, requestingAccount *gtsmode
|
|||
}
|
||||
}
|
||||
|
||||
if s.GTSAuthorAccount == nil {
|
||||
if s.Account == nil {
|
||||
a := >smodel.Account{}
|
||||
if err := c.db.GetByID(s.AccountID, a); err != nil {
|
||||
return nil, fmt.Errorf("error getting status author: %s", err)
|
||||
}
|
||||
s.GTSAuthorAccount = a
|
||||
s.Account = a
|
||||
}
|
||||
|
||||
mastoAuthorAccount, err := c.AccountToMastoPublic(s.GTSAuthorAccount)
|
||||
mastoAuthorAccount, err := c.AccountToMastoPublic(s.Account)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error parsing account of status author: %s", err)
|
||||
}
|
||||
|
|
@ -589,7 +589,7 @@ func (c *converter) InstanceToMasto(i *gtsmodel.Instance) (*model.Instance, erro
|
|||
if err := c.db.GetWhere([]db.Where{{Key: "username", Value: i.Domain}}, ia); err == nil {
|
||||
// instance account exists, get the header for the account if it exists
|
||||
attachment := >smodel.MediaAttachment{}
|
||||
if err := c.db.GetHeaderForAccountID(attachment, ia.ID); err == nil {
|
||||
if err := c.db.GetAccountHeader(attachment, ia.ID); err == nil {
|
||||
// header exists, set it on the api model
|
||||
mi.Thumbnail = attachment.URL
|
||||
}
|
||||
|
|
@ -659,11 +659,11 @@ func (c *converter) NotificationToMasto(n *gtsmodel.Notification) (*model.Notifi
|
|||
n.GTSStatus = status
|
||||
}
|
||||
|
||||
if n.GTSStatus.GTSAuthorAccount == nil {
|
||||
if n.GTSStatus.Account == nil {
|
||||
if n.GTSStatus.AccountID == n.GTSTargetAccount.ID {
|
||||
n.GTSStatus.GTSAuthorAccount = n.GTSTargetAccount
|
||||
n.GTSStatus.Account = n.GTSTargetAccount
|
||||
} else if n.GTSStatus.AccountID == n.GTSOriginAccount.ID {
|
||||
n.GTSStatus.GTSAuthorAccount = n.GTSOriginAccount
|
||||
n.GTSStatus.Account = n.GTSOriginAccount
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue