summaryrefslogtreecommitdiff
path: root/internal/typeutils/internal.go
blob: b081708a203d970d17b5e26aeded9679a4fc6bdf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package typeutils

import (
	"fmt"
	"time"

	"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
	"github.com/superseriousbusiness/gotosocial/internal/id"
	"github.com/superseriousbusiness/gotosocial/internal/util"
)

func (c *converter) FollowRequestToFollow(f *gtsmodel.FollowRequest) *gtsmodel.Follow {
	return &gtsmodel.Follow{
		ID:              f.ID,
		CreatedAt:       f.CreatedAt,
		UpdatedAt:       f.UpdatedAt,
		AccountID:       f.AccountID,
		TargetAccountID: f.TargetAccountID,
		ShowReblogs:     f.ShowReblogs,
		URI:             f.URI,
		Notify:          f.Notify,
	}
}

func (c *converter) StatusToBoost(s *gtsmodel.Status, boostingAccount *gtsmodel.Account) (*gtsmodel.Status, error) {
	// the wrapper won't use the same ID as the boosted status so we generate some new UUIDs
	uris := util.GenerateURIsForAccount(boostingAccount.Username, c.config.Protocol, c.config.Host)
	boostWrapperStatusID, err := id.NewULID()
	if err != nil {
		return nil, err
	}
	boostWrapperStatusURI := fmt.Sprintf("%s/%s", uris.StatusesURI, boostWrapperStatusID)
	boostWrapperStatusURL := fmt.Sprintf("%s/%s", uris.StatusesURL, boostWrapperStatusID)

	local := true
	if boostingAccount.Domain != "" {
		local = false
	}

	boostWrapperStatus := &gtsmodel.Status{
		ID:  boostWrapperStatusID,
		URI: boostWrapperStatusURI,
		URL: boostWrapperStatusURL,

		// the boosted status is not created now, but the boost certainly is
		CreatedAt:  time.Now(),
		UpdatedAt:  time.Now(),
		Local:      local,
		AccountID:  boostingAccount.ID,
		AccountURI: boostingAccount.URI,

		// replies can be boosted, but boosts are never replies
		InReplyToID:        "",
		InReplyToAccountID: "",

		// these will all be wrapped in the boosted status so set them empty here
		Attachments: []string{},
		Tags:        []string{},
		Mentions:    []string{},
		Emojis:      []string{},

		// the below fields will be taken from the target status
		Content:             s.Content,
		ContentWarning:      s.ContentWarning,
		ActivityStreamsType: s.ActivityStreamsType,
		Sensitive:           s.Sensitive,
		Language:            s.Language,
		Text:                s.Text,
		BoostOfID:           s.ID,
		Visibility:          s.Visibility,
		VisibilityAdvanced:  s.VisibilityAdvanced,

		// attach these here for convenience -- the boosted status/account won't go in the DB
		// but they're needed in the processor and for the frontend. Since we have them, we can
		// attach them so we don't need to fetch them again later (save some DB calls)
		GTSBoostedStatus: s,
	}

	return boostWrapperStatus, nil
}