2021-05-17 17:06:58 +00:00
|
|
|
/*
|
|
|
|
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/>.
|
|
|
|
*/
|
|
|
|
|
2021-05-30 11:12:00 +00:00
|
|
|
package processing
|
2021-05-17 17:06:58 +00:00
|
|
|
|
|
|
|
import (
|
2021-05-21 13:48:26 +00:00
|
|
|
"context"
|
2021-05-17 17:06:58 +00:00
|
|
|
"errors"
|
|
|
|
"fmt"
|
2021-05-21 13:48:26 +00:00
|
|
|
"net/url"
|
2021-05-17 17:06:58 +00:00
|
|
|
|
2021-05-21 13:48:26 +00:00
|
|
|
"github.com/go-fed/activity/streams"
|
2021-08-31 13:59:12 +00:00
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/ap"
|
2021-07-05 11:23:03 +00:00
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/db"
|
2021-05-17 17:06:58 +00:00
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
|
2021-08-31 13:59:12 +00:00
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/messages"
|
2021-05-17 17:06:58 +00:00
|
|
|
)
|
|
|
|
|
2021-09-04 11:29:56 +00:00
|
|
|
func (p *processor) ProcessFromClientAPI(ctx context.Context, clientMsg messages.FromClientAPI) error {
|
2021-05-21 13:48:26 +00:00
|
|
|
switch clientMsg.APActivityType {
|
2021-08-31 13:59:12 +00:00
|
|
|
case ap.ActivityCreate:
|
2021-05-21 13:48:26 +00:00
|
|
|
// CREATE
|
|
|
|
switch clientMsg.APObjectType {
|
2021-08-31 13:59:12 +00:00
|
|
|
case ap.ObjectNote:
|
2021-05-21 13:48:26 +00:00
|
|
|
// CREATE NOTE
|
|
|
|
status, ok := clientMsg.GTSModel.(*gtsmodel.Status)
|
|
|
|
if !ok {
|
|
|
|
return errors.New("note was not parseable as *gtsmodel.Status")
|
|
|
|
}
|
2021-05-17 17:06:58 +00:00
|
|
|
|
2021-08-25 13:34:33 +00:00
|
|
|
if err := p.timelineStatus(ctx, status); err != nil {
|
2021-06-13 16:42:28 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-08-25 13:34:33 +00:00
|
|
|
if err := p.notifyStatus(ctx, status); err != nil {
|
2021-05-21 13:48:26 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-09-09 14:15:25 +00:00
|
|
|
if status.Federated {
|
2021-08-25 13:34:33 +00:00
|
|
|
return p.federateStatus(ctx, status)
|
2021-05-21 13:48:26 +00:00
|
|
|
}
|
2021-08-31 13:59:12 +00:00
|
|
|
case ap.ActivityFollow:
|
2021-05-27 14:06:24 +00:00
|
|
|
// CREATE FOLLOW REQUEST
|
|
|
|
followRequest, ok := clientMsg.GTSModel.(*gtsmodel.FollowRequest)
|
2021-05-21 13:48:26 +00:00
|
|
|
if !ok {
|
2021-05-27 14:06:24 +00:00
|
|
|
return errors.New("followrequest was not parseable as *gtsmodel.FollowRequest")
|
2021-05-21 13:48:26 +00:00
|
|
|
}
|
|
|
|
|
2021-10-01 17:08:50 +00:00
|
|
|
if err := p.notifyFollowRequest(ctx, followRequest); err != nil {
|
2021-05-21 13:48:26 +00:00
|
|
|
return err
|
|
|
|
}
|
2021-05-17 17:06:58 +00:00
|
|
|
|
2021-08-25 13:34:33 +00:00
|
|
|
return p.federateFollow(ctx, followRequest, clientMsg.OriginAccount, clientMsg.TargetAccount)
|
2021-08-31 13:59:12 +00:00
|
|
|
case ap.ActivityLike:
|
2021-05-24 16:49:48 +00:00
|
|
|
// CREATE LIKE/FAVE
|
|
|
|
fave, ok := clientMsg.GTSModel.(*gtsmodel.StatusFave)
|
|
|
|
if !ok {
|
|
|
|
return errors.New("fave was not parseable as *gtsmodel.StatusFave")
|
|
|
|
}
|
|
|
|
|
2021-09-27 15:42:20 +00:00
|
|
|
if err := p.notifyFave(ctx, fave); err != nil {
|
2021-05-24 16:49:48 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-08-25 13:34:33 +00:00
|
|
|
return p.federateFave(ctx, fave, clientMsg.OriginAccount, clientMsg.TargetAccount)
|
2021-08-31 13:59:12 +00:00
|
|
|
case ap.ActivityAnnounce:
|
2021-05-28 17:57:04 +00:00
|
|
|
// CREATE BOOST/ANNOUNCE
|
|
|
|
boostWrapperStatus, ok := clientMsg.GTSModel.(*gtsmodel.Status)
|
|
|
|
if !ok {
|
|
|
|
return errors.New("boost was not parseable as *gtsmodel.Status")
|
|
|
|
}
|
|
|
|
|
2021-08-25 13:34:33 +00:00
|
|
|
if err := p.timelineStatus(ctx, boostWrapperStatus); err != nil {
|
2021-06-17 16:02:33 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-08-25 13:34:33 +00:00
|
|
|
if err := p.notifyAnnounce(ctx, boostWrapperStatus); err != nil {
|
2021-05-28 17:57:04 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-08-25 13:34:33 +00:00
|
|
|
return p.federateAnnounce(ctx, boostWrapperStatus, clientMsg.OriginAccount, clientMsg.TargetAccount)
|
2021-08-31 13:59:12 +00:00
|
|
|
case ap.ActivityBlock:
|
2021-07-11 14:22:21 +00:00
|
|
|
// CREATE BLOCK
|
|
|
|
block, ok := clientMsg.GTSModel.(*gtsmodel.Block)
|
|
|
|
if !ok {
|
|
|
|
return errors.New("block was not parseable as *gtsmodel.Block")
|
|
|
|
}
|
|
|
|
|
|
|
|
// remove any of the blocking account's statuses from the blocked account's timeline, and vice versa
|
2021-08-25 13:34:33 +00:00
|
|
|
if err := p.timelineManager.WipeStatusesFromAccountID(ctx, block.AccountID, block.TargetAccountID); err != nil {
|
2021-07-11 14:22:21 +00:00
|
|
|
return err
|
|
|
|
}
|
2021-08-25 13:34:33 +00:00
|
|
|
if err := p.timelineManager.WipeStatusesFromAccountID(ctx, block.TargetAccountID, block.AccountID); err != nil {
|
2021-07-11 14:22:21 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: same with notifications
|
|
|
|
// TODO: same with bookmarks
|
|
|
|
|
2021-08-25 13:34:33 +00:00
|
|
|
return p.federateBlock(ctx, block)
|
2021-05-21 13:48:26 +00:00
|
|
|
}
|
2021-08-31 13:59:12 +00:00
|
|
|
case ap.ActivityUpdate:
|
2021-05-21 13:48:26 +00:00
|
|
|
// UPDATE
|
2021-05-28 20:47:18 +00:00
|
|
|
switch clientMsg.APObjectType {
|
2021-08-31 13:59:12 +00:00
|
|
|
case ap.ObjectProfile, ap.ActorPerson:
|
2021-05-28 20:47:18 +00:00
|
|
|
// UPDATE ACCOUNT/PROFILE
|
|
|
|
account, ok := clientMsg.GTSModel.(*gtsmodel.Account)
|
|
|
|
if !ok {
|
|
|
|
return errors.New("account was not parseable as *gtsmodel.Account")
|
|
|
|
}
|
|
|
|
|
2021-08-25 13:34:33 +00:00
|
|
|
return p.federateAccountUpdate(ctx, account, clientMsg.OriginAccount)
|
2021-05-28 20:47:18 +00:00
|
|
|
}
|
2021-08-31 13:59:12 +00:00
|
|
|
case ap.ActivityAccept:
|
2021-05-21 13:48:26 +00:00
|
|
|
// ACCEPT
|
|
|
|
switch clientMsg.APObjectType {
|
2021-08-31 13:59:12 +00:00
|
|
|
case ap.ActivityFollow:
|
2021-05-21 13:48:26 +00:00
|
|
|
// ACCEPT FOLLOW
|
|
|
|
follow, ok := clientMsg.GTSModel.(*gtsmodel.Follow)
|
|
|
|
if !ok {
|
|
|
|
return errors.New("accept was not parseable as *gtsmodel.Follow")
|
|
|
|
}
|
2021-05-27 14:06:24 +00:00
|
|
|
|
2021-08-25 13:34:33 +00:00
|
|
|
if err := p.notifyFollow(ctx, follow, clientMsg.TargetAccount); err != nil {
|
2021-05-27 14:06:24 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-10-16 11:27:43 +00:00
|
|
|
return p.federateAcceptFollowRequest(ctx, follow)
|
|
|
|
}
|
|
|
|
case ap.ActivityReject:
|
|
|
|
// REJECT
|
|
|
|
switch clientMsg.APObjectType {
|
|
|
|
case ap.ActivityFollow:
|
|
|
|
// REJECT FOLLOW (request)
|
|
|
|
followRequest, ok := clientMsg.GTSModel.(*gtsmodel.FollowRequest)
|
|
|
|
if !ok {
|
|
|
|
return errors.New("reject was not parseable as *gtsmodel.FollowRequest")
|
|
|
|
}
|
|
|
|
|
|
|
|
return p.federateRejectFollowRequest(ctx, followRequest)
|
2021-05-21 13:48:26 +00:00
|
|
|
}
|
2021-08-31 13:59:12 +00:00
|
|
|
case ap.ActivityUndo:
|
2021-05-21 13:48:26 +00:00
|
|
|
// UNDO
|
|
|
|
switch clientMsg.APObjectType {
|
2021-08-31 13:59:12 +00:00
|
|
|
case ap.ActivityFollow:
|
2021-05-21 13:48:26 +00:00
|
|
|
// UNDO FOLLOW
|
|
|
|
follow, ok := clientMsg.GTSModel.(*gtsmodel.Follow)
|
|
|
|
if !ok {
|
|
|
|
return errors.New("undo was not parseable as *gtsmodel.Follow")
|
|
|
|
}
|
2021-08-25 13:34:33 +00:00
|
|
|
return p.federateUnfollow(ctx, follow, clientMsg.OriginAccount, clientMsg.TargetAccount)
|
2021-08-31 13:59:12 +00:00
|
|
|
case ap.ActivityBlock:
|
2021-07-11 14:22:21 +00:00
|
|
|
// UNDO BLOCK
|
|
|
|
block, ok := clientMsg.GTSModel.(*gtsmodel.Block)
|
|
|
|
if !ok {
|
|
|
|
return errors.New("undo was not parseable as *gtsmodel.Block")
|
|
|
|
}
|
2021-08-25 13:34:33 +00:00
|
|
|
return p.federateUnblock(ctx, block)
|
2021-08-31 13:59:12 +00:00
|
|
|
case ap.ActivityLike:
|
2021-06-13 16:42:28 +00:00
|
|
|
// UNDO LIKE/FAVE
|
|
|
|
fave, ok := clientMsg.GTSModel.(*gtsmodel.StatusFave)
|
|
|
|
if !ok {
|
|
|
|
return errors.New("undo was not parseable as *gtsmodel.StatusFave")
|
|
|
|
}
|
2021-08-25 13:34:33 +00:00
|
|
|
return p.federateUnfave(ctx, fave, clientMsg.OriginAccount, clientMsg.TargetAccount)
|
2021-08-31 13:59:12 +00:00
|
|
|
case ap.ActivityAnnounce:
|
2021-06-21 13:56:00 +00:00
|
|
|
// UNDO ANNOUNCE/BOOST
|
|
|
|
boost, ok := clientMsg.GTSModel.(*gtsmodel.Status)
|
|
|
|
if !ok {
|
|
|
|
return errors.New("undo was not parseable as *gtsmodel.Status")
|
|
|
|
}
|
|
|
|
|
2021-08-25 13:34:33 +00:00
|
|
|
if err := p.deleteStatusFromTimelines(ctx, boost); err != nil {
|
2021-06-21 13:56:00 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-08-25 13:34:33 +00:00
|
|
|
return p.federateUnannounce(ctx, boost, clientMsg.OriginAccount, clientMsg.TargetAccount)
|
2021-06-13 16:42:28 +00:00
|
|
|
}
|
2021-08-31 13:59:12 +00:00
|
|
|
case ap.ActivityDelete:
|
2021-06-13 16:42:28 +00:00
|
|
|
// DELETE
|
|
|
|
switch clientMsg.APObjectType {
|
2021-08-31 13:59:12 +00:00
|
|
|
case ap.ObjectNote:
|
2021-06-13 16:42:28 +00:00
|
|
|
// DELETE STATUS/NOTE
|
|
|
|
statusToDelete, ok := clientMsg.GTSModel.(*gtsmodel.Status)
|
|
|
|
if !ok {
|
|
|
|
return errors.New("note was not parseable as *gtsmodel.Status")
|
|
|
|
}
|
|
|
|
|
2021-08-20 10:26:56 +00:00
|
|
|
if statusToDelete.Account == nil {
|
|
|
|
statusToDelete.Account = clientMsg.OriginAccount
|
2021-07-05 11:23:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// delete all attachments for this status
|
2021-08-20 10:26:56 +00:00
|
|
|
for _, a := range statusToDelete.AttachmentIDs {
|
2021-08-25 13:34:33 +00:00
|
|
|
if err := p.mediaProcessor.Delete(ctx, a); err != nil {
|
2021-07-05 11:23:03 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// delete all mentions for this status
|
2021-08-20 10:26:56 +00:00
|
|
|
for _, m := range statusToDelete.MentionIDs {
|
2021-08-25 13:34:33 +00:00
|
|
|
if err := p.db.DeleteByID(ctx, m, >smodel.Mention{}); err != nil {
|
2021-07-05 11:23:03 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// delete all notifications for this status
|
2021-08-25 13:34:33 +00:00
|
|
|
if err := p.db.DeleteWhere(ctx, []db.Where{{Key: "status_id", Value: statusToDelete.ID}}, &[]*gtsmodel.Notification{}); err != nil {
|
2021-07-05 11:23:03 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// delete this status from any and all timelines
|
2021-08-25 13:34:33 +00:00
|
|
|
if err := p.deleteStatusFromTimelines(ctx, statusToDelete); err != nil {
|
2021-06-13 16:42:28 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-08-25 13:34:33 +00:00
|
|
|
return p.federateStatusDelete(ctx, statusToDelete)
|
2021-08-31 13:59:12 +00:00
|
|
|
case ap.ObjectProfile, ap.ActorPerson:
|
2021-07-05 11:23:03 +00:00
|
|
|
// DELETE ACCOUNT/PROFILE
|
|
|
|
|
2021-07-06 11:29:11 +00:00
|
|
|
// the origin of the delete could be either a domain block, or an action by another (or this) account
|
|
|
|
var origin string
|
|
|
|
if domainBlock, ok := clientMsg.GTSModel.(*gtsmodel.DomainBlock); ok {
|
|
|
|
// origin is a domain block
|
|
|
|
origin = domainBlock.ID
|
|
|
|
} else {
|
|
|
|
// origin is whichever account caused this message
|
|
|
|
origin = clientMsg.OriginAccount.ID
|
2021-07-05 11:23:03 +00:00
|
|
|
}
|
2021-08-25 13:34:33 +00:00
|
|
|
return p.accountProcessor.Delete(ctx, clientMsg.TargetAccount, origin)
|
2021-05-17 17:06:58 +00:00
|
|
|
}
|
|
|
|
}
|
2021-05-21 13:48:26 +00:00
|
|
|
return nil
|
2021-05-17 17:06:58 +00:00
|
|
|
}
|
|
|
|
|
2021-07-05 11:23:03 +00:00
|
|
|
// TODO: move all the below functions into federation.Federator
|
|
|
|
|
2021-08-25 13:34:33 +00:00
|
|
|
func (p *processor) federateStatus(ctx context.Context, status *gtsmodel.Status) error {
|
2021-08-20 10:26:56 +00:00
|
|
|
if status.Account == nil {
|
2021-08-25 13:34:33 +00:00
|
|
|
statusAccount, err := p.db.GetAccountByID(ctx, status.AccountID)
|
|
|
|
if err != nil {
|
2021-07-05 11:23:03 +00:00
|
|
|
return fmt.Errorf("federateStatus: error fetching status author account: %s", err)
|
|
|
|
}
|
2021-08-25 13:34:33 +00:00
|
|
|
status.Account = statusAccount
|
2021-07-05 11:23:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// do nothing if this isn't our status
|
2021-08-20 10:26:56 +00:00
|
|
|
if status.Account.Domain != "" {
|
2021-07-05 11:23:03 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-08-25 13:34:33 +00:00
|
|
|
asStatus, err := p.tc.StatusToAS(ctx, status)
|
2021-05-21 13:48:26 +00:00
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("federateStatus: error converting status to as format: %s", err)
|
|
|
|
}
|
|
|
|
|
2021-08-20 10:26:56 +00:00
|
|
|
outboxIRI, err := url.Parse(status.Account.OutboxURI)
|
2021-05-21 13:48:26 +00:00
|
|
|
if err != nil {
|
2021-08-20 10:26:56 +00:00
|
|
|
return fmt.Errorf("federateStatus: error parsing outboxURI %s: %s", status.Account.OutboxURI, err)
|
2021-05-21 13:48:26 +00:00
|
|
|
}
|
|
|
|
|
2021-08-25 13:34:33 +00:00
|
|
|
_, err = p.federator.FederatingActor().Send(ctx, outboxIRI, asStatus)
|
2021-05-21 13:48:26 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-08-25 13:34:33 +00:00
|
|
|
func (p *processor) federateStatusDelete(ctx context.Context, status *gtsmodel.Status) error {
|
2021-08-20 10:26:56 +00:00
|
|
|
if status.Account == nil {
|
2021-08-25 13:34:33 +00:00
|
|
|
statusAccount, err := p.db.GetAccountByID(ctx, status.AccountID)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("federateStatusDelete: error fetching status author account: %s", err)
|
2021-07-05 11:23:03 +00:00
|
|
|
}
|
2021-08-25 13:34:33 +00:00
|
|
|
status.Account = statusAccount
|
2021-07-05 11:23:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// do nothing if this isn't our status
|
2021-08-20 10:26:56 +00:00
|
|
|
if status.Account.Domain != "" {
|
2021-07-05 11:23:03 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-08-25 13:34:33 +00:00
|
|
|
asStatus, err := p.tc.StatusToAS(ctx, status)
|
2021-06-13 16:42:28 +00:00
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("federateStatusDelete: error converting status to as format: %s", err)
|
|
|
|
}
|
|
|
|
|
2021-08-20 10:26:56 +00:00
|
|
|
outboxIRI, err := url.Parse(status.Account.OutboxURI)
|
2021-06-13 16:42:28 +00:00
|
|
|
if err != nil {
|
2021-08-20 10:26:56 +00:00
|
|
|
return fmt.Errorf("federateStatusDelete: error parsing outboxURI %s: %s", status.Account.OutboxURI, err)
|
2021-06-13 16:42:28 +00:00
|
|
|
}
|
|
|
|
|
2021-08-20 10:26:56 +00:00
|
|
|
actorIRI, err := url.Parse(status.Account.URI)
|
2021-06-13 16:42:28 +00:00
|
|
|
if err != nil {
|
2021-08-20 10:26:56 +00:00
|
|
|
return fmt.Errorf("federateStatusDelete: error parsing actorIRI %s: %s", status.Account.URI, err)
|
2021-06-13 16:42:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// create a delete and set the appropriate actor on it
|
|
|
|
delete := streams.NewActivityStreamsDelete()
|
|
|
|
|
|
|
|
// set the actor for the delete
|
|
|
|
deleteActor := streams.NewActivityStreamsActorProperty()
|
|
|
|
deleteActor.AppendIRI(actorIRI)
|
|
|
|
delete.SetActivityStreamsActor(deleteActor)
|
|
|
|
|
|
|
|
// Set the status as the 'object' property.
|
|
|
|
deleteObject := streams.NewActivityStreamsObjectProperty()
|
|
|
|
deleteObject.AppendActivityStreamsNote(asStatus)
|
|
|
|
delete.SetActivityStreamsObject(deleteObject)
|
|
|
|
|
|
|
|
// set the to and cc as the original to/cc of the original status
|
|
|
|
delete.SetActivityStreamsTo(asStatus.GetActivityStreamsTo())
|
|
|
|
delete.SetActivityStreamsCc(asStatus.GetActivityStreamsCc())
|
|
|
|
|
2021-08-25 13:34:33 +00:00
|
|
|
_, err = p.federator.FederatingActor().Send(ctx, outboxIRI, delete)
|
2021-06-13 16:42:28 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-08-25 13:34:33 +00:00
|
|
|
func (p *processor) federateFollow(ctx context.Context, followRequest *gtsmodel.FollowRequest, originAccount *gtsmodel.Account, targetAccount *gtsmodel.Account) error {
|
2021-05-21 13:48:26 +00:00
|
|
|
// if both accounts are local there's nothing to do here
|
|
|
|
if originAccount.Domain == "" && targetAccount.Domain == "" {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-08-25 13:34:33 +00:00
|
|
|
follow := p.tc.FollowRequestToFollow(ctx, followRequest)
|
2021-05-27 14:06:24 +00:00
|
|
|
|
2021-08-25 13:34:33 +00:00
|
|
|
asFollow, err := p.tc.FollowToAS(ctx, follow, originAccount, targetAccount)
|
2021-05-21 13:48:26 +00:00
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("federateFollow: error converting follow to as format: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
outboxIRI, err := url.Parse(originAccount.OutboxURI)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("federateFollow: error parsing outboxURI %s: %s", originAccount.OutboxURI, err)
|
|
|
|
}
|
|
|
|
|
2021-08-25 13:34:33 +00:00
|
|
|
_, err = p.federator.FederatingActor().Send(ctx, outboxIRI, asFollow)
|
2021-05-21 13:48:26 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-08-25 13:34:33 +00:00
|
|
|
func (p *processor) federateUnfollow(ctx context.Context, follow *gtsmodel.Follow, originAccount *gtsmodel.Account, targetAccount *gtsmodel.Account) error {
|
2021-05-21 13:48:26 +00:00
|
|
|
// if both accounts are local there's nothing to do here
|
|
|
|
if originAccount.Domain == "" && targetAccount.Domain == "" {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// recreate the follow
|
2021-08-25 13:34:33 +00:00
|
|
|
asFollow, err := p.tc.FollowToAS(ctx, follow, originAccount, targetAccount)
|
2021-05-21 13:48:26 +00:00
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("federateUnfollow: error converting follow to as format: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
targetAccountURI, err := url.Parse(targetAccount.URI)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("error parsing uri %s: %s", targetAccount.URI, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// create an Undo and set the appropriate actor on it
|
|
|
|
undo := streams.NewActivityStreamsUndo()
|
|
|
|
undo.SetActivityStreamsActor(asFollow.GetActivityStreamsActor())
|
|
|
|
|
|
|
|
// Set the recreated follow as the 'object' property.
|
|
|
|
undoObject := streams.NewActivityStreamsObjectProperty()
|
|
|
|
undoObject.AppendActivityStreamsFollow(asFollow)
|
|
|
|
undo.SetActivityStreamsObject(undoObject)
|
|
|
|
|
|
|
|
// Set the To of the undo as the target of the recreated follow
|
|
|
|
undoTo := streams.NewActivityStreamsToProperty()
|
|
|
|
undoTo.AppendIRI(targetAccountURI)
|
|
|
|
undo.SetActivityStreamsTo(undoTo)
|
|
|
|
|
|
|
|
outboxIRI, err := url.Parse(originAccount.OutboxURI)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("federateUnfollow: error parsing outboxURI %s: %s", originAccount.OutboxURI, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// send off the Undo
|
2021-08-25 13:34:33 +00:00
|
|
|
_, err = p.federator.FederatingActor().Send(ctx, outboxIRI, undo)
|
2021-05-21 13:48:26 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-08-25 13:34:33 +00:00
|
|
|
func (p *processor) federateUnfave(ctx context.Context, fave *gtsmodel.StatusFave, originAccount *gtsmodel.Account, targetAccount *gtsmodel.Account) error {
|
2021-06-13 16:42:28 +00:00
|
|
|
// if both accounts are local there's nothing to do here
|
|
|
|
if originAccount.Domain == "" && targetAccount.Domain == "" {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// create the AS fave
|
2021-08-25 13:34:33 +00:00
|
|
|
asFave, err := p.tc.FaveToAS(ctx, fave)
|
2021-06-13 16:42:28 +00:00
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("federateFave: error converting fave to as format: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
targetAccountURI, err := url.Parse(targetAccount.URI)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("error parsing uri %s: %s", targetAccount.URI, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// create an Undo and set the appropriate actor on it
|
|
|
|
undo := streams.NewActivityStreamsUndo()
|
|
|
|
undo.SetActivityStreamsActor(asFave.GetActivityStreamsActor())
|
|
|
|
|
|
|
|
// Set the fave as the 'object' property.
|
|
|
|
undoObject := streams.NewActivityStreamsObjectProperty()
|
|
|
|
undoObject.AppendActivityStreamsLike(asFave)
|
|
|
|
undo.SetActivityStreamsObject(undoObject)
|
|
|
|
|
|
|
|
// Set the To of the undo as the target of the fave
|
|
|
|
undoTo := streams.NewActivityStreamsToProperty()
|
|
|
|
undoTo.AppendIRI(targetAccountURI)
|
|
|
|
undo.SetActivityStreamsTo(undoTo)
|
|
|
|
|
|
|
|
outboxIRI, err := url.Parse(originAccount.OutboxURI)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("federateFave: error parsing outboxURI %s: %s", originAccount.OutboxURI, err)
|
|
|
|
}
|
2021-08-25 13:34:33 +00:00
|
|
|
_, err = p.federator.FederatingActor().Send(ctx, outboxIRI, undo)
|
2021-06-13 16:42:28 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-08-25 13:34:33 +00:00
|
|
|
func (p *processor) federateUnannounce(ctx context.Context, boost *gtsmodel.Status, originAccount *gtsmodel.Account, targetAccount *gtsmodel.Account) error {
|
2021-07-05 11:23:03 +00:00
|
|
|
if originAccount.Domain != "" {
|
|
|
|
// nothing to do here
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-08-25 13:34:33 +00:00
|
|
|
asAnnounce, err := p.tc.BoostToAS(ctx, boost, originAccount, targetAccount)
|
2021-06-21 13:56:00 +00:00
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("federateUnannounce: error converting status to announce: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// create an Undo and set the appropriate actor on it
|
|
|
|
undo := streams.NewActivityStreamsUndo()
|
|
|
|
undo.SetActivityStreamsActor(asAnnounce.GetActivityStreamsActor())
|
|
|
|
|
|
|
|
// Set the boost as the 'object' property.
|
|
|
|
undoObject := streams.NewActivityStreamsObjectProperty()
|
|
|
|
undoObject.AppendActivityStreamsAnnounce(asAnnounce)
|
|
|
|
undo.SetActivityStreamsObject(undoObject)
|
|
|
|
|
|
|
|
// set the to
|
|
|
|
undo.SetActivityStreamsTo(asAnnounce.GetActivityStreamsTo())
|
|
|
|
|
|
|
|
// set the cc
|
|
|
|
undo.SetActivityStreamsCc(asAnnounce.GetActivityStreamsCc())
|
|
|
|
|
|
|
|
outboxIRI, err := url.Parse(originAccount.OutboxURI)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("federateUnannounce: error parsing outboxURI %s: %s", originAccount.OutboxURI, err)
|
|
|
|
}
|
|
|
|
|
2021-08-25 13:34:33 +00:00
|
|
|
_, err = p.federator.FederatingActor().Send(ctx, outboxIRI, undo)
|
2021-06-21 13:56:00 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-10-16 11:27:43 +00:00
|
|
|
func (p *processor) federateAcceptFollowRequest(ctx context.Context, follow *gtsmodel.Follow) error {
|
|
|
|
if follow.Account == nil {
|
|
|
|
a, err := p.db.GetAccountByID(ctx, follow.AccountID)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
follow.Account = a
|
|
|
|
}
|
|
|
|
originAccount := follow.Account
|
|
|
|
|
|
|
|
if follow.TargetAccount == nil {
|
|
|
|
a, err := p.db.GetAccountByID(ctx, follow.TargetAccountID)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
follow.TargetAccount = a
|
|
|
|
}
|
|
|
|
targetAccount := follow.TargetAccount
|
|
|
|
|
|
|
|
// if target account isn't from our domain we shouldn't do anything
|
|
|
|
if targetAccount.Domain != "" {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-05-21 13:48:26 +00:00
|
|
|
// if both accounts are local there's nothing to do here
|
|
|
|
if originAccount.Domain == "" && targetAccount.Domain == "" {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// recreate the AS follow
|
2021-08-25 13:34:33 +00:00
|
|
|
asFollow, err := p.tc.FollowToAS(ctx, follow, originAccount, targetAccount)
|
2021-05-21 13:48:26 +00:00
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("federateUnfollow: error converting follow to as format: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
acceptingAccountURI, err := url.Parse(targetAccount.URI)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("error parsing uri %s: %s", targetAccount.URI, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
requestingAccountURI, err := url.Parse(originAccount.URI)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("error parsing uri %s: %s", targetAccount.URI, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// create an Accept
|
|
|
|
accept := streams.NewActivityStreamsAccept()
|
|
|
|
|
|
|
|
// set the accepting actor on it
|
|
|
|
acceptActorProp := streams.NewActivityStreamsActorProperty()
|
|
|
|
acceptActorProp.AppendIRI(acceptingAccountURI)
|
|
|
|
accept.SetActivityStreamsActor(acceptActorProp)
|
|
|
|
|
|
|
|
// Set the recreated follow as the 'object' property.
|
|
|
|
acceptObject := streams.NewActivityStreamsObjectProperty()
|
|
|
|
acceptObject.AppendActivityStreamsFollow(asFollow)
|
|
|
|
accept.SetActivityStreamsObject(acceptObject)
|
|
|
|
|
|
|
|
// Set the To of the accept as the originator of the follow
|
|
|
|
acceptTo := streams.NewActivityStreamsToProperty()
|
|
|
|
acceptTo.AppendIRI(requestingAccountURI)
|
|
|
|
accept.SetActivityStreamsTo(acceptTo)
|
|
|
|
|
|
|
|
outboxIRI, err := url.Parse(targetAccount.OutboxURI)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("federateAcceptFollowRequest: error parsing outboxURI %s: %s", originAccount.OutboxURI, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// send off the accept using the accepter's outbox
|
2021-08-25 13:34:33 +00:00
|
|
|
_, err = p.federator.FederatingActor().Send(ctx, outboxIRI, accept)
|
2021-05-21 13:48:26 +00:00
|
|
|
return err
|
2021-10-16 11:27:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (p *processor) federateRejectFollowRequest(ctx context.Context, followRequest *gtsmodel.FollowRequest) error {
|
|
|
|
if followRequest.Account == nil {
|
|
|
|
a, err := p.db.GetAccountByID(ctx, followRequest.AccountID)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
followRequest.Account = a
|
|
|
|
}
|
|
|
|
originAccount := followRequest.Account
|
|
|
|
|
|
|
|
if followRequest.TargetAccount == nil {
|
|
|
|
a, err := p.db.GetAccountByID(ctx, followRequest.TargetAccountID)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
followRequest.TargetAccount = a
|
|
|
|
}
|
|
|
|
targetAccount := followRequest.TargetAccount
|
|
|
|
|
|
|
|
// if target account isn't from our domain we shouldn't do anything
|
|
|
|
if targetAccount.Domain != "" {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// if both accounts are local there's nothing to do here
|
|
|
|
if originAccount.Domain == "" && targetAccount.Domain == "" {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// recreate the AS follow
|
|
|
|
follow := p.tc.FollowRequestToFollow(ctx, followRequest)
|
|
|
|
asFollow, err := p.tc.FollowToAS(ctx, follow, originAccount, targetAccount)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("federateUnfollow: error converting follow to as format: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
rejectingAccountURI, err := url.Parse(targetAccount.URI)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("error parsing uri %s: %s", targetAccount.URI, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
requestingAccountURI, err := url.Parse(originAccount.URI)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("error parsing uri %s: %s", targetAccount.URI, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// create a Reject
|
|
|
|
reject := streams.NewActivityStreamsReject()
|
|
|
|
|
|
|
|
// set the rejecting actor on it
|
|
|
|
acceptActorProp := streams.NewActivityStreamsActorProperty()
|
|
|
|
acceptActorProp.AppendIRI(rejectingAccountURI)
|
|
|
|
reject.SetActivityStreamsActor(acceptActorProp)
|
|
|
|
|
|
|
|
// Set the recreated follow as the 'object' property.
|
|
|
|
acceptObject := streams.NewActivityStreamsObjectProperty()
|
|
|
|
acceptObject.AppendActivityStreamsFollow(asFollow)
|
|
|
|
reject.SetActivityStreamsObject(acceptObject)
|
|
|
|
|
|
|
|
// Set the To of the reject as the originator of the follow
|
|
|
|
acceptTo := streams.NewActivityStreamsToProperty()
|
|
|
|
acceptTo.AppendIRI(requestingAccountURI)
|
|
|
|
reject.SetActivityStreamsTo(acceptTo)
|
|
|
|
|
|
|
|
outboxIRI, err := url.Parse(targetAccount.OutboxURI)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("federateRejectFollowRequest: error parsing outboxURI %s: %s", originAccount.OutboxURI, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// send off the reject using the rejecting account's outbox
|
|
|
|
_, err = p.federator.FederatingActor().Send(ctx, outboxIRI, reject)
|
|
|
|
return err
|
2021-05-17 17:06:58 +00:00
|
|
|
}
|
2021-05-24 16:49:48 +00:00
|
|
|
|
2021-08-25 13:34:33 +00:00
|
|
|
func (p *processor) federateFave(ctx context.Context, fave *gtsmodel.StatusFave, originAccount *gtsmodel.Account, targetAccount *gtsmodel.Account) error {
|
2021-05-24 16:49:48 +00:00
|
|
|
// if both accounts are local there's nothing to do here
|
|
|
|
if originAccount.Domain == "" && targetAccount.Domain == "" {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// create the AS fave
|
2021-08-25 13:34:33 +00:00
|
|
|
asFave, err := p.tc.FaveToAS(ctx, fave)
|
2021-05-24 16:49:48 +00:00
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("federateFave: error converting fave to as format: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
outboxIRI, err := url.Parse(originAccount.OutboxURI)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("federateFave: error parsing outboxURI %s: %s", originAccount.OutboxURI, err)
|
|
|
|
}
|
2021-08-25 13:34:33 +00:00
|
|
|
_, err = p.federator.FederatingActor().Send(ctx, outboxIRI, asFave)
|
2021-05-24 16:49:48 +00:00
|
|
|
return err
|
|
|
|
}
|
2021-05-28 17:57:04 +00:00
|
|
|
|
2021-08-25 13:34:33 +00:00
|
|
|
func (p *processor) federateAnnounce(ctx context.Context, boostWrapperStatus *gtsmodel.Status, boostingAccount *gtsmodel.Account, boostedAccount *gtsmodel.Account) error {
|
|
|
|
announce, err := p.tc.BoostToAS(ctx, boostWrapperStatus, boostingAccount, boostedAccount)
|
2021-05-28 17:57:04 +00:00
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("federateAnnounce: error converting status to announce: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
outboxIRI, err := url.Parse(boostingAccount.OutboxURI)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("federateAnnounce: error parsing outboxURI %s: %s", boostingAccount.OutboxURI, err)
|
|
|
|
}
|
2021-05-28 20:47:18 +00:00
|
|
|
|
2021-08-25 13:34:33 +00:00
|
|
|
_, err = p.federator.FederatingActor().Send(ctx, outboxIRI, announce)
|
2021-05-28 17:57:04 +00:00
|
|
|
return err
|
|
|
|
}
|
2021-05-28 20:47:18 +00:00
|
|
|
|
2021-08-25 13:34:33 +00:00
|
|
|
func (p *processor) federateAccountUpdate(ctx context.Context, updatedAccount *gtsmodel.Account, originAccount *gtsmodel.Account) error {
|
|
|
|
person, err := p.tc.AccountToAS(ctx, updatedAccount)
|
2021-05-28 20:47:18 +00:00
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("federateAccountUpdate: error converting account to person: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
update, err := p.tc.WrapPersonInUpdate(person, originAccount)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("federateAccountUpdate: error wrapping person in update: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
outboxIRI, err := url.Parse(originAccount.OutboxURI)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("federateAnnounce: error parsing outboxURI %s: %s", originAccount.OutboxURI, err)
|
|
|
|
}
|
|
|
|
|
2021-08-25 13:34:33 +00:00
|
|
|
_, err = p.federator.FederatingActor().Send(ctx, outboxIRI, update)
|
2021-05-28 20:47:18 +00:00
|
|
|
return err
|
|
|
|
}
|
2021-07-11 14:22:21 +00:00
|
|
|
|
2021-08-25 13:34:33 +00:00
|
|
|
func (p *processor) federateBlock(ctx context.Context, block *gtsmodel.Block) error {
|
2021-07-11 14:22:21 +00:00
|
|
|
if block.Account == nil {
|
2021-08-25 13:34:33 +00:00
|
|
|
blockAccount, err := p.db.GetAccountByID(ctx, block.AccountID)
|
|
|
|
if err != nil {
|
2021-07-11 14:22:21 +00:00
|
|
|
return fmt.Errorf("federateBlock: error getting block account from database: %s", err)
|
|
|
|
}
|
2021-08-25 13:34:33 +00:00
|
|
|
block.Account = blockAccount
|
2021-07-11 14:22:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if block.TargetAccount == nil {
|
2021-08-25 13:34:33 +00:00
|
|
|
blockTargetAccount, err := p.db.GetAccountByID(ctx, block.TargetAccountID)
|
|
|
|
if err != nil {
|
2021-07-11 14:22:21 +00:00
|
|
|
return fmt.Errorf("federateBlock: error getting block target account from database: %s", err)
|
|
|
|
}
|
2021-08-25 13:34:33 +00:00
|
|
|
block.TargetAccount = blockTargetAccount
|
2021-07-11 14:22:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// if both accounts are local there's nothing to do here
|
|
|
|
if block.Account.Domain == "" && block.TargetAccount.Domain == "" {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-08-25 13:34:33 +00:00
|
|
|
asBlock, err := p.tc.BlockToAS(ctx, block)
|
2021-07-11 14:22:21 +00:00
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("federateBlock: error converting block to AS format: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
outboxIRI, err := url.Parse(block.Account.OutboxURI)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("federateBlock: error parsing outboxURI %s: %s", block.Account.OutboxURI, err)
|
|
|
|
}
|
|
|
|
|
2021-08-25 13:34:33 +00:00
|
|
|
_, err = p.federator.FederatingActor().Send(ctx, outboxIRI, asBlock)
|
2021-07-11 14:22:21 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-08-25 13:34:33 +00:00
|
|
|
func (p *processor) federateUnblock(ctx context.Context, block *gtsmodel.Block) error {
|
2021-07-11 14:22:21 +00:00
|
|
|
if block.Account == nil {
|
2021-08-25 13:34:33 +00:00
|
|
|
blockAccount, err := p.db.GetAccountByID(ctx, block.AccountID)
|
|
|
|
if err != nil {
|
2021-07-11 14:22:21 +00:00
|
|
|
return fmt.Errorf("federateUnblock: error getting block account from database: %s", err)
|
|
|
|
}
|
2021-08-25 13:34:33 +00:00
|
|
|
block.Account = blockAccount
|
2021-07-11 14:22:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if block.TargetAccount == nil {
|
2021-08-25 13:34:33 +00:00
|
|
|
blockTargetAccount, err := p.db.GetAccountByID(ctx, block.TargetAccountID)
|
|
|
|
if err != nil {
|
2021-07-11 14:22:21 +00:00
|
|
|
return fmt.Errorf("federateUnblock: error getting block target account from database: %s", err)
|
|
|
|
}
|
2021-08-25 13:34:33 +00:00
|
|
|
block.TargetAccount = blockTargetAccount
|
2021-07-11 14:22:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// if both accounts are local there's nothing to do here
|
|
|
|
if block.Account.Domain == "" && block.TargetAccount.Domain == "" {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-08-25 13:34:33 +00:00
|
|
|
asBlock, err := p.tc.BlockToAS(ctx, block)
|
2021-07-11 14:22:21 +00:00
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("federateUnblock: error converting block to AS format: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
targetAccountURI, err := url.Parse(block.TargetAccount.URI)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("federateUnblock: error parsing uri %s: %s", block.TargetAccount.URI, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// create an Undo and set the appropriate actor on it
|
|
|
|
undo := streams.NewActivityStreamsUndo()
|
|
|
|
undo.SetActivityStreamsActor(asBlock.GetActivityStreamsActor())
|
|
|
|
|
|
|
|
// Set the block as the 'object' property.
|
|
|
|
undoObject := streams.NewActivityStreamsObjectProperty()
|
|
|
|
undoObject.AppendActivityStreamsBlock(asBlock)
|
|
|
|
undo.SetActivityStreamsObject(undoObject)
|
|
|
|
|
|
|
|
// Set the To of the undo as the target of the block
|
|
|
|
undoTo := streams.NewActivityStreamsToProperty()
|
|
|
|
undoTo.AppendIRI(targetAccountURI)
|
|
|
|
undo.SetActivityStreamsTo(undoTo)
|
|
|
|
|
|
|
|
outboxIRI, err := url.Parse(block.Account.OutboxURI)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("federateUnblock: error parsing outboxURI %s: %s", block.Account.OutboxURI, err)
|
|
|
|
}
|
2021-08-25 13:34:33 +00:00
|
|
|
_, err = p.federator.FederatingActor().Send(ctx, outboxIRI, undo)
|
2021-07-11 14:22:21 +00:00
|
|
|
return err
|
|
|
|
}
|