2023-03-12 15:00:57 +00:00
|
|
|
// GoToSocial
|
|
|
|
// Copyright (C) GoToSocial Authors admin@gotosocial.org
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
//
|
|
|
|
// 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/>.
|
|
|
|
|
2021-05-27 15:06:24 +01:00
|
|
|
package federatingdb
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
"net/url"
|
|
|
|
|
2021-11-13 16:29:43 +00:00
|
|
|
"github.com/superseriousbusiness/activity/streams/vocab"
|
2023-09-20 16:49:46 +01:00
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/gtserror"
|
2021-05-27 15:06:24 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
// Followers obtains the Followers Collection for an actor with the
|
|
|
|
// given id.
|
|
|
|
//
|
|
|
|
// If modified, the library will then call Update.
|
|
|
|
//
|
|
|
|
// The library makes this call only after acquiring a lock first.
|
2021-08-25 14:34:33 +01:00
|
|
|
func (f *federatingDB) Followers(ctx context.Context, actorIRI *url.URL) (followers vocab.ActivityStreamsCollection, err error) {
|
2021-10-04 14:24:19 +01:00
|
|
|
acct, err := f.getAccountForIRI(ctx, actorIRI)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2021-05-27 15:06:24 +01:00
|
|
|
}
|
|
|
|
|
2023-09-20 16:49:46 +01:00
|
|
|
// Fetch followers for account from database.
|
2023-09-12 14:00:35 +01:00
|
|
|
follows, err := f.state.DB.GetAccountFollowers(ctx, acct.ID, nil)
|
2021-08-20 11:26:56 +01:00
|
|
|
if err != nil {
|
2021-10-04 14:24:19 +01:00
|
|
|
return nil, fmt.Errorf("Followers: db error getting followers for account id %s: %s", acct.ID, err)
|
2021-05-27 15:06:24 +01:00
|
|
|
}
|
|
|
|
|
2023-09-20 16:49:46 +01:00
|
|
|
// Convert the followers to a slice of account URIs.
|
2023-03-20 18:10:08 +00:00
|
|
|
iris := make([]*url.URL, 0, len(follows))
|
|
|
|
for _, follow := range follows {
|
2021-10-04 14:24:19 +01:00
|
|
|
u, err := url.Parse(follow.Account.URI)
|
2021-05-27 15:06:24 +01:00
|
|
|
if err != nil {
|
2023-09-20 16:49:46 +01:00
|
|
|
return nil, gtserror.Newf("invalid account uri: %v", err)
|
2021-05-27 15:06:24 +01:00
|
|
|
}
|
2021-10-04 14:24:19 +01:00
|
|
|
iris = append(iris, u)
|
2021-05-27 15:06:24 +01:00
|
|
|
}
|
2021-10-04 14:24:19 +01:00
|
|
|
|
|
|
|
return f.collectIRIs(ctx, iris)
|
2021-05-27 15:06:24 +01:00
|
|
|
}
|