mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-12-30 00:36:14 -06:00
rework mention creation a bit
This commit is contained in:
parent
30f688dbe2
commit
6ba383b4c6
1 changed files with 28 additions and 8 deletions
|
|
@ -318,6 +318,7 @@ func (d *deref) populateStatusFields(ctx context.Context, status *gtsmodel.Statu
|
||||||
//
|
//
|
||||||
// We should dereference any accounts mentioned here which we don't have in our db yet, by their URI.
|
// We should dereference any accounts mentioned here which we don't have in our db yet, by their URI.
|
||||||
mentionIDs := []string{}
|
mentionIDs := []string{}
|
||||||
|
newMentions := []*gtsmodel.Mention{}
|
||||||
for _, m := range status.Mentions {
|
for _, m := range status.Mentions {
|
||||||
if m.ID != "" {
|
if m.ID != "" {
|
||||||
// we've already populated this mention, since it has an ID
|
// we've already populated this mention, since it has an ID
|
||||||
|
|
@ -338,15 +339,32 @@ func (d *deref) populateStatusFields(ctx context.Context, status *gtsmodel.Statu
|
||||||
}
|
}
|
||||||
|
|
||||||
var targetAccount *gtsmodel.Account
|
var targetAccount *gtsmodel.Account
|
||||||
if a, err := d.db.GetAccountByURL(ctx, targetAccountURI.String()); err == nil {
|
var found bool
|
||||||
targetAccount = a
|
errs := []string{}
|
||||||
} else if a, _, err := d.GetRemoteAccount(ctx, requestingUsername, targetAccountURI, false); err == nil {
|
|
||||||
|
if !found {
|
||||||
|
a, err := d.db.GetAccountByURL(ctx, targetAccountURI.String())
|
||||||
|
aaaaaaaaaaaaaif err == nil && a != nil {
|
||||||
targetAccount = a
|
targetAccount = a
|
||||||
|
found = true
|
||||||
} else {
|
} else {
|
||||||
// we can't find the target account so bail
|
errs = append(errs, err.Error())
|
||||||
l.Debug("can't retrieve account targeted by mention")
|
|
||||||
continue
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if !found {
|
||||||
|
if a, _, err := d.GetRemoteAccount(ctx, requestingUsername, targetAccountURI, false); err == nil && a != nil {
|
||||||
|
targetAccount = a
|
||||||
|
found = true
|
||||||
|
} else if err != nil {
|
||||||
|
errs = append(errs, err.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if !found {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
mID, err := id.NewRandomULID()
|
mID, err := id.NewRandomULID()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -373,8 +391,10 @@ func (d *deref) populateStatusFields(ctx context.Context, status *gtsmodel.Statu
|
||||||
return fmt.Errorf("error creating mention: %s", err)
|
return fmt.Errorf("error creating mention: %s", err)
|
||||||
}
|
}
|
||||||
mentionIDs = append(mentionIDs, m.ID)
|
mentionIDs = append(mentionIDs, m.ID)
|
||||||
|
newMentions = append(newMentions, m)
|
||||||
}
|
}
|
||||||
status.MentionIDs = mentionIDs
|
status.MentionIDs = mentionIDs
|
||||||
|
status.Mentions = newMentions
|
||||||
|
|
||||||
// status has replyToURI but we don't have an ID yet for the status it replies to
|
// status has replyToURI but we don't have an ID yet for the status it replies to
|
||||||
if status.InReplyToURI != "" && status.InReplyToID == "" {
|
if status.InReplyToURI != "" && status.InReplyToID == "" {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue