diff options
author | 2021-05-23 18:07:04 +0200 | |
---|---|---|
committer | 2021-05-23 18:07:04 +0200 | |
commit | ee65d19ff343134c55ca968114dcbfe4b7b4431d (patch) | |
tree | 778141fb4dc2ff17c78594663b0c0cd2a47f79fc /internal/message | |
parent | small fiddling to allow whalebird to work (a bit) (diff) | |
download | gotosocial-ee65d19ff343134c55ca968114dcbfe4b7b4431d.tar.xz |
status deletes, profile updates (#30)
1. Proper DELETE of federated statuses (not yet deleting all the media and stuff -- i still have to implement this -- but the actual status is toast).
2. Proper UPDATE of profiles. When you change your profile picture on your remote instance, that will now register properly in GoToSocial.
3. Scrolling down the home timeline - it no longer just sort of ends, and will keep loading older statuses as you scroll.
4. Little bugfixes -- still had some nil pointer errors when dereferencing remote accounts.
Diffstat (limited to 'internal/message')
-rw-r--r-- | internal/message/accountprocess.go | 6 | ||||
-rw-r--r-- | internal/message/fediprocess.go | 42 | ||||
-rw-r--r-- | internal/message/fromfederatorprocess.go | 23 | ||||
-rw-r--r-- | internal/message/frprocess.go | 4 | ||||
-rw-r--r-- | internal/message/processor.go | 4 | ||||
-rw-r--r-- | internal/message/processorutil.go | 12 |
6 files changed, 75 insertions, 16 deletions
diff --git a/internal/message/accountprocess.go b/internal/message/accountprocess.go index 29fd55034..424081c34 100644 --- a/internal/message/accountprocess.go +++ b/internal/message/accountprocess.go @@ -83,7 +83,7 @@ func (p *processor) AccountGet(authed *oauth.Auth, targetAccountID string) (*api if authed.Account != nil { requestingUsername = authed.Account.Username } - if err := p.dereferenceAccountFields(targetAccount, requestingUsername); err != nil { + if err := p.dereferenceAccountFields(targetAccount, requestingUsername, false); err != nil { p.log.WithField("func", "AccountGet").Debugf("dereferencing account: %s", err) } @@ -295,7 +295,7 @@ func (p *processor) AccountFollowersGet(authed *oauth.Auth, targetAccountID stri } // derefence account fields in case we haven't done it already - if err := p.dereferenceAccountFields(a, authed.Account.Username); err != nil { + if err := p.dereferenceAccountFields(a, authed.Account.Username, false); err != nil { // don't bail if we can't fetch them, we'll try another time p.log.WithField("func", "AccountFollowersGet").Debugf("error dereferencing account fields: %s", err) } @@ -346,7 +346,7 @@ func (p *processor) AccountFollowingGet(authed *oauth.Auth, targetAccountID stri } // derefence account fields in case we haven't done it already - if err := p.dereferenceAccountFields(a, authed.Account.Username); err != nil { + if err := p.dereferenceAccountFields(a, authed.Account.Username, false); err != nil { // don't bail if we can't fetch them, we'll try another time p.log.WithField("func", "AccountFollowingGet").Debugf("error dereferencing account fields: %s", err) } diff --git a/internal/message/fediprocess.go b/internal/message/fediprocess.go index 491997bf2..173da18ee 100644 --- a/internal/message/fediprocess.go +++ b/internal/message/fediprocess.go @@ -68,7 +68,7 @@ func (p *processor) authenticateAndDereferenceFediRequest(username string, r *ht } // convert it to our internal account representation - requestingAccount, err = p.tc.ASRepresentationToAccount(requestingPerson) + requestingAccount, err = p.tc.ASRepresentationToAccount(requestingPerson, false) if err != nil { return nil, fmt.Errorf("couldn't convert dereferenced uri %s to gtsmodel account: %s", requestingAccountURI.String(), err) } @@ -163,6 +163,46 @@ func (p *processor) GetFediFollowers(requestedUsername string, request *http.Req return data, nil } +func (p *processor) GetFediFollowing(requestedUsername string, request *http.Request) (interface{}, ErrorWithCode) { + // get the account the request is referring to + requestedAccount := >smodel.Account{} + if err := p.db.GetLocalAccountByUsername(requestedUsername, requestedAccount); err != nil { + return nil, NewErrorNotFound(fmt.Errorf("database error getting account with username %s: %s", requestedUsername, err)) + } + + // authenticate the request + requestingAccount, err := p.authenticateAndDereferenceFediRequest(requestedUsername, request) + if err != nil { + return nil, NewErrorNotAuthorized(err) + } + + blocked, err := p.db.Blocked(requestedAccount.ID, requestingAccount.ID) + if err != nil { + return nil, NewErrorInternalError(err) + } + + if blocked { + return nil, NewErrorNotAuthorized(fmt.Errorf("block exists between accounts %s and %s", requestedAccount.ID, requestingAccount.ID)) + } + + requestedAccountURI, err := url.Parse(requestedAccount.URI) + if err != nil { + return nil, NewErrorInternalError(fmt.Errorf("error parsing url %s: %s", requestedAccount.URI, err)) + } + + requestedFollowing, err := p.federator.FederatingDB().Following(context.Background(), requestedAccountURI) + if err != nil { + return nil, NewErrorInternalError(fmt.Errorf("error fetching following for uri %s: %s", requestedAccountURI.String(), err)) + } + + data, err := streams.Serialize(requestedFollowing) + if err != nil { + return nil, NewErrorInternalError(err) + } + + return data, nil +} + func (p *processor) GetFediStatus(requestedUsername string, requestedStatusID string, request *http.Request) (interface{}, ErrorWithCode) { // get the account the request is referring to requestedAccount := >smodel.Account{} diff --git a/internal/message/fromfederatorprocess.go b/internal/message/fromfederatorprocess.go index ffaa1b93b..d3ebce400 100644 --- a/internal/message/fromfederatorprocess.go +++ b/internal/message/fromfederatorprocess.go @@ -68,7 +68,7 @@ func (p *processor) processFromFederator(federatorMsg gtsmodel.FromFederator) er } l.Debug("will now derefence incoming account") - if err := p.dereferenceAccountFields(incomingAccount, ""); err != nil { + if err := p.dereferenceAccountFields(incomingAccount, "", false); err != nil { return fmt.Errorf("error dereferencing account from federator: %s", err) } if err := p.db.UpdateByID(incomingAccount.ID, incomingAccount); err != nil { @@ -86,13 +86,26 @@ func (p *processor) processFromFederator(federatorMsg gtsmodel.FromFederator) er } l.Debug("will now derefence incoming account") - if err := p.dereferenceAccountFields(incomingAccount, ""); err != nil { + if err := p.dereferenceAccountFields(incomingAccount, federatorMsg.ReceivingAccount.Username, true); err != nil { return fmt.Errorf("error dereferencing account from federator: %s", err) } if err := p.db.UpdateByID(incomingAccount.ID, incomingAccount); err != nil { return fmt.Errorf("error updating dereferenced account in the db: %s", err) } } + case gtsmodel.ActivityStreamsDelete: + // DELETE + switch federatorMsg.APObjectType { + case gtsmodel.ActivityStreamsNote: + // DELETE A STATUS + // TODO: handle side effects of status deletion here: + // 1. delete all media associated with status + // 2. delete boosts of status + // 3. etc etc etc + case gtsmodel.ActivityStreamsProfile: + // DELETE A PROFILE/ACCOUNT + // TODO: handle side effects of account deletion here: delete all objects, statuses, media etc associated with account + } } return nil @@ -220,7 +233,7 @@ func (p *processor) dereferenceStatusFields(status *gtsmodel.Status) error { continue } - targetAccount, err = p.tc.ASRepresentationToAccount(accountable) + targetAccount, err = p.tc.ASRepresentationToAccount(accountable, false) if err != nil { l.Debugf("error converting remote account with uri %s into gts model: %s", uri.String(), err) continue @@ -243,7 +256,7 @@ func (p *processor) dereferenceStatusFields(status *gtsmodel.Status) error { return nil } -func (p *processor) dereferenceAccountFields(account *gtsmodel.Account, requestingUsername string) error { +func (p *processor) dereferenceAccountFields(account *gtsmodel.Account, requestingUsername string, refresh bool) error { l := p.log.WithFields(logrus.Fields{ "func": "dereferenceAccountFields", "requestingUsername": requestingUsername, @@ -255,7 +268,7 @@ func (p *processor) dereferenceAccountFields(account *gtsmodel.Account, requesti } // fetch the header and avatar - if err := p.fetchHeaderAndAviForAccount(account, t); err != nil { + if err := p.fetchHeaderAndAviForAccount(account, t, refresh); err != nil { // if this doesn't work, just skip it -- we can do it later l.Debugf("error fetching header/avi for account: %s", err) } diff --git a/internal/message/frprocess.go b/internal/message/frprocess.go index 5d02836e6..41ab285c2 100644 --- a/internal/message/frprocess.go +++ b/internal/message/frprocess.go @@ -68,8 +68,8 @@ func (p *processor) FollowRequestAccept(auth *oauth.Auth, accountID string) (*ap APObjectType: gtsmodel.ActivityStreamsFollow, APActivityType: gtsmodel.ActivityStreamsAccept, GTSModel: follow, - OriginAccount: originAccount, - TargetAccount: targetAccount, + OriginAccount: originAccount, + TargetAccount: targetAccount, } gtsR, err := p.db.GetRelationship(auth.Account.ID, accountID) diff --git a/internal/message/processor.go b/internal/message/processor.go index 54b2ada04..bcd64d47a 100644 --- a/internal/message/processor.go +++ b/internal/message/processor.go @@ -140,6 +140,10 @@ type Processor interface { // authentication before returning a JSON serializable interface to the caller. GetFediFollowers(requestedUsername string, request *http.Request) (interface{}, ErrorWithCode) + // GetFediFollowing handles the getting of a fedi/activitypub representation of a user/account's following, performing appropriate + // authentication before returning a JSON serializable interface to the caller. + GetFediFollowing(requestedUsername string, request *http.Request) (interface{}, ErrorWithCode) + // GetFediStatus handles the getting of a fedi/activitypub representation of a particular status, performing appropriate // authentication before returning a JSON serializable interface to the caller. GetFediStatus(requestedUsername string, requestedStatusID string, request *http.Request) (interface{}, ErrorWithCode) diff --git a/internal/message/processorutil.go b/internal/message/processorutil.go index 67c96abe0..b053f31a2 100644 --- a/internal/message/processorutil.go +++ b/internal/message/processorutil.go @@ -130,8 +130,10 @@ func (p *processor) processReplyToID(form *apimodel.AdvancedStatusCreateForm, th return fmt.Errorf("status with id %s not replyable: %s", form.InReplyToID, err) } - if !repliedStatus.VisibilityAdvanced.Replyable { - return fmt.Errorf("status with id %s is marked as not replyable", form.InReplyToID) + if repliedStatus.VisibilityAdvanced != nil { + if !repliedStatus.VisibilityAdvanced.Replyable { + return fmt.Errorf("status with id %s is marked as not replyable", form.InReplyToID) + } } // check replied account is known to us @@ -329,8 +331,8 @@ func (p *processor) updateAccountHeader(header *multipart.FileHeader, accountID // // SIDE EFFECTS: remote header and avatar will be stored in local storage, and the database will be updated // to reflect the creation of these new attachments. -func (p *processor) fetchHeaderAndAviForAccount(targetAccount *gtsmodel.Account, t transport.Transport) error { - if targetAccount.AvatarRemoteURL != "" && targetAccount.AvatarMediaAttachmentID == "" { +func (p *processor) fetchHeaderAndAviForAccount(targetAccount *gtsmodel.Account, t transport.Transport, refresh bool) error { + if targetAccount.AvatarRemoteURL != "" && (targetAccount.AvatarMediaAttachmentID == "" || refresh) { a, err := p.mediaHandler.ProcessRemoteHeaderOrAvatar(t, >smodel.MediaAttachment{ RemoteURL: targetAccount.AvatarRemoteURL, Avatar: true, @@ -341,7 +343,7 @@ func (p *processor) fetchHeaderAndAviForAccount(targetAccount *gtsmodel.Account, targetAccount.AvatarMediaAttachmentID = a.ID } - if targetAccount.HeaderRemoteURL != "" && targetAccount.HeaderMediaAttachmentID == "" { + if targetAccount.HeaderRemoteURL != "" && (targetAccount.HeaderMediaAttachmentID == "" || refresh) { a, err := p.mediaHandler.ProcessRemoteHeaderOrAvatar(t, >smodel.MediaAttachment{ RemoteURL: targetAccount.HeaderRemoteURL, Header: true, |