faved.go (2554B)
1 // GoToSocial 2 // Copyright (C) GoToSocial Authors admin@gotosocial.org 3 // SPDX-License-Identifier: AGPL-3.0-or-later 4 // 5 // This program is free software: you can redistribute it and/or modify 6 // it under the terms of the GNU Affero General Public License as published by 7 // the Free Software Foundation, either version 3 of the License, or 8 // (at your option) any later version. 9 // 10 // This program is distributed in the hope that it will be useful, 11 // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 // GNU Affero General Public License for more details. 14 // 15 // You should have received a copy of the GNU Affero General Public License 16 // along with this program. If not, see <http://www.gnu.org/licenses/>. 17 18 package timeline 19 20 import ( 21 "context" 22 "errors" 23 "fmt" 24 25 apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model" 26 "github.com/superseriousbusiness/gotosocial/internal/db" 27 "github.com/superseriousbusiness/gotosocial/internal/gtserror" 28 "github.com/superseriousbusiness/gotosocial/internal/log" 29 "github.com/superseriousbusiness/gotosocial/internal/oauth" 30 "github.com/superseriousbusiness/gotosocial/internal/util" 31 ) 32 33 func (p *Processor) FavedTimelineGet(ctx context.Context, authed *oauth.Auth, maxID string, minID string, limit int) (*apimodel.PageableResponse, gtserror.WithCode) { 34 statuses, nextMaxID, prevMinID, err := p.state.DB.GetFavedTimeline(ctx, authed.Account.ID, maxID, minID, limit) 35 if err != nil && !errors.Is(err, db.ErrNoEntries) { 36 err = fmt.Errorf("FavedTimelineGet: db error getting statuses: %w", err) 37 return nil, gtserror.NewErrorInternalError(err) 38 } 39 40 count := len(statuses) 41 if count == 0 { 42 return util.EmptyPageableResponse(), nil 43 } 44 45 items := make([]interface{}, 0, count) 46 for _, s := range statuses { 47 visible, err := p.filter.StatusVisible(ctx, authed.Account, s) 48 if err != nil { 49 log.Debugf(ctx, "skipping status %s because of an error checking status visibility: %s", s.ID, err) 50 continue 51 } 52 53 if !visible { 54 continue 55 } 56 57 apiStatus, err := p.tc.StatusToAPIStatus(ctx, s, authed.Account) 58 if err != nil { 59 log.Debugf(ctx, "skipping status %s because it couldn't be converted to its api representation: %s", s.ID, err) 60 continue 61 } 62 63 items = append(items, apiStatus) 64 } 65 66 return util.PackagePageableResponse(util.PageableResponseParams{ 67 Items: items, 68 Path: "api/v1/favourites", 69 NextMaxIDValue: nextMaxID, 70 PrevMinIDValue: prevMinID, 71 Limit: limit, 72 }) 73 }