| 
									
										
										
										
											2023-03-12 16:00:57 +01: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-17 19:06:58 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-30 13:12:00 +02:00
										 |  |  | package processing | 
					
						
							| 
									
										
										
										
											2021-05-17 19:06:58 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | import ( | 
					
						
							| 
									
										
										
										
											2021-05-21 15:48:26 +02:00
										 |  |  | 	"context" | 
					
						
							| 
									
										
										
										
											2021-05-17 19:06:58 +02:00
										 |  |  | 	"errors" | 
					
						
							|  |  |  | 	"fmt" | 
					
						
							| 
									
										
										
										
											2021-05-21 15:48:26 +02:00
										 |  |  | 	"net/url" | 
					
						
							| 
									
										
										
										
											2021-05-17 19:06:58 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-19 09:47:55 +01:00
										 |  |  | 	"codeberg.org/gruf/go-kv" | 
					
						
							|  |  |  | 	"codeberg.org/gruf/go-logger/v2/level" | 
					
						
							| 
									
										
										
										
											2022-03-15 16:12:35 +01:00
										 |  |  | 	"github.com/superseriousbusiness/activity/pub" | 
					
						
							| 
									
										
										
										
											2021-11-13 17:29:43 +01:00
										 |  |  | 	"github.com/superseriousbusiness/activity/streams" | 
					
						
							| 
									
										
										
										
											2021-08-31 15:59:12 +02:00
										 |  |  | 	"github.com/superseriousbusiness/gotosocial/internal/ap" | 
					
						
							| 
									
										
										
										
											2023-06-11 11:18:44 +02:00
										 |  |  | 	"github.com/superseriousbusiness/gotosocial/internal/gtserror" | 
					
						
							| 
									
										
										
										
											2021-05-17 19:06:58 +02:00
										 |  |  | 	"github.com/superseriousbusiness/gotosocial/internal/gtsmodel" | 
					
						
							| 
									
										
										
										
											2022-07-19 09:47:55 +01:00
										 |  |  | 	"github.com/superseriousbusiness/gotosocial/internal/log" | 
					
						
							| 
									
										
										
										
											2021-08-31 15:59:12 +02:00
										 |  |  | 	"github.com/superseriousbusiness/gotosocial/internal/messages" | 
					
						
							| 
									
										
										
										
											2021-05-17 19:06:58 +02:00
										 |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-22 16:05:26 +01:00
										 |  |  | func (p *Processor) ProcessFromClientAPI(ctx context.Context, clientMsg messages.FromClientAPI) error { | 
					
						
							| 
									
										
										
										
											2022-07-19 09:47:55 +01:00
										 |  |  | 	// Allocate new log fields slice | 
					
						
							|  |  |  | 	fields := make([]kv.Field, 3, 4) | 
					
						
							|  |  |  | 	fields[0] = kv.Field{"activityType", clientMsg.APActivityType} | 
					
						
							|  |  |  | 	fields[1] = kv.Field{"objectType", clientMsg.APObjectType} | 
					
						
							|  |  |  | 	fields[2] = kv.Field{"fromAccount", clientMsg.OriginAccount.Username} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if clientMsg.GTSModel != nil && | 
					
						
							|  |  |  | 		log.Level() >= level.DEBUG { | 
					
						
							|  |  |  | 		// Append converted model to log | 
					
						
							|  |  |  | 		fields = append(fields, kv.Field{ | 
					
						
							|  |  |  | 			"model", clientMsg.GTSModel, | 
					
						
							|  |  |  | 		}) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Log this federated message | 
					
						
							| 
									
										
										
										
											2023-02-17 12:02:29 +01:00
										 |  |  | 	l := log.WithContext(ctx).WithFields(fields...) | 
					
						
							| 
									
										
										
										
											2022-07-19 09:47:55 +01:00
										 |  |  | 	l.Info("processing from client") | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-21 15:48:26 +02:00
										 |  |  | 	switch clientMsg.APActivityType { | 
					
						
							| 
									
										
										
										
											2021-08-31 15:59:12 +02:00
										 |  |  | 	case ap.ActivityCreate: | 
					
						
							| 
									
										
										
										
											2021-05-21 15:48:26 +02:00
										 |  |  | 		// CREATE | 
					
						
							|  |  |  | 		switch clientMsg.APObjectType { | 
					
						
							| 
									
										
										
										
											2021-10-31 15:46:23 +01:00
										 |  |  | 		case ap.ObjectProfile, ap.ActorPerson: | 
					
						
							|  |  |  | 			// CREATE ACCOUNT/PROFILE | 
					
						
							|  |  |  | 			return p.processCreateAccountFromClientAPI(ctx, clientMsg) | 
					
						
							| 
									
										
										
										
											2021-08-31 15:59:12 +02:00
										 |  |  | 		case ap.ObjectNote: | 
					
						
							| 
									
										
										
										
											2021-05-21 15:48:26 +02:00
										 |  |  | 			// CREATE NOTE | 
					
						
							| 
									
										
										
										
											2021-10-31 15:46:23 +01:00
										 |  |  | 			return p.processCreateStatusFromClientAPI(ctx, clientMsg) | 
					
						
							| 
									
										
										
										
											2021-08-31 15:59:12 +02:00
										 |  |  | 		case ap.ActivityFollow: | 
					
						
							| 
									
										
										
										
											2021-05-27 16:06:24 +02:00
										 |  |  | 			// CREATE FOLLOW REQUEST | 
					
						
							| 
									
										
										
										
											2021-10-31 15:46:23 +01:00
										 |  |  | 			return p.processCreateFollowRequestFromClientAPI(ctx, clientMsg) | 
					
						
							| 
									
										
										
										
											2021-08-31 15:59:12 +02:00
										 |  |  | 		case ap.ActivityLike: | 
					
						
							| 
									
										
										
										
											2021-05-24 18:49:48 +02:00
										 |  |  | 			// CREATE LIKE/FAVE | 
					
						
							| 
									
										
										
										
											2021-10-31 15:46:23 +01:00
										 |  |  | 			return p.processCreateFaveFromClientAPI(ctx, clientMsg) | 
					
						
							| 
									
										
										
										
											2021-08-31 15:59:12 +02:00
										 |  |  | 		case ap.ActivityAnnounce: | 
					
						
							| 
									
										
										
										
											2021-05-28 19:57:04 +02:00
										 |  |  | 			// CREATE BOOST/ANNOUNCE | 
					
						
							| 
									
										
										
										
											2021-10-31 15:46:23 +01:00
										 |  |  | 			return p.processCreateAnnounceFromClientAPI(ctx, clientMsg) | 
					
						
							| 
									
										
										
										
											2021-08-31 15:59:12 +02:00
										 |  |  | 		case ap.ActivityBlock: | 
					
						
							| 
									
										
										
										
											2021-07-11 16:22:21 +02:00
										 |  |  | 			// CREATE BLOCK | 
					
						
							| 
									
										
										
										
											2021-10-31 15:46:23 +01:00
										 |  |  | 			return p.processCreateBlockFromClientAPI(ctx, clientMsg) | 
					
						
							| 
									
										
										
										
											2021-05-21 15:48:26 +02:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2021-08-31 15:59:12 +02:00
										 |  |  | 	case ap.ActivityUpdate: | 
					
						
							| 
									
										
										
										
											2021-05-21 15:48:26 +02:00
										 |  |  | 		// UPDATE | 
					
						
							| 
									
										
										
										
											2021-05-28 22:47:18 +02:00
										 |  |  | 		switch clientMsg.APObjectType { | 
					
						
							| 
									
										
										
										
											2021-08-31 15:59:12 +02:00
										 |  |  | 		case ap.ObjectProfile, ap.ActorPerson: | 
					
						
							| 
									
										
										
										
											2021-05-28 22:47:18 +02:00
										 |  |  | 			// UPDATE ACCOUNT/PROFILE | 
					
						
							| 
									
										
										
										
											2021-10-31 15:46:23 +01:00
										 |  |  | 			return p.processUpdateAccountFromClientAPI(ctx, clientMsg) | 
					
						
							| 
									
										
										
										
											2023-03-19 13:11:46 +01:00
										 |  |  | 		case ap.ActivityFlag: | 
					
						
							|  |  |  | 			// UPDATE A FLAG/REPORT (mark as resolved/closed) | 
					
						
							|  |  |  | 			return p.processUpdateReportFromClientAPI(ctx, clientMsg) | 
					
						
							| 
									
										
										
										
											2021-05-28 22:47:18 +02:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2021-08-31 15:59:12 +02:00
										 |  |  | 	case ap.ActivityAccept: | 
					
						
							| 
									
										
										
										
											2021-05-21 15:48:26 +02:00
										 |  |  | 		// ACCEPT | 
					
						
							| 
									
										
										
										
											2021-11-22 08:46:19 +01:00
										 |  |  | 		if clientMsg.APObjectType == ap.ActivityFollow { | 
					
						
							| 
									
										
										
										
											2021-05-21 15:48:26 +02:00
										 |  |  | 			// ACCEPT FOLLOW | 
					
						
							| 
									
										
										
										
											2021-10-31 15:46:23 +01:00
										 |  |  | 			return p.processAcceptFollowFromClientAPI(ctx, clientMsg) | 
					
						
							| 
									
										
										
										
											2021-10-16 13:27:43 +02:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	case ap.ActivityReject: | 
					
						
							|  |  |  | 		// REJECT | 
					
						
							| 
									
										
										
										
											2021-11-22 08:46:19 +01:00
										 |  |  | 		if clientMsg.APObjectType == ap.ActivityFollow { | 
					
						
							| 
									
										
										
										
											2021-10-16 13:27:43 +02:00
										 |  |  | 			// REJECT FOLLOW (request) | 
					
						
							| 
									
										
										
										
											2021-10-31 15:46:23 +01:00
										 |  |  | 			return p.processRejectFollowFromClientAPI(ctx, clientMsg) | 
					
						
							| 
									
										
										
										
											2021-05-21 15:48:26 +02:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2021-08-31 15:59:12 +02:00
										 |  |  | 	case ap.ActivityUndo: | 
					
						
							| 
									
										
										
										
											2021-05-21 15:48:26 +02:00
										 |  |  | 		// UNDO | 
					
						
							|  |  |  | 		switch clientMsg.APObjectType { | 
					
						
							| 
									
										
										
										
											2021-08-31 15:59:12 +02:00
										 |  |  | 		case ap.ActivityFollow: | 
					
						
							| 
									
										
										
										
											2021-05-21 15:48:26 +02:00
										 |  |  | 			// UNDO FOLLOW | 
					
						
							| 
									
										
										
										
											2021-10-31 15:46:23 +01:00
										 |  |  | 			return p.processUndoFollowFromClientAPI(ctx, clientMsg) | 
					
						
							| 
									
										
										
										
											2021-08-31 15:59:12 +02:00
										 |  |  | 		case ap.ActivityBlock: | 
					
						
							| 
									
										
										
										
											2021-07-11 16:22:21 +02:00
										 |  |  | 			// UNDO BLOCK | 
					
						
							| 
									
										
										
										
											2021-10-31 15:46:23 +01:00
										 |  |  | 			return p.processUndoBlockFromClientAPI(ctx, clientMsg) | 
					
						
							| 
									
										
										
										
											2021-08-31 15:59:12 +02:00
										 |  |  | 		case ap.ActivityLike: | 
					
						
							| 
									
										
										
										
											2021-06-13 18:42:28 +02:00
										 |  |  | 			// UNDO LIKE/FAVE | 
					
						
							| 
									
										
										
										
											2021-10-31 15:46:23 +01:00
										 |  |  | 			return p.processUndoFaveFromClientAPI(ctx, clientMsg) | 
					
						
							| 
									
										
										
										
											2021-08-31 15:59:12 +02:00
										 |  |  | 		case ap.ActivityAnnounce: | 
					
						
							| 
									
										
										
										
											2021-06-21 15:56:00 +02:00
										 |  |  | 			// UNDO ANNOUNCE/BOOST | 
					
						
							| 
									
										
										
										
											2021-10-31 15:46:23 +01:00
										 |  |  | 			return p.processUndoAnnounceFromClientAPI(ctx, clientMsg) | 
					
						
							| 
									
										
										
										
											2021-06-13 18:42:28 +02:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2021-08-31 15:59:12 +02:00
										 |  |  | 	case ap.ActivityDelete: | 
					
						
							| 
									
										
										
										
											2021-06-13 18:42:28 +02:00
										 |  |  | 		// DELETE | 
					
						
							|  |  |  | 		switch clientMsg.APObjectType { | 
					
						
							| 
									
										
										
										
											2021-08-31 15:59:12 +02:00
										 |  |  | 		case ap.ObjectNote: | 
					
						
							| 
									
										
										
										
											2021-06-13 18:42:28 +02:00
										 |  |  | 			// DELETE STATUS/NOTE | 
					
						
							| 
									
										
										
										
											2021-10-31 15:46:23 +01:00
										 |  |  | 			return p.processDeleteStatusFromClientAPI(ctx, clientMsg) | 
					
						
							| 
									
										
										
										
											2021-08-31 15:59:12 +02:00
										 |  |  | 		case ap.ObjectProfile, ap.ActorPerson: | 
					
						
							| 
									
										
										
										
											2021-07-05 13:23:03 +02:00
										 |  |  | 			// DELETE ACCOUNT/PROFILE | 
					
						
							| 
									
										
										
										
											2021-10-31 15:46:23 +01:00
										 |  |  | 			return p.processDeleteAccountFromClientAPI(ctx, clientMsg) | 
					
						
							| 
									
										
										
										
											2021-05-17 19:06:58 +02:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2023-01-23 13:14:21 +01:00
										 |  |  | 	case ap.ActivityFlag: | 
					
						
							|  |  |  | 		// FLAG | 
					
						
							|  |  |  | 		if clientMsg.APObjectType == ap.ObjectProfile { | 
					
						
							|  |  |  | 			// FLAG/REPORT A PROFILE | 
					
						
							|  |  |  | 			return p.processReportAccountFromClientAPI(ctx, clientMsg) | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2021-05-17 19:06:58 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2021-05-21 15:48:26 +02:00
										 |  |  | 	return nil | 
					
						
							| 
									
										
										
										
											2021-05-17 19:06:58 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-22 16:05:26 +01:00
										 |  |  | func (p *Processor) processCreateAccountFromClientAPI(ctx context.Context, clientMsg messages.FromClientAPI) error { | 
					
						
							| 
									
										
										
										
											2021-10-31 15:46:23 +01:00
										 |  |  | 	account, ok := clientMsg.GTSModel.(*gtsmodel.Account) | 
					
						
							|  |  |  | 	if !ok { | 
					
						
							|  |  |  | 		return errors.New("account was not parseable as *gtsmodel.Account") | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-20 19:10:08 +01:00
										 |  |  | 	// Do nothing if this isn't our activity. | 
					
						
							|  |  |  | 	if !account.IsLocal() { | 
					
						
							| 
									
										
										
										
											2021-10-31 15:46:23 +01:00
										 |  |  | 		return nil | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// get the user this account belongs to | 
					
						
							| 
									
										
										
										
											2023-03-01 18:26:53 +00:00
										 |  |  | 	user, err := p.state.DB.GetUserByAccountID(ctx, account.ID) | 
					
						
							| 
									
										
										
										
											2022-10-03 10:46:11 +02:00
										 |  |  | 	if err != nil { | 
					
						
							| 
									
										
										
										
											2021-10-31 15:46:23 +01:00
										 |  |  | 		return err | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// email a confirmation to this user | 
					
						
							| 
									
										
										
										
											2023-02-22 16:05:26 +01:00
										 |  |  | 	return p.User().EmailSendConfirmation(ctx, user, account.Username) | 
					
						
							| 
									
										
										
										
											2021-10-31 15:46:23 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-22 16:05:26 +01:00
										 |  |  | func (p *Processor) processCreateStatusFromClientAPI(ctx context.Context, clientMsg messages.FromClientAPI) error { | 
					
						
							| 
									
										
										
										
											2021-10-31 15:46:23 +01:00
										 |  |  | 	status, ok := clientMsg.GTSModel.(*gtsmodel.Status) | 
					
						
							|  |  |  | 	if !ok { | 
					
						
							| 
									
										
										
										
											2023-06-11 11:18:44 +02:00
										 |  |  | 		return gtserror.New("status was not parseable as *gtsmodel.Status") | 
					
						
							| 
									
										
										
										
											2021-10-31 15:46:23 +01:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-10 21:56:02 +02:00
										 |  |  | 	if err := p.timelineAndNotifyStatus(ctx, status); err != nil { | 
					
						
							| 
									
										
										
										
											2023-06-11 11:18:44 +02:00
										 |  |  | 		return gtserror.Newf("error timelining status: %w", err) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if status.InReplyToID != "" { | 
					
						
							|  |  |  | 		// Interaction counts changed on the replied status; | 
					
						
							|  |  |  | 		// uncache the prepared version from all timelines. | 
					
						
							|  |  |  | 		p.invalidateStatusFromTimelines(ctx, status.InReplyToID) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if err := p.federateStatus(ctx, status); err != nil { | 
					
						
							|  |  |  | 		return gtserror.Newf("error federating status: %w", err) | 
					
						
							| 
									
										
										
										
											2021-10-31 15:46:23 +01:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-11 11:18:44 +02:00
										 |  |  | 	return nil | 
					
						
							| 
									
										
										
										
											2021-10-31 15:46:23 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-22 16:05:26 +01:00
										 |  |  | func (p *Processor) processCreateFollowRequestFromClientAPI(ctx context.Context, clientMsg messages.FromClientAPI) error { | 
					
						
							| 
									
										
										
										
											2021-10-31 15:46:23 +01:00
										 |  |  | 	followRequest, ok := clientMsg.GTSModel.(*gtsmodel.FollowRequest) | 
					
						
							|  |  |  | 	if !ok { | 
					
						
							|  |  |  | 		return errors.New("followrequest was not parseable as *gtsmodel.FollowRequest") | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if err := p.notifyFollowRequest(ctx, followRequest); err != nil { | 
					
						
							|  |  |  | 		return err | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return p.federateFollow(ctx, followRequest, clientMsg.OriginAccount, clientMsg.TargetAccount) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-22 16:05:26 +01:00
										 |  |  | func (p *Processor) processCreateFaveFromClientAPI(ctx context.Context, clientMsg messages.FromClientAPI) error { | 
					
						
							| 
									
										
										
										
											2023-06-11 11:18:44 +02:00
										 |  |  | 	statusFave, ok := clientMsg.GTSModel.(*gtsmodel.StatusFave) | 
					
						
							| 
									
										
										
										
											2021-10-31 15:46:23 +01:00
										 |  |  | 	if !ok { | 
					
						
							| 
									
										
										
										
											2023-06-11 11:18:44 +02:00
										 |  |  | 		return gtserror.New("statusFave was not parseable as *gtsmodel.StatusFave") | 
					
						
							| 
									
										
										
										
											2021-10-31 15:46:23 +01:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-11 11:18:44 +02:00
										 |  |  | 	if err := p.notifyFave(ctx, statusFave); err != nil { | 
					
						
							|  |  |  | 		return gtserror.Newf("error notifying status fave: %w", err) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Interaction counts changed on the faved status; | 
					
						
							|  |  |  | 	// uncache the prepared version from all timelines. | 
					
						
							|  |  |  | 	p.invalidateStatusFromTimelines(ctx, statusFave.StatusID) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if err := p.federateFave(ctx, statusFave, clientMsg.OriginAccount, clientMsg.TargetAccount); err != nil { | 
					
						
							|  |  |  | 		return gtserror.Newf("error federating status fave: %w", err) | 
					
						
							| 
									
										
										
										
											2021-10-31 15:46:23 +01:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-11 11:18:44 +02:00
										 |  |  | 	return nil | 
					
						
							| 
									
										
										
										
											2021-10-31 15:46:23 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-22 16:05:26 +01:00
										 |  |  | func (p *Processor) processCreateAnnounceFromClientAPI(ctx context.Context, clientMsg messages.FromClientAPI) error { | 
					
						
							| 
									
										
										
										
											2023-06-11 11:18:44 +02:00
										 |  |  | 	status, ok := clientMsg.GTSModel.(*gtsmodel.Status) | 
					
						
							| 
									
										
										
										
											2021-10-31 15:46:23 +01:00
										 |  |  | 	if !ok { | 
					
						
							|  |  |  | 		return errors.New("boost was not parseable as *gtsmodel.Status") | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-11 11:18:44 +02:00
										 |  |  | 	// Timeline and notify. | 
					
						
							|  |  |  | 	if err := p.timelineAndNotifyStatus(ctx, status); err != nil { | 
					
						
							|  |  |  | 		return gtserror.Newf("error timelining boost: %w", err) | 
					
						
							| 
									
										
										
										
											2021-10-31 15:46:23 +01:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-11 11:18:44 +02:00
										 |  |  | 	if err := p.notifyAnnounce(ctx, status); err != nil { | 
					
						
							|  |  |  | 		return gtserror.Newf("error notifying boost: %w", err) | 
					
						
							| 
									
										
										
										
											2021-10-31 15:46:23 +01:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-11 11:18:44 +02:00
										 |  |  | 	// Interaction counts changed on the boosted status; | 
					
						
							|  |  |  | 	// uncache the prepared version from all timelines. | 
					
						
							|  |  |  | 	p.invalidateStatusFromTimelines(ctx, status.BoostOfID) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if err := p.federateAnnounce(ctx, status, clientMsg.OriginAccount, clientMsg.TargetAccount); err != nil { | 
					
						
							|  |  |  | 		return gtserror.Newf("error federating boost: %w", err) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return nil | 
					
						
							| 
									
										
										
										
											2021-10-31 15:46:23 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-22 16:05:26 +01:00
										 |  |  | func (p *Processor) processCreateBlockFromClientAPI(ctx context.Context, clientMsg messages.FromClientAPI) error { | 
					
						
							| 
									
										
										
										
											2021-10-31 15:46:23 +01:00
										 |  |  | 	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 | 
					
						
							| 
									
										
										
										
											2023-05-25 10:37:38 +02:00
										 |  |  | 	if err := p.state.Timelines.Home.WipeItemsFromAccountID(ctx, block.AccountID, block.TargetAccountID); err != nil { | 
					
						
							| 
									
										
										
										
											2021-10-31 15:46:23 +01:00
										 |  |  | 		return err | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2023-05-25 10:37:38 +02:00
										 |  |  | 	if err := p.state.Timelines.Home.WipeItemsFromAccountID(ctx, block.TargetAccountID, block.AccountID); err != nil { | 
					
						
							| 
									
										
										
										
											2021-10-31 15:46:23 +01:00
										 |  |  | 		return err | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// TODO: same with notifications | 
					
						
							|  |  |  | 	// TODO: same with bookmarks | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return p.federateBlock(ctx, block) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-22 16:05:26 +01:00
										 |  |  | func (p *Processor) processUpdateAccountFromClientAPI(ctx context.Context, clientMsg messages.FromClientAPI) error { | 
					
						
							| 
									
										
										
										
											2021-10-31 15:46:23 +01:00
										 |  |  | 	account, ok := clientMsg.GTSModel.(*gtsmodel.Account) | 
					
						
							|  |  |  | 	if !ok { | 
					
						
							|  |  |  | 		return errors.New("account was not parseable as *gtsmodel.Account") | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return p.federateAccountUpdate(ctx, account, clientMsg.OriginAccount) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-19 13:11:46 +01:00
										 |  |  | func (p *Processor) processUpdateReportFromClientAPI(ctx context.Context, clientMsg messages.FromClientAPI) error { | 
					
						
							|  |  |  | 	report, ok := clientMsg.GTSModel.(*gtsmodel.Report) | 
					
						
							|  |  |  | 	if !ok { | 
					
						
							|  |  |  | 		return errors.New("report was not parseable as *gtsmodel.Report") | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if report.Account.IsRemote() { | 
					
						
							|  |  |  | 		// Report creator is a remote account, | 
					
						
							|  |  |  | 		// we shouldn't email or notify them. | 
					
						
							|  |  |  | 		return nil | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-10 21:56:02 +02:00
										 |  |  | 	return p.emailReportClosed(ctx, report) | 
					
						
							| 
									
										
										
										
											2023-03-19 13:11:46 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-22 16:05:26 +01:00
										 |  |  | func (p *Processor) processAcceptFollowFromClientAPI(ctx context.Context, clientMsg messages.FromClientAPI) error { | 
					
						
							| 
									
										
										
										
											2021-10-31 15:46:23 +01:00
										 |  |  | 	follow, ok := clientMsg.GTSModel.(*gtsmodel.Follow) | 
					
						
							|  |  |  | 	if !ok { | 
					
						
							|  |  |  | 		return errors.New("accept was not parseable as *gtsmodel.Follow") | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if err := p.notifyFollow(ctx, follow, clientMsg.TargetAccount); err != nil { | 
					
						
							|  |  |  | 		return err | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return p.federateAcceptFollowRequest(ctx, follow) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-22 16:05:26 +01:00
										 |  |  | func (p *Processor) processRejectFollowFromClientAPI(ctx context.Context, clientMsg messages.FromClientAPI) error { | 
					
						
							| 
									
										
										
										
											2021-10-31 15:46:23 +01:00
										 |  |  | 	followRequest, ok := clientMsg.GTSModel.(*gtsmodel.FollowRequest) | 
					
						
							|  |  |  | 	if !ok { | 
					
						
							|  |  |  | 		return errors.New("reject was not parseable as *gtsmodel.FollowRequest") | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return p.federateRejectFollowRequest(ctx, followRequest) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-22 16:05:26 +01:00
										 |  |  | func (p *Processor) processUndoFollowFromClientAPI(ctx context.Context, clientMsg messages.FromClientAPI) error { | 
					
						
							| 
									
										
										
										
											2021-10-31 15:46:23 +01:00
										 |  |  | 	follow, ok := clientMsg.GTSModel.(*gtsmodel.Follow) | 
					
						
							|  |  |  | 	if !ok { | 
					
						
							|  |  |  | 		return errors.New("undo was not parseable as *gtsmodel.Follow") | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return p.federateUnfollow(ctx, follow, clientMsg.OriginAccount, clientMsg.TargetAccount) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-22 16:05:26 +01:00
										 |  |  | func (p *Processor) processUndoBlockFromClientAPI(ctx context.Context, clientMsg messages.FromClientAPI) error { | 
					
						
							| 
									
										
										
										
											2021-10-31 15:46:23 +01:00
										 |  |  | 	block, ok := clientMsg.GTSModel.(*gtsmodel.Block) | 
					
						
							|  |  |  | 	if !ok { | 
					
						
							|  |  |  | 		return errors.New("undo was not parseable as *gtsmodel.Block") | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return p.federateUnblock(ctx, block) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-22 16:05:26 +01:00
										 |  |  | func (p *Processor) processUndoFaveFromClientAPI(ctx context.Context, clientMsg messages.FromClientAPI) error { | 
					
						
							| 
									
										
										
										
											2023-06-11 11:18:44 +02:00
										 |  |  | 	statusFave, ok := clientMsg.GTSModel.(*gtsmodel.StatusFave) | 
					
						
							| 
									
										
										
										
											2021-10-31 15:46:23 +01:00
										 |  |  | 	if !ok { | 
					
						
							| 
									
										
										
										
											2023-06-11 11:18:44 +02:00
										 |  |  | 		return gtserror.New("statusFave was not parseable as *gtsmodel.StatusFave") | 
					
						
							| 
									
										
										
										
											2021-10-31 15:46:23 +01:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2023-06-11 11:18:44 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// Interaction counts changed on the faved status; | 
					
						
							|  |  |  | 	// uncache the prepared version from all timelines. | 
					
						
							|  |  |  | 	p.invalidateStatusFromTimelines(ctx, statusFave.StatusID) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if err := p.federateUnfave(ctx, statusFave, clientMsg.OriginAccount, clientMsg.TargetAccount); err != nil { | 
					
						
							|  |  |  | 		return gtserror.Newf("error federating status unfave: %w", err) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return nil | 
					
						
							| 
									
										
										
										
											2021-10-31 15:46:23 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-22 16:05:26 +01:00
										 |  |  | func (p *Processor) processUndoAnnounceFromClientAPI(ctx context.Context, clientMsg messages.FromClientAPI) error { | 
					
						
							| 
									
										
										
										
											2023-06-11 11:18:44 +02:00
										 |  |  | 	status, ok := clientMsg.GTSModel.(*gtsmodel.Status) | 
					
						
							| 
									
										
										
										
											2021-10-31 15:46:23 +01:00
										 |  |  | 	if !ok { | 
					
						
							| 
									
										
										
										
											2023-06-11 11:18:44 +02:00
										 |  |  | 		return errors.New("boost was not parseable as *gtsmodel.Status") | 
					
						
							| 
									
										
										
										
											2021-10-31 15:46:23 +01:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-11 11:18:44 +02:00
										 |  |  | 	if err := p.state.DB.DeleteStatusByID(ctx, status.ID); err != nil { | 
					
						
							|  |  |  | 		return gtserror.Newf("db error deleting boost: %w", err) | 
					
						
							| 
									
										
										
										
											2022-09-21 19:55:52 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-11 11:18:44 +02:00
										 |  |  | 	if err := p.deleteStatusFromTimelines(ctx, status.ID); err != nil { | 
					
						
							|  |  |  | 		return gtserror.Newf("error removing boost from timelines: %w", err) | 
					
						
							| 
									
										
										
										
											2021-10-31 15:46:23 +01:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-11 11:18:44 +02:00
										 |  |  | 	// Interaction counts changed on the boosted status; | 
					
						
							|  |  |  | 	// uncache the prepared version from all timelines. | 
					
						
							|  |  |  | 	p.invalidateStatusFromTimelines(ctx, status.BoostOfID) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if err := p.federateUnannounce(ctx, status, clientMsg.OriginAccount, clientMsg.TargetAccount); err != nil { | 
					
						
							|  |  |  | 		return gtserror.Newf("error federating status unboost: %w", err) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return nil | 
					
						
							| 
									
										
										
										
											2021-10-31 15:46:23 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-22 16:05:26 +01:00
										 |  |  | func (p *Processor) processDeleteStatusFromClientAPI(ctx context.Context, clientMsg messages.FromClientAPI) error { | 
					
						
							| 
									
										
										
										
											2023-06-11 11:18:44 +02:00
										 |  |  | 	status, ok := clientMsg.GTSModel.(*gtsmodel.Status) | 
					
						
							| 
									
										
										
										
											2021-10-31 15:46:23 +01:00
										 |  |  | 	if !ok { | 
					
						
							| 
									
										
										
										
											2023-06-11 11:18:44 +02:00
										 |  |  | 		return gtserror.New("status was not parseable as *gtsmodel.Status") | 
					
						
							| 
									
										
										
										
											2021-10-31 15:46:23 +01:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-11 11:18:44 +02:00
										 |  |  | 	if err := p.state.DB.PopulateStatus(ctx, status); err != nil { | 
					
						
							|  |  |  | 		return gtserror.Newf("db error populating status: %w", err) | 
					
						
							| 
									
										
										
										
											2021-10-31 15:46:23 +01:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-11 11:18:44 +02:00
										 |  |  | 	// Don't delete attachments, just unattach them: this | 
					
						
							|  |  |  | 	// request comes from the client API and the poster | 
					
						
							|  |  |  | 	// may want to use attachments again in a new post. | 
					
						
							| 
									
										
										
										
											2022-06-24 17:17:40 +02:00
										 |  |  | 	deleteAttachments := false | 
					
						
							| 
									
										
										
										
											2023-06-11 11:18:44 +02:00
										 |  |  | 	if err := p.wipeStatus(ctx, status, deleteAttachments); err != nil { | 
					
						
							|  |  |  | 		return gtserror.Newf("error wiping status: %w", err) | 
					
						
							| 
									
										
										
										
											2021-10-31 15:46:23 +01:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-11 11:18:44 +02:00
										 |  |  | 	if status.InReplyToID != "" { | 
					
						
							|  |  |  | 		// Interaction counts changed on the replied status; | 
					
						
							|  |  |  | 		// uncache the prepared version from all timelines. | 
					
						
							|  |  |  | 		p.invalidateStatusFromTimelines(ctx, status.InReplyToID) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if err := p.federateStatusDelete(ctx, status); err != nil { | 
					
						
							|  |  |  | 		return gtserror.Newf("error federating status delete: %w", err) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return nil | 
					
						
							| 
									
										
										
										
											2021-10-31 15:46:23 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-22 16:05:26 +01:00
										 |  |  | func (p *Processor) processDeleteAccountFromClientAPI(ctx context.Context, clientMsg messages.FromClientAPI) error { | 
					
						
							| 
									
										
										
										
											2021-10-31 15:46:23 +01: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 | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2022-03-15 16:12:35 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if err := p.federateAccountDelete(ctx, clientMsg.TargetAccount); err != nil { | 
					
						
							|  |  |  | 		return err | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-22 16:05:26 +01:00
										 |  |  | 	return p.account.Delete(ctx, clientMsg.TargetAccount, origin) | 
					
						
							| 
									
										
										
										
											2021-10-31 15:46:23 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-22 16:05:26 +01:00
										 |  |  | func (p *Processor) processReportAccountFromClientAPI(ctx context.Context, clientMsg messages.FromClientAPI) error { | 
					
						
							| 
									
										
										
										
											2023-01-27 14:48:11 +01:00
										 |  |  | 	report, ok := clientMsg.GTSModel.(*gtsmodel.Report) | 
					
						
							|  |  |  | 	if !ok { | 
					
						
							|  |  |  | 		return errors.New("report was not parseable as *gtsmodel.Report") | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-19 13:11:46 +01:00
										 |  |  | 	if *report.Forwarded { | 
					
						
							|  |  |  | 		if err := p.federateReport(ctx, report); err != nil { | 
					
						
							|  |  |  | 			return fmt.Errorf("processReportAccountFromClientAPI: error federating report: %w", err) | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2023-01-27 14:48:11 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-10 21:56:02 +02:00
										 |  |  | 	if err := p.emailReport(ctx, report); err != nil { | 
					
						
							| 
									
										
										
										
											2023-03-19 13:11:46 +01:00
										 |  |  | 		return fmt.Errorf("processReportAccountFromClientAPI: error notifying report: %w", err) | 
					
						
							| 
									
										
										
										
											2023-01-27 14:48:11 +01:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-19 13:11:46 +01:00
										 |  |  | 	return nil | 
					
						
							| 
									
										
										
										
											2023-01-23 13:14:21 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-05 13:23:03 +02:00
										 |  |  | // TODO: move all the below functions into federation.Federator | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-22 16:05:26 +01:00
										 |  |  | func (p *Processor) federateAccountDelete(ctx context.Context, account *gtsmodel.Account) error { | 
					
						
							| 
									
										
										
										
											2023-03-20 19:10:08 +01:00
										 |  |  | 	// Do nothing if this isn't our activity. | 
					
						
							|  |  |  | 	if !account.IsLocal() { | 
					
						
							| 
									
										
										
										
											2022-03-15 16:12:35 +01:00
										 |  |  | 		return nil | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	outboxIRI, err := url.Parse(account.OutboxURI) | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		return fmt.Errorf("federateAccountDelete: error parsing outboxURI %s: %s", account.OutboxURI, err) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	actorIRI, err := url.Parse(account.URI) | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		return fmt.Errorf("federateAccountDelete: error parsing actorIRI %s: %s", account.URI, err) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	followersIRI, err := url.Parse(account.FollowersURI) | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		return fmt.Errorf("federateAccountDelete: error parsing followersIRI %s: %s", account.FollowersURI, err) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	publicIRI, err := url.Parse(pub.PublicActivityPubIRI) | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		return fmt.Errorf("federateAccountDelete: error parsing url %s: %s", pub.PublicActivityPubIRI, err) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// create a delete and set the appropriate actor on it | 
					
						
							|  |  |  | 	delete := streams.NewActivityStreamsDelete() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// set the actor for the delete; no matter who deleted it we should use the account owner for this | 
					
						
							|  |  |  | 	deleteActor := streams.NewActivityStreamsActorProperty() | 
					
						
							|  |  |  | 	deleteActor.AppendIRI(actorIRI) | 
					
						
							|  |  |  | 	delete.SetActivityStreamsActor(deleteActor) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Set the account IRI as the 'object' property. | 
					
						
							|  |  |  | 	deleteObject := streams.NewActivityStreamsObjectProperty() | 
					
						
							|  |  |  | 	deleteObject.AppendIRI(actorIRI) | 
					
						
							|  |  |  | 	delete.SetActivityStreamsObject(deleteObject) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// send to followers... | 
					
						
							|  |  |  | 	deleteTo := streams.NewActivityStreamsToProperty() | 
					
						
							|  |  |  | 	deleteTo.AppendIRI(followersIRI) | 
					
						
							|  |  |  | 	delete.SetActivityStreamsTo(deleteTo) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// ... and CC to public | 
					
						
							|  |  |  | 	deleteCC := streams.NewActivityStreamsCcProperty() | 
					
						
							|  |  |  | 	deleteCC.AppendIRI(publicIRI) | 
					
						
							|  |  |  | 	delete.SetActivityStreamsCc(deleteCC) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	_, err = p.federator.FederatingActor().Send(ctx, outboxIRI, delete) | 
					
						
							|  |  |  | 	return err | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-22 16:05:26 +01:00
										 |  |  | func (p *Processor) federateStatus(ctx context.Context, status *gtsmodel.Status) error { | 
					
						
							| 
									
										
										
										
											2021-10-31 15:46:23 +01:00
										 |  |  | 	// do nothing if the status shouldn't be federated | 
					
						
							| 
									
										
										
										
											2022-08-15 12:35:05 +02:00
										 |  |  | 	if !*status.Federated { | 
					
						
							| 
									
										
										
										
											2021-10-31 15:46:23 +01:00
										 |  |  | 		return nil | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-20 12:26:56 +02:00
										 |  |  | 	if status.Account == nil { | 
					
						
							| 
									
										
										
										
											2023-03-01 18:26:53 +00:00
										 |  |  | 		statusAccount, err := p.state.DB.GetAccountByID(ctx, status.AccountID) | 
					
						
							| 
									
										
										
										
											2021-08-25 15:34:33 +02:00
										 |  |  | 		if err != nil { | 
					
						
							| 
									
										
										
										
											2021-07-05 13:23:03 +02:00
										 |  |  | 			return fmt.Errorf("federateStatus: error fetching status author account: %s", err) | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2021-08-25 15:34:33 +02:00
										 |  |  | 		status.Account = statusAccount | 
					
						
							| 
									
										
										
										
											2021-07-05 13:23:03 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-20 19:10:08 +01:00
										 |  |  | 	// Do nothing if this isn't our activity. | 
					
						
							|  |  |  | 	if !status.Account.IsLocal() { | 
					
						
							| 
									
										
										
										
											2021-07-05 13:23:03 +02:00
										 |  |  | 		return nil | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-25 15:34:33 +02:00
										 |  |  | 	asStatus, err := p.tc.StatusToAS(ctx, status) | 
					
						
							| 
									
										
										
										
											2021-05-21 15:48:26 +02:00
										 |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		return fmt.Errorf("federateStatus: error converting status to as format: %s", err) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-24 11:57:39 +02:00
										 |  |  | 	create, err := p.tc.WrapNoteInCreate(asStatus, false) | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		return fmt.Errorf("federateStatus: error wrapping status in create: %s", err) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-20 12:26:56 +02:00
										 |  |  | 	outboxIRI, err := url.Parse(status.Account.OutboxURI) | 
					
						
							| 
									
										
										
										
											2021-05-21 15:48:26 +02:00
										 |  |  | 	if err != nil { | 
					
						
							| 
									
										
										
										
											2021-08-20 12:26:56 +02:00
										 |  |  | 		return fmt.Errorf("federateStatus: error parsing outboxURI %s: %s", status.Account.OutboxURI, err) | 
					
						
							| 
									
										
										
										
											2021-05-21 15:48:26 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-24 11:57:39 +02:00
										 |  |  | 	_, err = p.federator.FederatingActor().Send(ctx, outboxIRI, create) | 
					
						
							| 
									
										
										
										
											2021-05-21 15:48:26 +02:00
										 |  |  | 	return err | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-22 16:05:26 +01:00
										 |  |  | func (p *Processor) federateStatusDelete(ctx context.Context, status *gtsmodel.Status) error { | 
					
						
							| 
									
										
										
										
											2021-08-20 12:26:56 +02:00
										 |  |  | 	if status.Account == nil { | 
					
						
							| 
									
										
										
										
											2023-03-01 18:26:53 +00:00
										 |  |  | 		statusAccount, err := p.state.DB.GetAccountByID(ctx, status.AccountID) | 
					
						
							| 
									
										
										
										
											2021-08-25 15:34:33 +02:00
										 |  |  | 		if err != nil { | 
					
						
							|  |  |  | 			return fmt.Errorf("federateStatusDelete: error fetching status author account: %s", err) | 
					
						
							| 
									
										
										
										
											2021-07-05 13:23:03 +02:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2021-08-25 15:34:33 +02:00
										 |  |  | 		status.Account = statusAccount | 
					
						
							| 
									
										
										
										
											2021-07-05 13:23:03 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-20 19:10:08 +01:00
										 |  |  | 	// Do nothing if this isn't our activity. | 
					
						
							|  |  |  | 	if !status.Account.IsLocal() { | 
					
						
							| 
									
										
										
										
											2021-07-05 13:23:03 +02:00
										 |  |  | 		return nil | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-03 20:56:34 +01:00
										 |  |  | 	delete, err := p.tc.StatusToASDelete(ctx, status) | 
					
						
							| 
									
										
										
										
											2021-06-13 18:42:28 +02:00
										 |  |  | 	if err != nil { | 
					
						
							| 
									
										
										
										
											2023-03-03 20:56:34 +01:00
										 |  |  | 		return fmt.Errorf("federateStatusDelete: error creating Delete: %w", err) | 
					
						
							| 
									
										
										
										
											2021-06-13 18:42:28 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-20 12:26:56 +02:00
										 |  |  | 	outboxIRI, err := url.Parse(status.Account.OutboxURI) | 
					
						
							| 
									
										
										
										
											2021-06-13 18:42:28 +02:00
										 |  |  | 	if err != nil { | 
					
						
							| 
									
										
										
										
											2023-03-03 20:56:34 +01:00
										 |  |  | 		return fmt.Errorf("federateStatusDelete: error parsing outboxURI %s: %w", status.Account.OutboxURI, err) | 
					
						
							| 
									
										
										
										
											2021-06-13 18:42:28 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-25 15:34:33 +02:00
										 |  |  | 	_, err = p.federator.FederatingActor().Send(ctx, outboxIRI, delete) | 
					
						
							| 
									
										
										
										
											2021-06-13 18:42:28 +02:00
										 |  |  | 	return err | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-22 16:05:26 +01:00
										 |  |  | func (p *Processor) federateFollow(ctx context.Context, followRequest *gtsmodel.FollowRequest, originAccount *gtsmodel.Account, targetAccount *gtsmodel.Account) error { | 
					
						
							| 
									
										
										
										
											2023-03-20 19:10:08 +01:00
										 |  |  | 	// Do nothing if both accounts are local. | 
					
						
							|  |  |  | 	if originAccount.IsLocal() && targetAccount.IsLocal() { | 
					
						
							| 
									
										
										
										
											2021-05-21 15:48:26 +02:00
										 |  |  | 		return nil | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-25 15:34:33 +02:00
										 |  |  | 	follow := p.tc.FollowRequestToFollow(ctx, followRequest) | 
					
						
							| 
									
										
										
										
											2021-05-27 16:06:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-25 15:34:33 +02:00
										 |  |  | 	asFollow, err := p.tc.FollowToAS(ctx, follow, originAccount, targetAccount) | 
					
						
							| 
									
										
										
										
											2021-05-21 15:48:26 +02: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 15:34:33 +02:00
										 |  |  | 	_, err = p.federator.FederatingActor().Send(ctx, outboxIRI, asFollow) | 
					
						
							| 
									
										
										
										
											2021-05-21 15:48:26 +02:00
										 |  |  | 	return err | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-22 16:05:26 +01:00
										 |  |  | func (p *Processor) federateUnfollow(ctx context.Context, follow *gtsmodel.Follow, originAccount *gtsmodel.Account, targetAccount *gtsmodel.Account) error { | 
					
						
							| 
									
										
										
										
											2023-03-20 19:10:08 +01:00
										 |  |  | 	// Do nothing if both accounts are local. | 
					
						
							|  |  |  | 	if originAccount.IsLocal() && targetAccount.IsLocal() { | 
					
						
							| 
									
										
										
										
											2021-05-21 15:48:26 +02:00
										 |  |  | 		return nil | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// recreate the follow | 
					
						
							| 
									
										
										
										
											2021-08-25 15:34:33 +02:00
										 |  |  | 	asFollow, err := p.tc.FollowToAS(ctx, follow, originAccount, targetAccount) | 
					
						
							| 
									
										
										
										
											2021-05-21 15:48:26 +02: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 15:34:33 +02:00
										 |  |  | 	_, err = p.federator.FederatingActor().Send(ctx, outboxIRI, undo) | 
					
						
							| 
									
										
										
										
											2021-05-21 15:48:26 +02:00
										 |  |  | 	return err | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-22 16:05:26 +01:00
										 |  |  | func (p *Processor) federateUnfave(ctx context.Context, fave *gtsmodel.StatusFave, originAccount *gtsmodel.Account, targetAccount *gtsmodel.Account) error { | 
					
						
							| 
									
										
										
										
											2023-03-20 19:10:08 +01:00
										 |  |  | 	// Do nothing if both accounts are local. | 
					
						
							|  |  |  | 	if originAccount.IsLocal() && targetAccount.IsLocal() { | 
					
						
							| 
									
										
										
										
											2021-06-13 18:42:28 +02:00
										 |  |  | 		return nil | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// create the AS fave | 
					
						
							| 
									
										
										
										
											2021-08-25 15:34:33 +02:00
										 |  |  | 	asFave, err := p.tc.FaveToAS(ctx, fave) | 
					
						
							| 
									
										
										
										
											2021-06-13 18:42:28 +02: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 15:34:33 +02:00
										 |  |  | 	_, err = p.federator.FederatingActor().Send(ctx, outboxIRI, undo) | 
					
						
							| 
									
										
										
										
											2021-06-13 18:42:28 +02:00
										 |  |  | 	return err | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-22 16:05:26 +01:00
										 |  |  | func (p *Processor) federateUnannounce(ctx context.Context, boost *gtsmodel.Status, originAccount *gtsmodel.Account, targetAccount *gtsmodel.Account) error { | 
					
						
							| 
									
										
										
										
											2023-03-20 19:10:08 +01:00
										 |  |  | 	// Do nothing if this isn't our activity. | 
					
						
							|  |  |  | 	if !originAccount.IsLocal() { | 
					
						
							| 
									
										
										
										
											2021-07-05 13:23:03 +02:00
										 |  |  | 		return nil | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-25 15:34:33 +02:00
										 |  |  | 	asAnnounce, err := p.tc.BoostToAS(ctx, boost, originAccount, targetAccount) | 
					
						
							| 
									
										
										
										
											2021-06-21 15:56:00 +02: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 15:34:33 +02:00
										 |  |  | 	_, err = p.federator.FederatingActor().Send(ctx, outboxIRI, undo) | 
					
						
							| 
									
										
										
										
											2021-06-21 15:56:00 +02:00
										 |  |  | 	return err | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-22 16:05:26 +01:00
										 |  |  | func (p *Processor) federateAcceptFollowRequest(ctx context.Context, follow *gtsmodel.Follow) error { | 
					
						
							| 
									
										
										
										
											2021-10-16 13:27:43 +02:00
										 |  |  | 	if follow.Account == nil { | 
					
						
							| 
									
										
										
										
											2023-03-01 18:26:53 +00:00
										 |  |  | 		a, err := p.state.DB.GetAccountByID(ctx, follow.AccountID) | 
					
						
							| 
									
										
										
										
											2021-10-16 13:27:43 +02:00
										 |  |  | 		if err != nil { | 
					
						
							|  |  |  | 			return err | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		follow.Account = a | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	originAccount := follow.Account | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if follow.TargetAccount == nil { | 
					
						
							| 
									
										
										
										
											2023-03-01 18:26:53 +00:00
										 |  |  | 		a, err := p.state.DB.GetAccountByID(ctx, follow.TargetAccountID) | 
					
						
							| 
									
										
										
										
											2021-10-16 13:27:43 +02:00
										 |  |  | 		if err != nil { | 
					
						
							|  |  |  | 			return err | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		follow.TargetAccount = a | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	targetAccount := follow.TargetAccount | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-20 19:10:08 +01:00
										 |  |  | 	// Do nothing if target account *isn't* local, | 
					
						
							|  |  |  | 	// or both origin + target *are* local. | 
					
						
							|  |  |  | 	if targetAccount.IsRemote() || originAccount.IsLocal() { | 
					
						
							| 
									
										
										
										
											2021-05-21 15:48:26 +02:00
										 |  |  | 		return nil | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// recreate the AS follow | 
					
						
							| 
									
										
										
										
											2021-08-25 15:34:33 +02:00
										 |  |  | 	asFollow, err := p.tc.FollowToAS(ctx, follow, originAccount, targetAccount) | 
					
						
							| 
									
										
										
										
											2021-05-21 15:48:26 +02: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 15:34:33 +02:00
										 |  |  | 	_, err = p.federator.FederatingActor().Send(ctx, outboxIRI, accept) | 
					
						
							| 
									
										
										
										
											2021-05-21 15:48:26 +02:00
										 |  |  | 	return err | 
					
						
							| 
									
										
										
										
											2021-10-16 13:27:43 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-22 16:05:26 +01:00
										 |  |  | func (p *Processor) federateRejectFollowRequest(ctx context.Context, followRequest *gtsmodel.FollowRequest) error { | 
					
						
							| 
									
										
										
										
											2021-10-16 13:27:43 +02:00
										 |  |  | 	if followRequest.Account == nil { | 
					
						
							| 
									
										
										
										
											2023-03-01 18:26:53 +00:00
										 |  |  | 		a, err := p.state.DB.GetAccountByID(ctx, followRequest.AccountID) | 
					
						
							| 
									
										
										
										
											2021-10-16 13:27:43 +02:00
										 |  |  | 		if err != nil { | 
					
						
							|  |  |  | 			return err | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		followRequest.Account = a | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	originAccount := followRequest.Account | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if followRequest.TargetAccount == nil { | 
					
						
							| 
									
										
										
										
											2023-03-01 18:26:53 +00:00
										 |  |  | 		a, err := p.state.DB.GetAccountByID(ctx, followRequest.TargetAccountID) | 
					
						
							| 
									
										
										
										
											2021-10-16 13:27:43 +02:00
										 |  |  | 		if err != nil { | 
					
						
							|  |  |  | 			return err | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		followRequest.TargetAccount = a | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	targetAccount := followRequest.TargetAccount | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-20 19:10:08 +01:00
										 |  |  | 	// Do nothing if target account *isn't* local, | 
					
						
							|  |  |  | 	// or both origin + target *are* local. | 
					
						
							|  |  |  | 	if targetAccount.IsRemote() || originAccount.IsLocal() { | 
					
						
							| 
									
										
										
										
											2021-10-16 13:27:43 +02:00
										 |  |  | 		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 19:06:58 +02:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2021-05-24 18:49:48 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-22 16:05:26 +01:00
										 |  |  | func (p *Processor) federateFave(ctx context.Context, fave *gtsmodel.StatusFave, originAccount *gtsmodel.Account, targetAccount *gtsmodel.Account) error { | 
					
						
							| 
									
										
										
										
											2023-03-20 19:10:08 +01:00
										 |  |  | 	// Do nothing if both accounts are local. | 
					
						
							|  |  |  | 	if originAccount.IsLocal() && targetAccount.IsLocal() { | 
					
						
							| 
									
										
										
										
											2021-05-24 18:49:48 +02:00
										 |  |  | 		return nil | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// create the AS fave | 
					
						
							| 
									
										
										
										
											2021-08-25 15:34:33 +02:00
										 |  |  | 	asFave, err := p.tc.FaveToAS(ctx, fave) | 
					
						
							| 
									
										
										
										
											2021-05-24 18:49:48 +02: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 15:34:33 +02:00
										 |  |  | 	_, err = p.federator.FederatingActor().Send(ctx, outboxIRI, asFave) | 
					
						
							| 
									
										
										
										
											2021-05-24 18:49:48 +02:00
										 |  |  | 	return err | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2021-05-28 19:57:04 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-22 16:05:26 +01:00
										 |  |  | func (p *Processor) federateAnnounce(ctx context.Context, boostWrapperStatus *gtsmodel.Status, boostingAccount *gtsmodel.Account, boostedAccount *gtsmodel.Account) error { | 
					
						
							| 
									
										
										
										
											2021-08-25 15:34:33 +02:00
										 |  |  | 	announce, err := p.tc.BoostToAS(ctx, boostWrapperStatus, boostingAccount, boostedAccount) | 
					
						
							| 
									
										
										
										
											2021-05-28 19:57:04 +02: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 22:47:18 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-25 15:34:33 +02:00
										 |  |  | 	_, err = p.federator.FederatingActor().Send(ctx, outboxIRI, announce) | 
					
						
							| 
									
										
										
										
											2021-05-28 19:57:04 +02:00
										 |  |  | 	return err | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2021-05-28 22:47:18 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-22 16:05:26 +01:00
										 |  |  | func (p *Processor) federateAccountUpdate(ctx context.Context, updatedAccount *gtsmodel.Account, originAccount *gtsmodel.Account) error { | 
					
						
							| 
									
										
										
										
											2021-08-25 15:34:33 +02:00
										 |  |  | 	person, err := p.tc.AccountToAS(ctx, updatedAccount) | 
					
						
							| 
									
										
										
										
											2021-05-28 22:47:18 +02: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 15:34:33 +02:00
										 |  |  | 	_, err = p.federator.FederatingActor().Send(ctx, outboxIRI, update) | 
					
						
							| 
									
										
										
										
											2021-05-28 22:47:18 +02:00
										 |  |  | 	return err | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2021-07-11 16:22:21 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-22 16:05:26 +01:00
										 |  |  | func (p *Processor) federateBlock(ctx context.Context, block *gtsmodel.Block) error { | 
					
						
							| 
									
										
										
										
											2021-07-11 16:22:21 +02:00
										 |  |  | 	if block.Account == nil { | 
					
						
							| 
									
										
										
										
											2023-03-01 18:26:53 +00:00
										 |  |  | 		blockAccount, err := p.state.DB.GetAccountByID(ctx, block.AccountID) | 
					
						
							| 
									
										
										
										
											2021-08-25 15:34:33 +02:00
										 |  |  | 		if err != nil { | 
					
						
							| 
									
										
										
										
											2021-07-11 16:22:21 +02:00
										 |  |  | 			return fmt.Errorf("federateBlock: error getting block account from database: %s", err) | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2021-08-25 15:34:33 +02:00
										 |  |  | 		block.Account = blockAccount | 
					
						
							| 
									
										
										
										
											2021-07-11 16:22:21 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if block.TargetAccount == nil { | 
					
						
							| 
									
										
										
										
											2023-03-01 18:26:53 +00:00
										 |  |  | 		blockTargetAccount, err := p.state.DB.GetAccountByID(ctx, block.TargetAccountID) | 
					
						
							| 
									
										
										
										
											2021-08-25 15:34:33 +02:00
										 |  |  | 		if err != nil { | 
					
						
							| 
									
										
										
										
											2021-07-11 16:22:21 +02:00
										 |  |  | 			return fmt.Errorf("federateBlock: error getting block target account from database: %s", err) | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2021-08-25 15:34:33 +02:00
										 |  |  | 		block.TargetAccount = blockTargetAccount | 
					
						
							| 
									
										
										
										
											2021-07-11 16:22:21 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-20 19:10:08 +01:00
										 |  |  | 	// Do nothing if both accounts are local. | 
					
						
							|  |  |  | 	if block.Account.IsLocal() && block.TargetAccount.IsLocal() { | 
					
						
							| 
									
										
										
										
											2021-07-11 16:22:21 +02:00
										 |  |  | 		return nil | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-25 15:34:33 +02:00
										 |  |  | 	asBlock, err := p.tc.BlockToAS(ctx, block) | 
					
						
							| 
									
										
										
										
											2021-07-11 16:22:21 +02: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 15:34:33 +02:00
										 |  |  | 	_, err = p.federator.FederatingActor().Send(ctx, outboxIRI, asBlock) | 
					
						
							| 
									
										
										
										
											2021-07-11 16:22:21 +02:00
										 |  |  | 	return err | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-22 16:05:26 +01:00
										 |  |  | func (p *Processor) federateUnblock(ctx context.Context, block *gtsmodel.Block) error { | 
					
						
							| 
									
										
										
										
											2021-07-11 16:22:21 +02:00
										 |  |  | 	if block.Account == nil { | 
					
						
							| 
									
										
										
										
											2023-03-01 18:26:53 +00:00
										 |  |  | 		blockAccount, err := p.state.DB.GetAccountByID(ctx, block.AccountID) | 
					
						
							| 
									
										
										
										
											2021-08-25 15:34:33 +02:00
										 |  |  | 		if err != nil { | 
					
						
							| 
									
										
										
										
											2021-07-11 16:22:21 +02:00
										 |  |  | 			return fmt.Errorf("federateUnblock: error getting block account from database: %s", err) | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2021-08-25 15:34:33 +02:00
										 |  |  | 		block.Account = blockAccount | 
					
						
							| 
									
										
										
										
											2021-07-11 16:22:21 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if block.TargetAccount == nil { | 
					
						
							| 
									
										
										
										
											2023-03-01 18:26:53 +00:00
										 |  |  | 		blockTargetAccount, err := p.state.DB.GetAccountByID(ctx, block.TargetAccountID) | 
					
						
							| 
									
										
										
										
											2021-08-25 15:34:33 +02:00
										 |  |  | 		if err != nil { | 
					
						
							| 
									
										
										
										
											2021-07-11 16:22:21 +02:00
										 |  |  | 			return fmt.Errorf("federateUnblock: error getting block target account from database: %s", err) | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2021-08-25 15:34:33 +02:00
										 |  |  | 		block.TargetAccount = blockTargetAccount | 
					
						
							| 
									
										
										
										
											2021-07-11 16:22:21 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-20 19:10:08 +01:00
										 |  |  | 	// Do nothing if both accounts are local. | 
					
						
							|  |  |  | 	if block.Account.IsLocal() && block.TargetAccount.IsLocal() { | 
					
						
							| 
									
										
										
										
											2021-07-11 16:22:21 +02:00
										 |  |  | 		return nil | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-25 15:34:33 +02:00
										 |  |  | 	asBlock, err := p.tc.BlockToAS(ctx, block) | 
					
						
							| 
									
										
										
										
											2021-07-11 16:22:21 +02: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 15:34:33 +02:00
										 |  |  | 	_, err = p.federator.FederatingActor().Send(ctx, outboxIRI, undo) | 
					
						
							| 
									
										
										
										
											2021-07-11 16:22:21 +02:00
										 |  |  | 	return err | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2023-01-27 14:48:11 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-22 16:05:26 +01:00
										 |  |  | func (p *Processor) federateReport(ctx context.Context, report *gtsmodel.Report) error { | 
					
						
							| 
									
										
										
										
											2023-01-27 14:48:11 +01:00
										 |  |  | 	if report.TargetAccount == nil { | 
					
						
							| 
									
										
										
										
											2023-03-01 18:26:53 +00:00
										 |  |  | 		reportTargetAccount, err := p.state.DB.GetAccountByID(ctx, report.TargetAccountID) | 
					
						
							| 
									
										
										
										
											2023-01-27 14:48:11 +01:00
										 |  |  | 		if err != nil { | 
					
						
							|  |  |  | 			return fmt.Errorf("federateReport: error getting report target account from database: %w", err) | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		report.TargetAccount = reportTargetAccount | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if len(report.StatusIDs) > 0 && len(report.Statuses) == 0 { | 
					
						
							| 
									
										
										
										
											2023-03-01 18:26:53 +00:00
										 |  |  | 		statuses, err := p.state.DB.GetStatuses(ctx, report.StatusIDs) | 
					
						
							| 
									
										
										
										
											2023-01-27 14:48:11 +01:00
										 |  |  | 		if err != nil { | 
					
						
							|  |  |  | 			return fmt.Errorf("federateReport: error getting report statuses from database: %w", err) | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		report.Statuses = statuses | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	flag, err := p.tc.ReportToASFlag(ctx, report) | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		return fmt.Errorf("federateReport: error converting report to AS flag: %w", err) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// add bto so that our federating actor knows where to | 
					
						
							|  |  |  | 	// send the Flag; it'll still use a shared inbox if possible | 
					
						
							|  |  |  | 	reportTargetURI, err := url.Parse(report.TargetAccount.URI) | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		return fmt.Errorf("federateReport: error parsing outboxURI %s: %w", report.TargetAccount.URI, err) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	bTo := streams.NewActivityStreamsBtoProperty() | 
					
						
							|  |  |  | 	bTo.AppendIRI(reportTargetURI) | 
					
						
							|  |  |  | 	flag.SetActivityStreamsBto(bTo) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// deliver the flag using the outbox of the | 
					
						
							|  |  |  | 	// instance account to anonymize the report | 
					
						
							| 
									
										
										
										
											2023-03-01 18:26:53 +00:00
										 |  |  | 	instanceAccount, err := p.state.DB.GetInstanceAccount(ctx, "") | 
					
						
							| 
									
										
										
										
											2023-01-27 14:48:11 +01:00
										 |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		return fmt.Errorf("federateReport: error getting instance account: %w", err) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	outboxIRI, err := url.Parse(instanceAccount.OutboxURI) | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		return fmt.Errorf("federateReport: error parsing outboxURI %s: %w", instanceAccount.OutboxURI, err) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	_, err = p.federator.FederatingActor().Send(ctx, outboxIRI, flag) | 
					
						
							|  |  |  | 	return err | 
					
						
							|  |  |  | } |