summaryrefslogtreecommitdiff
path: root/internal/typeutils
diff options
context:
space:
mode:
authorLibravatar tobi <31960611+tsmethurst@users.noreply.github.com>2021-10-04 15:24:19 +0200
committerLibravatar GitHub <noreply@github.com>2021-10-04 15:24:19 +0200
commite04b187702acb0c9908237a35b3a9857e2167b3f (patch)
tree29839b8d5bbc28d34aba759a48dd7b005f1444f5 /internal/typeutils
parentFollow request auto approval (#259) (diff)
downloadgotosocial-e04b187702acb0c9908237a35b3a9857e2167b3f.tar.xz
Refactor/tidy (#261)
* tidy up streaming * cut down code duplication * test get followers/following * test streaming processor * fix some test models * add TimeMustParse * fix uri / url typo * make trace logging less verbose * make logging more consistent * disable quote on logging * remove context.Background * remove many extraneous mastodon references * regenerate swagger * don't log query on no rows result * log latency first for easier reading
Diffstat (limited to 'internal/typeutils')
-rw-r--r--internal/typeutils/converter.go68
-rw-r--r--internal/typeutils/frontendtointernal.go3
-rw-r--r--internal/typeutils/internaltoas.go6
-rw-r--r--internal/typeutils/internaltofrontend.go158
4 files changed, 116 insertions, 119 deletions
diff --git a/internal/typeutils/converter.go b/internal/typeutils/converter.go
index 40cb5b969..4515fcbf0 100644
--- a/internal/typeutils/converter.go
+++ b/internal/typeutils/converter.go
@@ -43,58 +43,58 @@ const (
// That said, it *absolutely should not* manipulate database entries in any way, only examine them.
type TypeConverter interface {
/*
- INTERNAL (gts) MODEL TO FRONTEND (mastodon) MODEL
+ INTERNAL (gts) MODEL TO FRONTEND (api) MODEL
*/
- // AccountToMastoSensitive takes a db model account as a param, and returns a populated mastotype account, or an error
+ // AccountToAPIAccountSensitive takes a db model account as a param, and returns a populated apitype account, or an error
// if something goes wrong. The returned account should be ready to serialize on an API level, and may have sensitive fields,
// so serve it only to an authorized user who should have permission to see it.
- AccountToMastoSensitive(ctx context.Context, account *gtsmodel.Account) (*model.Account, error)
- // AccountToMastoPublic takes a db model account as a param, and returns a populated mastotype account, or an error
+ AccountToAPIAccountSensitive(ctx context.Context, account *gtsmodel.Account) (*model.Account, error)
+ // AccountToAPIAccountPublic takes a db model account as a param, and returns a populated apitype account, or an error
// if something goes wrong. The returned account should be ready to serialize on an API level, and may NOT have sensitive fields.
// In other words, this is the public record that the server has of an account.
- AccountToMastoPublic(ctx context.Context, account *gtsmodel.Account) (*model.Account, error)
- // AccountToMastoBlocked takes a db model account as a param, and returns a mastotype account, or an error if
+ AccountToAPIAccountPublic(ctx context.Context, account *gtsmodel.Account) (*model.Account, error)
+ // AccountToAPIAccountBlocked takes a db model account as a param, and returns a apitype account, or an error if
// something goes wrong. The returned account will be a bare minimum representation of the account. This function should be used
// when someone wants to view an account they've blocked.
- AccountToMastoBlocked(ctx context.Context, account *gtsmodel.Account) (*model.Account, error)
- // AppToMastoSensitive takes a db model application as a param, and returns a populated mastotype application, or an error
+ AccountToAPIAccountBlocked(ctx context.Context, account *gtsmodel.Account) (*model.Account, error)
+ // AppToAPIAppSensitive takes a db model application as a param, and returns a populated apitype application, or an error
// if something goes wrong. The returned application should be ready to serialize on an API level, and may have sensitive fields
// (such as client id and client secret), so serve it only to an authorized user who should have permission to see it.
- AppToMastoSensitive(ctx context.Context, application *gtsmodel.Application) (*model.Application, error)
- // AppToMastoPublic takes a db model application as a param, and returns a populated mastotype application, or an error
+ AppToAPIAppSensitive(ctx context.Context, application *gtsmodel.Application) (*model.Application, error)
+ // AppToAPIAppPublic takes a db model application as a param, and returns a populated apitype application, or an error
// if something goes wrong. The returned application should be ready to serialize on an API level, and has sensitive
// fields sanitized so that it can be served to non-authorized accounts without revealing any private information.
- AppToMastoPublic(ctx context.Context, application *gtsmodel.Application) (*model.Application, error)
- // AttachmentToMasto converts a gts model media attacahment into its mastodon representation for serialization on the API.
- AttachmentToMasto(ctx context.Context, attachment *gtsmodel.MediaAttachment) (model.Attachment, error)
- // MentionToMasto converts a gts model mention into its mastodon (frontend) representation for serialization on the API.
- MentionToMasto(ctx context.Context, m *gtsmodel.Mention) (model.Mention, error)
- // EmojiToMasto converts a gts model emoji into its mastodon (frontend) representation for serialization on the API.
- EmojiToMasto(ctx context.Context, e *gtsmodel.Emoji) (model.Emoji, error)
- // TagToMasto converts a gts model tag into its mastodon (frontend) representation for serialization on the API.
- TagToMasto(ctx context.Context, t *gtsmodel.Tag) (model.Tag, error)
- // StatusToMasto converts a gts model status into its mastodon (frontend) representation for serialization on the API.
+ AppToAPIAppPublic(ctx context.Context, application *gtsmodel.Application) (*model.Application, error)
+ // AttachmentToAPIAttachment converts a gts model media attacahment into its api representation for serialization on the API.
+ AttachmentToAPIAttachment(ctx context.Context, attachment *gtsmodel.MediaAttachment) (model.Attachment, error)
+ // MentionToAPIMention converts a gts model mention into its api (frontend) representation for serialization on the API.
+ MentionToAPIMention(ctx context.Context, m *gtsmodel.Mention) (model.Mention, error)
+ // EmojiToAPIEmoji converts a gts model emoji into its api (frontend) representation for serialization on the API.
+ EmojiToAPIEmoji(ctx context.Context, e *gtsmodel.Emoji) (model.Emoji, error)
+ // TagToAPITag converts a gts model tag into its api (frontend) representation for serialization on the API.
+ TagToAPITag(ctx context.Context, t *gtsmodel.Tag) (model.Tag, error)
+ // StatusToAPIStatus converts a gts model status into its api (frontend) representation for serialization on the API.
//
// Requesting account can be nil.
- StatusToMasto(ctx context.Context, s *gtsmodel.Status, requestingAccount *gtsmodel.Account) (*model.Status, error)
- // VisToMasto converts a gts visibility into its mastodon equivalent
- VisToMasto(ctx context.Context, m gtsmodel.Visibility) model.Visibility
- // InstanceToMasto converts a gts instance into its mastodon equivalent for serving at /api/v1/instance
- InstanceToMasto(ctx context.Context, i *gtsmodel.Instance) (*model.Instance, error)
- // RelationshipToMasto converts a gts relationship into its mastodon equivalent for serving in various places
- RelationshipToMasto(ctx context.Context, r *gtsmodel.Relationship) (*model.Relationship, error)
- // NotificationToMasto converts a gts notification into a mastodon notification
- NotificationToMasto(ctx context.Context, n *gtsmodel.Notification) (*model.Notification, error)
- // DomainBlockTomasto converts a gts model domin block into a mastodon domain block, for serving at /api/v1/admin/domain_blocks
- DomainBlockToMasto(ctx context.Context, b *gtsmodel.DomainBlock, export bool) (*model.DomainBlock, error)
+ StatusToAPIStatus(ctx context.Context, s *gtsmodel.Status, requestingAccount *gtsmodel.Account) (*model.Status, error)
+ // VisToAPIVis converts a gts visibility into its api equivalent
+ VisToAPIVis(ctx context.Context, m gtsmodel.Visibility) model.Visibility
+ // InstanceToAPIInstance converts a gts instance into its api equivalent for serving at /api/v1/instance
+ InstanceToAPIInstance(ctx context.Context, i *gtsmodel.Instance) (*model.Instance, error)
+ // RelationshipToAPIRelationship converts a gts relationship into its api equivalent for serving in various places
+ RelationshipToAPIRelationship(ctx context.Context, r *gtsmodel.Relationship) (*model.Relationship, error)
+ // NotificationToAPINotification converts a gts notification into a api notification
+ NotificationToAPINotification(ctx context.Context, n *gtsmodel.Notification) (*model.Notification, error)
+ // DomainBlockToAPIDomainBlock converts a gts model domin block into a api domain block, for serving at /api/v1/admin/domain_blocks
+ DomainBlockToAPIDomainBlock(ctx context.Context, b *gtsmodel.DomainBlock, export bool) (*model.DomainBlock, error)
/*
- FRONTEND (mastodon) MODEL TO INTERNAL (gts) MODEL
+ FRONTEND (api) MODEL TO INTERNAL (gts) MODEL
*/
- // MastoVisToVis converts a mastodon visibility into its gts equivalent.
- MastoVisToVis(m model.Visibility) gtsmodel.Visibility
+ // APIVisToVis converts an API model visibility into its internal gts equivalent.
+ APIVisToVis(m model.Visibility) gtsmodel.Visibility
/*
ACTIVITYSTREAMS MODEL TO INTERNAL (gts) MODEL
diff --git a/internal/typeutils/frontendtointernal.go b/internal/typeutils/frontendtointernal.go
index 75c5168aa..371bff99a 100644
--- a/internal/typeutils/frontendtointernal.go
+++ b/internal/typeutils/frontendtointernal.go
@@ -23,8 +23,7 @@ import (
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
)
-// MastoVisToVis converts a mastodon visibility into its gts equivalent.
-func (c *converter) MastoVisToVis(m model.Visibility) gtsmodel.Visibility {
+func (c *converter) APIVisToVis(m model.Visibility) gtsmodel.Visibility {
switch m {
case model.VisibilityPublic:
return gtsmodel.VisibilityPublic
diff --git a/internal/typeutils/internaltoas.go b/internal/typeutils/internaltoas.go
index 819b78267..1689db496 100644
--- a/internal/typeutils/internaltoas.go
+++ b/internal/typeutils/internaltoas.go
@@ -31,8 +31,7 @@ import (
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
)
-// Converts a gts model account into an Activity Streams person type, following
-// the spec laid out for mastodon here: https://docs.joinmastodon.org/spec/activitypub/
+// Converts a gts model account into an Activity Streams person type.
func (c *converter) AccountToAS(ctx context.Context, a *gtsmodel.Account) (vocab.ActivityStreamsPerson, error) {
person := streams.NewActivityStreamsPerson()
@@ -267,8 +266,7 @@ func (c *converter) AccountToAS(ctx context.Context, a *gtsmodel.Account) (vocab
return person, nil
}
-// Converts a gts model account into a VERY MINIMAL Activity Streams person type, following
-// the spec laid out for mastodon here: https://docs.joinmastodon.org/spec/activitypub/
+// Converts a gts model account into a VERY MINIMAL Activity Streams person type.
//
// The returned account will just have the Type, Username, PublicKey, and ID properties set.
func (c *converter) AccountToASMinimal(ctx context.Context, a *gtsmodel.Account) (vocab.ActivityStreamsPerson, error) {
diff --git a/internal/typeutils/internaltofrontend.go b/internal/typeutils/internaltofrontend.go
index 67d6cef94..70899d2d8 100644
--- a/internal/typeutils/internaltofrontend.go
+++ b/internal/typeutils/internaltofrontend.go
@@ -29,9 +29,9 @@ import (
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
)
-func (c *converter) AccountToMastoSensitive(ctx context.Context, a *gtsmodel.Account) (*model.Account, error) {
+func (c *converter) AccountToAPIAccountSensitive(ctx context.Context, a *gtsmodel.Account) (*model.Account, error) {
// we can build this sensitive account easily by first getting the public account....
- mastoAccount, err := c.AccountToMastoPublic(ctx, a)
+ apiAccount, err := c.AccountToAPIAccountPublic(ctx, a)
if err != nil {
return nil, err
}
@@ -50,19 +50,19 @@ func (c *converter) AccountToMastoSensitive(ctx context.Context, a *gtsmodel.Acc
frc = len(frs)
}
- mastoAccount.Source = &model.Source{
- Privacy: c.VisToMasto(ctx, a.Privacy),
+ apiAccount.Source = &model.Source{
+ Privacy: c.VisToAPIVis(ctx, a.Privacy),
Sensitive: a.Sensitive,
Language: a.Language,
Note: a.Note,
- Fields: mastoAccount.Fields,
+ Fields: apiAccount.Fields,
FollowRequestsCount: frc,
}
- return mastoAccount, nil
+ return apiAccount, nil
}
-func (c *converter) AccountToMastoPublic(ctx context.Context, a *gtsmodel.Account) (*model.Account, error) {
+func (c *converter) AccountToAPIAccountPublic(ctx context.Context, a *gtsmodel.Account) (*model.Account, error) {
if a == nil {
return nil, fmt.Errorf("given account was nil")
}
@@ -179,7 +179,7 @@ func (c *converter) AccountToMastoPublic(ctx context.Context, a *gtsmodel.Accoun
return accountFrontend, nil
}
-func (c *converter) AccountToMastoBlocked(ctx context.Context, a *gtsmodel.Account) (*model.Account, error) {
+func (c *converter) AccountToAPIAccountBlocked(ctx context.Context, a *gtsmodel.Account) (*model.Account, error) {
var acct string
if a.Domain != "" {
// this is a remote user
@@ -206,7 +206,7 @@ func (c *converter) AccountToMastoBlocked(ctx context.Context, a *gtsmodel.Accou
}, nil
}
-func (c *converter) AppToMastoSensitive(ctx context.Context, a *gtsmodel.Application) (*model.Application, error) {
+func (c *converter) AppToAPIAppSensitive(ctx context.Context, a *gtsmodel.Application) (*model.Application, error) {
return &model.Application{
ID: a.ID,
Name: a.Name,
@@ -217,14 +217,14 @@ func (c *converter) AppToMastoSensitive(ctx context.Context, a *gtsmodel.Applica
}, nil
}
-func (c *converter) AppToMastoPublic(ctx context.Context, a *gtsmodel.Application) (*model.Application, error) {
+func (c *converter) AppToAPIAppPublic(ctx context.Context, a *gtsmodel.Application) (*model.Application, error) {
return &model.Application{
Name: a.Name,
Website: a.Website,
}, nil
}
-func (c *converter) AttachmentToMasto(ctx context.Context, a *gtsmodel.MediaAttachment) (model.Attachment, error) {
+func (c *converter) AttachmentToAPIAttachment(ctx context.Context, a *gtsmodel.MediaAttachment) (model.Attachment, error) {
return model.Attachment{
ID: a.ID,
Type: strings.ToLower(string(a.Type)),
@@ -255,7 +255,7 @@ func (c *converter) AttachmentToMasto(ctx context.Context, a *gtsmodel.MediaAtta
}, nil
}
-func (c *converter) MentionToMasto(ctx context.Context, m *gtsmodel.Mention) (model.Mention, error) {
+func (c *converter) MentionToAPIMention(ctx context.Context, m *gtsmodel.Mention) (model.Mention, error) {
if m.TargetAccount == nil {
targetAccount, err := c.db.GetAccountByID(ctx, m.TargetAccountID)
if err != nil {
@@ -284,7 +284,7 @@ func (c *converter) MentionToMasto(ctx context.Context, m *gtsmodel.Mention) (mo
}, nil
}
-func (c *converter) EmojiToMasto(ctx context.Context, e *gtsmodel.Emoji) (model.Emoji, error) {
+func (c *converter) EmojiToAPIEmoji(ctx context.Context, e *gtsmodel.Emoji) (model.Emoji, error) {
return model.Emoji{
Shortcode: e.Shortcode,
URL: e.ImageURL,
@@ -294,14 +294,14 @@ func (c *converter) EmojiToMasto(ctx context.Context, e *gtsmodel.Emoji) (model.
}, nil
}
-func (c *converter) TagToMasto(ctx context.Context, t *gtsmodel.Tag) (model.Tag, error) {
+func (c *converter) TagToAPITag(ctx context.Context, t *gtsmodel.Tag) (model.Tag, error) {
return model.Tag{
Name: t.Name,
URL: t.URL,
}, nil
}
-func (c *converter) StatusToMasto(ctx context.Context, s *gtsmodel.Status, requestingAccount *gtsmodel.Account) (*model.Status, error) {
+func (c *converter) StatusToAPIStatus(ctx context.Context, s *gtsmodel.Status, requestingAccount *gtsmodel.Account) (*model.Status, error) {
l := c.log
repliesCount, err := c.db.CountStatusReplies(ctx, s)
@@ -319,7 +319,7 @@ func (c *converter) StatusToMasto(ctx context.Context, s *gtsmodel.Status, reque
return nil, fmt.Errorf("error counting faves: %s", err)
}
- var mastoRebloggedStatus *model.Status
+ var apiRebloggedStatus *model.Status
if s.BoostOfID != "" {
// the boosted status might have been set on this struct already so check first before doing db calls
if s.BoostOf == nil {
@@ -342,19 +342,19 @@ func (c *converter) StatusToMasto(ctx context.Context, s *gtsmodel.Status, reque
s.BoostOf.Account = ba
}
- mastoRebloggedStatus, err = c.StatusToMasto(ctx, s.BoostOf, requestingAccount)
+ apiRebloggedStatus, err = c.StatusToAPIStatus(ctx, s.BoostOf, requestingAccount)
if err != nil {
- return nil, fmt.Errorf("error converting boosted status to mastotype: %s", err)
+ return nil, fmt.Errorf("error converting boosted status to apitype: %s", err)
}
}
- var mastoApplication *model.Application
+ var apiApplication *model.Application
if s.CreatedWithApplicationID != "" {
gtsApplication := &gtsmodel.Application{}
if err := c.db.GetByID(ctx, s.CreatedWithApplicationID, gtsApplication); err != nil {
return nil, fmt.Errorf("error fetching application used to create status: %s", err)
}
- mastoApplication, err = c.AppToMastoPublic(ctx, gtsApplication)
+ apiApplication, err = c.AppToAPIAppPublic(ctx, gtsApplication)
if err != nil {
return nil, fmt.Errorf("error parsing application used to create status: %s", err)
}
@@ -368,25 +368,25 @@ func (c *converter) StatusToMasto(ctx context.Context, s *gtsmodel.Status, reque
s.Account = a
}
- mastoAuthorAccount, err := c.AccountToMastoPublic(ctx, s.Account)
+ apiAuthorAccount, err := c.AccountToAPIAccountPublic(ctx, s.Account)
if err != nil {
return nil, fmt.Errorf("error parsing account of status author: %s", err)
}
- mastoAttachments := []model.Attachment{}
+ apiAttachments := []model.Attachment{}
// the status might already have some gts attachments on it if it's not been pulled directly from the database
- // if so, we can directly convert the gts attachments into masto ones
+ // if so, we can directly convert the gts attachments into api ones
if s.Attachments != nil {
for _, gtsAttachment := range s.Attachments {
- mastoAttachment, err := c.AttachmentToMasto(ctx, gtsAttachment)
+ apiAttachment, err := c.AttachmentToAPIAttachment(ctx, gtsAttachment)
if err != nil {
l.Errorf("error converting attachment with id %s: %s", gtsAttachment.ID, err)
continue
}
- mastoAttachments = append(mastoAttachments, mastoAttachment)
+ apiAttachments = append(apiAttachments, apiAttachment)
}
// the status doesn't have gts attachments on it, but it does have attachment IDs
- // in this case, we need to pull the gts attachments from the db to convert them into masto ones
+ // in this case, we need to pull the gts attachments from the db to convert them into api ones
} else {
for _, aID := range s.AttachmentIDs {
gtsAttachment, err := c.db.GetAttachmentByID(ctx, aID)
@@ -394,29 +394,29 @@ func (c *converter) StatusToMasto(ctx context.Context, s *gtsmodel.Status, reque
l.Errorf("error getting attachment with id %s: %s", aID, err)
continue
}
- mastoAttachment, err := c.AttachmentToMasto(ctx, gtsAttachment)
+ apiAttachment, err := c.AttachmentToAPIAttachment(ctx, gtsAttachment)
if err != nil {
l.Errorf("error converting attachment with id %s: %s", aID, err)
continue
}
- mastoAttachments = append(mastoAttachments, mastoAttachment)
+ apiAttachments = append(apiAttachments, apiAttachment)
}
}
- mastoMentions := []model.Mention{}
+ apiMentions := []model.Mention{}
// the status might already have some gts mentions on it if it's not been pulled directly from the database
- // if so, we can directly convert the gts mentions into masto ones
+ // if so, we can directly convert the gts mentions into api ones
if s.Mentions != nil {
for _, gtsMention := range s.Mentions {
- mastoMention, err := c.MentionToMasto(ctx, gtsMention)
+ apiMention, err := c.MentionToAPIMention(ctx, gtsMention)
if err != nil {
l.Errorf("error converting mention with id %s: %s", gtsMention.ID, err)
continue
}
- mastoMentions = append(mastoMentions, mastoMention)
+ apiMentions = append(apiMentions, apiMention)
}
// the status doesn't have gts mentions on it, but it does have mention IDs
- // in this case, we need to pull the gts mentions from the db to convert them into masto ones
+ // in this case, we need to pull the gts mentions from the db to convert them into api ones
} else {
for _, mID := range s.MentionIDs {
gtsMention, err := c.db.GetMention(ctx, mID)
@@ -424,29 +424,29 @@ func (c *converter) StatusToMasto(ctx context.Context, s *gtsmodel.Status, reque
l.Errorf("error getting mention with id %s: %s", mID, err)
continue
}
- mastoMention, err := c.MentionToMasto(ctx, gtsMention)
+ apiMention, err := c.MentionToAPIMention(ctx, gtsMention)
if err != nil {
l.Errorf("error converting mention with id %s: %s", gtsMention.ID, err)
continue
}
- mastoMentions = append(mastoMentions, mastoMention)
+ apiMentions = append(apiMentions, apiMention)
}
}
- mastoTags := []model.Tag{}
+ apiTags := []model.Tag{}
// the status might already have some gts tags on it if it's not been pulled directly from the database
- // if so, we can directly convert the gts tags into masto ones
+ // if so, we can directly convert the gts tags into api ones
if s.Tags != nil {
for _, gtsTag := range s.Tags {
- mastoTag, err := c.TagToMasto(ctx, gtsTag)
+ apiTag, err := c.TagToAPITag(ctx, gtsTag)
if err != nil {
l.Errorf("error converting tag with id %s: %s", gtsTag.ID, err)
continue
}
- mastoTags = append(mastoTags, mastoTag)
+ apiTags = append(apiTags, apiTag)
}
// the status doesn't have gts tags on it, but it does have tag IDs
- // in this case, we need to pull the gts tags from the db to convert them into masto ones
+ // in this case, we need to pull the gts tags from the db to convert them into api ones
} else {
for _, t := range s.TagIDs {
gtsTag := &gtsmodel.Tag{}
@@ -454,29 +454,29 @@ func (c *converter) StatusToMasto(ctx context.Context, s *gtsmodel.Status, reque
l.Errorf("error getting tag with id %s: %s", t, err)
continue
}
- mastoTag, err := c.TagToMasto(ctx, gtsTag)
+ apiTag, err := c.TagToAPITag(ctx, gtsTag)
if err != nil {
l.Errorf("error converting tag with id %s: %s", gtsTag.ID, err)
continue
}
- mastoTags = append(mastoTags, mastoTag)
+ apiTags = append(apiTags, apiTag)
}
}
- mastoEmojis := []model.Emoji{}
+ apiEmojis := []model.Emoji{}
// the status might already have some gts emojis on it if it's not been pulled directly from the database
- // if so, we can directly convert the gts emojis into masto ones
+ // if so, we can directly convert the gts emojis into api ones
if s.Emojis != nil {
for _, gtsEmoji := range s.Emojis {
- mastoEmoji, err := c.EmojiToMasto(ctx, gtsEmoji)
+ apiEmoji, err := c.EmojiToAPIEmoji(ctx, gtsEmoji)
if err != nil {
l.Errorf("error converting emoji with id %s: %s", gtsEmoji.ID, err)
continue
}
- mastoEmojis = append(mastoEmojis, mastoEmoji)
+ apiEmojis = append(apiEmojis, apiEmoji)
}
// the status doesn't have gts emojis on it, but it does have emoji IDs
- // in this case, we need to pull the gts emojis from the db to convert them into masto ones
+ // in this case, we need to pull the gts emojis from the db to convert them into api ones
} else {
for _, e := range s.EmojiIDs {
gtsEmoji := &gtsmodel.Emoji{}
@@ -484,17 +484,17 @@ func (c *converter) StatusToMasto(ctx context.Context, s *gtsmodel.Status, reque
l.Errorf("error getting emoji with id %s: %s", e, err)
continue
}
- mastoEmoji, err := c.EmojiToMasto(ctx, gtsEmoji)
+ apiEmoji, err := c.EmojiToAPIEmoji(ctx, gtsEmoji)
if err != nil {
l.Errorf("error converting emoji with id %s: %s", gtsEmoji.ID, err)
continue
}
- mastoEmojis = append(mastoEmojis, mastoEmoji)
+ apiEmojis = append(apiEmojis, apiEmoji)
}
}
- var mastoCard *model.Card
- var mastoPoll *model.Poll
+ var apiCard *model.Card
+ var apiPoll *model.Poll
statusInteractions := &statusInteractions{}
si, err := c.interactionsWithStatusForAccount(ctx, s, requestingAccount)
@@ -509,7 +509,7 @@ func (c *converter) StatusToMasto(ctx context.Context, s *gtsmodel.Status, reque
InReplyToAccountID: s.InReplyToAccountID,
Sensitive: s.Sensitive,
SpoilerText: s.ContentWarning,
- Visibility: c.VisToMasto(ctx, s.Visibility),
+ Visibility: c.VisToAPIVis(ctx, s.Visibility),
Language: s.Language,
URI: s.URI,
URL: s.URL,
@@ -522,26 +522,26 @@ func (c *converter) StatusToMasto(ctx context.Context, s *gtsmodel.Status, reque
Reblogged: statusInteractions.Reblogged,
Pinned: s.Pinned,
Content: s.Content,
- Application: mastoApplication,
- Account: mastoAuthorAccount,
- MediaAttachments: mastoAttachments,
- Mentions: mastoMentions,
- Tags: mastoTags,
- Emojis: mastoEmojis,
- Card: mastoCard, // TODO: implement cards
- Poll: mastoPoll, // TODO: implement polls
+ Application: apiApplication,
+ Account: apiAuthorAccount,
+ MediaAttachments: apiAttachments,
+ Mentions: apiMentions,
+ Tags: apiTags,
+ Emojis: apiEmojis,
+ Card: apiCard, // TODO: implement cards
+ Poll: apiPoll, // TODO: implement polls
Text: s.Text,
}
- if mastoRebloggedStatus != nil {
- apiStatus.Reblog = &model.StatusReblogged{Status: mastoRebloggedStatus}
+ if apiRebloggedStatus != nil {
+ apiStatus.Reblog = &model.StatusReblogged{Status: apiRebloggedStatus}
}
return apiStatus, nil
}
-// VisToMasto converts a gts visibility into its mastodon equivalent
-func (c *converter) VisToMasto(ctx context.Context, m gtsmodel.Visibility) model.Visibility {
+// VisToapi converts a gts visibility into its api equivalent
+func (c *converter) VisToAPIVis(ctx context.Context, m gtsmodel.Visibility) model.Visibility {
switch m {
case gtsmodel.VisibilityPublic:
return model.VisibilityPublic
@@ -555,7 +555,7 @@ func (c *converter) VisToMasto(ctx context.Context, m gtsmodel.Visibility) model
return ""
}
-func (c *converter) InstanceToMasto(ctx context.Context, i *gtsmodel.Instance) (*model.Instance, error) {
+func (c *converter) InstanceToAPIInstance(ctx context.Context, i *gtsmodel.Instance) (*model.Instance, error) {
mi := &model.Instance{
URI: i.URI,
Title: i.Title,
@@ -614,7 +614,7 @@ func (c *converter) InstanceToMasto(ctx context.Context, i *gtsmodel.Instance) (
i.ContactAccount = contactAccount
}
}
- ma, err := c.AccountToMastoPublic(ctx, i.ContactAccount)
+ ma, err := c.AccountToAPIAccountPublic(ctx, i.ContactAccount)
if err == nil {
mi.ContactAccount = ma
}
@@ -623,7 +623,7 @@ func (c *converter) InstanceToMasto(ctx context.Context, i *gtsmodel.Instance) (
return mi, nil
}
-func (c *converter) RelationshipToMasto(ctx context.Context, r *gtsmodel.Relationship) (*model.Relationship, error) {
+func (c *converter) RelationshipToAPIRelationship(ctx context.Context, r *gtsmodel.Relationship) (*model.Relationship, error) {
return &model.Relationship{
ID: r.ID,
Following: r.Following,
@@ -641,11 +641,11 @@ func (c *converter) RelationshipToMasto(ctx context.Context, r *gtsmodel.Relatio
}, nil
}
-func (c *converter) NotificationToMasto(ctx context.Context, n *gtsmodel.Notification) (*model.Notification, error) {
+func (c *converter) NotificationToAPINotification(ctx context.Context, n *gtsmodel.Notification) (*model.Notification, error) {
if n.TargetAccount == nil {
tAccount, err := c.db.GetAccountByID(ctx, n.TargetAccountID)
if err != nil {
- return nil, fmt.Errorf("NotificationToMasto: error getting target account with id %s from the db: %s", n.TargetAccountID, err)
+ return nil, fmt.Errorf("NotificationToapi: error getting target account with id %s from the db: %s", n.TargetAccountID, err)
}
n.TargetAccount = tAccount
}
@@ -653,22 +653,22 @@ func (c *converter) NotificationToMasto(ctx context.Context, n *gtsmodel.Notific
if n.OriginAccount == nil {
ogAccount, err := c.db.GetAccountByID(ctx, n.OriginAccountID)
if err != nil {
- return nil, fmt.Errorf("NotificationToMasto: error getting origin account with id %s from the db: %s", n.OriginAccountID, err)
+ return nil, fmt.Errorf("NotificationToapi: error getting origin account with id %s from the db: %s", n.OriginAccountID, err)
}
n.OriginAccount = ogAccount
}
- mastoAccount, err := c.AccountToMastoPublic(ctx, n.OriginAccount)
+ apiAccount, err := c.AccountToAPIAccountPublic(ctx, n.OriginAccount)
if err != nil {
- return nil, fmt.Errorf("NotificationToMasto: error converting account to masto: %s", err)
+ return nil, fmt.Errorf("NotificationToapi: error converting account to api: %s", err)
}
- var mastoStatus *model.Status
+ var apiStatus *model.Status
if n.StatusID != "" {
if n.Status == nil {
status, err := c.db.GetStatusByID(ctx, n.StatusID)
if err != nil {
- return nil, fmt.Errorf("NotificationToMasto: error getting status with id %s from the db: %s", n.StatusID, err)
+ return nil, fmt.Errorf("NotificationToapi: error getting status with id %s from the db: %s", n.StatusID, err)
}
n.Status = status
}
@@ -682,9 +682,9 @@ func (c *converter) NotificationToMasto(ctx context.Context, n *gtsmodel.Notific
}
var err error
- mastoStatus, err = c.StatusToMasto(ctx, n.Status, nil)
+ apiStatus, err = c.StatusToAPIStatus(ctx, n.Status, nil)
if err != nil {
- return nil, fmt.Errorf("NotificationToMasto: error converting status to masto: %s", err)
+ return nil, fmt.Errorf("NotificationToapi: error converting status to api: %s", err)
}
}
@@ -692,12 +692,12 @@ func (c *converter) NotificationToMasto(ctx context.Context, n *gtsmodel.Notific
ID: n.ID,
Type: string(n.NotificationType),
CreatedAt: n.CreatedAt.Format(time.RFC3339),
- Account: mastoAccount,
- Status: mastoStatus,
+ Account: apiAccount,
+ Status: apiStatus,
}, nil
}
-func (c *converter) DomainBlockToMasto(ctx context.Context, b *gtsmodel.DomainBlock, export bool) (*model.DomainBlock, error) {
+func (c *converter) DomainBlockToAPIDomainBlock(ctx context.Context, b *gtsmodel.DomainBlock, export bool) (*model.DomainBlock, error) {
domainBlock := &model.DomainBlock{
Domain: b.Domain,