more fiddling

This commit is contained in:
tsmethurst 2021-08-17 19:03:41 +02:00
commit a3322b2bf3
65 changed files with 712 additions and 508 deletions

View file

@ -188,22 +188,22 @@ func (c *converter) ASStatusToStatus(statusable ap.Statusable) (*gtsmodel.Status
// attachments to dereference and fetch later on (we don't do that here)
if attachments, err := ap.ExtractAttachments(statusable); err == nil {
status.GTSMediaAttachments = attachments
status.Attachments = attachments
}
// hashtags to dereference later on
if hashtags, err := ap.ExtractHashtags(statusable); err == nil {
status.GTSTags = hashtags
status.Tags = hashtags
}
// emojis to dereference and fetch later on
if emojis, err := ap.ExtractEmojis(statusable); err == nil {
status.GTSEmojis = emojis
status.Emojis = emojis
}
// mentions to dereference later on
if mentions, err := ap.ExtractMentions(statusable); err == nil {
status.GTSMentions = mentions
status.Mentions = mentions
}
// cw string for this status
@ -515,10 +515,10 @@ func (c *converter) ASAnnounceToStatus(announceable ap.Announceable) (*gtsmodel.
status.AccountURI = boostingAccount.URI
// these will all be wrapped in the boosted status so set them empty here
status.Attachments = []string{}
status.Tags = []string{}
status.Mentions = []string{}
status.Emojis = []string{}
status.AttachmentIDs = []string{}
status.TagIDs = []string{}
status.MentionIDs = []string{}
status.EmojiIDs = []string{}
// parse the visibility from the To and CC entries
var visibility gtsmodel.Visibility

View file

@ -54,10 +54,10 @@ func (c *converter) StatusToBoost(s *gtsmodel.Status, boostingAccount *gtsmodel.
InReplyToAccountID: "",
// these will all be wrapped in the boosted status so set them empty here
Attachments: []string{},
Tags: []string{},
Mentions: []string{},
Emojis: []string{},
AttachmentIDs: []string{},
TagIDs: []string{},
MentionIDs: []string{},
EmojiIDs: []string{},
// the below fields will be taken from the target status
Content: s.Content,

View file

@ -408,7 +408,7 @@ func (c *converter) StatusToAS(s *gtsmodel.Status) (vocab.ActivityStreamsNote, e
tagProp := streams.NewActivityStreamsTagProperty()
// tag -- mentions
for _, m := range s.GTSMentions {
for _, m := range s.Mentions {
asMention, err := c.MentionToAS(m)
if err != nil {
return nil, fmt.Errorf("StatusToAS: error converting mention to AS mention: %s", err)
@ -441,10 +441,10 @@ func (c *converter) StatusToAS(s *gtsmodel.Status) (vocab.ActivityStreamsNote, e
switch s.Visibility {
case gtsmodel.VisibilityDirect:
// if DIRECT, then only mentioned users should be added to TO, and nothing to CC
for _, m := range s.GTSMentions {
iri, err := url.Parse(m.GTSAccount.URI)
for _, m := range s.Mentions {
iri, err := url.Parse(m.OriginAccount.URI)
if err != nil {
return nil, fmt.Errorf("StatusToAS: error parsing uri %s: %s", m.GTSAccount.URI, err)
return nil, fmt.Errorf("StatusToAS: error parsing uri %s: %s", m.OriginAccount.URI, err)
}
toProp.AppendIRI(iri)
}
@ -453,10 +453,10 @@ func (c *converter) StatusToAS(s *gtsmodel.Status) (vocab.ActivityStreamsNote, e
case gtsmodel.VisibilityFollowersOnly:
// if FOLLOWERS ONLY then we want to add followers to TO, and mentions to CC
toProp.AppendIRI(authorFollowersURI)
for _, m := range s.GTSMentions {
iri, err := url.Parse(m.GTSAccount.URI)
for _, m := range s.Mentions {
iri, err := url.Parse(m.OriginAccount.URI)
if err != nil {
return nil, fmt.Errorf("StatusToAS: error parsing uri %s: %s", m.GTSAccount.URI, err)
return nil, fmt.Errorf("StatusToAS: error parsing uri %s: %s", m.OriginAccount.URI, err)
}
ccProp.AppendIRI(iri)
}
@ -464,10 +464,10 @@ func (c *converter) StatusToAS(s *gtsmodel.Status) (vocab.ActivityStreamsNote, e
// if UNLOCKED, we want to add followers to TO, and public and mentions to CC
toProp.AppendIRI(authorFollowersURI)
ccProp.AppendIRI(publicURI)
for _, m := range s.GTSMentions {
iri, err := url.Parse(m.GTSAccount.URI)
for _, m := range s.Mentions {
iri, err := url.Parse(m.OriginAccount.URI)
if err != nil {
return nil, fmt.Errorf("StatusToAS: error parsing uri %s: %s", m.GTSAccount.URI, err)
return nil, fmt.Errorf("StatusToAS: error parsing uri %s: %s", m.OriginAccount.URI, err)
}
ccProp.AppendIRI(iri)
}
@ -475,10 +475,10 @@ func (c *converter) StatusToAS(s *gtsmodel.Status) (vocab.ActivityStreamsNote, e
// if PUBLIC, we want to add public to TO, and followers and mentions to CC
toProp.AppendIRI(publicURI)
ccProp.AppendIRI(authorFollowersURI)
for _, m := range s.GTSMentions {
iri, err := url.Parse(m.GTSAccount.URI)
for _, m := range s.Mentions {
iri, err := url.Parse(m.OriginAccount.URI)
if err != nil {
return nil, fmt.Errorf("StatusToAS: error parsing uri %s: %s", m.GTSAccount.URI, err)
return nil, fmt.Errorf("StatusToAS: error parsing uri %s: %s", m.OriginAccount.URI, err)
}
ccProp.AppendIRI(iri)
}
@ -496,7 +496,7 @@ func (c *converter) StatusToAS(s *gtsmodel.Status) (vocab.ActivityStreamsNote, e
// attachment
attachmentProp := streams.NewActivityStreamsAttachmentProperty()
for _, a := range s.GTSMediaAttachments {
for _, a := range s.Attachments {
doc, err := c.AttachmentToAS(a)
if err != nil {
return nil, fmt.Errorf("StatusToAS: error converting attachment: %s", err)
@ -565,12 +565,12 @@ func (c *converter) FollowToAS(f *gtsmodel.Follow, originAccount *gtsmodel.Accou
}
func (c *converter) MentionToAS(m *gtsmodel.Mention) (vocab.ActivityStreamsMention, error) {
if m.GTSAccount == nil {
if m.OriginAccount == nil {
a := &gtsmodel.Account{}
if err := c.db.GetWhere([]db.Where{{Key: "target_account_id", Value: m.TargetAccountID}}, a); err != nil {
return nil, fmt.Errorf("MentionToAS: error getting target account from db: %s", err)
}
m.GTSAccount = a
m.OriginAccount = a
}
// create the mention
@ -578,21 +578,21 @@ func (c *converter) MentionToAS(m *gtsmodel.Mention) (vocab.ActivityStreamsMenti
// href -- this should be the URI of the mentioned user
hrefProp := streams.NewActivityStreamsHrefProperty()
hrefURI, err := url.Parse(m.GTSAccount.URI)
hrefURI, err := url.Parse(m.OriginAccount.URI)
if err != nil {
return nil, fmt.Errorf("MentionToAS: error parsing uri %s: %s", m.GTSAccount.URI, err)
return nil, fmt.Errorf("MentionToAS: error parsing uri %s: %s", m.OriginAccount.URI, err)
}
hrefProp.SetIRI(hrefURI)
mention.SetActivityStreamsHref(hrefProp)
// name -- this should be the namestring of the mentioned user, something like @whatever@example.org
var domain string
if m.GTSAccount.Domain == "" {
if m.OriginAccount.Domain == "" {
domain = c.config.AccountDomain
} else {
domain = m.GTSAccount.Domain
domain = m.OriginAccount.Domain
}
username := m.GTSAccount.Username
username := m.OriginAccount.Username
nameString := fmt.Sprintf("@%s@%s", username, domain)
nameProp := streams.NewActivityStreamsNameProperty()
nameProp.AppendXMLSchemaString(nameString)

View file

@ -357,8 +357,8 @@ func (c *converter) StatusToMasto(s *gtsmodel.Status, requestingAccount *gtsmode
mastoAttachments := []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 s.GTSMediaAttachments != nil {
for _, gtsAttachment := range s.GTSMediaAttachments {
if s.Attachments != nil {
for _, gtsAttachment := range s.Attachments {
mastoAttachment, err := c.AttachmentToMasto(gtsAttachment)
if err != nil {
return nil, fmt.Errorf("error converting attachment with id %s: %s", gtsAttachment.ID, err)
@ -368,7 +368,7 @@ func (c *converter) StatusToMasto(s *gtsmodel.Status, requestingAccount *gtsmode
// 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
} else {
for _, a := range s.Attachments {
for _, a := range s.AttachmentIDs {
gtsAttachment := &gtsmodel.MediaAttachment{}
if err := c.db.GetByID(a, gtsAttachment); err != nil {
return nil, fmt.Errorf("error getting attachment with id %s: %s", a, err)
@ -384,8 +384,8 @@ func (c *converter) StatusToMasto(s *gtsmodel.Status, requestingAccount *gtsmode
mastoMentions := []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 s.GTSMentions != nil {
for _, gtsMention := range s.GTSMentions {
if s.Mentions != nil {
for _, gtsMention := range s.Mentions {
mastoMention, err := c.MentionToMasto(gtsMention)
if err != nil {
return nil, fmt.Errorf("error converting mention with id %s: %s", gtsMention.ID, err)
@ -395,7 +395,7 @@ func (c *converter) StatusToMasto(s *gtsmodel.Status, requestingAccount *gtsmode
// 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
} else {
for _, m := range s.Mentions {
for _, m := range s.MentionIDs {
gtsMention := &gtsmodel.Mention{}
if err := c.db.GetByID(m, gtsMention); err != nil {
return nil, fmt.Errorf("error getting mention with id %s: %s", m, err)
@ -411,8 +411,8 @@ func (c *converter) StatusToMasto(s *gtsmodel.Status, requestingAccount *gtsmode
mastoTags := []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 s.GTSTags != nil {
for _, gtsTag := range s.GTSTags {
if s.Tags != nil {
for _, gtsTag := range s.Tags {
mastoTag, err := c.TagToMasto(gtsTag)
if err != nil {
return nil, fmt.Errorf("error converting tag with id %s: %s", gtsTag.ID, err)
@ -422,7 +422,7 @@ func (c *converter) StatusToMasto(s *gtsmodel.Status, requestingAccount *gtsmode
// 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
} else {
for _, t := range s.Tags {
for _, t := range s.TagIDs {
gtsTag := &gtsmodel.Tag{}
if err := c.db.GetByID(t, gtsTag); err != nil {
return nil, fmt.Errorf("error getting tag with id %s: %s", t, err)
@ -438,8 +438,8 @@ func (c *converter) StatusToMasto(s *gtsmodel.Status, requestingAccount *gtsmode
mastoEmojis := []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 s.GTSEmojis != nil {
for _, gtsEmoji := range s.GTSEmojis {
if s.Emojis != nil {
for _, gtsEmoji := range s.Emojis {
mastoEmoji, err := c.EmojiToMasto(gtsEmoji)
if err != nil {
return nil, fmt.Errorf("error converting emoji with id %s: %s", gtsEmoji.ID, err)
@ -449,7 +449,7 @@ func (c *converter) StatusToMasto(s *gtsmodel.Status, requestingAccount *gtsmode
// 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
} else {
for _, e := range s.Emojis {
for _, e := range s.EmojiIDs {
gtsEmoji := &gtsmodel.Emoji{}
if err := c.db.GetByID(e, gtsEmoji); err != nil {
return nil, fmt.Errorf("error getting emoji with id %s: %s", e, err)
@ -609,46 +609,46 @@ func (c *converter) RelationshipToMasto(r *gtsmodel.Relationship) (*model.Relati
func (c *converter) NotificationToMasto(n *gtsmodel.Notification) (*model.Notification, error) {
if n.GTSTargetAccount == nil {
if n.TargetAccount == nil {
tAccount := &gtsmodel.Account{}
if err := c.db.GetByID(n.TargetAccountID, tAccount); err != nil {
return nil, fmt.Errorf("NotificationToMasto: error getting target account with id %s from the db: %s", n.TargetAccountID, err)
}
n.GTSTargetAccount = tAccount
n.TargetAccount = tAccount
}
if n.GTSOriginAccount == nil {
if n.OriginAccount == nil {
ogAccount := &gtsmodel.Account{}
if err := c.db.GetByID(n.OriginAccountID, ogAccount); err != nil {
return nil, fmt.Errorf("NotificationToMasto: error getting origin account with id %s from the db: %s", n.OriginAccountID, err)
}
n.GTSOriginAccount = ogAccount
n.OriginAccount = ogAccount
}
mastoAccount, err := c.AccountToMastoPublic(n.GTSOriginAccount)
mastoAccount, err := c.AccountToMastoPublic(n.OriginAccount)
if err != nil {
return nil, fmt.Errorf("NotificationToMasto: error converting account to masto: %s", err)
}
var mastoStatus *model.Status
if n.StatusID != "" {
if n.GTSStatus == nil {
if n.Status == nil {
status := &gtsmodel.Status{}
if err := c.db.GetByID(n.StatusID, status); err != nil {
return nil, fmt.Errorf("NotificationToMasto: error getting status with id %s from the db: %s", n.StatusID, err)
}
n.GTSStatus = status
n.Status = status
}
if n.GTSStatus.Account == nil {
if n.GTSStatus.AccountID == n.GTSTargetAccount.ID {
n.GTSStatus.Account = n.GTSTargetAccount
} else if n.GTSStatus.AccountID == n.GTSOriginAccount.ID {
n.GTSStatus.Account = n.GTSOriginAccount
if n.Status.Account == nil {
if n.Status.AccountID == n.TargetAccount.ID {
n.Status.Account = n.TargetAccount
} else if n.Status.AccountID == n.OriginAccount.ID {
n.Status.Account = n.OriginAccount
}
}
var err error
mastoStatus, err = c.StatusToMasto(n.GTSStatus, nil)
mastoStatus, err = c.StatusToMasto(n.Status, nil)
if err != nil {
return nil, fmt.Errorf("NotificationToMasto: error converting status to masto: %s", err)
}