summaryrefslogtreecommitdiff
path: root/internal/typeutils/internal.go
diff options
context:
space:
mode:
authorLibravatar Tobi Smethurst <31960611+tsmethurst@users.noreply.github.com>2021-05-27 16:06:24 +0200
committerLibravatar GitHub <noreply@github.com>2021-05-27 16:06:24 +0200
commit40add686913b7eb6edd5a780e37e7513b43a337f (patch)
tree75549dff97e5a15f732a505d4d00aa7a686bdad8 /internal/typeutils/internal.go
parentFaves (#31) (diff)
downloadgotosocial-40add686913b7eb6edd5a780e37e7513b43a337f.tar.xz
Notifications (#34)
Notifications working for: * Mentions * Faves * New follow requests * New followers
Diffstat (limited to 'internal/typeutils/internal.go')
-rw-r--r--internal/typeutils/internal.go76
1 files changed, 76 insertions, 0 deletions
diff --git a/internal/typeutils/internal.go b/internal/typeutils/internal.go
new file mode 100644
index 000000000..3110b382c
--- /dev/null
+++ b/internal/typeutils/internal.go
@@ -0,0 +1,76 @@
+package typeutils
+
+import (
+ "fmt"
+ "time"
+
+ "github.com/google/uuid"
+ "github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
+ "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 := uuid.NewString()
+ 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,
+
+ // 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: util.HTMLFormat(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
+}