internal.go (3643B)
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 typeutils 19 20 import ( 21 "context" 22 "time" 23 24 "github.com/superseriousbusiness/gotosocial/internal/gtsmodel" 25 "github.com/superseriousbusiness/gotosocial/internal/id" 26 "github.com/superseriousbusiness/gotosocial/internal/uris" 27 ) 28 29 func (c *converter) FollowRequestToFollow(ctx context.Context, f *gtsmodel.FollowRequest) *gtsmodel.Follow { 30 showReblogs := *f.ShowReblogs 31 notify := *f.Notify 32 return >smodel.Follow{ 33 ID: f.ID, 34 CreatedAt: f.CreatedAt, 35 UpdatedAt: f.UpdatedAt, 36 AccountID: f.AccountID, 37 TargetAccountID: f.TargetAccountID, 38 ShowReblogs: &showReblogs, 39 URI: f.URI, 40 Notify: ¬ify, 41 } 42 } 43 44 func (c *converter) StatusToBoost(ctx context.Context, s *gtsmodel.Status, boostingAccount *gtsmodel.Account) (*gtsmodel.Status, error) { 45 // the wrapper won't use the same ID as the boosted status so we generate some new UUIDs 46 accountURIs := uris.GenerateURIsForAccount(boostingAccount.Username) 47 boostWrapperStatusID := id.NewULID() 48 boostWrapperStatusURI := accountURIs.StatusesURI + "/" + boostWrapperStatusID 49 boostWrapperStatusURL := accountURIs.StatusesURL + "/" + boostWrapperStatusID 50 51 local := true 52 if boostingAccount.Domain != "" { 53 local = false 54 } 55 56 sensitive := *s.Sensitive 57 federated := *s.Federated 58 boostable := *s.Boostable 59 replyable := *s.Replyable 60 likeable := *s.Likeable 61 62 boostWrapperStatus := >smodel.Status{ 63 ID: boostWrapperStatusID, 64 URI: boostWrapperStatusURI, 65 URL: boostWrapperStatusURL, 66 67 // the boosted status is not created now, but the boost certainly is 68 CreatedAt: time.Now(), 69 UpdatedAt: time.Now(), 70 Local: &local, 71 AccountID: boostingAccount.ID, 72 AccountURI: boostingAccount.URI, 73 74 // replies can be boosted, but boosts are never replies 75 InReplyToID: "", 76 InReplyToAccountID: "", 77 78 // these will all be wrapped in the boosted status so set them empty here 79 AttachmentIDs: []string{}, 80 TagIDs: []string{}, 81 MentionIDs: []string{}, 82 EmojiIDs: []string{}, 83 84 // the below fields will be taken from the target status 85 Content: s.Content, 86 ContentWarning: s.ContentWarning, 87 ActivityStreamsType: s.ActivityStreamsType, 88 Sensitive: &sensitive, 89 Language: s.Language, 90 Text: s.Text, 91 BoostOfID: s.ID, 92 BoostOfAccountID: s.AccountID, 93 Visibility: s.Visibility, 94 Federated: &federated, 95 Boostable: &boostable, 96 Replyable: &replyable, 97 Likeable: &likeable, 98 99 // attach these here for convenience -- the boosted status/account won't go in the DB 100 // but they're needed in the processor and for the frontend. Since we have them, we can 101 // attach them so we don't need to fetch them again later (save some DB calls) 102 BoostOf: s, 103 } 104 105 return boostWrapperStatus, nil 106 }