some more updates

This commit is contained in:
tsmethurst 2021-08-20 11:59:40 +02:00
commit 58f71fa1a5
27 changed files with 417 additions and 186 deletions

View file

@ -34,16 +34,16 @@ func (p *processor) FollowersGet(requestingAccount *gtsmodel.Account, targetAcco
return nil, gtserror.NewErrorNotFound(fmt.Errorf("block exists between accounts"))
}
followers := []gtsmodel.Follow{}
accounts := []apimodel.Account{}
if err := p.db.GetAccountFollowers(targetAccountID, &followers, false); err != nil {
follows, err := p.db.GetAccountFollowedBy(targetAccountID, false)
if err != nil {
if err == db.ErrNoEntries {
return accounts, nil
}
return nil, gtserror.NewErrorInternalError(err)
}
for _, f := range followers {
for _, f := range follows {
blocked, err := p.db.IsBlocked(requestingAccount.ID, f.AccountID, true)
if err != nil {
return nil, gtserror.NewErrorInternalError(err)
@ -52,15 +52,18 @@ func (p *processor) FollowersGet(requestingAccount *gtsmodel.Account, targetAcco
continue
}
a := &gtsmodel.Account{}
if err := p.db.GetByID(f.AccountID, a); err != nil {
if err == db.ErrNoEntries {
continue
if f.Account == nil {
a, err := p.db.GetAccountByID(f.AccountID)
if err != nil {
if err == db.ErrNoEntries {
continue
}
return nil, gtserror.NewErrorInternalError(err)
}
return nil, gtserror.NewErrorInternalError(err)
f.Account = a
}
account, err := p.tc.AccountToMastoPublic(a)
account, err := p.tc.AccountToMastoPublic(f.Account)
if err != nil {
return nil, gtserror.NewErrorInternalError(err)
}

View file

@ -34,16 +34,16 @@ func (p *processor) FollowingGet(requestingAccount *gtsmodel.Account, targetAcco
return nil, gtserror.NewErrorNotFound(fmt.Errorf("block exists between accounts"))
}
following := []gtsmodel.Follow{}
accounts := []apimodel.Account{}
if err := p.db.GetAccountFollows(targetAccountID, &following); err != nil {
follows, err := p.db.GetAccountFollows(targetAccountID)
if err != nil {
if err == db.ErrNoEntries {
return accounts, nil
}
return nil, gtserror.NewErrorInternalError(err)
}
for _, f := range following {
for _, f := range follows {
blocked, err := p.db.IsBlocked(requestingAccount.ID, f.AccountID, true)
if err != nil {
return nil, gtserror.NewErrorInternalError(err)
@ -52,15 +52,18 @@ func (p *processor) FollowingGet(requestingAccount *gtsmodel.Account, targetAcco
continue
}
a := &gtsmodel.Account{}
if err := p.db.GetByID(f.TargetAccountID, a); err != nil {
if err == db.ErrNoEntries {
continue
if f.TargetAccount == nil {
a, err := p.db.GetAccountByID(f.TargetAccountID)
if err != nil {
if err == db.ErrNoEntries {
continue
}
return nil, gtserror.NewErrorInternalError(err)
}
return nil, gtserror.NewErrorInternalError(err)
f.TargetAccount = a
}
account, err := p.tc.AccountToMastoPublic(a)
account, err := p.tc.AccountToMastoPublic(f.TargetAccount)
if err != nil {
return nil, gtserror.NewErrorInternalError(err)
}

View file

@ -320,23 +320,24 @@ func (p *processor) timelineStatus(status *gtsmodel.Status) error {
}
// get local followers of the account that posted the status
followers := []gtsmodel.Follow{}
if err := p.db.GetAccountFollowers(status.AccountID, &followers, true); err != nil {
follows, err := p.db.GetAccountFollowedBy(status.AccountID, true)
if err != nil {
return fmt.Errorf("timelineStatus: error getting followers for account id %s: %s", status.AccountID, err)
}
// if the poster is local, add a fake entry for them to the followers list so they can see their own status in their timeline
if status.Account.Domain == "" {
followers = append(followers, gtsmodel.Follow{
follows = append(follows, &gtsmodel.Follow{
AccountID: status.AccountID,
Account: status.Account,
})
}
wg := sync.WaitGroup{}
wg.Add(len(followers))
errors := make(chan error, len(followers))
wg.Add(len(follows))
errors := make(chan error, len(follows))
for _, f := range followers {
for _, f := range follows {
go p.timelineStatusForAccount(status, f.AccountID, errors, &wg)
}

View file

@ -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 processing
import (