| 
									
										
										
										
											2023-08-09 19:14:33 +02: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/>. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | package workers | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import ( | 
					
						
							|  |  |  | 	"context" | 
					
						
							|  |  |  | 	"errors" | 
					
						
							| 
									
										
										
										
											2024-08-24 11:49:37 +02:00
										 |  |  | 	"time" | 
					
						
							| 
									
										
										
										
											2023-08-09 19:14:33 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-04-26 15:34:10 +02:00
										 |  |  | 	"code.superseriousbusiness.org/gotosocial/internal/ap" | 
					
						
							|  |  |  | 	"code.superseriousbusiness.org/gotosocial/internal/db" | 
					
						
							|  |  |  | 	"code.superseriousbusiness.org/gotosocial/internal/gtscontext" | 
					
						
							|  |  |  | 	"code.superseriousbusiness.org/gotosocial/internal/gtserror" | 
					
						
							|  |  |  | 	"code.superseriousbusiness.org/gotosocial/internal/gtsmodel" | 
					
						
							|  |  |  | 	"code.superseriousbusiness.org/gotosocial/internal/id" | 
					
						
							|  |  |  | 	"code.superseriousbusiness.org/gotosocial/internal/log" | 
					
						
							|  |  |  | 	"code.superseriousbusiness.org/gotosocial/internal/messages" | 
					
						
							|  |  |  | 	"code.superseriousbusiness.org/gotosocial/internal/processing/account" | 
					
						
							|  |  |  | 	"code.superseriousbusiness.org/gotosocial/internal/processing/common" | 
					
						
							|  |  |  | 	"code.superseriousbusiness.org/gotosocial/internal/state" | 
					
						
							|  |  |  | 	"code.superseriousbusiness.org/gotosocial/internal/typeutils" | 
					
						
							|  |  |  | 	"code.superseriousbusiness.org/gotosocial/internal/uris" | 
					
						
							|  |  |  | 	"code.superseriousbusiness.org/gotosocial/internal/util" | 
					
						
							| 
									
										
										
										
											2023-08-09 19:14:33 +02:00
										 |  |  | 	"codeberg.org/gruf/go-kv" | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // clientAPI wraps processing functions | 
					
						
							|  |  |  | // specifically for messages originating | 
					
						
							|  |  |  | // from the client/REST API. | 
					
						
							|  |  |  | type clientAPI struct { | 
					
						
							| 
									
										
										
										
											2024-03-13 13:53:29 +01:00
										 |  |  | 	state     *state.State | 
					
						
							|  |  |  | 	converter *typeutils.Converter | 
					
						
							| 
									
										
										
										
											2024-05-02 14:43:00 +02:00
										 |  |  | 	surface   *Surface | 
					
						
							| 
									
										
										
										
											2024-03-13 13:53:29 +01:00
										 |  |  | 	federate  *federate | 
					
						
							|  |  |  | 	account   *account.Processor | 
					
						
							| 
									
										
										
										
											2024-08-24 11:49:37 +02:00
										 |  |  | 	common    *common.Processor | 
					
						
							| 
									
										
										
										
											2024-04-26 13:50:46 +01:00
										 |  |  | 	utils     *utils | 
					
						
							| 
									
										
										
										
											2023-08-09 19:14:33 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-26 13:50:46 +01:00
										 |  |  | func (p *Processor) ProcessFromClientAPI(ctx context.Context, cMsg *messages.FromClientAPI) error { | 
					
						
							| 
									
										
										
										
											2023-08-09 19:14:33 +02:00
										 |  |  | 	// Allocate new log fields slice | 
					
						
							|  |  |  | 	fields := make([]kv.Field, 3, 4) | 
					
						
							|  |  |  | 	fields[0] = kv.Field{"activityType", cMsg.APActivityType} | 
					
						
							|  |  |  | 	fields[1] = kv.Field{"objectType", cMsg.APObjectType} | 
					
						
							| 
									
										
										
										
											2024-04-26 13:50:46 +01:00
										 |  |  | 	fields[2] = kv.Field{"fromAccount", cMsg.Origin.Username} | 
					
						
							| 
									
										
										
										
											2023-08-09 19:14:33 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// Include GTSModel in logs if appropriate. | 
					
						
							|  |  |  | 	if cMsg.GTSModel != nil && | 
					
						
							| 
									
										
										
										
											2024-09-20 13:30:33 +00:00
										 |  |  | 		log.Level() >= log.DEBUG { | 
					
						
							| 
									
										
										
										
											2023-08-09 19:14:33 +02:00
										 |  |  | 		fields = append(fields, kv.Field{ | 
					
						
							|  |  |  | 			"model", cMsg.GTSModel, | 
					
						
							|  |  |  | 		}) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	l := log.WithContext(ctx).WithFields(fields...) | 
					
						
							|  |  |  | 	l.Info("processing from client API") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	switch cMsg.APActivityType { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// CREATE SOMETHING | 
					
						
							|  |  |  | 	case ap.ActivityCreate: | 
					
						
							|  |  |  | 		switch cMsg.APObjectType { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-06-06 15:43:25 +02:00
										 |  |  | 		// CREATE USER (ie., new user+account sign-up) | 
					
						
							|  |  |  | 		case ap.ObjectProfile: | 
					
						
							|  |  |  | 			return p.clientAPI.CreateUser(ctx, cMsg) | 
					
						
							| 
									
										
										
										
											2023-08-09 19:14:33 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		// CREATE NOTE/STATUS | 
					
						
							|  |  |  | 		case ap.ObjectNote: | 
					
						
							|  |  |  | 			return p.clientAPI.CreateStatus(ctx, cMsg) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-08 14:32:17 +00:00
										 |  |  | 		// CREATE QUESTION | 
					
						
							|  |  |  | 		// (note we don't handle poll *votes* as AS | 
					
						
							|  |  |  | 		// question type when federating (just notes), | 
					
						
							|  |  |  | 		// but it makes for a nicer type switch here. | 
					
						
							|  |  |  | 		case ap.ActivityQuestion: | 
					
						
							|  |  |  | 			return p.clientAPI.CreatePollVote(ctx, cMsg) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-09 19:14:33 +02:00
										 |  |  | 		// CREATE FOLLOW (request) | 
					
						
							|  |  |  | 		case ap.ActivityFollow: | 
					
						
							|  |  |  | 			return p.clientAPI.CreateFollowReq(ctx, cMsg) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// CREATE LIKE/FAVE | 
					
						
							|  |  |  | 		case ap.ActivityLike: | 
					
						
							|  |  |  | 			return p.clientAPI.CreateLike(ctx, cMsg) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// CREATE ANNOUNCE/BOOST | 
					
						
							|  |  |  | 		case ap.ActivityAnnounce: | 
					
						
							|  |  |  | 			return p.clientAPI.CreateAnnounce(ctx, cMsg) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// CREATE BLOCK | 
					
						
							|  |  |  | 		case ap.ActivityBlock: | 
					
						
							|  |  |  | 			return p.clientAPI.CreateBlock(ctx, cMsg) | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// UPDATE SOMETHING | 
					
						
							|  |  |  | 	case ap.ActivityUpdate: | 
					
						
							|  |  |  | 		switch cMsg.APObjectType { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-04 13:09:42 +01:00
										 |  |  | 		// UPDATE NOTE/STATUS | 
					
						
							|  |  |  | 		case ap.ObjectNote: | 
					
						
							|  |  |  | 			return p.clientAPI.UpdateStatus(ctx, cMsg) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-06-06 15:43:25 +02:00
										 |  |  | 		// UPDATE ACCOUNT (ie., bio, settings, etc) | 
					
						
							|  |  |  | 		case ap.ActorPerson: | 
					
						
							| 
									
										
										
										
											2023-08-09 19:14:33 +02:00
										 |  |  | 			return p.clientAPI.UpdateAccount(ctx, cMsg) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// UPDATE A FLAG/REPORT (mark as resolved/closed) | 
					
						
							|  |  |  | 		case ap.ActivityFlag: | 
					
						
							|  |  |  | 			return p.clientAPI.UpdateReport(ctx, cMsg) | 
					
						
							| 
									
										
										
										
											2024-06-06 15:43:25 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		// UPDATE USER (ie., email address) | 
					
						
							|  |  |  | 		case ap.ObjectProfile: | 
					
						
							|  |  |  | 			return p.clientAPI.UpdateUser(ctx, cMsg) | 
					
						
							| 
									
										
										
										
											2023-08-09 19:14:33 +02:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// ACCEPT SOMETHING | 
					
						
							|  |  |  | 	case ap.ActivityAccept: | 
					
						
							|  |  |  | 		switch cMsg.APObjectType { //nolint:gocritic | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// ACCEPT FOLLOW (request) | 
					
						
							|  |  |  | 		case ap.ActivityFollow: | 
					
						
							|  |  |  | 			return p.clientAPI.AcceptFollow(ctx, cMsg) | 
					
						
							| 
									
										
										
										
											2024-04-13 13:25:10 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-06-06 15:43:25 +02:00
										 |  |  | 		// ACCEPT USER (ie., new user+account sign-up) | 
					
						
							|  |  |  | 		case ap.ObjectProfile: | 
					
						
							|  |  |  | 			return p.clientAPI.AcceptUser(ctx, cMsg) | 
					
						
							| 
									
										
										
										
											2024-07-26 12:04:28 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		// ACCEPT NOTE/STATUS (ie., accept a reply) | 
					
						
							|  |  |  | 		case ap.ObjectNote: | 
					
						
							|  |  |  | 			return p.clientAPI.AcceptReply(ctx, cMsg) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// ACCEPT LIKE | 
					
						
							|  |  |  | 		case ap.ActivityLike: | 
					
						
							|  |  |  | 			return p.clientAPI.AcceptLike(ctx, cMsg) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// ACCEPT BOOST | 
					
						
							|  |  |  | 		case ap.ActivityAnnounce: | 
					
						
							|  |  |  | 			return p.clientAPI.AcceptAnnounce(ctx, cMsg) | 
					
						
							| 
									
										
										
										
											2023-08-09 19:14:33 +02:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// REJECT SOMETHING | 
					
						
							|  |  |  | 	case ap.ActivityReject: | 
					
						
							|  |  |  | 		switch cMsg.APObjectType { //nolint:gocritic | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// REJECT FOLLOW (request) | 
					
						
							|  |  |  | 		case ap.ActivityFollow: | 
					
						
							|  |  |  | 			return p.clientAPI.RejectFollowRequest(ctx, cMsg) | 
					
						
							| 
									
										
										
										
											2024-04-13 13:25:10 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-06-06 15:43:25 +02:00
										 |  |  | 		// REJECT USER (ie., new user+account sign-up) | 
					
						
							|  |  |  | 		case ap.ObjectProfile: | 
					
						
							|  |  |  | 			return p.clientAPI.RejectUser(ctx, cMsg) | 
					
						
							| 
									
										
										
										
											2024-08-24 11:49:37 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		// REJECT NOTE/STATUS (ie., reject a reply) | 
					
						
							|  |  |  | 		case ap.ObjectNote: | 
					
						
							|  |  |  | 			return p.clientAPI.RejectReply(ctx, cMsg) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// REJECT LIKE | 
					
						
							|  |  |  | 		case ap.ActivityLike: | 
					
						
							|  |  |  | 			return p.clientAPI.RejectLike(ctx, cMsg) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// REJECT BOOST | 
					
						
							|  |  |  | 		case ap.ActivityAnnounce: | 
					
						
							|  |  |  | 			return p.clientAPI.RejectAnnounce(ctx, cMsg) | 
					
						
							| 
									
										
										
										
											2023-08-09 19:14:33 +02:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// UNDO SOMETHING | 
					
						
							|  |  |  | 	case ap.ActivityUndo: | 
					
						
							|  |  |  | 		switch cMsg.APObjectType { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// UNDO FOLLOW (request) | 
					
						
							|  |  |  | 		case ap.ActivityFollow: | 
					
						
							|  |  |  | 			return p.clientAPI.UndoFollow(ctx, cMsg) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// UNDO BLOCK | 
					
						
							|  |  |  | 		case ap.ActivityBlock: | 
					
						
							|  |  |  | 			return p.clientAPI.UndoBlock(ctx, cMsg) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// UNDO LIKE/FAVE | 
					
						
							|  |  |  | 		case ap.ActivityLike: | 
					
						
							|  |  |  | 			return p.clientAPI.UndoFave(ctx, cMsg) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// UNDO ANNOUNCE/BOOST | 
					
						
							|  |  |  | 		case ap.ActivityAnnounce: | 
					
						
							|  |  |  | 			return p.clientAPI.UndoAnnounce(ctx, cMsg) | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// DELETE SOMETHING | 
					
						
							|  |  |  | 	case ap.ActivityDelete: | 
					
						
							|  |  |  | 		switch cMsg.APObjectType { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// DELETE NOTE/STATUS | 
					
						
							|  |  |  | 		case ap.ObjectNote: | 
					
						
							|  |  |  | 			return p.clientAPI.DeleteStatus(ctx, cMsg) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-06-06 15:43:25 +02:00
										 |  |  | 		// DELETE REMOTE ACCOUNT or LOCAL USER+ACCOUNT | 
					
						
							|  |  |  | 		case ap.ActorPerson, ap.ObjectProfile: | 
					
						
							|  |  |  | 			return p.clientAPI.DeleteAccountOrUser(ctx, cMsg) | 
					
						
							| 
									
										
										
										
											2023-08-09 19:14:33 +02:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// FLAG/REPORT SOMETHING | 
					
						
							|  |  |  | 	case ap.ActivityFlag: | 
					
						
							|  |  |  | 		switch cMsg.APObjectType { //nolint:gocritic | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-06-06 15:43:25 +02:00
										 |  |  | 		// FLAG/REPORT ACCOUNT | 
					
						
							|  |  |  | 		case ap.ActorPerson: | 
					
						
							| 
									
										
										
										
											2023-08-09 19:14:33 +02:00
										 |  |  | 			return p.clientAPI.ReportAccount(ctx, cMsg) | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2024-03-13 13:53:29 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// MOVE SOMETHING | 
					
						
							|  |  |  | 	case ap.ActivityMove: | 
					
						
							|  |  |  | 		switch cMsg.APObjectType { //nolint:gocritic | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-06-06 15:43:25 +02:00
										 |  |  | 		// MOVE ACCOUNT | 
					
						
							|  |  |  | 		case ap.ActorPerson: | 
					
						
							| 
									
										
										
										
											2024-03-13 13:53:29 +01:00
										 |  |  | 			return p.clientAPI.MoveAccount(ctx, cMsg) | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2023-08-09 19:14:33 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-08 14:32:17 +00:00
										 |  |  | 	return gtserror.Newf("unhandled: %s %s", cMsg.APActivityType, cMsg.APObjectType) | 
					
						
							| 
									
										
										
										
											2023-08-09 19:14:33 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-06-06 15:43:25 +02:00
										 |  |  | func (p *clientAPI) CreateUser(ctx context.Context, cMsg *messages.FromClientAPI) error { | 
					
						
							| 
									
										
										
										
											2024-04-11 11:45:53 +02:00
										 |  |  | 	newUser, ok := cMsg.GTSModel.(*gtsmodel.User) | 
					
						
							| 
									
										
										
										
											2023-08-09 19:14:33 +02:00
										 |  |  | 	if !ok { | 
					
						
							| 
									
										
										
										
											2024-04-11 11:45:53 +02:00
										 |  |  | 		return gtserror.Newf("%T not parseable as *gtsmodel.User", cMsg.GTSModel) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Notify mods of the new signup. | 
					
						
							|  |  |  | 	if err := p.surface.notifySignup(ctx, newUser); err != nil { | 
					
						
							|  |  |  | 		log.Errorf(ctx, "error notifying mods of new sign-up: %v", err) | 
					
						
							| 
									
										
										
										
											2023-08-09 19:14:33 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-11 11:45:53 +02:00
										 |  |  | 	// Send "new sign up" email to mods. | 
					
						
							|  |  |  | 	if err := p.surface.emailAdminNewSignup(ctx, newUser); err != nil { | 
					
						
							|  |  |  | 		log.Errorf(ctx, "error emailing new signup: %v", err) | 
					
						
							| 
									
										
										
										
											2023-08-09 19:14:33 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-11 11:45:53 +02:00
										 |  |  | 	// Send "please confirm your address" email to the new user. | 
					
						
							| 
									
										
										
										
											2024-06-06 15:43:25 +02:00
										 |  |  | 	if err := p.surface.emailUserPleaseConfirm(ctx, newUser, true); err != nil { | 
					
						
							| 
									
										
										
										
											2023-11-08 14:32:17 +00:00
										 |  |  | 		log.Errorf(ctx, "error emailing confirm: %v", err) | 
					
						
							| 
									
										
										
										
											2023-08-09 19:14:33 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return nil | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-26 13:50:46 +01:00
										 |  |  | func (p *clientAPI) CreateStatus(ctx context.Context, cMsg *messages.FromClientAPI) error { | 
					
						
							| 
									
										
										
										
											2025-02-12 09:49:33 -08:00
										 |  |  | 	var status *gtsmodel.Status | 
					
						
							| 
									
										
										
										
											2025-02-17 11:44:41 +00:00
										 |  |  | 	var backfill bool | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Check passed client message model type. | 
					
						
							|  |  |  | 	switch model := cMsg.GTSModel.(type) { | 
					
						
							|  |  |  | 	case *gtsmodel.Status: | 
					
						
							|  |  |  | 		status = model | 
					
						
							|  |  |  | 	case *gtsmodel.BackfillStatus: | 
					
						
							|  |  |  | 		status = model.Status | 
					
						
							| 
									
										
										
										
											2025-02-12 09:49:33 -08:00
										 |  |  | 		backfill = true | 
					
						
							| 
									
										
										
										
											2025-02-17 11:44:41 +00:00
										 |  |  | 	default: | 
					
						
							|  |  |  | 		return gtserror.Newf("%T not parseable as *gtsmodel.Status or *gtsmodel.BackfillStatus", cMsg.GTSModel) | 
					
						
							| 
									
										
										
										
											2023-08-09 19:14:33 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-07-26 12:04:28 +02:00
										 |  |  | 	// If pending approval is true then status must | 
					
						
							|  |  |  | 	// reply to a status (either one of ours or a | 
					
						
							|  |  |  | 	// remote) that requires approval for the reply. | 
					
						
							| 
									
										
										
										
											2024-08-11 09:23:36 +00:00
										 |  |  | 	pendingApproval := util.PtrOrZero(status.PendingApproval) | 
					
						
							| 
									
										
										
										
											2024-07-26 12:04:28 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	switch { | 
					
						
							|  |  |  | 	case pendingApproval && !status.PreApproved: | 
					
						
							|  |  |  | 		// If approval is required and status isn't | 
					
						
							|  |  |  | 		// preapproved, then send out the Create to | 
					
						
							|  |  |  | 		// only the replied-to account (if it's remote), | 
					
						
							|  |  |  | 		// and/or notify the account that's being | 
					
						
							|  |  |  | 		// interacted with (if it's local): they can | 
					
						
							|  |  |  | 		// approve or deny the interaction later. | 
					
						
							| 
									
										
										
										
											2024-08-24 11:49:37 +02:00
										 |  |  | 		if err := p.utils.requestReply(ctx, status); err != nil { | 
					
						
							|  |  |  | 			return gtserror.Newf("error pending reply: %w", err) | 
					
						
							| 
									
										
										
										
											2024-07-26 12:04:28 +02:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// Send Create to *remote* account inbox ONLY. | 
					
						
							|  |  |  | 		if err := p.federate.CreateStatus(ctx, status); err != nil { | 
					
						
							| 
									
										
										
										
											2024-08-24 11:49:37 +02:00
										 |  |  | 			return gtserror.Newf("error federating pending reply: %w", err) | 
					
						
							| 
									
										
										
										
											2024-07-26 12:04:28 +02:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// Return early. | 
					
						
							|  |  |  | 		return nil | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	case pendingApproval && status.PreApproved: | 
					
						
							|  |  |  | 		// If approval is required and status is | 
					
						
							|  |  |  | 		// preapproved, that means this is a reply | 
					
						
							|  |  |  | 		// to one of our statuses with permission | 
					
						
							|  |  |  | 		// that matched on a following/followers | 
					
						
							|  |  |  | 		// collection. Do the Accept immediately and | 
					
						
							|  |  |  | 		// then process everything else as normal, | 
					
						
							|  |  |  | 		// sending out the Create with the approval | 
					
						
							|  |  |  | 		// URI attached. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-24 11:49:37 +02:00
										 |  |  | 		// Store an already-accepted interaction request. | 
					
						
							|  |  |  | 		id := id.NewULID() | 
					
						
							|  |  |  | 		approval := >smodel.InteractionRequest{ | 
					
						
							|  |  |  | 			ID:                   id, | 
					
						
							|  |  |  | 			StatusID:             status.InReplyToID, | 
					
						
							|  |  |  | 			TargetAccountID:      status.InReplyToAccountID, | 
					
						
							|  |  |  | 			TargetAccount:        status.InReplyToAccount, | 
					
						
							|  |  |  | 			InteractingAccountID: status.AccountID, | 
					
						
							|  |  |  | 			InteractingAccount:   status.Account, | 
					
						
							|  |  |  | 			InteractionURI:       status.URI, | 
					
						
							|  |  |  | 			InteractionType:      gtsmodel.InteractionLike, | 
					
						
							|  |  |  | 			Reply:                status, | 
					
						
							|  |  |  | 			URI:                  uris.GenerateURIForAccept(status.InReplyToAccount.Username, id), | 
					
						
							|  |  |  | 			AcceptedAt:           time.Now(), | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		if err := p.state.DB.PutInteractionRequest(ctx, approval); err != nil { | 
					
						
							|  |  |  | 			return gtserror.Newf("db error putting pre-approved interaction request: %w", err) | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// Mark the status as now approved. | 
					
						
							|  |  |  | 		status.PendingApproval = util.Ptr(false) | 
					
						
							|  |  |  | 		status.PreApproved = false | 
					
						
							|  |  |  | 		status.ApprovedByURI = approval.URI | 
					
						
							|  |  |  | 		if err := p.state.DB.UpdateStatus( | 
					
						
							|  |  |  | 			ctx, | 
					
						
							|  |  |  | 			status, | 
					
						
							|  |  |  | 			"pending_approval", | 
					
						
							|  |  |  | 			"approved_by_uri", | 
					
						
							|  |  |  | 		); err != nil { | 
					
						
							|  |  |  | 			return gtserror.Newf("db error updating status: %w", err) | 
					
						
							| 
									
										
										
										
											2024-07-26 12:04:28 +02:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if err := p.federate.AcceptInteraction(ctx, approval); err != nil { | 
					
						
							|  |  |  | 			return gtserror.Newf("error federating pre-approval of reply: %w", err) | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// Don't return, just continue as normal. | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-16 13:10:13 +02:00
										 |  |  | 	// Update stats for the actor account. | 
					
						
							| 
									
										
										
										
											2024-04-26 13:50:46 +01:00
										 |  |  | 	if err := p.utils.incrementStatusesCount(ctx, cMsg.Origin, status); err != nil { | 
					
						
							| 
									
										
										
										
											2024-04-16 13:10:13 +02:00
										 |  |  | 		log.Errorf(ctx, "error updating account stats: %v", err) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-02-17 11:44:41 +00:00
										 |  |  | 	// We specifically do not timeline | 
					
						
							|  |  |  | 	// or notify for backfilled statuses, | 
					
						
							|  |  |  | 	// as these are more for archival than | 
					
						
							|  |  |  | 	// newly posted content for user feeds. | 
					
						
							| 
									
										
										
										
											2025-02-12 09:49:33 -08:00
										 |  |  | 	if !backfill { | 
					
						
							| 
									
										
										
										
											2025-02-17 11:44:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-02-12 09:49:33 -08:00
										 |  |  | 		if err := p.surface.timelineAndNotifyStatus(ctx, status); err != nil { | 
					
						
							|  |  |  | 			log.Errorf(ctx, "error timelining and notifying status: %v", err) | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2023-08-09 19:14:33 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-02-12 09:49:33 -08:00
										 |  |  | 		if err := p.federate.CreateStatus(ctx, status); err != nil { | 
					
						
							|  |  |  | 			log.Errorf(ctx, "error federating status: %v", err) | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2024-08-24 11:49:37 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-09 19:14:33 +02:00
										 |  |  | 	if status.InReplyToID != "" { | 
					
						
							|  |  |  | 		// Interaction counts changed on the replied status; | 
					
						
							|  |  |  | 		// uncache the prepared version from all timelines. | 
					
						
							| 
									
										
											  
											
												[performance] rewrite timelines to rely on new timeline cache type (#3941)
* start work rewriting timeline cache type
* further work rewriting timeline caching
* more work integration new timeline code
* remove old code
* add local timeline, fix up merge conflicts
* remove old use of go-bytes
* implement new timeline code into more areas of codebase, pull in latest go-mangler, go-mutexes, go-structr
* remove old timeline package, add local timeline cache
* remove references to old timeline types that needed starting up in tests
* start adding page validation
* fix test-identified timeline cache package issues
* fix up more tests, fix missing required changes, etc
* add exclusion for test.out in gitignore
* clarify some things better in code comments
* tweak cache size limits
* fix list timeline cache fetching
* further list timeline fixes
* linter, ssssssssshhhhhhhhhhhh please
* fix linter hints
* reslice the output if it's beyond length of 'lim'
* remove old timeline initialization code, bump go-structr to v0.9.4
* continued from previous commit
* improved code comments
* don't allow multiple entries for BoostOfID values to prevent repeated boosts of same boosts
* finish writing more code comments
* some variable renaming, for ease of following
* change the way we update lo,hi paging values during timeline load
* improved code comments for updated / returned lo , hi paging values
* finish writing code comments for the StatusTimeline{} type itself
* fill in more code comments
* update go-structr version to latest with changed timeline unique indexing logic
* have a local and public timeline *per user*
* rewrite calls to public / local timeline calls
* remove the zero length check, as lo, hi values might still be set
* simplify timeline cache loading, fix lo/hi returns, fix timeline invalidation side-effects missing for some federated actions
* swap the lo, hi values :facepalm:
* add (now) missing slice reverse of tag timeline statuses when paging ASC
* remove local / public caches (is out of scope for this work), share more timeline code
* remove unnecessary change
* again, remove more unused code
* remove unused function to appease the linter
* move boost checking to prepare function
* fix use of timeline.lastOrder, fix incorrect range functions used
* remove comments for repeat code
* remove the boost logic from prepare function
* do a maximum of 5 loads, not 10
* add repeat boost filtering logic, update go-structr, general improvements
* more code comments
* add important note
* fix timeline tests now that timelines are returned in page order
* remove unused field
* add StatusTimeline{} tests
* add more status timeline tests
* start adding preloading support
* ensure repeat boosts are marked in preloaded entries
* share a bunch of the database load code in timeline cache, don't clear timelines on relationship change
* add logic to allow dynamic clear / preloading of timelines
* comment-out unused functions, but leave in place as we might end-up using them
* fix timeline preload state check
* much improved status timeline code comments
* more code comments, don't bother inserting statuses if timeline not preloaded
* shift around some logic to make sure things aren't accidentally left set
* finish writing code comments
* remove trim-after-insert behaviour
* fix-up some comments referring to old logic
* remove unsetting of lo, hi
* fix preload repeatBoost checking logic
* don't return on status filter errors, these are usually transient
* better concurrency safety in Clear() and Done()
* fix test broken due to addition of preloader
* fix repeatBoost logic that doesn't account for already-hidden repeatBoosts
* ensure edit submodels are dropped on cache insertion
* update code-comment to expand CAS accronym
* use a plus1hULID() instead of 24h
* remove unused functions
* add note that public / local timeline requester can be nil
* fix incorrect visibility filtering of tag timeline statuses
* ensure we filter home timeline statuses on local only
* some small re-orderings to confirm query params in correct places
* fix the local only home timeline filter func
											
										 
											2025-04-26 09:56:15 +00:00
										 |  |  | 		p.surface.invalidateStatusFromTimelines(status.InReplyToID) | 
					
						
							| 
									
										
										
										
											2023-08-09 19:14:33 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-08 14:32:17 +00:00
										 |  |  | 	return nil | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-26 13:50:46 +01:00
										 |  |  | func (p *clientAPI) CreatePollVote(ctx context.Context, cMsg *messages.FromClientAPI) error { | 
					
						
							| 
									
										
										
										
											2023-11-08 14:32:17 +00:00
										 |  |  | 	// Cast the create poll vote attached to message. | 
					
						
							|  |  |  | 	vote, ok := cMsg.GTSModel.(*gtsmodel.PollVote) | 
					
						
							|  |  |  | 	if !ok { | 
					
						
							|  |  |  | 		return gtserror.Newf("cannot cast %T -> *gtsmodel.Pollvote", cMsg.GTSModel) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Ensure the vote is fully populated in order to get original poll. | 
					
						
							|  |  |  | 	if err := p.state.DB.PopulatePollVote(ctx, vote); err != nil { | 
					
						
							|  |  |  | 		return gtserror.Newf("error populating poll vote from db: %w", err) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Ensure the poll on the vote is fully populated to get origin status. | 
					
						
							|  |  |  | 	if err := p.state.DB.PopulatePoll(ctx, vote.Poll); err != nil { | 
					
						
							|  |  |  | 		return gtserror.Newf("error populating poll from db: %w", err) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Get the origin status, | 
					
						
							|  |  |  | 	// (also set the poll on it). | 
					
						
							|  |  |  | 	status := vote.Poll.Status | 
					
						
							|  |  |  | 	status.Poll = vote.Poll | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if *status.Local { | 
					
						
							|  |  |  | 		// These are poll votes in a local status, we only need to | 
					
						
							|  |  |  | 		// federate the updated status model with latest vote counts. | 
					
						
							|  |  |  | 		if err := p.federate.UpdateStatus(ctx, status); err != nil { | 
					
						
							|  |  |  | 			log.Errorf(ctx, "error federating status update: %v", err) | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		// These are votes in a remote poll, federate to origin the new poll vote(s). | 
					
						
							|  |  |  | 		if err := p.federate.CreatePollVote(ctx, vote.Poll, vote); err != nil { | 
					
						
							|  |  |  | 			log.Errorf(ctx, "error federating poll vote: %v", err) | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2023-08-09 19:14:33 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-24 11:49:37 +02:00
										 |  |  | 	// Interaction counts changed on the source status, uncache from timelines. | 
					
						
							| 
									
										
											  
											
												[performance] rewrite timelines to rely on new timeline cache type (#3941)
* start work rewriting timeline cache type
* further work rewriting timeline caching
* more work integration new timeline code
* remove old code
* add local timeline, fix up merge conflicts
* remove old use of go-bytes
* implement new timeline code into more areas of codebase, pull in latest go-mangler, go-mutexes, go-structr
* remove old timeline package, add local timeline cache
* remove references to old timeline types that needed starting up in tests
* start adding page validation
* fix test-identified timeline cache package issues
* fix up more tests, fix missing required changes, etc
* add exclusion for test.out in gitignore
* clarify some things better in code comments
* tweak cache size limits
* fix list timeline cache fetching
* further list timeline fixes
* linter, ssssssssshhhhhhhhhhhh please
* fix linter hints
* reslice the output if it's beyond length of 'lim'
* remove old timeline initialization code, bump go-structr to v0.9.4
* continued from previous commit
* improved code comments
* don't allow multiple entries for BoostOfID values to prevent repeated boosts of same boosts
* finish writing more code comments
* some variable renaming, for ease of following
* change the way we update lo,hi paging values during timeline load
* improved code comments for updated / returned lo , hi paging values
* finish writing code comments for the StatusTimeline{} type itself
* fill in more code comments
* update go-structr version to latest with changed timeline unique indexing logic
* have a local and public timeline *per user*
* rewrite calls to public / local timeline calls
* remove the zero length check, as lo, hi values might still be set
* simplify timeline cache loading, fix lo/hi returns, fix timeline invalidation side-effects missing for some federated actions
* swap the lo, hi values :facepalm:
* add (now) missing slice reverse of tag timeline statuses when paging ASC
* remove local / public caches (is out of scope for this work), share more timeline code
* remove unnecessary change
* again, remove more unused code
* remove unused function to appease the linter
* move boost checking to prepare function
* fix use of timeline.lastOrder, fix incorrect range functions used
* remove comments for repeat code
* remove the boost logic from prepare function
* do a maximum of 5 loads, not 10
* add repeat boost filtering logic, update go-structr, general improvements
* more code comments
* add important note
* fix timeline tests now that timelines are returned in page order
* remove unused field
* add StatusTimeline{} tests
* add more status timeline tests
* start adding preloading support
* ensure repeat boosts are marked in preloaded entries
* share a bunch of the database load code in timeline cache, don't clear timelines on relationship change
* add logic to allow dynamic clear / preloading of timelines
* comment-out unused functions, but leave in place as we might end-up using them
* fix timeline preload state check
* much improved status timeline code comments
* more code comments, don't bother inserting statuses if timeline not preloaded
* shift around some logic to make sure things aren't accidentally left set
* finish writing code comments
* remove trim-after-insert behaviour
* fix-up some comments referring to old logic
* remove unsetting of lo, hi
* fix preload repeatBoost checking logic
* don't return on status filter errors, these are usually transient
* better concurrency safety in Clear() and Done()
* fix test broken due to addition of preloader
* fix repeatBoost logic that doesn't account for already-hidden repeatBoosts
* ensure edit submodels are dropped on cache insertion
* update code-comment to expand CAS accronym
* use a plus1hULID() instead of 24h
* remove unused functions
* add note that public / local timeline requester can be nil
* fix incorrect visibility filtering of tag timeline statuses
* ensure we filter home timeline statuses on local only
* some small re-orderings to confirm query params in correct places
* fix the local only home timeline filter func
											
										 
											2025-04-26 09:56:15 +00:00
										 |  |  | 	p.surface.invalidateStatusFromTimelines(vote.Poll.StatusID) | 
					
						
							| 
									
										
										
										
											2024-08-24 11:49:37 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-09 19:14:33 +02:00
										 |  |  | 	return nil | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-26 13:50:46 +01:00
										 |  |  | func (p *clientAPI) CreateFollowReq(ctx context.Context, cMsg *messages.FromClientAPI) error { | 
					
						
							| 
									
										
										
										
											2023-08-09 19:14:33 +02:00
										 |  |  | 	followRequest, ok := cMsg.GTSModel.(*gtsmodel.FollowRequest) | 
					
						
							|  |  |  | 	if !ok { | 
					
						
							|  |  |  | 		return gtserror.Newf("%T not parseable as *gtsmodel.FollowRequest", cMsg.GTSModel) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-06-12 14:23:10 +02:00
										 |  |  | 	// If target is a local, unlocked account, | 
					
						
							|  |  |  | 	// we can skip side effects for the follow | 
					
						
							|  |  |  | 	// request and accept the follow immediately. | 
					
						
							|  |  |  | 	if cMsg.Target.IsLocal() && !*cMsg.Target.Locked { | 
					
						
							|  |  |  | 		// Accept the FR first to get the Follow. | 
					
						
							|  |  |  | 		follow, err := p.state.DB.AcceptFollowRequest( | 
					
						
							|  |  |  | 			ctx, | 
					
						
							|  |  |  | 			cMsg.Origin.ID, | 
					
						
							|  |  |  | 			cMsg.Target.ID, | 
					
						
							|  |  |  | 		) | 
					
						
							|  |  |  | 		if err != nil { | 
					
						
							|  |  |  | 			return gtserror.Newf("db error accepting follow req: %w", err) | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// Use AcceptFollow to do side effects. | 
					
						
							|  |  |  | 		return p.AcceptFollow(ctx, &messages.FromClientAPI{ | 
					
						
							|  |  |  | 			APObjectType:   ap.ActivityFollow, | 
					
						
							|  |  |  | 			APActivityType: ap.ActivityAccept, | 
					
						
							|  |  |  | 			GTSModel:       follow, | 
					
						
							|  |  |  | 			Origin:         cMsg.Origin, | 
					
						
							|  |  |  | 			Target:         cMsg.Target, | 
					
						
							|  |  |  | 		}) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-16 13:10:13 +02:00
										 |  |  | 	// Update stats for the target account. | 
					
						
							| 
									
										
										
										
											2024-04-26 13:50:46 +01:00
										 |  |  | 	if err := p.utils.incrementFollowRequestsCount(ctx, cMsg.Target); err != nil { | 
					
						
							| 
									
										
										
										
											2024-04-16 13:10:13 +02:00
										 |  |  | 		log.Errorf(ctx, "error updating account stats: %v", err) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-09 19:14:33 +02:00
										 |  |  | 	if err := p.surface.notifyFollowRequest(ctx, followRequest); err != nil { | 
					
						
							| 
									
										
										
										
											2023-11-08 14:32:17 +00:00
										 |  |  | 		log.Errorf(ctx, "error notifying follow request: %v", err) | 
					
						
							| 
									
										
										
										
											2023-08-09 19:14:33 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-08 14:32:17 +00:00
										 |  |  | 	// Convert the follow request to follow model (requests are sent as follows). | 
					
						
							|  |  |  | 	follow := p.converter.FollowRequestToFollow(ctx, followRequest) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-09 19:14:33 +02:00
										 |  |  | 	if err := p.federate.Follow( | 
					
						
							|  |  |  | 		ctx, | 
					
						
							| 
									
										
										
										
											2023-11-08 14:32:17 +00:00
										 |  |  | 		follow, | 
					
						
							| 
									
										
										
										
											2023-08-09 19:14:33 +02:00
										 |  |  | 	); err != nil { | 
					
						
							| 
									
										
										
										
											2023-11-08 14:32:17 +00:00
										 |  |  | 		log.Errorf(ctx, "error federating follow request: %v", err) | 
					
						
							| 
									
										
										
										
											2023-08-09 19:14:33 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return nil | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-26 13:50:46 +01:00
										 |  |  | func (p *clientAPI) CreateLike(ctx context.Context, cMsg *messages.FromClientAPI) error { | 
					
						
							| 
									
										
										
										
											2023-08-09 19:14:33 +02:00
										 |  |  | 	fave, ok := cMsg.GTSModel.(*gtsmodel.StatusFave) | 
					
						
							|  |  |  | 	if !ok { | 
					
						
							|  |  |  | 		return gtserror.Newf("%T not parseable as *gtsmodel.StatusFave", cMsg.GTSModel) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-25 16:04:53 +02:00
										 |  |  | 	// Ensure fave populated. | 
					
						
							|  |  |  | 	if err := p.state.DB.PopulateStatusFave(ctx, fave); err != nil { | 
					
						
							|  |  |  | 		return gtserror.Newf("error populating status fave: %w", err) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-07-26 12:04:28 +02:00
										 |  |  | 	// If pending approval is true then fave must | 
					
						
							|  |  |  | 	// target a status (either one of ours or a | 
					
						
							|  |  |  | 	// remote) that requires approval for the fave. | 
					
						
							| 
									
										
										
										
											2024-08-24 11:49:37 +02:00
										 |  |  | 	pendingApproval := util.PtrOrZero(fave.PendingApproval) | 
					
						
							| 
									
										
										
										
											2024-07-26 12:04:28 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	switch { | 
					
						
							|  |  |  | 	case pendingApproval && !fave.PreApproved: | 
					
						
							|  |  |  | 		// If approval is required and fave isn't | 
					
						
							|  |  |  | 		// preapproved, then send out the Like to | 
					
						
							|  |  |  | 		// only the faved account (if it's remote), | 
					
						
							|  |  |  | 		// and/or notify the account that's being | 
					
						
							|  |  |  | 		// interacted with (if it's local): they can | 
					
						
							|  |  |  | 		// approve or deny the interaction later. | 
					
						
							| 
									
										
										
										
											2024-08-24 11:49:37 +02:00
										 |  |  | 		if err := p.utils.requestFave(ctx, fave); err != nil { | 
					
						
							|  |  |  | 			return gtserror.Newf("error pending fave: %w", err) | 
					
						
							| 
									
										
										
										
											2024-07-26 12:04:28 +02:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// Send Like to *remote* account inbox ONLY. | 
					
						
							|  |  |  | 		if err := p.federate.Like(ctx, fave); err != nil { | 
					
						
							| 
									
										
										
										
											2024-08-24 11:49:37 +02:00
										 |  |  | 			return gtserror.Newf("error federating pending Like: %v", err) | 
					
						
							| 
									
										
										
										
											2024-07-26 12:04:28 +02:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// Return early. | 
					
						
							|  |  |  | 		return nil | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	case pendingApproval && fave.PreApproved: | 
					
						
							|  |  |  | 		// If approval is required and fave is | 
					
						
							|  |  |  | 		// preapproved, that means this is a fave | 
					
						
							|  |  |  | 		// of one of our statuses with permission | 
					
						
							|  |  |  | 		// that matched on a following/followers | 
					
						
							|  |  |  | 		// collection. Do the Accept immediately and | 
					
						
							|  |  |  | 		// then process everything else as normal, | 
					
						
							|  |  |  | 		// sending out the Like with the approval | 
					
						
							|  |  |  | 		// URI attached. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-24 11:49:37 +02:00
										 |  |  | 		// Store an already-accepted interaction request. | 
					
						
							|  |  |  | 		id := id.NewULID() | 
					
						
							|  |  |  | 		approval := >smodel.InteractionRequest{ | 
					
						
							|  |  |  | 			ID:                   id, | 
					
						
							|  |  |  | 			StatusID:             fave.StatusID, | 
					
						
							|  |  |  | 			TargetAccountID:      fave.TargetAccountID, | 
					
						
							|  |  |  | 			TargetAccount:        fave.TargetAccount, | 
					
						
							|  |  |  | 			InteractingAccountID: fave.AccountID, | 
					
						
							|  |  |  | 			InteractingAccount:   fave.Account, | 
					
						
							|  |  |  | 			InteractionURI:       fave.URI, | 
					
						
							|  |  |  | 			InteractionType:      gtsmodel.InteractionLike, | 
					
						
							|  |  |  | 			Like:                 fave, | 
					
						
							|  |  |  | 			URI:                  uris.GenerateURIForAccept(fave.TargetAccount.Username, id), | 
					
						
							|  |  |  | 			AcceptedAt:           time.Now(), | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		if err := p.state.DB.PutInteractionRequest(ctx, approval); err != nil { | 
					
						
							|  |  |  | 			return gtserror.Newf("db error putting pre-approved interaction request: %w", err) | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// Mark the fave itself as now approved. | 
					
						
							|  |  |  | 		fave.PendingApproval = util.Ptr(false) | 
					
						
							|  |  |  | 		fave.PreApproved = false | 
					
						
							|  |  |  | 		fave.ApprovedByURI = approval.URI | 
					
						
							|  |  |  | 		if err := p.state.DB.UpdateStatusFave( | 
					
						
							|  |  |  | 			ctx, | 
					
						
							|  |  |  | 			fave, | 
					
						
							|  |  |  | 			"pending_approval", | 
					
						
							|  |  |  | 			"approved_by_uri", | 
					
						
							|  |  |  | 		); err != nil { | 
					
						
							|  |  |  | 			return gtserror.Newf("db error updating status fave: %w", err) | 
					
						
							| 
									
										
										
										
											2024-07-26 12:04:28 +02:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if err := p.federate.AcceptInteraction(ctx, approval); err != nil { | 
					
						
							|  |  |  | 			return gtserror.Newf("error federating pre-approval of fave: %w", err) | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// Don't return, just continue as normal. | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-09 19:14:33 +02:00
										 |  |  | 	if err := p.surface.notifyFave(ctx, fave); err != nil { | 
					
						
							| 
									
										
										
										
											2023-11-08 14:32:17 +00:00
										 |  |  | 		log.Errorf(ctx, "error notifying fave: %v", err) | 
					
						
							| 
									
										
										
										
											2023-08-09 19:14:33 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if err := p.federate.Like(ctx, fave); err != nil { | 
					
						
							| 
									
										
										
										
											2023-11-08 14:32:17 +00:00
										 |  |  | 		log.Errorf(ctx, "error federating like: %v", err) | 
					
						
							| 
									
										
										
										
											2023-08-09 19:14:33 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-24 11:49:37 +02:00
										 |  |  | 	// Interaction counts changed on the faved status; | 
					
						
							|  |  |  | 	// uncache the prepared version from all timelines. | 
					
						
							| 
									
										
											  
											
												[performance] rewrite timelines to rely on new timeline cache type (#3941)
* start work rewriting timeline cache type
* further work rewriting timeline caching
* more work integration new timeline code
* remove old code
* add local timeline, fix up merge conflicts
* remove old use of go-bytes
* implement new timeline code into more areas of codebase, pull in latest go-mangler, go-mutexes, go-structr
* remove old timeline package, add local timeline cache
* remove references to old timeline types that needed starting up in tests
* start adding page validation
* fix test-identified timeline cache package issues
* fix up more tests, fix missing required changes, etc
* add exclusion for test.out in gitignore
* clarify some things better in code comments
* tweak cache size limits
* fix list timeline cache fetching
* further list timeline fixes
* linter, ssssssssshhhhhhhhhhhh please
* fix linter hints
* reslice the output if it's beyond length of 'lim'
* remove old timeline initialization code, bump go-structr to v0.9.4
* continued from previous commit
* improved code comments
* don't allow multiple entries for BoostOfID values to prevent repeated boosts of same boosts
* finish writing more code comments
* some variable renaming, for ease of following
* change the way we update lo,hi paging values during timeline load
* improved code comments for updated / returned lo , hi paging values
* finish writing code comments for the StatusTimeline{} type itself
* fill in more code comments
* update go-structr version to latest with changed timeline unique indexing logic
* have a local and public timeline *per user*
* rewrite calls to public / local timeline calls
* remove the zero length check, as lo, hi values might still be set
* simplify timeline cache loading, fix lo/hi returns, fix timeline invalidation side-effects missing for some federated actions
* swap the lo, hi values :facepalm:
* add (now) missing slice reverse of tag timeline statuses when paging ASC
* remove local / public caches (is out of scope for this work), share more timeline code
* remove unnecessary change
* again, remove more unused code
* remove unused function to appease the linter
* move boost checking to prepare function
* fix use of timeline.lastOrder, fix incorrect range functions used
* remove comments for repeat code
* remove the boost logic from prepare function
* do a maximum of 5 loads, not 10
* add repeat boost filtering logic, update go-structr, general improvements
* more code comments
* add important note
* fix timeline tests now that timelines are returned in page order
* remove unused field
* add StatusTimeline{} tests
* add more status timeline tests
* start adding preloading support
* ensure repeat boosts are marked in preloaded entries
* share a bunch of the database load code in timeline cache, don't clear timelines on relationship change
* add logic to allow dynamic clear / preloading of timelines
* comment-out unused functions, but leave in place as we might end-up using them
* fix timeline preload state check
* much improved status timeline code comments
* more code comments, don't bother inserting statuses if timeline not preloaded
* shift around some logic to make sure things aren't accidentally left set
* finish writing code comments
* remove trim-after-insert behaviour
* fix-up some comments referring to old logic
* remove unsetting of lo, hi
* fix preload repeatBoost checking logic
* don't return on status filter errors, these are usually transient
* better concurrency safety in Clear() and Done()
* fix test broken due to addition of preloader
* fix repeatBoost logic that doesn't account for already-hidden repeatBoosts
* ensure edit submodels are dropped on cache insertion
* update code-comment to expand CAS accronym
* use a plus1hULID() instead of 24h
* remove unused functions
* add note that public / local timeline requester can be nil
* fix incorrect visibility filtering of tag timeline statuses
* ensure we filter home timeline statuses on local only
* some small re-orderings to confirm query params in correct places
* fix the local only home timeline filter func
											
										 
											2025-04-26 09:56:15 +00:00
										 |  |  | 	p.surface.invalidateStatusFromTimelines(fave.StatusID) | 
					
						
							| 
									
										
										
										
											2024-08-24 11:49:37 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-09 19:14:33 +02:00
										 |  |  | 	return nil | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-26 13:50:46 +01:00
										 |  |  | func (p *clientAPI) CreateAnnounce(ctx context.Context, cMsg *messages.FromClientAPI) error { | 
					
						
							| 
									
										
										
										
											2023-08-09 19:14:33 +02:00
										 |  |  | 	boost, ok := cMsg.GTSModel.(*gtsmodel.Status) | 
					
						
							|  |  |  | 	if !ok { | 
					
						
							|  |  |  | 		return gtserror.Newf("%T not parseable as *gtsmodel.Status", cMsg.GTSModel) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-07-26 12:04:28 +02:00
										 |  |  | 	// If pending approval is true then status must | 
					
						
							|  |  |  | 	// boost a status (either one of ours or a | 
					
						
							|  |  |  | 	// remote) that requires approval for the boost. | 
					
						
							| 
									
										
										
										
											2024-08-24 11:49:37 +02:00
										 |  |  | 	pendingApproval := util.PtrOrZero(boost.PendingApproval) | 
					
						
							| 
									
										
										
										
											2024-07-26 12:04:28 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	switch { | 
					
						
							|  |  |  | 	case pendingApproval && !boost.PreApproved: | 
					
						
							|  |  |  | 		// If approval is required and boost isn't | 
					
						
							|  |  |  | 		// preapproved, then send out the Announce to | 
					
						
							|  |  |  | 		// only the boosted account (if it's remote), | 
					
						
							|  |  |  | 		// and/or notify the account that's being | 
					
						
							|  |  |  | 		// interacted with (if it's local): they can | 
					
						
							|  |  |  | 		// approve or deny the interaction later. | 
					
						
							| 
									
										
										
										
											2024-08-24 11:49:37 +02:00
										 |  |  | 		if err := p.utils.requestAnnounce(ctx, boost); err != nil { | 
					
						
							|  |  |  | 			return gtserror.Newf("error pending boost: %w", err) | 
					
						
							| 
									
										
										
										
											2024-07-26 12:04:28 +02:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// Send Announce to *remote* account inbox ONLY. | 
					
						
							|  |  |  | 		if err := p.federate.Announce(ctx, boost); err != nil { | 
					
						
							| 
									
										
										
										
											2024-08-24 11:49:37 +02:00
										 |  |  | 			return gtserror.Newf("error federating pending Announce: %v", err) | 
					
						
							| 
									
										
										
										
											2024-07-26 12:04:28 +02:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// Return early. | 
					
						
							|  |  |  | 		return nil | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	case pendingApproval && boost.PreApproved: | 
					
						
							|  |  |  | 		// If approval is required and boost is | 
					
						
							|  |  |  | 		// preapproved, that means this is a boost | 
					
						
							|  |  |  | 		// of one of our statuses with permission | 
					
						
							|  |  |  | 		// that matched on a following/followers | 
					
						
							|  |  |  | 		// collection. Do the Accept immediately and | 
					
						
							|  |  |  | 		// then process everything else as normal, | 
					
						
							|  |  |  | 		// sending out the Create with the approval | 
					
						
							|  |  |  | 		// URI attached. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-24 11:49:37 +02:00
										 |  |  | 		// Store an already-accepted interaction request. | 
					
						
							|  |  |  | 		id := id.NewULID() | 
					
						
							|  |  |  | 		approval := >smodel.InteractionRequest{ | 
					
						
							|  |  |  | 			ID:                   id, | 
					
						
							|  |  |  | 			StatusID:             boost.BoostOfID, | 
					
						
							|  |  |  | 			TargetAccountID:      boost.BoostOfAccountID, | 
					
						
							|  |  |  | 			TargetAccount:        boost.BoostOfAccount, | 
					
						
							|  |  |  | 			InteractingAccountID: boost.AccountID, | 
					
						
							|  |  |  | 			InteractingAccount:   boost.Account, | 
					
						
							|  |  |  | 			InteractionURI:       boost.URI, | 
					
						
							|  |  |  | 			InteractionType:      gtsmodel.InteractionLike, | 
					
						
							|  |  |  | 			Announce:             boost, | 
					
						
							|  |  |  | 			URI:                  uris.GenerateURIForAccept(boost.BoostOfAccount.Username, id), | 
					
						
							|  |  |  | 			AcceptedAt:           time.Now(), | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		if err := p.state.DB.PutInteractionRequest(ctx, approval); err != nil { | 
					
						
							|  |  |  | 			return gtserror.Newf("db error putting pre-approved interaction request: %w", err) | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// Mark the boost itself as now approved. | 
					
						
							|  |  |  | 		boost.PendingApproval = util.Ptr(false) | 
					
						
							|  |  |  | 		boost.PreApproved = false | 
					
						
							|  |  |  | 		boost.ApprovedByURI = approval.URI | 
					
						
							|  |  |  | 		if err := p.state.DB.UpdateStatus( | 
					
						
							|  |  |  | 			ctx, | 
					
						
							|  |  |  | 			boost, | 
					
						
							|  |  |  | 			"pending_approval", | 
					
						
							|  |  |  | 			"approved_by_uri", | 
					
						
							|  |  |  | 		); err != nil { | 
					
						
							|  |  |  | 			return gtserror.Newf("db error updating status: %w", err) | 
					
						
							| 
									
										
										
										
											2024-07-26 12:04:28 +02:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if err := p.federate.AcceptInteraction(ctx, approval); err != nil { | 
					
						
							|  |  |  | 			return gtserror.Newf("error federating pre-approval of boost: %w", err) | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// Don't return, just continue as normal. | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-16 13:10:13 +02:00
										 |  |  | 	// Update stats for the actor account. | 
					
						
							| 
									
										
										
										
											2024-04-26 13:50:46 +01:00
										 |  |  | 	if err := p.utils.incrementStatusesCount(ctx, cMsg.Origin, boost); err != nil { | 
					
						
							| 
									
										
										
										
											2024-04-16 13:10:13 +02:00
										 |  |  | 		log.Errorf(ctx, "error updating account stats: %v", err) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-09 19:14:33 +02:00
										 |  |  | 	// Timeline and notify the boost wrapper status. | 
					
						
							|  |  |  | 	if err := p.surface.timelineAndNotifyStatus(ctx, boost); err != nil { | 
					
						
							| 
									
										
										
										
											2023-11-08 14:32:17 +00:00
										 |  |  | 		log.Errorf(ctx, "error timelining and notifying status: %v", err) | 
					
						
							| 
									
										
										
										
											2023-08-09 19:14:33 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Notify the boost target account. | 
					
						
							|  |  |  | 	if err := p.surface.notifyAnnounce(ctx, boost); err != nil { | 
					
						
							| 
									
										
										
										
											2023-11-08 14:32:17 +00:00
										 |  |  | 		log.Errorf(ctx, "error notifying boost: %v", err) | 
					
						
							| 
									
										
										
										
											2023-08-09 19:14:33 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if err := p.federate.Announce(ctx, boost); err != nil { | 
					
						
							| 
									
										
										
										
											2023-11-08 14:32:17 +00:00
										 |  |  | 		log.Errorf(ctx, "error federating announce: %v", err) | 
					
						
							| 
									
										
										
										
											2023-08-09 19:14:33 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-24 11:49:37 +02:00
										 |  |  | 	// Interaction counts changed on the boosted status; | 
					
						
							|  |  |  | 	// uncache the prepared version from all timelines. | 
					
						
							| 
									
										
											  
											
												[performance] rewrite timelines to rely on new timeline cache type (#3941)
* start work rewriting timeline cache type
* further work rewriting timeline caching
* more work integration new timeline code
* remove old code
* add local timeline, fix up merge conflicts
* remove old use of go-bytes
* implement new timeline code into more areas of codebase, pull in latest go-mangler, go-mutexes, go-structr
* remove old timeline package, add local timeline cache
* remove references to old timeline types that needed starting up in tests
* start adding page validation
* fix test-identified timeline cache package issues
* fix up more tests, fix missing required changes, etc
* add exclusion for test.out in gitignore
* clarify some things better in code comments
* tweak cache size limits
* fix list timeline cache fetching
* further list timeline fixes
* linter, ssssssssshhhhhhhhhhhh please
* fix linter hints
* reslice the output if it's beyond length of 'lim'
* remove old timeline initialization code, bump go-structr to v0.9.4
* continued from previous commit
* improved code comments
* don't allow multiple entries for BoostOfID values to prevent repeated boosts of same boosts
* finish writing more code comments
* some variable renaming, for ease of following
* change the way we update lo,hi paging values during timeline load
* improved code comments for updated / returned lo , hi paging values
* finish writing code comments for the StatusTimeline{} type itself
* fill in more code comments
* update go-structr version to latest with changed timeline unique indexing logic
* have a local and public timeline *per user*
* rewrite calls to public / local timeline calls
* remove the zero length check, as lo, hi values might still be set
* simplify timeline cache loading, fix lo/hi returns, fix timeline invalidation side-effects missing for some federated actions
* swap the lo, hi values :facepalm:
* add (now) missing slice reverse of tag timeline statuses when paging ASC
* remove local / public caches (is out of scope for this work), share more timeline code
* remove unnecessary change
* again, remove more unused code
* remove unused function to appease the linter
* move boost checking to prepare function
* fix use of timeline.lastOrder, fix incorrect range functions used
* remove comments for repeat code
* remove the boost logic from prepare function
* do a maximum of 5 loads, not 10
* add repeat boost filtering logic, update go-structr, general improvements
* more code comments
* add important note
* fix timeline tests now that timelines are returned in page order
* remove unused field
* add StatusTimeline{} tests
* add more status timeline tests
* start adding preloading support
* ensure repeat boosts are marked in preloaded entries
* share a bunch of the database load code in timeline cache, don't clear timelines on relationship change
* add logic to allow dynamic clear / preloading of timelines
* comment-out unused functions, but leave in place as we might end-up using them
* fix timeline preload state check
* much improved status timeline code comments
* more code comments, don't bother inserting statuses if timeline not preloaded
* shift around some logic to make sure things aren't accidentally left set
* finish writing code comments
* remove trim-after-insert behaviour
* fix-up some comments referring to old logic
* remove unsetting of lo, hi
* fix preload repeatBoost checking logic
* don't return on status filter errors, these are usually transient
* better concurrency safety in Clear() and Done()
* fix test broken due to addition of preloader
* fix repeatBoost logic that doesn't account for already-hidden repeatBoosts
* ensure edit submodels are dropped on cache insertion
* update code-comment to expand CAS accronym
* use a plus1hULID() instead of 24h
* remove unused functions
* add note that public / local timeline requester can be nil
* fix incorrect visibility filtering of tag timeline statuses
* ensure we filter home timeline statuses on local only
* some small re-orderings to confirm query params in correct places
* fix the local only home timeline filter func
											
										 
											2025-04-26 09:56:15 +00:00
										 |  |  | 	p.surface.invalidateStatusFromTimelines(boost.BoostOfID) | 
					
						
							| 
									
										
										
										
											2024-08-24 11:49:37 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-09 19:14:33 +02:00
										 |  |  | 	return nil | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-26 13:50:46 +01:00
										 |  |  | func (p *clientAPI) CreateBlock(ctx context.Context, cMsg *messages.FromClientAPI) error { | 
					
						
							| 
									
										
										
										
											2023-08-09 19:14:33 +02:00
										 |  |  | 	block, ok := cMsg.GTSModel.(*gtsmodel.Block) | 
					
						
							|  |  |  | 	if !ok { | 
					
						
							|  |  |  | 		return gtserror.Newf("%T not parseable as *gtsmodel.Block", cMsg.GTSModel) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
											  
											
												[performance] rewrite timelines to rely on new timeline cache type (#3941)
* start work rewriting timeline cache type
* further work rewriting timeline caching
* more work integration new timeline code
* remove old code
* add local timeline, fix up merge conflicts
* remove old use of go-bytes
* implement new timeline code into more areas of codebase, pull in latest go-mangler, go-mutexes, go-structr
* remove old timeline package, add local timeline cache
* remove references to old timeline types that needed starting up in tests
* start adding page validation
* fix test-identified timeline cache package issues
* fix up more tests, fix missing required changes, etc
* add exclusion for test.out in gitignore
* clarify some things better in code comments
* tweak cache size limits
* fix list timeline cache fetching
* further list timeline fixes
* linter, ssssssssshhhhhhhhhhhh please
* fix linter hints
* reslice the output if it's beyond length of 'lim'
* remove old timeline initialization code, bump go-structr to v0.9.4
* continued from previous commit
* improved code comments
* don't allow multiple entries for BoostOfID values to prevent repeated boosts of same boosts
* finish writing more code comments
* some variable renaming, for ease of following
* change the way we update lo,hi paging values during timeline load
* improved code comments for updated / returned lo , hi paging values
* finish writing code comments for the StatusTimeline{} type itself
* fill in more code comments
* update go-structr version to latest with changed timeline unique indexing logic
* have a local and public timeline *per user*
* rewrite calls to public / local timeline calls
* remove the zero length check, as lo, hi values might still be set
* simplify timeline cache loading, fix lo/hi returns, fix timeline invalidation side-effects missing for some federated actions
* swap the lo, hi values :facepalm:
* add (now) missing slice reverse of tag timeline statuses when paging ASC
* remove local / public caches (is out of scope for this work), share more timeline code
* remove unnecessary change
* again, remove more unused code
* remove unused function to appease the linter
* move boost checking to prepare function
* fix use of timeline.lastOrder, fix incorrect range functions used
* remove comments for repeat code
* remove the boost logic from prepare function
* do a maximum of 5 loads, not 10
* add repeat boost filtering logic, update go-structr, general improvements
* more code comments
* add important note
* fix timeline tests now that timelines are returned in page order
* remove unused field
* add StatusTimeline{} tests
* add more status timeline tests
* start adding preloading support
* ensure repeat boosts are marked in preloaded entries
* share a bunch of the database load code in timeline cache, don't clear timelines on relationship change
* add logic to allow dynamic clear / preloading of timelines
* comment-out unused functions, but leave in place as we might end-up using them
* fix timeline preload state check
* much improved status timeline code comments
* more code comments, don't bother inserting statuses if timeline not preloaded
* shift around some logic to make sure things aren't accidentally left set
* finish writing code comments
* remove trim-after-insert behaviour
* fix-up some comments referring to old logic
* remove unsetting of lo, hi
* fix preload repeatBoost checking logic
* don't return on status filter errors, these are usually transient
* better concurrency safety in Clear() and Done()
* fix test broken due to addition of preloader
* fix repeatBoost logic that doesn't account for already-hidden repeatBoosts
* ensure edit submodels are dropped on cache insertion
* update code-comment to expand CAS accronym
* use a plus1hULID() instead of 24h
* remove unused functions
* add note that public / local timeline requester can be nil
* fix incorrect visibility filtering of tag timeline statuses
* ensure we filter home timeline statuses on local only
* some small re-orderings to confirm query params in correct places
* fix the local only home timeline filter func
											
										 
											2025-04-26 09:56:15 +00:00
										 |  |  | 	if block.Account.IsLocal() { | 
					
						
							|  |  |  | 		// Remove posts by target from origin's timelines. | 
					
						
							|  |  |  | 		p.surface.removeRelationshipFromTimelines(ctx, | 
					
						
							|  |  |  | 			block.AccountID, | 
					
						
							|  |  |  | 			block.TargetAccountID, | 
					
						
							|  |  |  | 		) | 
					
						
							| 
									
										
										
										
											2023-08-09 19:14:33 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
											  
											
												[performance] rewrite timelines to rely on new timeline cache type (#3941)
* start work rewriting timeline cache type
* further work rewriting timeline caching
* more work integration new timeline code
* remove old code
* add local timeline, fix up merge conflicts
* remove old use of go-bytes
* implement new timeline code into more areas of codebase, pull in latest go-mangler, go-mutexes, go-structr
* remove old timeline package, add local timeline cache
* remove references to old timeline types that needed starting up in tests
* start adding page validation
* fix test-identified timeline cache package issues
* fix up more tests, fix missing required changes, etc
* add exclusion for test.out in gitignore
* clarify some things better in code comments
* tweak cache size limits
* fix list timeline cache fetching
* further list timeline fixes
* linter, ssssssssshhhhhhhhhhhh please
* fix linter hints
* reslice the output if it's beyond length of 'lim'
* remove old timeline initialization code, bump go-structr to v0.9.4
* continued from previous commit
* improved code comments
* don't allow multiple entries for BoostOfID values to prevent repeated boosts of same boosts
* finish writing more code comments
* some variable renaming, for ease of following
* change the way we update lo,hi paging values during timeline load
* improved code comments for updated / returned lo , hi paging values
* finish writing code comments for the StatusTimeline{} type itself
* fill in more code comments
* update go-structr version to latest with changed timeline unique indexing logic
* have a local and public timeline *per user*
* rewrite calls to public / local timeline calls
* remove the zero length check, as lo, hi values might still be set
* simplify timeline cache loading, fix lo/hi returns, fix timeline invalidation side-effects missing for some federated actions
* swap the lo, hi values :facepalm:
* add (now) missing slice reverse of tag timeline statuses when paging ASC
* remove local / public caches (is out of scope for this work), share more timeline code
* remove unnecessary change
* again, remove more unused code
* remove unused function to appease the linter
* move boost checking to prepare function
* fix use of timeline.lastOrder, fix incorrect range functions used
* remove comments for repeat code
* remove the boost logic from prepare function
* do a maximum of 5 loads, not 10
* add repeat boost filtering logic, update go-structr, general improvements
* more code comments
* add important note
* fix timeline tests now that timelines are returned in page order
* remove unused field
* add StatusTimeline{} tests
* add more status timeline tests
* start adding preloading support
* ensure repeat boosts are marked in preloaded entries
* share a bunch of the database load code in timeline cache, don't clear timelines on relationship change
* add logic to allow dynamic clear / preloading of timelines
* comment-out unused functions, but leave in place as we might end-up using them
* fix timeline preload state check
* much improved status timeline code comments
* more code comments, don't bother inserting statuses if timeline not preloaded
* shift around some logic to make sure things aren't accidentally left set
* finish writing code comments
* remove trim-after-insert behaviour
* fix-up some comments referring to old logic
* remove unsetting of lo, hi
* fix preload repeatBoost checking logic
* don't return on status filter errors, these are usually transient
* better concurrency safety in Clear() and Done()
* fix test broken due to addition of preloader
* fix repeatBoost logic that doesn't account for already-hidden repeatBoosts
* ensure edit submodels are dropped on cache insertion
* update code-comment to expand CAS accronym
* use a plus1hULID() instead of 24h
* remove unused functions
* add note that public / local timeline requester can be nil
* fix incorrect visibility filtering of tag timeline statuses
* ensure we filter home timeline statuses on local only
* some small re-orderings to confirm query params in correct places
* fix the local only home timeline filter func
											
										 
											2025-04-26 09:56:15 +00:00
										 |  |  | 	if block.TargetAccount.IsLocal() { | 
					
						
							|  |  |  | 		// Remove posts by origin from target's timelines. | 
					
						
							|  |  |  | 		p.surface.removeRelationshipFromTimelines(ctx, | 
					
						
							|  |  |  | 			block.TargetAccountID, | 
					
						
							|  |  |  | 			block.AccountID, | 
					
						
							|  |  |  | 		) | 
					
						
							| 
									
										
										
										
											2023-08-09 19:14:33 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// TODO: same with notifications? | 
					
						
							|  |  |  | 	// TODO: same with bookmarks? | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if err := p.federate.Block(ctx, block); err != nil { | 
					
						
							| 
									
										
										
										
											2023-11-08 14:32:17 +00:00
										 |  |  | 		log.Errorf(ctx, "error federating block: %v", err) | 
					
						
							| 
									
										
										
										
											2023-08-09 19:14:33 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return nil | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-26 13:50:46 +01:00
										 |  |  | func (p *clientAPI) UpdateStatus(ctx context.Context, cMsg *messages.FromClientAPI) error { | 
					
						
							| 
									
										
										
										
											2023-10-04 13:09:42 +01:00
										 |  |  | 	// Cast the updated Status model attached to msg. | 
					
						
							|  |  |  | 	status, ok := cMsg.GTSModel.(*gtsmodel.Status) | 
					
						
							|  |  |  | 	if !ok { | 
					
						
							|  |  |  | 		return gtserror.Newf("cannot cast %T -> *gtsmodel.Status", cMsg.GTSModel) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Federate the updated status changes out remotely. | 
					
						
							|  |  |  | 	if err := p.federate.UpdateStatus(ctx, status); err != nil { | 
					
						
							| 
									
										
										
										
											2023-11-08 14:32:17 +00:00
										 |  |  | 		log.Errorf(ctx, "error federating status update: %v", err) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if status.Poll != nil && status.Poll.Closing { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// If the latest status has a newly closed poll, at least compared | 
					
						
							|  |  |  | 		// to the existing version, then notify poll close to all voters. | 
					
						
							|  |  |  | 		if err := p.surface.notifyPollClose(ctx, status); err != nil { | 
					
						
							|  |  |  | 			log.Errorf(ctx, "error notifying poll close: %v", err) | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2023-10-04 13:09:42 +01:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-05-04 09:45:10 +00:00
										 |  |  | 	// Notify any *new* mentions added | 
					
						
							|  |  |  | 	// to this status by the editor. | 
					
						
							|  |  |  | 	for _, mention := range status.Mentions { | 
					
						
							|  |  |  | 		// Check if we've seen | 
					
						
							|  |  |  | 		// this mention already. | 
					
						
							|  |  |  | 		if !mention.IsNew { | 
					
						
							|  |  |  | 			// Already seen | 
					
						
							|  |  |  | 			// it, skip. | 
					
						
							|  |  |  | 			continue | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// Haven't seen this mention | 
					
						
							|  |  |  | 		// yet, notify it if necessary. | 
					
						
							|  |  |  | 		mention.Status = status | 
					
						
							|  |  |  | 		if err := p.surface.notifyMention(ctx, mention); err != nil { | 
					
						
							|  |  |  | 			log.Errorf(ctx, "error notifying mention: %v", err) | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-05-31 17:30:57 +02:00
										 |  |  | 	if len(status.EditIDs) > 0 { | 
					
						
							|  |  |  | 		// Ensure edits are fully populated for this status before anything. | 
					
						
							|  |  |  | 		if err := p.surface.State.DB.PopulateStatusEdits(ctx, status); err != nil { | 
					
						
							|  |  |  | 			log.Error(ctx, "error populating updated status edits: %v") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			// Then send notifications of a status edit | 
					
						
							|  |  |  | 			// to any local interactors of the status. | 
					
						
							|  |  |  | 		} else if err := p.surface.notifyStatusEdit(ctx, | 
					
						
							|  |  |  | 			status, | 
					
						
							|  |  |  | 			status.Edits[len(status.Edits)-1], // latest | 
					
						
							|  |  |  | 		); err != nil { | 
					
						
							| 
									
										
										
										
											2025-05-11 13:38:13 +00:00
										 |  |  | 			log.Errorf(ctx, "error notifying status edit: %v", err) | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-16 11:55:49 +00:00
										 |  |  | 	// Push message that the status has been edited to streams. | 
					
						
							|  |  |  | 	if err := p.surface.timelineStatusUpdate(ctx, status); err != nil { | 
					
						
							|  |  |  | 		log.Errorf(ctx, "error streaming status edit: %v", err) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-24 11:49:37 +02:00
										 |  |  | 	// Status representation has changed, invalidate from timelines. | 
					
						
							| 
									
										
											  
											
												[performance] rewrite timelines to rely on new timeline cache type (#3941)
* start work rewriting timeline cache type
* further work rewriting timeline caching
* more work integration new timeline code
* remove old code
* add local timeline, fix up merge conflicts
* remove old use of go-bytes
* implement new timeline code into more areas of codebase, pull in latest go-mangler, go-mutexes, go-structr
* remove old timeline package, add local timeline cache
* remove references to old timeline types that needed starting up in tests
* start adding page validation
* fix test-identified timeline cache package issues
* fix up more tests, fix missing required changes, etc
* add exclusion for test.out in gitignore
* clarify some things better in code comments
* tweak cache size limits
* fix list timeline cache fetching
* further list timeline fixes
* linter, ssssssssshhhhhhhhhhhh please
* fix linter hints
* reslice the output if it's beyond length of 'lim'
* remove old timeline initialization code, bump go-structr to v0.9.4
* continued from previous commit
* improved code comments
* don't allow multiple entries for BoostOfID values to prevent repeated boosts of same boosts
* finish writing more code comments
* some variable renaming, for ease of following
* change the way we update lo,hi paging values during timeline load
* improved code comments for updated / returned lo , hi paging values
* finish writing code comments for the StatusTimeline{} type itself
* fill in more code comments
* update go-structr version to latest with changed timeline unique indexing logic
* have a local and public timeline *per user*
* rewrite calls to public / local timeline calls
* remove the zero length check, as lo, hi values might still be set
* simplify timeline cache loading, fix lo/hi returns, fix timeline invalidation side-effects missing for some federated actions
* swap the lo, hi values :facepalm:
* add (now) missing slice reverse of tag timeline statuses when paging ASC
* remove local / public caches (is out of scope for this work), share more timeline code
* remove unnecessary change
* again, remove more unused code
* remove unused function to appease the linter
* move boost checking to prepare function
* fix use of timeline.lastOrder, fix incorrect range functions used
* remove comments for repeat code
* remove the boost logic from prepare function
* do a maximum of 5 loads, not 10
* add repeat boost filtering logic, update go-structr, general improvements
* more code comments
* add important note
* fix timeline tests now that timelines are returned in page order
* remove unused field
* add StatusTimeline{} tests
* add more status timeline tests
* start adding preloading support
* ensure repeat boosts are marked in preloaded entries
* share a bunch of the database load code in timeline cache, don't clear timelines on relationship change
* add logic to allow dynamic clear / preloading of timelines
* comment-out unused functions, but leave in place as we might end-up using them
* fix timeline preload state check
* much improved status timeline code comments
* more code comments, don't bother inserting statuses if timeline not preloaded
* shift around some logic to make sure things aren't accidentally left set
* finish writing code comments
* remove trim-after-insert behaviour
* fix-up some comments referring to old logic
* remove unsetting of lo, hi
* fix preload repeatBoost checking logic
* don't return on status filter errors, these are usually transient
* better concurrency safety in Clear() and Done()
* fix test broken due to addition of preloader
* fix repeatBoost logic that doesn't account for already-hidden repeatBoosts
* ensure edit submodels are dropped on cache insertion
* update code-comment to expand CAS accronym
* use a plus1hULID() instead of 24h
* remove unused functions
* add note that public / local timeline requester can be nil
* fix incorrect visibility filtering of tag timeline statuses
* ensure we filter home timeline statuses on local only
* some small re-orderings to confirm query params in correct places
* fix the local only home timeline filter func
											
										 
											2025-04-26 09:56:15 +00:00
										 |  |  | 	p.surface.invalidateStatusFromTimelines(status.ID) | 
					
						
							| 
									
										
										
										
											2024-08-24 11:49:37 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-04 13:09:42 +01:00
										 |  |  | 	return nil | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-26 13:50:46 +01:00
										 |  |  | func (p *clientAPI) UpdateAccount(ctx context.Context, cMsg *messages.FromClientAPI) error { | 
					
						
							| 
									
										
										
										
											2023-08-09 19:14:33 +02:00
										 |  |  | 	account, ok := cMsg.GTSModel.(*gtsmodel.Account) | 
					
						
							|  |  |  | 	if !ok { | 
					
						
							| 
									
										
										
										
											2023-10-04 13:09:42 +01:00
										 |  |  | 		return gtserror.Newf("cannot cast %T -> *gtsmodel.Account", cMsg.GTSModel) | 
					
						
							| 
									
										
										
										
											2023-08-09 19:14:33 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if err := p.federate.UpdateAccount(ctx, account); err != nil { | 
					
						
							| 
									
										
										
										
											2023-11-08 14:32:17 +00:00
										 |  |  | 		log.Errorf(ctx, "error federating account update: %v", err) | 
					
						
							| 
									
										
										
										
											2023-08-09 19:14:33 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-05-02 16:01:30 +00:00
										 |  |  | 	// Account representation has changed, invalidate from timelines. | 
					
						
							|  |  |  | 	p.surface.invalidateTimelineEntriesByAccount(account.ID) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-09 19:14:33 +02:00
										 |  |  | 	return nil | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-26 13:50:46 +01:00
										 |  |  | func (p *clientAPI) UpdateReport(ctx context.Context, cMsg *messages.FromClientAPI) error { | 
					
						
							| 
									
										
										
										
											2023-08-09 19:14:33 +02:00
										 |  |  | 	report, ok := cMsg.GTSModel.(*gtsmodel.Report) | 
					
						
							|  |  |  | 	if !ok { | 
					
						
							|  |  |  | 		return gtserror.Newf("%T not parseable as *gtsmodel.Report", cMsg.GTSModel) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if report.Account.IsRemote() { | 
					
						
							|  |  |  | 		// Report creator is a remote account, | 
					
						
							|  |  |  | 		// we shouldn't try to email them! | 
					
						
							|  |  |  | 		return nil | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-11 11:45:53 +02:00
										 |  |  | 	if err := p.surface.emailUserReportClosed(ctx, report); err != nil { | 
					
						
							| 
									
										
										
										
											2023-11-08 14:32:17 +00:00
										 |  |  | 		log.Errorf(ctx, "error emailing report closed: %v", err) | 
					
						
							| 
									
										
										
										
											2023-08-09 19:14:33 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return nil | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-06-06 15:43:25 +02:00
										 |  |  | func (p *clientAPI) UpdateUser(ctx context.Context, cMsg *messages.FromClientAPI) error { | 
					
						
							|  |  |  | 	user, ok := cMsg.GTSModel.(*gtsmodel.User) | 
					
						
							|  |  |  | 	if !ok { | 
					
						
							|  |  |  | 		return gtserror.Newf("cannot cast %T -> *gtsmodel.User", cMsg.GTSModel) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// The only possible "UpdateUser" action is to update the | 
					
						
							|  |  |  | 	// user's email address, so we can safely assume by this | 
					
						
							|  |  |  | 	// point that a new unconfirmed email address has been set. | 
					
						
							|  |  |  | 	if err := p.surface.emailUserPleaseConfirm(ctx, user, false); err != nil { | 
					
						
							|  |  |  | 		log.Errorf(ctx, "error emailing report closed: %v", err) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return nil | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-26 13:50:46 +01:00
										 |  |  | func (p *clientAPI) AcceptFollow(ctx context.Context, cMsg *messages.FromClientAPI) error { | 
					
						
							| 
									
										
										
										
											2023-08-09 19:14:33 +02:00
										 |  |  | 	follow, ok := cMsg.GTSModel.(*gtsmodel.Follow) | 
					
						
							|  |  |  | 	if !ok { | 
					
						
							|  |  |  | 		return gtserror.Newf("%T not parseable as *gtsmodel.Follow", cMsg.GTSModel) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-16 13:10:13 +02:00
										 |  |  | 	// Update stats for the target account. | 
					
						
							| 
									
										
										
										
											2024-04-26 13:50:46 +01:00
										 |  |  | 	if err := p.utils.decrementFollowRequestsCount(ctx, cMsg.Target); err != nil { | 
					
						
							| 
									
										
										
										
											2024-04-16 13:10:13 +02:00
										 |  |  | 		log.Errorf(ctx, "error updating account stats: %v", err) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-26 13:50:46 +01:00
										 |  |  | 	if err := p.utils.incrementFollowersCount(ctx, cMsg.Target); err != nil { | 
					
						
							| 
									
										
										
										
											2024-04-16 13:10:13 +02:00
										 |  |  | 		log.Errorf(ctx, "error updating account stats: %v", err) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Update stats for the origin account. | 
					
						
							| 
									
										
										
										
											2024-04-26 13:50:46 +01:00
										 |  |  | 	if err := p.utils.incrementFollowingCount(ctx, cMsg.Origin); err != nil { | 
					
						
							| 
									
										
										
										
											2024-04-16 13:10:13 +02:00
										 |  |  | 		log.Errorf(ctx, "error updating account stats: %v", err) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-09 19:14:33 +02:00
										 |  |  | 	if err := p.surface.notifyFollow(ctx, follow); err != nil { | 
					
						
							| 
									
										
										
										
											2023-11-08 14:32:17 +00:00
										 |  |  | 		log.Errorf(ctx, "error notifying follow: %v", err) | 
					
						
							| 
									
										
										
										
											2023-08-09 19:14:33 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if err := p.federate.AcceptFollow(ctx, follow); err != nil { | 
					
						
							| 
									
										
										
										
											2023-11-08 14:32:17 +00:00
										 |  |  | 		log.Errorf(ctx, "error federating follow accept: %v", err) | 
					
						
							| 
									
										
										
										
											2023-08-09 19:14:33 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return nil | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-26 13:50:46 +01:00
										 |  |  | func (p *clientAPI) RejectFollowRequest(ctx context.Context, cMsg *messages.FromClientAPI) error { | 
					
						
							| 
									
										
										
										
											2023-08-09 19:14:33 +02:00
										 |  |  | 	followReq, ok := cMsg.GTSModel.(*gtsmodel.FollowRequest) | 
					
						
							|  |  |  | 	if !ok { | 
					
						
							|  |  |  | 		return gtserror.Newf("%T not parseable as *gtsmodel.FollowRequest", cMsg.GTSModel) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-16 13:10:13 +02:00
										 |  |  | 	// Update stats for the target account. | 
					
						
							| 
									
										
										
										
											2024-04-26 13:50:46 +01:00
										 |  |  | 	if err := p.utils.decrementFollowRequestsCount(ctx, cMsg.Target); err != nil { | 
					
						
							| 
									
										
										
										
											2024-04-16 13:10:13 +02:00
										 |  |  | 		log.Errorf(ctx, "error updating account stats: %v", err) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-09 19:14:33 +02:00
										 |  |  | 	if err := p.federate.RejectFollow( | 
					
						
							|  |  |  | 		ctx, | 
					
						
							| 
									
										
										
										
											2023-09-23 17:44:11 +01:00
										 |  |  | 		p.converter.FollowRequestToFollow(ctx, followReq), | 
					
						
							| 
									
										
										
										
											2023-08-09 19:14:33 +02:00
										 |  |  | 	); err != nil { | 
					
						
							| 
									
										
										
										
											2023-11-08 14:32:17 +00:00
										 |  |  | 		log.Errorf(ctx, "error federating follow reject: %v", err) | 
					
						
							| 
									
										
										
										
											2023-08-09 19:14:33 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return nil | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-26 13:50:46 +01:00
										 |  |  | func (p *clientAPI) UndoFollow(ctx context.Context, cMsg *messages.FromClientAPI) error { | 
					
						
							| 
									
										
										
										
											2023-08-09 19:14:33 +02:00
										 |  |  | 	follow, ok := cMsg.GTSModel.(*gtsmodel.Follow) | 
					
						
							|  |  |  | 	if !ok { | 
					
						
							|  |  |  | 		return gtserror.Newf("%T not parseable as *gtsmodel.Follow", cMsg.GTSModel) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-16 13:10:13 +02:00
										 |  |  | 	// Update stats for the origin account. | 
					
						
							| 
									
										
										
										
											2024-04-26 13:50:46 +01:00
										 |  |  | 	if err := p.utils.decrementFollowingCount(ctx, cMsg.Origin); err != nil { | 
					
						
							| 
									
										
										
										
											2024-04-16 13:10:13 +02:00
										 |  |  | 		log.Errorf(ctx, "error updating account stats: %v", err) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Update stats for the target account. | 
					
						
							| 
									
										
										
										
											2024-04-26 13:50:46 +01:00
										 |  |  | 	if err := p.utils.decrementFollowersCount(ctx, cMsg.Target); err != nil { | 
					
						
							| 
									
										
										
										
											2024-04-16 13:10:13 +02:00
										 |  |  | 		log.Errorf(ctx, "error updating account stats: %v", err) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
											  
											
												[performance] rewrite timelines to rely on new timeline cache type (#3941)
* start work rewriting timeline cache type
* further work rewriting timeline caching
* more work integration new timeline code
* remove old code
* add local timeline, fix up merge conflicts
* remove old use of go-bytes
* implement new timeline code into more areas of codebase, pull in latest go-mangler, go-mutexes, go-structr
* remove old timeline package, add local timeline cache
* remove references to old timeline types that needed starting up in tests
* start adding page validation
* fix test-identified timeline cache package issues
* fix up more tests, fix missing required changes, etc
* add exclusion for test.out in gitignore
* clarify some things better in code comments
* tweak cache size limits
* fix list timeline cache fetching
* further list timeline fixes
* linter, ssssssssshhhhhhhhhhhh please
* fix linter hints
* reslice the output if it's beyond length of 'lim'
* remove old timeline initialization code, bump go-structr to v0.9.4
* continued from previous commit
* improved code comments
* don't allow multiple entries for BoostOfID values to prevent repeated boosts of same boosts
* finish writing more code comments
* some variable renaming, for ease of following
* change the way we update lo,hi paging values during timeline load
* improved code comments for updated / returned lo , hi paging values
* finish writing code comments for the StatusTimeline{} type itself
* fill in more code comments
* update go-structr version to latest with changed timeline unique indexing logic
* have a local and public timeline *per user*
* rewrite calls to public / local timeline calls
* remove the zero length check, as lo, hi values might still be set
* simplify timeline cache loading, fix lo/hi returns, fix timeline invalidation side-effects missing for some federated actions
* swap the lo, hi values :facepalm:
* add (now) missing slice reverse of tag timeline statuses when paging ASC
* remove local / public caches (is out of scope for this work), share more timeline code
* remove unnecessary change
* again, remove more unused code
* remove unused function to appease the linter
* move boost checking to prepare function
* fix use of timeline.lastOrder, fix incorrect range functions used
* remove comments for repeat code
* remove the boost logic from prepare function
* do a maximum of 5 loads, not 10
* add repeat boost filtering logic, update go-structr, general improvements
* more code comments
* add important note
* fix timeline tests now that timelines are returned in page order
* remove unused field
* add StatusTimeline{} tests
* add more status timeline tests
* start adding preloading support
* ensure repeat boosts are marked in preloaded entries
* share a bunch of the database load code in timeline cache, don't clear timelines on relationship change
* add logic to allow dynamic clear / preloading of timelines
* comment-out unused functions, but leave in place as we might end-up using them
* fix timeline preload state check
* much improved status timeline code comments
* more code comments, don't bother inserting statuses if timeline not preloaded
* shift around some logic to make sure things aren't accidentally left set
* finish writing code comments
* remove trim-after-insert behaviour
* fix-up some comments referring to old logic
* remove unsetting of lo, hi
* fix preload repeatBoost checking logic
* don't return on status filter errors, these are usually transient
* better concurrency safety in Clear() and Done()
* fix test broken due to addition of preloader
* fix repeatBoost logic that doesn't account for already-hidden repeatBoosts
* ensure edit submodels are dropped on cache insertion
* update code-comment to expand CAS accronym
* use a plus1hULID() instead of 24h
* remove unused functions
* add note that public / local timeline requester can be nil
* fix incorrect visibility filtering of tag timeline statuses
* ensure we filter home timeline statuses on local only
* some small re-orderings to confirm query params in correct places
* fix the local only home timeline filter func
											
										 
											2025-04-26 09:56:15 +00:00
										 |  |  | 	if follow.Account.IsLocal() { | 
					
						
							|  |  |  | 		// Remove posts by target from origin's timelines. | 
					
						
							|  |  |  | 		p.surface.removeRelationshipFromTimelines(ctx, | 
					
						
							|  |  |  | 			follow.AccountID, | 
					
						
							|  |  |  | 			follow.TargetAccountID, | 
					
						
							|  |  |  | 		) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if follow.TargetAccount.IsLocal() { | 
					
						
							|  |  |  | 		// Remove posts by origin from target's timelines. | 
					
						
							|  |  |  | 		p.surface.removeRelationshipFromTimelines(ctx, | 
					
						
							|  |  |  | 			follow.TargetAccountID, | 
					
						
							|  |  |  | 			follow.AccountID, | 
					
						
							|  |  |  | 		) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-09 19:14:33 +02:00
										 |  |  | 	if err := p.federate.UndoFollow(ctx, follow); err != nil { | 
					
						
							| 
									
										
										
										
											2023-11-08 14:32:17 +00:00
										 |  |  | 		log.Errorf(ctx, "error federating follow undo: %v", err) | 
					
						
							| 
									
										
										
										
											2023-08-09 19:14:33 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return nil | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-26 13:50:46 +01:00
										 |  |  | func (p *clientAPI) UndoBlock(ctx context.Context, cMsg *messages.FromClientAPI) error { | 
					
						
							| 
									
										
										
										
											2023-08-09 19:14:33 +02:00
										 |  |  | 	block, ok := cMsg.GTSModel.(*gtsmodel.Block) | 
					
						
							|  |  |  | 	if !ok { | 
					
						
							|  |  |  | 		return gtserror.Newf("%T not parseable as *gtsmodel.Block", cMsg.GTSModel) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if err := p.federate.UndoBlock(ctx, block); err != nil { | 
					
						
							| 
									
										
										
										
											2023-11-08 14:32:17 +00:00
										 |  |  | 		log.Errorf(ctx, "error federating block undo: %v", err) | 
					
						
							| 
									
										
										
										
											2023-08-09 19:14:33 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return nil | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-26 13:50:46 +01:00
										 |  |  | func (p *clientAPI) UndoFave(ctx context.Context, cMsg *messages.FromClientAPI) error { | 
					
						
							| 
									
										
										
										
											2023-08-09 19:14:33 +02:00
										 |  |  | 	statusFave, ok := cMsg.GTSModel.(*gtsmodel.StatusFave) | 
					
						
							|  |  |  | 	if !ok { | 
					
						
							|  |  |  | 		return gtserror.Newf("%T not parseable as *gtsmodel.StatusFave", cMsg.GTSModel) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if err := p.federate.UndoLike(ctx, statusFave); err != nil { | 
					
						
							| 
									
										
										
										
											2023-11-08 14:32:17 +00:00
										 |  |  | 		log.Errorf(ctx, "error federating like undo: %v", err) | 
					
						
							| 
									
										
										
										
											2023-08-09 19:14:33 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-24 11:49:37 +02:00
										 |  |  | 	// Interaction counts changed on the faved status; | 
					
						
							|  |  |  | 	// uncache the prepared version from all timelines. | 
					
						
							| 
									
										
											  
											
												[performance] rewrite timelines to rely on new timeline cache type (#3941)
* start work rewriting timeline cache type
* further work rewriting timeline caching
* more work integration new timeline code
* remove old code
* add local timeline, fix up merge conflicts
* remove old use of go-bytes
* implement new timeline code into more areas of codebase, pull in latest go-mangler, go-mutexes, go-structr
* remove old timeline package, add local timeline cache
* remove references to old timeline types that needed starting up in tests
* start adding page validation
* fix test-identified timeline cache package issues
* fix up more tests, fix missing required changes, etc
* add exclusion for test.out in gitignore
* clarify some things better in code comments
* tweak cache size limits
* fix list timeline cache fetching
* further list timeline fixes
* linter, ssssssssshhhhhhhhhhhh please
* fix linter hints
* reslice the output if it's beyond length of 'lim'
* remove old timeline initialization code, bump go-structr to v0.9.4
* continued from previous commit
* improved code comments
* don't allow multiple entries for BoostOfID values to prevent repeated boosts of same boosts
* finish writing more code comments
* some variable renaming, for ease of following
* change the way we update lo,hi paging values during timeline load
* improved code comments for updated / returned lo , hi paging values
* finish writing code comments for the StatusTimeline{} type itself
* fill in more code comments
* update go-structr version to latest with changed timeline unique indexing logic
* have a local and public timeline *per user*
* rewrite calls to public / local timeline calls
* remove the zero length check, as lo, hi values might still be set
* simplify timeline cache loading, fix lo/hi returns, fix timeline invalidation side-effects missing for some federated actions
* swap the lo, hi values :facepalm:
* add (now) missing slice reverse of tag timeline statuses when paging ASC
* remove local / public caches (is out of scope for this work), share more timeline code
* remove unnecessary change
* again, remove more unused code
* remove unused function to appease the linter
* move boost checking to prepare function
* fix use of timeline.lastOrder, fix incorrect range functions used
* remove comments for repeat code
* remove the boost logic from prepare function
* do a maximum of 5 loads, not 10
* add repeat boost filtering logic, update go-structr, general improvements
* more code comments
* add important note
* fix timeline tests now that timelines are returned in page order
* remove unused field
* add StatusTimeline{} tests
* add more status timeline tests
* start adding preloading support
* ensure repeat boosts are marked in preloaded entries
* share a bunch of the database load code in timeline cache, don't clear timelines on relationship change
* add logic to allow dynamic clear / preloading of timelines
* comment-out unused functions, but leave in place as we might end-up using them
* fix timeline preload state check
* much improved status timeline code comments
* more code comments, don't bother inserting statuses if timeline not preloaded
* shift around some logic to make sure things aren't accidentally left set
* finish writing code comments
* remove trim-after-insert behaviour
* fix-up some comments referring to old logic
* remove unsetting of lo, hi
* fix preload repeatBoost checking logic
* don't return on status filter errors, these are usually transient
* better concurrency safety in Clear() and Done()
* fix test broken due to addition of preloader
* fix repeatBoost logic that doesn't account for already-hidden repeatBoosts
* ensure edit submodels are dropped on cache insertion
* update code-comment to expand CAS accronym
* use a plus1hULID() instead of 24h
* remove unused functions
* add note that public / local timeline requester can be nil
* fix incorrect visibility filtering of tag timeline statuses
* ensure we filter home timeline statuses on local only
* some small re-orderings to confirm query params in correct places
* fix the local only home timeline filter func
											
										 
											2025-04-26 09:56:15 +00:00
										 |  |  | 	p.surface.invalidateStatusFromTimelines(statusFave.StatusID) | 
					
						
							| 
									
										
										
										
											2024-08-24 11:49:37 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-09 19:14:33 +02:00
										 |  |  | 	return nil | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-26 13:50:46 +01:00
										 |  |  | func (p *clientAPI) UndoAnnounce(ctx context.Context, cMsg *messages.FromClientAPI) error { | 
					
						
							| 
									
										
										
										
											2023-08-09 19:14:33 +02:00
										 |  |  | 	status, ok := cMsg.GTSModel.(*gtsmodel.Status) | 
					
						
							|  |  |  | 	if !ok { | 
					
						
							|  |  |  | 		return gtserror.Newf("%T not parseable as *gtsmodel.Status", cMsg.GTSModel) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if err := p.state.DB.DeleteStatusByID(ctx, status.ID); err != nil { | 
					
						
							|  |  |  | 		return gtserror.Newf("db error deleting status: %w", err) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-16 13:10:13 +02:00
										 |  |  | 	// Update stats for the origin account. | 
					
						
							| 
									
										
										
										
											2024-08-11 09:23:36 +00:00
										 |  |  | 	if err := p.utils.decrementStatusesCount(ctx, cMsg.Origin, status); err != nil { | 
					
						
							| 
									
										
										
										
											2024-04-16 13:10:13 +02:00
										 |  |  | 		log.Errorf(ctx, "error updating account stats: %v", err) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
											  
											
												[performance] rewrite timelines to rely on new timeline cache type (#3941)
* start work rewriting timeline cache type
* further work rewriting timeline caching
* more work integration new timeline code
* remove old code
* add local timeline, fix up merge conflicts
* remove old use of go-bytes
* implement new timeline code into more areas of codebase, pull in latest go-mangler, go-mutexes, go-structr
* remove old timeline package, add local timeline cache
* remove references to old timeline types that needed starting up in tests
* start adding page validation
* fix test-identified timeline cache package issues
* fix up more tests, fix missing required changes, etc
* add exclusion for test.out in gitignore
* clarify some things better in code comments
* tweak cache size limits
* fix list timeline cache fetching
* further list timeline fixes
* linter, ssssssssshhhhhhhhhhhh please
* fix linter hints
* reslice the output if it's beyond length of 'lim'
* remove old timeline initialization code, bump go-structr to v0.9.4
* continued from previous commit
* improved code comments
* don't allow multiple entries for BoostOfID values to prevent repeated boosts of same boosts
* finish writing more code comments
* some variable renaming, for ease of following
* change the way we update lo,hi paging values during timeline load
* improved code comments for updated / returned lo , hi paging values
* finish writing code comments for the StatusTimeline{} type itself
* fill in more code comments
* update go-structr version to latest with changed timeline unique indexing logic
* have a local and public timeline *per user*
* rewrite calls to public / local timeline calls
* remove the zero length check, as lo, hi values might still be set
* simplify timeline cache loading, fix lo/hi returns, fix timeline invalidation side-effects missing for some federated actions
* swap the lo, hi values :facepalm:
* add (now) missing slice reverse of tag timeline statuses when paging ASC
* remove local / public caches (is out of scope for this work), share more timeline code
* remove unnecessary change
* again, remove more unused code
* remove unused function to appease the linter
* move boost checking to prepare function
* fix use of timeline.lastOrder, fix incorrect range functions used
* remove comments for repeat code
* remove the boost logic from prepare function
* do a maximum of 5 loads, not 10
* add repeat boost filtering logic, update go-structr, general improvements
* more code comments
* add important note
* fix timeline tests now that timelines are returned in page order
* remove unused field
* add StatusTimeline{} tests
* add more status timeline tests
* start adding preloading support
* ensure repeat boosts are marked in preloaded entries
* share a bunch of the database load code in timeline cache, don't clear timelines on relationship change
* add logic to allow dynamic clear / preloading of timelines
* comment-out unused functions, but leave in place as we might end-up using them
* fix timeline preload state check
* much improved status timeline code comments
* more code comments, don't bother inserting statuses if timeline not preloaded
* shift around some logic to make sure things aren't accidentally left set
* finish writing code comments
* remove trim-after-insert behaviour
* fix-up some comments referring to old logic
* remove unsetting of lo, hi
* fix preload repeatBoost checking logic
* don't return on status filter errors, these are usually transient
* better concurrency safety in Clear() and Done()
* fix test broken due to addition of preloader
* fix repeatBoost logic that doesn't account for already-hidden repeatBoosts
* ensure edit submodels are dropped on cache insertion
* update code-comment to expand CAS accronym
* use a plus1hULID() instead of 24h
* remove unused functions
* add note that public / local timeline requester can be nil
* fix incorrect visibility filtering of tag timeline statuses
* ensure we filter home timeline statuses on local only
* some small re-orderings to confirm query params in correct places
* fix the local only home timeline filter func
											
										 
											2025-04-26 09:56:15 +00:00
										 |  |  | 	// Delete the boost wrapper status from timelines. | 
					
						
							|  |  |  | 	p.surface.deleteStatusFromTimelines(ctx, status.ID) | 
					
						
							| 
									
										
										
										
											2023-08-09 19:14:33 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if err := p.federate.UndoAnnounce(ctx, status); err != nil { | 
					
						
							| 
									
										
										
										
											2023-11-08 14:32:17 +00:00
										 |  |  | 		log.Errorf(ctx, "error federating announce undo: %v", err) | 
					
						
							| 
									
										
										
										
											2023-08-09 19:14:33 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-24 11:49:37 +02:00
										 |  |  | 	// Interaction counts changed on the boosted status; | 
					
						
							|  |  |  | 	// uncache the prepared version from all timelines. | 
					
						
							| 
									
										
											  
											
												[performance] rewrite timelines to rely on new timeline cache type (#3941)
* start work rewriting timeline cache type
* further work rewriting timeline caching
* more work integration new timeline code
* remove old code
* add local timeline, fix up merge conflicts
* remove old use of go-bytes
* implement new timeline code into more areas of codebase, pull in latest go-mangler, go-mutexes, go-structr
* remove old timeline package, add local timeline cache
* remove references to old timeline types that needed starting up in tests
* start adding page validation
* fix test-identified timeline cache package issues
* fix up more tests, fix missing required changes, etc
* add exclusion for test.out in gitignore
* clarify some things better in code comments
* tweak cache size limits
* fix list timeline cache fetching
* further list timeline fixes
* linter, ssssssssshhhhhhhhhhhh please
* fix linter hints
* reslice the output if it's beyond length of 'lim'
* remove old timeline initialization code, bump go-structr to v0.9.4
* continued from previous commit
* improved code comments
* don't allow multiple entries for BoostOfID values to prevent repeated boosts of same boosts
* finish writing more code comments
* some variable renaming, for ease of following
* change the way we update lo,hi paging values during timeline load
* improved code comments for updated / returned lo , hi paging values
* finish writing code comments for the StatusTimeline{} type itself
* fill in more code comments
* update go-structr version to latest with changed timeline unique indexing logic
* have a local and public timeline *per user*
* rewrite calls to public / local timeline calls
* remove the zero length check, as lo, hi values might still be set
* simplify timeline cache loading, fix lo/hi returns, fix timeline invalidation side-effects missing for some federated actions
* swap the lo, hi values :facepalm:
* add (now) missing slice reverse of tag timeline statuses when paging ASC
* remove local / public caches (is out of scope for this work), share more timeline code
* remove unnecessary change
* again, remove more unused code
* remove unused function to appease the linter
* move boost checking to prepare function
* fix use of timeline.lastOrder, fix incorrect range functions used
* remove comments for repeat code
* remove the boost logic from prepare function
* do a maximum of 5 loads, not 10
* add repeat boost filtering logic, update go-structr, general improvements
* more code comments
* add important note
* fix timeline tests now that timelines are returned in page order
* remove unused field
* add StatusTimeline{} tests
* add more status timeline tests
* start adding preloading support
* ensure repeat boosts are marked in preloaded entries
* share a bunch of the database load code in timeline cache, don't clear timelines on relationship change
* add logic to allow dynamic clear / preloading of timelines
* comment-out unused functions, but leave in place as we might end-up using them
* fix timeline preload state check
* much improved status timeline code comments
* more code comments, don't bother inserting statuses if timeline not preloaded
* shift around some logic to make sure things aren't accidentally left set
* finish writing code comments
* remove trim-after-insert behaviour
* fix-up some comments referring to old logic
* remove unsetting of lo, hi
* fix preload repeatBoost checking logic
* don't return on status filter errors, these are usually transient
* better concurrency safety in Clear() and Done()
* fix test broken due to addition of preloader
* fix repeatBoost logic that doesn't account for already-hidden repeatBoosts
* ensure edit submodels are dropped on cache insertion
* update code-comment to expand CAS accronym
* use a plus1hULID() instead of 24h
* remove unused functions
* add note that public / local timeline requester can be nil
* fix incorrect visibility filtering of tag timeline statuses
* ensure we filter home timeline statuses on local only
* some small re-orderings to confirm query params in correct places
* fix the local only home timeline filter func
											
										 
											2025-04-26 09:56:15 +00:00
										 |  |  | 	p.surface.invalidateStatusFromTimelines(status.BoostOfID) | 
					
						
							| 
									
										
										
										
											2024-08-24 11:49:37 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-09 19:14:33 +02:00
										 |  |  | 	return nil | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-26 13:50:46 +01:00
										 |  |  | func (p *clientAPI) DeleteStatus(ctx context.Context, cMsg *messages.FromClientAPI) error { | 
					
						
							| 
									
										
										
										
											2023-08-09 19:14:33 +02:00
										 |  |  | 	status, ok := cMsg.GTSModel.(*gtsmodel.Status) | 
					
						
							|  |  |  | 	if !ok { | 
					
						
							|  |  |  | 		return gtserror.Newf("%T not parseable as *gtsmodel.Status", cMsg.GTSModel) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Try to populate status structs if possible, | 
					
						
							|  |  |  | 	// in order to more thoroughly remove them. | 
					
						
							|  |  |  | 	if err := p.state.DB.PopulateStatus( | 
					
						
							|  |  |  | 		ctx, status, | 
					
						
							|  |  |  | 	); err != nil && !errors.Is(err, db.ErrNoEntries) { | 
					
						
							|  |  |  | 		return gtserror.Newf("db error populating status: %w", err) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-26 13:50:46 +01:00
										 |  |  | 	// Drop any outgoing queued AP requests about / targeting | 
					
						
							|  |  |  | 	// this status, (stops queued likes, boosts, creates etc). | 
					
						
							|  |  |  | 	p.state.Workers.Delivery.Queue.Delete("ObjectID", status.URI) | 
					
						
							|  |  |  | 	p.state.Workers.Delivery.Queue.Delete("TargetID", status.URI) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Drop any incoming queued client messages about / targeting | 
					
						
							|  |  |  | 	// status, (stops processing of local origin data for status). | 
					
						
							|  |  |  | 	p.state.Workers.Client.Queue.Delete("TargetURI", status.URI) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Drop any incoming queued federator messages targeting status, | 
					
						
							|  |  |  | 	// (stops processing of remote origin data targeting this status). | 
					
						
							|  |  |  | 	p.state.Workers.Federator.Queue.Delete("TargetURI", status.URI) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-09-10 14:34:49 +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 later. | 
					
						
							|  |  |  | 	const deleteAttachments = false | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// This is just a deletion, not a Reject, | 
					
						
							|  |  |  | 	// we don't need to take a copy of this status. | 
					
						
							|  |  |  | 	const copyToSinBin = false | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Perform the actual status deletion. | 
					
						
							|  |  |  | 	if err := p.utils.wipeStatus( | 
					
						
							|  |  |  | 		ctx, | 
					
						
							|  |  |  | 		status, | 
					
						
							|  |  |  | 		deleteAttachments, | 
					
						
							|  |  |  | 		copyToSinBin, | 
					
						
							|  |  |  | 	); err != nil { | 
					
						
							| 
									
										
										
										
											2023-11-08 14:32:17 +00:00
										 |  |  | 		log.Errorf(ctx, "error wiping status: %v", err) | 
					
						
							| 
									
										
										
										
											2023-08-09 19:14:33 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-16 13:10:13 +02:00
										 |  |  | 	// Update stats for the origin account. | 
					
						
							| 
									
										
										
										
											2024-08-11 09:23:36 +00:00
										 |  |  | 	if err := p.utils.decrementStatusesCount(ctx, cMsg.Origin, status); err != nil { | 
					
						
							| 
									
										
										
										
											2024-04-16 13:10:13 +02:00
										 |  |  | 		log.Errorf(ctx, "error updating account stats: %v", err) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-24 11:49:37 +02:00
										 |  |  | 	if err := p.federate.DeleteStatus(ctx, status); err != nil { | 
					
						
							|  |  |  | 		log.Errorf(ctx, "error federating status delete: %v", err) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-09 19:14:33 +02:00
										 |  |  | 	if status.InReplyToID != "" { | 
					
						
							|  |  |  | 		// Interaction counts changed on the replied status; | 
					
						
							|  |  |  | 		// uncache the prepared version from all timelines. | 
					
						
							| 
									
										
											  
											
												[performance] rewrite timelines to rely on new timeline cache type (#3941)
* start work rewriting timeline cache type
* further work rewriting timeline caching
* more work integration new timeline code
* remove old code
* add local timeline, fix up merge conflicts
* remove old use of go-bytes
* implement new timeline code into more areas of codebase, pull in latest go-mangler, go-mutexes, go-structr
* remove old timeline package, add local timeline cache
* remove references to old timeline types that needed starting up in tests
* start adding page validation
* fix test-identified timeline cache package issues
* fix up more tests, fix missing required changes, etc
* add exclusion for test.out in gitignore
* clarify some things better in code comments
* tweak cache size limits
* fix list timeline cache fetching
* further list timeline fixes
* linter, ssssssssshhhhhhhhhhhh please
* fix linter hints
* reslice the output if it's beyond length of 'lim'
* remove old timeline initialization code, bump go-structr to v0.9.4
* continued from previous commit
* improved code comments
* don't allow multiple entries for BoostOfID values to prevent repeated boosts of same boosts
* finish writing more code comments
* some variable renaming, for ease of following
* change the way we update lo,hi paging values during timeline load
* improved code comments for updated / returned lo , hi paging values
* finish writing code comments for the StatusTimeline{} type itself
* fill in more code comments
* update go-structr version to latest with changed timeline unique indexing logic
* have a local and public timeline *per user*
* rewrite calls to public / local timeline calls
* remove the zero length check, as lo, hi values might still be set
* simplify timeline cache loading, fix lo/hi returns, fix timeline invalidation side-effects missing for some federated actions
* swap the lo, hi values :facepalm:
* add (now) missing slice reverse of tag timeline statuses when paging ASC
* remove local / public caches (is out of scope for this work), share more timeline code
* remove unnecessary change
* again, remove more unused code
* remove unused function to appease the linter
* move boost checking to prepare function
* fix use of timeline.lastOrder, fix incorrect range functions used
* remove comments for repeat code
* remove the boost logic from prepare function
* do a maximum of 5 loads, not 10
* add repeat boost filtering logic, update go-structr, general improvements
* more code comments
* add important note
* fix timeline tests now that timelines are returned in page order
* remove unused field
* add StatusTimeline{} tests
* add more status timeline tests
* start adding preloading support
* ensure repeat boosts are marked in preloaded entries
* share a bunch of the database load code in timeline cache, don't clear timelines on relationship change
* add logic to allow dynamic clear / preloading of timelines
* comment-out unused functions, but leave in place as we might end-up using them
* fix timeline preload state check
* much improved status timeline code comments
* more code comments, don't bother inserting statuses if timeline not preloaded
* shift around some logic to make sure things aren't accidentally left set
* finish writing code comments
* remove trim-after-insert behaviour
* fix-up some comments referring to old logic
* remove unsetting of lo, hi
* fix preload repeatBoost checking logic
* don't return on status filter errors, these are usually transient
* better concurrency safety in Clear() and Done()
* fix test broken due to addition of preloader
* fix repeatBoost logic that doesn't account for already-hidden repeatBoosts
* ensure edit submodels are dropped on cache insertion
* update code-comment to expand CAS accronym
* use a plus1hULID() instead of 24h
* remove unused functions
* add note that public / local timeline requester can be nil
* fix incorrect visibility filtering of tag timeline statuses
* ensure we filter home timeline statuses on local only
* some small re-orderings to confirm query params in correct places
* fix the local only home timeline filter func
											
										 
											2025-04-26 09:56:15 +00:00
										 |  |  | 		p.surface.invalidateStatusFromTimelines(status.InReplyToID) | 
					
						
							| 
									
										
										
										
											2023-08-09 19:14:33 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return nil | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-06-06 15:43:25 +02:00
										 |  |  | func (p *clientAPI) DeleteAccountOrUser(ctx context.Context, cMsg *messages.FromClientAPI) error { | 
					
						
							| 
									
										
										
										
											2023-08-09 19:14:33 +02:00
										 |  |  | 	// The originID of the delete, one of: | 
					
						
							|  |  |  | 	//   - ID of a domain block, for which | 
					
						
							|  |  |  | 	//     this account delete is a side effect. | 
					
						
							|  |  |  | 	//   - ID of the deleted account itself (self delete). | 
					
						
							|  |  |  | 	//   - ID of an admin account (account suspension). | 
					
						
							|  |  |  | 	var originID string | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if domainBlock, ok := cMsg.GTSModel.(*gtsmodel.DomainBlock); ok { | 
					
						
							|  |  |  | 		// Origin is a domain block. | 
					
						
							|  |  |  | 		originID = domainBlock.ID | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		// Origin is whichever account | 
					
						
							|  |  |  | 		// originated this message. | 
					
						
							| 
									
										
										
										
											2024-04-26 13:50:46 +01:00
										 |  |  | 		originID = cMsg.Origin.ID | 
					
						
							| 
									
										
										
										
											2023-08-09 19:14:33 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-26 13:50:46 +01:00
										 |  |  | 	// Extract target account. | 
					
						
							|  |  |  | 	account := cMsg.Target | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Drop any outgoing queued AP requests to / from / targeting | 
					
						
							|  |  |  | 	// this account, (stops queued likes, boosts, creates etc). | 
					
						
							|  |  |  | 	p.state.Workers.Delivery.Queue.Delete("ActorID", account.URI) | 
					
						
							|  |  |  | 	p.state.Workers.Delivery.Queue.Delete("ObjectID", account.URI) | 
					
						
							|  |  |  | 	p.state.Workers.Delivery.Queue.Delete("TargetID", account.URI) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Drop any incoming queued client messages to / from this | 
					
						
							|  |  |  | 	// account, (stops processing of local origin data for acccount). | 
					
						
							|  |  |  | 	p.state.Workers.Client.Queue.Delete("Origin.ID", account.ID) | 
					
						
							|  |  |  | 	p.state.Workers.Client.Queue.Delete("Target.ID", account.ID) | 
					
						
							|  |  |  | 	p.state.Workers.Client.Queue.Delete("TargetURI", account.URI) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Drop any incoming queued federator messages to this account, | 
					
						
							|  |  |  | 	// (stops processing of remote origin data targeting this account). | 
					
						
							|  |  |  | 	p.state.Workers.Federator.Queue.Delete("Receiving.ID", account.ID) | 
					
						
							|  |  |  | 	p.state.Workers.Federator.Queue.Delete("TargetURI", account.URI) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
											  
											
												[performance] rewrite timelines to rely on new timeline cache type (#3941)
* start work rewriting timeline cache type
* further work rewriting timeline caching
* more work integration new timeline code
* remove old code
* add local timeline, fix up merge conflicts
* remove old use of go-bytes
* implement new timeline code into more areas of codebase, pull in latest go-mangler, go-mutexes, go-structr
* remove old timeline package, add local timeline cache
* remove references to old timeline types that needed starting up in tests
* start adding page validation
* fix test-identified timeline cache package issues
* fix up more tests, fix missing required changes, etc
* add exclusion for test.out in gitignore
* clarify some things better in code comments
* tweak cache size limits
* fix list timeline cache fetching
* further list timeline fixes
* linter, ssssssssshhhhhhhhhhhh please
* fix linter hints
* reslice the output if it's beyond length of 'lim'
* remove old timeline initialization code, bump go-structr to v0.9.4
* continued from previous commit
* improved code comments
* don't allow multiple entries for BoostOfID values to prevent repeated boosts of same boosts
* finish writing more code comments
* some variable renaming, for ease of following
* change the way we update lo,hi paging values during timeline load
* improved code comments for updated / returned lo , hi paging values
* finish writing code comments for the StatusTimeline{} type itself
* fill in more code comments
* update go-structr version to latest with changed timeline unique indexing logic
* have a local and public timeline *per user*
* rewrite calls to public / local timeline calls
* remove the zero length check, as lo, hi values might still be set
* simplify timeline cache loading, fix lo/hi returns, fix timeline invalidation side-effects missing for some federated actions
* swap the lo, hi values :facepalm:
* add (now) missing slice reverse of tag timeline statuses when paging ASC
* remove local / public caches (is out of scope for this work), share more timeline code
* remove unnecessary change
* again, remove more unused code
* remove unused function to appease the linter
* move boost checking to prepare function
* fix use of timeline.lastOrder, fix incorrect range functions used
* remove comments for repeat code
* remove the boost logic from prepare function
* do a maximum of 5 loads, not 10
* add repeat boost filtering logic, update go-structr, general improvements
* more code comments
* add important note
* fix timeline tests now that timelines are returned in page order
* remove unused field
* add StatusTimeline{} tests
* add more status timeline tests
* start adding preloading support
* ensure repeat boosts are marked in preloaded entries
* share a bunch of the database load code in timeline cache, don't clear timelines on relationship change
* add logic to allow dynamic clear / preloading of timelines
* comment-out unused functions, but leave in place as we might end-up using them
* fix timeline preload state check
* much improved status timeline code comments
* more code comments, don't bother inserting statuses if timeline not preloaded
* shift around some logic to make sure things aren't accidentally left set
* finish writing code comments
* remove trim-after-insert behaviour
* fix-up some comments referring to old logic
* remove unsetting of lo, hi
* fix preload repeatBoost checking logic
* don't return on status filter errors, these are usually transient
* better concurrency safety in Clear() and Done()
* fix test broken due to addition of preloader
* fix repeatBoost logic that doesn't account for already-hidden repeatBoosts
* ensure edit submodels are dropped on cache insertion
* update code-comment to expand CAS accronym
* use a plus1hULID() instead of 24h
* remove unused functions
* add note that public / local timeline requester can be nil
* fix incorrect visibility filtering of tag timeline statuses
* ensure we filter home timeline statuses on local only
* some small re-orderings to confirm query params in correct places
* fix the local only home timeline filter func
											
										 
											2025-04-26 09:56:15 +00:00
										 |  |  | 	// Remove any entries authored by account from timelines. | 
					
						
							|  |  |  | 	p.surface.removeTimelineEntriesByAccount(account.ID) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Remove any of their cached timelines. | 
					
						
							|  |  |  | 	p.state.Caches.Timelines.Home.Delete(account.ID) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Get the IDs of all the lists owned by the given account ID. | 
					
						
							|  |  |  | 	listIDs, err := p.state.DB.GetListIDsByAccountID(ctx, account.ID) | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		log.Errorf(ctx, "error getting lists for account %s: %v", account.ID, err) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Remove list timelines of account. | 
					
						
							|  |  |  | 	for _, listID := range listIDs { | 
					
						
							|  |  |  | 		p.state.Caches.Timelines.List.Delete(listID) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-06-11 11:38:10 +02:00
										 |  |  | 	// Federate out a delete activity targeting account to remote servers. | 
					
						
							| 
									
										
										
										
											2024-04-26 13:50:46 +01:00
										 |  |  | 	if err := p.federate.DeleteAccount(ctx, cMsg.Target); err != nil { | 
					
						
							| 
									
										
										
										
											2023-11-08 14:32:17 +00:00
										 |  |  | 		log.Errorf(ctx, "error federating account delete: %v", err) | 
					
						
							| 
									
										
										
										
											2023-08-09 19:14:33 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-06-11 11:38:10 +02:00
										 |  |  | 	// And finally, perform the actual account deletion synchronously. | 
					
						
							|  |  |  | 	if err := p.account.Delete(ctx, account, originID); err != nil { | 
					
						
							| 
									
										
										
										
											2023-11-08 14:32:17 +00:00
										 |  |  | 		log.Errorf(ctx, "error deleting account: %v", err) | 
					
						
							| 
									
										
										
										
											2023-08-09 19:14:33 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return nil | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-26 13:50:46 +01:00
										 |  |  | func (p *clientAPI) ReportAccount(ctx context.Context, cMsg *messages.FromClientAPI) error { | 
					
						
							| 
									
										
										
										
											2023-08-09 19:14:33 +02:00
										 |  |  | 	report, ok := cMsg.GTSModel.(*gtsmodel.Report) | 
					
						
							|  |  |  | 	if !ok { | 
					
						
							|  |  |  | 		return gtserror.Newf("%T not parseable as *gtsmodel.Report", cMsg.GTSModel) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Federate this report to the | 
					
						
							|  |  |  | 	// remote instance if desired. | 
					
						
							|  |  |  | 	if *report.Forwarded { | 
					
						
							|  |  |  | 		if err := p.federate.Flag(ctx, report); err != nil { | 
					
						
							| 
									
										
										
										
											2023-11-08 14:32:17 +00:00
										 |  |  | 			log.Errorf(ctx, "error federating flag: %v", err) | 
					
						
							| 
									
										
										
										
											2023-08-09 19:14:33 +02:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-11 11:45:53 +02:00
										 |  |  | 	if err := p.surface.emailAdminReportOpened(ctx, report); err != nil { | 
					
						
							| 
									
										
										
										
											2023-11-08 14:32:17 +00:00
										 |  |  | 		log.Errorf(ctx, "error emailing report opened: %v", err) | 
					
						
							| 
									
										
										
										
											2023-08-09 19:14:33 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return nil | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2024-03-13 13:53:29 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-26 13:50:46 +01:00
										 |  |  | func (p *clientAPI) MoveAccount(ctx context.Context, cMsg *messages.FromClientAPI) error { | 
					
						
							| 
									
										
										
										
											2024-03-13 13:53:29 +01:00
										 |  |  | 	// Redirect each local follower of | 
					
						
							|  |  |  | 	// OriginAccount to follow move target. | 
					
						
							| 
									
										
										
										
											2024-04-26 13:50:46 +01:00
										 |  |  | 	p.utils.redirectFollowers(ctx, cMsg.Origin, cMsg.Target) | 
					
						
							| 
									
										
										
										
											2024-03-13 13:53:29 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// At this point, we know OriginAccount has the | 
					
						
							|  |  |  | 	// Move set on it. Just make sure it's populated. | 
					
						
							| 
									
										
										
										
											2024-04-26 13:50:46 +01:00
										 |  |  | 	if err := p.state.DB.PopulateMove(ctx, cMsg.Origin.Move); err != nil { | 
					
						
							| 
									
										
										
										
											2024-03-13 13:53:29 +01:00
										 |  |  | 		return gtserror.Newf("error populating Move: %w", err) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Now send the Move message out to | 
					
						
							|  |  |  | 	// OriginAccount's (remote) followers. | 
					
						
							| 
									
										
										
										
											2024-04-26 13:50:46 +01:00
										 |  |  | 	if err := p.federate.MoveAccount(ctx, cMsg.Origin); err != nil { | 
					
						
							| 
									
										
										
										
											2024-03-13 13:53:29 +01:00
										 |  |  | 		return gtserror.Newf("error federating account move: %w", err) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Mark the move attempt as successful. | 
					
						
							| 
									
										
										
										
											2024-04-26 13:50:46 +01:00
										 |  |  | 	cMsg.Origin.Move.SucceededAt = cMsg.Origin.Move.AttemptedAt | 
					
						
							| 
									
										
										
										
											2024-03-13 13:53:29 +01:00
										 |  |  | 	if err := p.state.DB.UpdateMove( | 
					
						
							|  |  |  | 		ctx, | 
					
						
							| 
									
										
										
										
											2024-04-26 13:50:46 +01:00
										 |  |  | 		cMsg.Origin.Move, | 
					
						
							| 
									
										
										
										
											2024-03-13 13:53:29 +01:00
										 |  |  | 		"succeeded_at", | 
					
						
							|  |  |  | 	); err != nil { | 
					
						
							|  |  |  | 		return gtserror.Newf("error marking move as successful: %w", err) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return nil | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2024-04-13 13:25:10 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-06-06 15:43:25 +02:00
										 |  |  | func (p *clientAPI) AcceptUser(ctx context.Context, cMsg *messages.FromClientAPI) error { | 
					
						
							| 
									
										
										
										
											2024-04-13 13:25:10 +02:00
										 |  |  | 	newUser, ok := cMsg.GTSModel.(*gtsmodel.User) | 
					
						
							|  |  |  | 	if !ok { | 
					
						
							|  |  |  | 		return gtserror.Newf("%T not parseable as *gtsmodel.User", cMsg.GTSModel) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Mark user as approved + clear sign-up IP. | 
					
						
							|  |  |  | 	newUser.Approved = util.Ptr(true) | 
					
						
							|  |  |  | 	newUser.SignUpIP = nil | 
					
						
							|  |  |  | 	if err := p.state.DB.UpdateUser(ctx, newUser, "approved", "sign_up_ip"); err != nil { | 
					
						
							|  |  |  | 		// Error now means we should return without | 
					
						
							|  |  |  | 		// sending email + let admin try to approve again. | 
					
						
							|  |  |  | 		return gtserror.Newf("db error updating user %s: %w", newUser.ID, err) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Send "your sign-up has been approved" email to the new user. | 
					
						
							|  |  |  | 	if err := p.surface.emailUserSignupApproved(ctx, newUser); err != nil { | 
					
						
							|  |  |  | 		log.Errorf(ctx, "error emailing: %v", err) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return nil | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-06-06 15:43:25 +02:00
										 |  |  | func (p *clientAPI) RejectUser(ctx context.Context, cMsg *messages.FromClientAPI) error { | 
					
						
							| 
									
										
										
										
											2024-04-13 13:25:10 +02:00
										 |  |  | 	deniedUser, ok := cMsg.GTSModel.(*gtsmodel.DeniedUser) | 
					
						
							|  |  |  | 	if !ok { | 
					
						
							|  |  |  | 		return gtserror.Newf("%T not parseable as *gtsmodel.DeniedUser", cMsg.GTSModel) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Remove the account. | 
					
						
							| 
									
										
										
										
											2024-04-26 13:50:46 +01:00
										 |  |  | 	if err := p.state.DB.DeleteAccount(ctx, cMsg.Target.ID); err != nil { | 
					
						
							| 
									
										
										
										
											2024-04-13 13:25:10 +02:00
										 |  |  | 		log.Errorf(ctx, | 
					
						
							|  |  |  | 			"db error deleting account %s: %v", | 
					
						
							| 
									
										
										
										
											2024-04-26 13:50:46 +01:00
										 |  |  | 			cMsg.Target.ID, err, | 
					
						
							| 
									
										
										
										
											2024-04-13 13:25:10 +02:00
										 |  |  | 		) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Remove the user. | 
					
						
							|  |  |  | 	if err := p.state.DB.DeleteUserByID(ctx, deniedUser.ID); err != nil { | 
					
						
							|  |  |  | 		log.Errorf(ctx, | 
					
						
							|  |  |  | 			"db error deleting user %s: %v", | 
					
						
							|  |  |  | 			deniedUser.ID, err, | 
					
						
							|  |  |  | 		) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Store the deniedUser entry. | 
					
						
							|  |  |  | 	if err := p.state.DB.PutDeniedUser(ctx, deniedUser); err != nil { | 
					
						
							|  |  |  | 		log.Errorf(ctx, | 
					
						
							|  |  |  | 			"db error putting denied user %s: %v", | 
					
						
							|  |  |  | 			deniedUser.ID, err, | 
					
						
							|  |  |  | 		) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if *deniedUser.SendEmail { | 
					
						
							|  |  |  | 		// Send "your sign-up has been rejected" email to the denied user. | 
					
						
							|  |  |  | 		if err := p.surface.emailUserSignupRejected(ctx, deniedUser); err != nil { | 
					
						
							|  |  |  | 			log.Errorf(ctx, "error emailing: %v", err) | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return nil | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2024-07-26 12:04:28 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | func (p *clientAPI) AcceptLike(ctx context.Context, cMsg *messages.FromClientAPI) error { | 
					
						
							| 
									
										
										
										
											2024-08-24 11:49:37 +02:00
										 |  |  | 	req, ok := cMsg.GTSModel.(*gtsmodel.InteractionRequest) | 
					
						
							|  |  |  | 	if !ok { | 
					
						
							|  |  |  | 		return gtserror.Newf("%T not parseable as *gtsmodel.InteractionRequest", cMsg.GTSModel) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Notify the fave (distinct from the notif for the pending fave). | 
					
						
							|  |  |  | 	if err := p.surface.notifyFave(ctx, req.Like); err != nil { | 
					
						
							|  |  |  | 		log.Errorf(ctx, "error notifying fave: %v", err) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Send out the Accept. | 
					
						
							|  |  |  | 	if err := p.federate.AcceptInteraction(ctx, req); err != nil { | 
					
						
							|  |  |  | 		log.Errorf(ctx, "error federating approval of like: %v", err) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Interaction counts changed on the faved status; | 
					
						
							|  |  |  | 	// uncache the prepared version from all timelines. | 
					
						
							| 
									
										
											  
											
												[performance] rewrite timelines to rely on new timeline cache type (#3941)
* start work rewriting timeline cache type
* further work rewriting timeline caching
* more work integration new timeline code
* remove old code
* add local timeline, fix up merge conflicts
* remove old use of go-bytes
* implement new timeline code into more areas of codebase, pull in latest go-mangler, go-mutexes, go-structr
* remove old timeline package, add local timeline cache
* remove references to old timeline types that needed starting up in tests
* start adding page validation
* fix test-identified timeline cache package issues
* fix up more tests, fix missing required changes, etc
* add exclusion for test.out in gitignore
* clarify some things better in code comments
* tweak cache size limits
* fix list timeline cache fetching
* further list timeline fixes
* linter, ssssssssshhhhhhhhhhhh please
* fix linter hints
* reslice the output if it's beyond length of 'lim'
* remove old timeline initialization code, bump go-structr to v0.9.4
* continued from previous commit
* improved code comments
* don't allow multiple entries for BoostOfID values to prevent repeated boosts of same boosts
* finish writing more code comments
* some variable renaming, for ease of following
* change the way we update lo,hi paging values during timeline load
* improved code comments for updated / returned lo , hi paging values
* finish writing code comments for the StatusTimeline{} type itself
* fill in more code comments
* update go-structr version to latest with changed timeline unique indexing logic
* have a local and public timeline *per user*
* rewrite calls to public / local timeline calls
* remove the zero length check, as lo, hi values might still be set
* simplify timeline cache loading, fix lo/hi returns, fix timeline invalidation side-effects missing for some federated actions
* swap the lo, hi values :facepalm:
* add (now) missing slice reverse of tag timeline statuses when paging ASC
* remove local / public caches (is out of scope for this work), share more timeline code
* remove unnecessary change
* again, remove more unused code
* remove unused function to appease the linter
* move boost checking to prepare function
* fix use of timeline.lastOrder, fix incorrect range functions used
* remove comments for repeat code
* remove the boost logic from prepare function
* do a maximum of 5 loads, not 10
* add repeat boost filtering logic, update go-structr, general improvements
* more code comments
* add important note
* fix timeline tests now that timelines are returned in page order
* remove unused field
* add StatusTimeline{} tests
* add more status timeline tests
* start adding preloading support
* ensure repeat boosts are marked in preloaded entries
* share a bunch of the database load code in timeline cache, don't clear timelines on relationship change
* add logic to allow dynamic clear / preloading of timelines
* comment-out unused functions, but leave in place as we might end-up using them
* fix timeline preload state check
* much improved status timeline code comments
* more code comments, don't bother inserting statuses if timeline not preloaded
* shift around some logic to make sure things aren't accidentally left set
* finish writing code comments
* remove trim-after-insert behaviour
* fix-up some comments referring to old logic
* remove unsetting of lo, hi
* fix preload repeatBoost checking logic
* don't return on status filter errors, these are usually transient
* better concurrency safety in Clear() and Done()
* fix test broken due to addition of preloader
* fix repeatBoost logic that doesn't account for already-hidden repeatBoosts
* ensure edit submodels are dropped on cache insertion
* update code-comment to expand CAS accronym
* use a plus1hULID() instead of 24h
* remove unused functions
* add note that public / local timeline requester can be nil
* fix incorrect visibility filtering of tag timeline statuses
* ensure we filter home timeline statuses on local only
* some small re-orderings to confirm query params in correct places
* fix the local only home timeline filter func
											
										 
											2025-04-26 09:56:15 +00:00
										 |  |  | 	p.surface.invalidateStatusFromTimelines(req.Like.StatusID) | 
					
						
							| 
									
										
										
										
											2024-08-24 11:49:37 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-07-26 12:04:28 +02:00
										 |  |  | 	return nil | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (p *clientAPI) AcceptReply(ctx context.Context, cMsg *messages.FromClientAPI) error { | 
					
						
							| 
									
										
										
										
											2024-08-24 11:49:37 +02:00
										 |  |  | 	req, ok := cMsg.GTSModel.(*gtsmodel.InteractionRequest) | 
					
						
							|  |  |  | 	if !ok { | 
					
						
							|  |  |  | 		return gtserror.Newf("%T not parseable as *gtsmodel.InteractionRequest", cMsg.GTSModel) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	var ( | 
					
						
							|  |  |  | 		interactingAcct = req.InteractingAccount | 
					
						
							|  |  |  | 		reply           = req.Reply | 
					
						
							|  |  |  | 	) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Update stats for the reply author account. | 
					
						
							|  |  |  | 	if err := p.utils.incrementStatusesCount(ctx, interactingAcct, reply); err != nil { | 
					
						
							|  |  |  | 		log.Errorf(ctx, "error updating account stats: %v", err) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Timeline the reply + notify relevant accounts. | 
					
						
							|  |  |  | 	if err := p.surface.timelineAndNotifyStatus(ctx, reply); err != nil { | 
					
						
							|  |  |  | 		log.Errorf(ctx, "error timelining and notifying status reply: %v", err) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Send out the Accept. | 
					
						
							|  |  |  | 	if err := p.federate.AcceptInteraction(ctx, req); err != nil { | 
					
						
							|  |  |  | 		log.Errorf(ctx, "error federating approval of reply: %v", err) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Interaction counts changed on the replied status; | 
					
						
							|  |  |  | 	// uncache the prepared version from all timelines. | 
					
						
							| 
									
										
											  
											
												[performance] rewrite timelines to rely on new timeline cache type (#3941)
* start work rewriting timeline cache type
* further work rewriting timeline caching
* more work integration new timeline code
* remove old code
* add local timeline, fix up merge conflicts
* remove old use of go-bytes
* implement new timeline code into more areas of codebase, pull in latest go-mangler, go-mutexes, go-structr
* remove old timeline package, add local timeline cache
* remove references to old timeline types that needed starting up in tests
* start adding page validation
* fix test-identified timeline cache package issues
* fix up more tests, fix missing required changes, etc
* add exclusion for test.out in gitignore
* clarify some things better in code comments
* tweak cache size limits
* fix list timeline cache fetching
* further list timeline fixes
* linter, ssssssssshhhhhhhhhhhh please
* fix linter hints
* reslice the output if it's beyond length of 'lim'
* remove old timeline initialization code, bump go-structr to v0.9.4
* continued from previous commit
* improved code comments
* don't allow multiple entries for BoostOfID values to prevent repeated boosts of same boosts
* finish writing more code comments
* some variable renaming, for ease of following
* change the way we update lo,hi paging values during timeline load
* improved code comments for updated / returned lo , hi paging values
* finish writing code comments for the StatusTimeline{} type itself
* fill in more code comments
* update go-structr version to latest with changed timeline unique indexing logic
* have a local and public timeline *per user*
* rewrite calls to public / local timeline calls
* remove the zero length check, as lo, hi values might still be set
* simplify timeline cache loading, fix lo/hi returns, fix timeline invalidation side-effects missing for some federated actions
* swap the lo, hi values :facepalm:
* add (now) missing slice reverse of tag timeline statuses when paging ASC
* remove local / public caches (is out of scope for this work), share more timeline code
* remove unnecessary change
* again, remove more unused code
* remove unused function to appease the linter
* move boost checking to prepare function
* fix use of timeline.lastOrder, fix incorrect range functions used
* remove comments for repeat code
* remove the boost logic from prepare function
* do a maximum of 5 loads, not 10
* add repeat boost filtering logic, update go-structr, general improvements
* more code comments
* add important note
* fix timeline tests now that timelines are returned in page order
* remove unused field
* add StatusTimeline{} tests
* add more status timeline tests
* start adding preloading support
* ensure repeat boosts are marked in preloaded entries
* share a bunch of the database load code in timeline cache, don't clear timelines on relationship change
* add logic to allow dynamic clear / preloading of timelines
* comment-out unused functions, but leave in place as we might end-up using them
* fix timeline preload state check
* much improved status timeline code comments
* more code comments, don't bother inserting statuses if timeline not preloaded
* shift around some logic to make sure things aren't accidentally left set
* finish writing code comments
* remove trim-after-insert behaviour
* fix-up some comments referring to old logic
* remove unsetting of lo, hi
* fix preload repeatBoost checking logic
* don't return on status filter errors, these are usually transient
* better concurrency safety in Clear() and Done()
* fix test broken due to addition of preloader
* fix repeatBoost logic that doesn't account for already-hidden repeatBoosts
* ensure edit submodels are dropped on cache insertion
* update code-comment to expand CAS accronym
* use a plus1hULID() instead of 24h
* remove unused functions
* add note that public / local timeline requester can be nil
* fix incorrect visibility filtering of tag timeline statuses
* ensure we filter home timeline statuses on local only
* some small re-orderings to confirm query params in correct places
* fix the local only home timeline filter func
											
										 
											2025-04-26 09:56:15 +00:00
										 |  |  | 	p.surface.invalidateStatusFromTimelines(reply.InReplyToID) | 
					
						
							| 
									
										
										
										
											2024-08-24 11:49:37 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-07-26 12:04:28 +02:00
										 |  |  | 	return nil | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (p *clientAPI) AcceptAnnounce(ctx context.Context, cMsg *messages.FromClientAPI) error { | 
					
						
							| 
									
										
										
										
											2024-08-24 11:49:37 +02:00
										 |  |  | 	req, ok := cMsg.GTSModel.(*gtsmodel.InteractionRequest) | 
					
						
							|  |  |  | 	if !ok { | 
					
						
							|  |  |  | 		return gtserror.Newf("%T not parseable as *gtsmodel.InteractionRequest", cMsg.GTSModel) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	var ( | 
					
						
							|  |  |  | 		interactingAcct = req.InteractingAccount | 
					
						
							|  |  |  | 		boost           = req.Announce | 
					
						
							|  |  |  | 	) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Update stats for the boost author account. | 
					
						
							|  |  |  | 	if err := p.utils.incrementStatusesCount(ctx, interactingAcct, boost); err != nil { | 
					
						
							|  |  |  | 		log.Errorf(ctx, "error updating account stats: %v", err) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Timeline and notify the announce. | 
					
						
							|  |  |  | 	if err := p.surface.timelineAndNotifyStatus(ctx, boost); err != nil { | 
					
						
							|  |  |  | 		log.Errorf(ctx, "error timelining and notifying status: %v", err) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Notify the announce (distinct from the notif for the pending announce). | 
					
						
							|  |  |  | 	if err := p.surface.notifyAnnounce(ctx, boost); err != nil { | 
					
						
							|  |  |  | 		log.Errorf(ctx, "error notifying announce: %v", err) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Send out the Accept. | 
					
						
							|  |  |  | 	if err := p.federate.AcceptInteraction(ctx, req); err != nil { | 
					
						
							|  |  |  | 		log.Errorf(ctx, "error federating approval of announce: %v", err) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Interaction counts changed on the original status; | 
					
						
							|  |  |  | 	// uncache the prepared version from all timelines. | 
					
						
							| 
									
										
											  
											
												[performance] rewrite timelines to rely on new timeline cache type (#3941)
* start work rewriting timeline cache type
* further work rewriting timeline caching
* more work integration new timeline code
* remove old code
* add local timeline, fix up merge conflicts
* remove old use of go-bytes
* implement new timeline code into more areas of codebase, pull in latest go-mangler, go-mutexes, go-structr
* remove old timeline package, add local timeline cache
* remove references to old timeline types that needed starting up in tests
* start adding page validation
* fix test-identified timeline cache package issues
* fix up more tests, fix missing required changes, etc
* add exclusion for test.out in gitignore
* clarify some things better in code comments
* tweak cache size limits
* fix list timeline cache fetching
* further list timeline fixes
* linter, ssssssssshhhhhhhhhhhh please
* fix linter hints
* reslice the output if it's beyond length of 'lim'
* remove old timeline initialization code, bump go-structr to v0.9.4
* continued from previous commit
* improved code comments
* don't allow multiple entries for BoostOfID values to prevent repeated boosts of same boosts
* finish writing more code comments
* some variable renaming, for ease of following
* change the way we update lo,hi paging values during timeline load
* improved code comments for updated / returned lo , hi paging values
* finish writing code comments for the StatusTimeline{} type itself
* fill in more code comments
* update go-structr version to latest with changed timeline unique indexing logic
* have a local and public timeline *per user*
* rewrite calls to public / local timeline calls
* remove the zero length check, as lo, hi values might still be set
* simplify timeline cache loading, fix lo/hi returns, fix timeline invalidation side-effects missing for some federated actions
* swap the lo, hi values :facepalm:
* add (now) missing slice reverse of tag timeline statuses when paging ASC
* remove local / public caches (is out of scope for this work), share more timeline code
* remove unnecessary change
* again, remove more unused code
* remove unused function to appease the linter
* move boost checking to prepare function
* fix use of timeline.lastOrder, fix incorrect range functions used
* remove comments for repeat code
* remove the boost logic from prepare function
* do a maximum of 5 loads, not 10
* add repeat boost filtering logic, update go-structr, general improvements
* more code comments
* add important note
* fix timeline tests now that timelines are returned in page order
* remove unused field
* add StatusTimeline{} tests
* add more status timeline tests
* start adding preloading support
* ensure repeat boosts are marked in preloaded entries
* share a bunch of the database load code in timeline cache, don't clear timelines on relationship change
* add logic to allow dynamic clear / preloading of timelines
* comment-out unused functions, but leave in place as we might end-up using them
* fix timeline preload state check
* much improved status timeline code comments
* more code comments, don't bother inserting statuses if timeline not preloaded
* shift around some logic to make sure things aren't accidentally left set
* finish writing code comments
* remove trim-after-insert behaviour
* fix-up some comments referring to old logic
* remove unsetting of lo, hi
* fix preload repeatBoost checking logic
* don't return on status filter errors, these are usually transient
* better concurrency safety in Clear() and Done()
* fix test broken due to addition of preloader
* fix repeatBoost logic that doesn't account for already-hidden repeatBoosts
* ensure edit submodels are dropped on cache insertion
* update code-comment to expand CAS accronym
* use a plus1hULID() instead of 24h
* remove unused functions
* add note that public / local timeline requester can be nil
* fix incorrect visibility filtering of tag timeline statuses
* ensure we filter home timeline statuses on local only
* some small re-orderings to confirm query params in correct places
* fix the local only home timeline filter func
											
										 
											2025-04-26 09:56:15 +00:00
										 |  |  | 	p.surface.invalidateStatusFromTimelines(boost.BoostOfID) | 
					
						
							| 
									
										
										
										
											2024-08-24 11:49:37 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return nil | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (p *clientAPI) RejectLike(ctx context.Context, cMsg *messages.FromClientAPI) error { | 
					
						
							|  |  |  | 	req, ok := cMsg.GTSModel.(*gtsmodel.InteractionRequest) | 
					
						
							|  |  |  | 	if !ok { | 
					
						
							|  |  |  | 		return gtserror.Newf("%T not parseable as *gtsmodel.InteractionRequest", cMsg.GTSModel) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// At this point the InteractionRequest should already | 
					
						
							|  |  |  | 	// be in the database, we just need to do side effects. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Send out the Reject. | 
					
						
							|  |  |  | 	if err := p.federate.RejectInteraction(ctx, req); err != nil { | 
					
						
							|  |  |  | 		log.Errorf(ctx, "error federating rejection of like: %v", err) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Get the rejected fave. | 
					
						
							|  |  |  | 	fave, err := p.state.DB.GetStatusFaveByURI( | 
					
						
							|  |  |  | 		gtscontext.SetBarebones(ctx), | 
					
						
							|  |  |  | 		req.InteractionURI, | 
					
						
							|  |  |  | 	) | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		return gtserror.Newf("db error getting rejected fave: %w", err) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Delete the status fave. | 
					
						
							|  |  |  | 	if err := p.state.DB.DeleteStatusFaveByID(ctx, fave.ID); err != nil { | 
					
						
							|  |  |  | 		return gtserror.Newf("db error deleting status fave: %w", err) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return nil | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (p *clientAPI) RejectReply(ctx context.Context, cMsg *messages.FromClientAPI) error { | 
					
						
							|  |  |  | 	req, ok := cMsg.GTSModel.(*gtsmodel.InteractionRequest) | 
					
						
							|  |  |  | 	if !ok { | 
					
						
							|  |  |  | 		return gtserror.Newf("%T not parseable as *gtsmodel.InteractionRequest", cMsg.GTSModel) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// At this point the InteractionRequest should already | 
					
						
							|  |  |  | 	// be in the database, we just need to do side effects. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Send out the Reject. | 
					
						
							|  |  |  | 	if err := p.federate.RejectInteraction(ctx, req); err != nil { | 
					
						
							|  |  |  | 		log.Errorf(ctx, "error federating rejection of reply: %v", err) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Get the rejected status. | 
					
						
							|  |  |  | 	status, err := p.state.DB.GetStatusByURI( | 
					
						
							|  |  |  | 		gtscontext.SetBarebones(ctx), | 
					
						
							|  |  |  | 		req.InteractionURI, | 
					
						
							|  |  |  | 	) | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		return gtserror.Newf("db error getting rejected reply: %w", err) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-09-10 14:34:49 +02:00
										 |  |  | 	// Delete attachments from this status. | 
					
						
							|  |  |  | 	// It's rejected so there's no possibility | 
					
						
							|  |  |  | 	// for the poster to delete + redraft it. | 
					
						
							|  |  |  | 	const deleteAttachments = true | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Keep a copy of the status in | 
					
						
							|  |  |  | 	// the sin bin for future review. | 
					
						
							|  |  |  | 	const copyToSinBin = true | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Perform the actual status deletion. | 
					
						
							|  |  |  | 	if err := p.utils.wipeStatus( | 
					
						
							|  |  |  | 		ctx, | 
					
						
							|  |  |  | 		status, | 
					
						
							|  |  |  | 		deleteAttachments, | 
					
						
							|  |  |  | 		copyToSinBin, | 
					
						
							|  |  |  | 	); err != nil { | 
					
						
							|  |  |  | 		log.Errorf(ctx, "error wiping reply: %v", err) | 
					
						
							| 
									
										
										
										
											2024-08-24 11:49:37 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return nil | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (p *clientAPI) RejectAnnounce(ctx context.Context, cMsg *messages.FromClientAPI) error { | 
					
						
							|  |  |  | 	req, ok := cMsg.GTSModel.(*gtsmodel.InteractionRequest) | 
					
						
							|  |  |  | 	if !ok { | 
					
						
							|  |  |  | 		return gtserror.Newf("%T not parseable as *gtsmodel.InteractionRequest", cMsg.GTSModel) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// At this point the InteractionRequest should already | 
					
						
							|  |  |  | 	// be in the database, we just need to do side effects. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Send out the Reject. | 
					
						
							|  |  |  | 	if err := p.federate.RejectInteraction(ctx, req); err != nil { | 
					
						
							|  |  |  | 		log.Errorf(ctx, "error federating rejection of announce: %v", err) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Get the rejected boost. | 
					
						
							|  |  |  | 	boost, err := p.state.DB.GetStatusByURI( | 
					
						
							|  |  |  | 		gtscontext.SetBarebones(ctx), | 
					
						
							|  |  |  | 		req.InteractionURI, | 
					
						
							|  |  |  | 	) | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		return gtserror.Newf("db error getting rejected announce: %w", err) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-09-10 14:34:49 +02:00
										 |  |  | 	// Boosts don't have attachments anyway | 
					
						
							|  |  |  | 	// so it doesn't matter what we set here. | 
					
						
							|  |  |  | 	const deleteAttachments = true | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// This is just a boost, don't | 
					
						
							|  |  |  | 	// keep a copy in the sin bin. | 
					
						
							|  |  |  | 	const copyToSinBin = true | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Perform the actual status deletion. | 
					
						
							|  |  |  | 	if err := p.utils.wipeStatus( | 
					
						
							|  |  |  | 		ctx, | 
					
						
							|  |  |  | 		boost, | 
					
						
							|  |  |  | 		deleteAttachments, | 
					
						
							|  |  |  | 		copyToSinBin, | 
					
						
							|  |  |  | 	); err != nil { | 
					
						
							|  |  |  | 		log.Errorf(ctx, "error wiping announce: %v", err) | 
					
						
							| 
									
										
										
										
											2024-08-24 11:49:37 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-07-26 12:04:28 +02:00
										 |  |  | 	return nil | 
					
						
							|  |  |  | } |