| 
									
										
										
										
											2023-05-25 10:37:38 +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 timeline | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import ( | 
					
						
							|  |  |  | 	"context" | 
					
						
							| 
									
										
										
										
											2025-02-13 12:34:45 +00:00
										 |  |  | 	"net/url" | 
					
						
							| 
									
										
										
										
											2023-05-25 10:37:38 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model" | 
					
						
							| 
									
										
										
										
											2024-05-06 04:49:08 -07:00
										 |  |  | 	statusfilter "github.com/superseriousbusiness/gotosocial/internal/filter/status" | 
					
						
							| 
									
										
										
										
											2023-05-25 10:37:38 +02:00
										 |  |  | 	"github.com/superseriousbusiness/gotosocial/internal/gtserror" | 
					
						
							|  |  |  | 	"github.com/superseriousbusiness/gotosocial/internal/gtsmodel" | 
					
						
							| 
									
										
										
										
											2025-04-08 22:04:43 +01:00
										 |  |  | 	"github.com/superseriousbusiness/gotosocial/internal/log" | 
					
						
							| 
									
										
										
										
											2024-12-30 17:12:55 +00:00
										 |  |  | 	"github.com/superseriousbusiness/gotosocial/internal/paging" | 
					
						
							| 
									
										
										
										
											2023-05-25 10:37:38 +02:00
										 |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-04-08 18:26:57 +01:00
										 |  |  | // HomeTimelineGet gets a pageable timeline of statuses | 
					
						
							|  |  |  | // in the home timeline of the requesting account. | 
					
						
							| 
									
										
										
										
											2024-12-30 17:12:55 +00:00
										 |  |  | func (p *Processor) HomeTimelineGet( | 
					
						
							|  |  |  | 	ctx context.Context, | 
					
						
							|  |  |  | 	requester *gtsmodel.Account, | 
					
						
							|  |  |  | 	page *paging.Page, | 
					
						
							|  |  |  | 	local bool, | 
					
						
							|  |  |  | ) ( | 
					
						
							|  |  |  | 	*apimodel.PageableResponse, | 
					
						
							|  |  |  | 	gtserror.WithCode, | 
					
						
							|  |  |  | ) { | 
					
						
							| 
									
										
										
										
											2025-04-25 16:09:09 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	var pageQuery url.Values | 
					
						
							|  |  |  | 	var postFilter func(*gtsmodel.Status) bool | 
					
						
							|  |  |  | 	if local { | 
					
						
							|  |  |  | 		// Set local = true query. | 
					
						
							|  |  |  | 		pageQuery = localOnlyTrue | 
					
						
							|  |  |  | 		postFilter = func(s *gtsmodel.Status) bool { | 
					
						
							|  |  |  | 			return *s.Local | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		// Set local = false query. | 
					
						
							|  |  |  | 		pageQuery = localOnlyFalse | 
					
						
							|  |  |  | 		postFilter = nil | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2025-02-13 12:34:45 +00:00
										 |  |  | 	return p.getStatusTimeline(ctx, | 
					
						
							| 
									
										
										
										
											2024-12-30 17:12:55 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		// Auth'd | 
					
						
							|  |  |  | 		// account. | 
					
						
							|  |  |  | 		requester, | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-03-25 12:33:57 +00:00
										 |  |  | 		// Keyed-by-account-ID, home timeline cache. | 
					
						
							| 
									
										
										
										
											2025-02-13 12:34:45 +00:00
										 |  |  | 		p.state.Caches.Timelines.Home.MustGet(requester.ID), | 
					
						
							| 
									
										
										
										
											2024-12-30 17:12:55 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		// Current | 
					
						
							|  |  |  | 		// page. | 
					
						
							|  |  |  | 		page, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// Home timeline endpoint. | 
					
						
							|  |  |  | 		"/api/v1/timelines/home", | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-02-13 12:34:45 +00:00
										 |  |  | 		// Set local-only timeline | 
					
						
							|  |  |  | 		// page query flag, (this map | 
					
						
							|  |  |  | 		// later gets copied before | 
					
						
							|  |  |  | 		// any further usage). | 
					
						
							| 
									
										
										
										
											2025-04-25 16:09:09 +01:00
										 |  |  | 		pageQuery, | 
					
						
							| 
									
										
										
										
											2024-12-30 17:12:55 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		// Status filter context. | 
					
						
							|  |  |  | 		statusfilter.FilterContextHome, | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-02-13 12:34:45 +00:00
										 |  |  | 		// Database load function. | 
					
						
							|  |  |  | 		func(pg *paging.Page) (statuses []*gtsmodel.Status, err error) { | 
					
						
							|  |  |  | 			return p.state.DB.GetHomeTimeline(ctx, requester.ID, pg) | 
					
						
							|  |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2024-12-30 17:12:55 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-04-25 16:09:09 +01:00
										 |  |  | 		// Filtering function, | 
					
						
							| 
									
										
										
										
											2025-02-13 12:34:45 +00:00
										 |  |  | 		// i.e. filter before caching. | 
					
						
							| 
									
										
										
										
											2025-04-08 22:04:43 +01:00
										 |  |  | 		func(s *gtsmodel.Status) bool { | 
					
						
							| 
									
										
										
										
											2024-12-30 17:12:55 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-02-13 12:34:45 +00:00
										 |  |  | 			// Check the visibility of passed status to requesting user. | 
					
						
							|  |  |  | 			ok, err := p.visFilter.StatusHomeTimelineable(ctx, requester, s) | 
					
						
							| 
									
										
										
										
											2025-04-08 22:04:43 +01:00
										 |  |  | 			if err != nil { | 
					
						
							|  |  |  | 				log.Errorf(ctx, "error filtering status %s: %v", s.URI, err) | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			return !ok | 
					
						
							| 
									
										
										
										
											2024-12-30 17:12:55 +00:00
										 |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2025-04-25 16:09:09 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		// Post filtering funtion, | 
					
						
							|  |  |  | 		// i.e. filter after caching. | 
					
						
							|  |  |  | 		postFilter, | 
					
						
							| 
									
										
										
										
											2023-05-25 10:37:38 +02:00
										 |  |  | 	) | 
					
						
							|  |  |  | } |