summaryrefslogtreecommitdiff
path: root/internal/message/accountprocess.go
diff options
context:
space:
mode:
authorLibravatar Tobi Smethurst <31960611+tsmethurst@users.noreply.github.com>2021-05-17 19:06:58 +0200
committerLibravatar GitHub <noreply@github.com>2021-05-17 19:06:58 +0200
commit6cd033449fd328410128bc3e840f4b8d3d74f052 (patch)
tree9868db8439533e078dea5bb34ae4949e9460f2cb /internal/message/accountprocess.go
parentupdate progress (diff)
downloadgotosocial-6cd033449fd328410128bc3e840f4b8d3d74f052.tar.xz
Refine statuses (#26)
Remote media is now dereferenced and attached properly to incoming federated statuses. Mentions are now dereferenced and attached properly to incoming federated statuses. Small fixes to status visibility. Allow URL params for filtering statuses: // ExcludeRepliesKey is for specifying whether to exclude replies in a list of returned statuses by an account. // PinnedKey is for specifying whether to include pinned statuses in a list of returned statuses by an account. // MaxIDKey is for specifying the maximum ID of the status to retrieve. // MediaOnlyKey is for specifying that only statuses with media should be returned in a list of returned statuses by an account. Add endpoint for fetching an account's statuses.
Diffstat (limited to 'internal/message/accountprocess.go')
-rw-r--r--internal/message/accountprocess.go127
1 files changed, 127 insertions, 0 deletions
diff --git a/internal/message/accountprocess.go b/internal/message/accountprocess.go
index 9433140d7..a10f6d016 100644
--- a/internal/message/accountprocess.go
+++ b/internal/message/accountprocess.go
@@ -1,3 +1,21 @@
+/*
+ GoToSocial
+ Copyright (C) 2021 GoToSocial Authors admin@gotosocial.org
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
package message
import (
@@ -166,3 +184,112 @@ func (p *processor) AccountUpdate(authed *oauth.Auth, form *apimodel.UpdateCrede
}
return acctSensitive, nil
}
+
+func (p *processor) AccountStatusesGet(authed *oauth.Auth, targetAccountID string, limit int, excludeReplies bool, maxID string, pinned bool, mediaOnly bool) ([]apimodel.Status, ErrorWithCode) {
+ targetAccount := &gtsmodel.Account{}
+ if err := p.db.GetByID(targetAccountID, targetAccount); err != nil {
+ if _, ok := err.(db.ErrNoEntries); ok {
+ return nil, NewErrorNotFound(fmt.Errorf("no entry found for account id %s", targetAccountID))
+ }
+ return nil, NewErrorInternalError(err)
+ }
+
+ statuses := []gtsmodel.Status{}
+ apiStatuses := []apimodel.Status{}
+ if err := p.db.GetStatusesByTimeDescending(targetAccountID, &statuses, limit, excludeReplies, maxID, pinned, mediaOnly); err != nil {
+ if _, ok := err.(db.ErrNoEntries); ok {
+ return apiStatuses, nil
+ }
+ return nil, NewErrorInternalError(err)
+ }
+
+ for _, s := range statuses {
+ relevantAccounts, err := p.db.PullRelevantAccountsFromStatus(&s)
+ if err != nil {
+ return nil, NewErrorInternalError(fmt.Errorf("error getting relevant statuses: %s", err))
+ }
+
+ visible, err := p.db.StatusVisible(&s, targetAccount, authed.Account, relevantAccounts)
+ if err != nil {
+ return nil, NewErrorInternalError(fmt.Errorf("error checking status visibility: %s", err))
+ }
+ if !visible {
+ continue
+ }
+
+ var boostedStatus *gtsmodel.Status
+ if s.BoostOfID != "" {
+ bs := &gtsmodel.Status{}
+ if err := p.db.GetByID(s.BoostOfID, bs); err != nil {
+ return nil, NewErrorInternalError(fmt.Errorf("error getting boosted status: %s", err))
+ }
+ boostedRelevantAccounts, err := p.db.PullRelevantAccountsFromStatus(bs)
+ if err != nil {
+ return nil, NewErrorInternalError(fmt.Errorf("error getting relevant accounts from boosted status: %s", err))
+ }
+
+ boostedVisible, err := p.db.StatusVisible(bs, relevantAccounts.BoostedAccount, authed.Account, boostedRelevantAccounts)
+ if err != nil {
+ return nil, NewErrorInternalError(fmt.Errorf("error checking boosted status visibility: %s", err))
+ }
+
+ if boostedVisible {
+ boostedStatus = bs
+ }
+ }
+
+ apiStatus, err := p.tc.StatusToMasto(&s, targetAccount, authed.Account, relevantAccounts.BoostedAccount, relevantAccounts.ReplyToAccount, boostedStatus)
+ if err != nil {
+ return nil, NewErrorInternalError(fmt.Errorf("error converting status to masto: %s", err))
+ }
+
+ apiStatuses = append(apiStatuses, *apiStatus)
+ }
+
+ return apiStatuses, nil
+}
+
+func (p *processor) AccountFollowersGet(authed *oauth.Auth, targetAccountID string) ([]apimodel.Account, ErrorWithCode) {
+ blocked, err := p.db.Blocked(authed.Account.ID, targetAccountID)
+ if err != nil {
+ return nil, NewErrorInternalError(err)
+ }
+
+ if blocked {
+ return nil, NewErrorNotFound(fmt.Errorf("block exists between accounts"))
+ }
+
+ followers := []gtsmodel.Follow{}
+ accounts := []apimodel.Account{}
+ if err := p.db.GetFollowersByAccountID(targetAccountID, &followers); err != nil {
+ if _, ok := err.(db.ErrNoEntries); ok {
+ return accounts, nil
+ }
+ return nil, NewErrorInternalError(err)
+ }
+
+ for _, f := range followers {
+ blocked, err := p.db.Blocked(authed.Account.ID, f.AccountID)
+ if err != nil {
+ return nil, NewErrorInternalError(err)
+ }
+ if blocked {
+ continue
+ }
+
+ a := &gtsmodel.Account{}
+ if err := p.db.GetByID(f.AccountID, a); err != nil {
+ if _, ok := err.(db.ErrNoEntries); ok {
+ continue
+ }
+ return nil, NewErrorInternalError(err)
+ }
+
+ account, err := p.tc.AccountToMastoPublic(a)
+ if err != nil {
+ return nil, NewErrorInternalError(err)
+ }
+ accounts = append(accounts, *account)
+ }
+ return accounts, nil
+}