1
0
Fork 0
mirror of https://codeberg.org/forgejo/forgejo.git synced 2024-11-24 08:57:03 -05:00

separate collecting activities from sending them

This commit is contained in:
Michael Jerger 2024-03-28 16:08:29 +01:00
parent 2ad685fd2c
commit b747342672

View file

@ -244,31 +244,30 @@ func SendLikeActivities(ctx context.Context, doer user.User, repoID int64) error
return err return err
} }
apclient, err := activitypub.NewClient(ctx, &doer, doer.APAPIURL()) likeActivityList := make([]forgefed.ForgeLike, 0)
if err != nil {
return err
}
for _, federatedRepo := range federatedRepos { for _, federatedRepo := range federatedRepos {
target := federatedRepo.Uri target := federatedRepo.Uri
log.Info("Federated Repo URI is: %v", target)
likeActivity, err := forgefed.NewForgeLike(doer.APAPIURL(), target, time.Now()) likeActivity, err := forgefed.NewForgeLike(doer.APAPIURL(), target, time.Now())
if err != nil { if err != nil {
return err return err
} }
log.Info("Like Activity: %v", likeActivity) likeActivityList = append(likeActivityList, likeActivity)
json, err := likeActivity.MarshalJSON() }
apclient, err := activitypub.NewClient(ctx, &doer, doer.APAPIURL())
if err != nil {
return err
}
for _, activity := range likeActivityList {
json, err := activity.MarshalJSON()
if err != nil { if err != nil {
return err return err
} }
// TODO: decouple loading & creating activities from sending them - use two loops. _, err = apclient.Post([]byte(json), fmt.Sprintf("%v/inbox/", activity.Object))
// TODO: set timeouts for outgoing request in oder to mitigate DOS by slow lories if err != nil {
// TODO: Check if we need to respect rate limits log.Error("error %v while sending activity: %q", err, activity)
// ToDo: Change this to the standalone table of FederatedRepos }
log.Info("Like JSON: %v", string(json))
log.Info("Target URI: %v", target)
apclient.Post([]byte(json), fmt.Sprintf("%v/inbox/", target))
} }
return nil return nil