From 6ba383b4c6a7b8fa3ee474c7d95c61c7e7997d7d Mon Sep 17 00:00:00 2001 From: tsmethurst Date: Thu, 26 Aug 2021 22:41:14 +0200 Subject: [PATCH] rework mention creation a bit --- internal/federation/dereferencing/status.go | 36 ++++++++++++++++----- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/internal/federation/dereferencing/status.go b/internal/federation/dereferencing/status.go index 93ead6523..6dbbf4c43 100644 --- a/internal/federation/dereferencing/status.go +++ b/internal/federation/dereferencing/status.go @@ -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. mentionIDs := []string{} + newMentions := []*gtsmodel.Mention{} for _, m := range status.Mentions { if m.ID != "" { // we've already populated this mention, since it has an ID @@ -338,16 +339,33 @@ func (d *deref) populateStatusFields(ctx context.Context, status *gtsmodel.Statu } var targetAccount *gtsmodel.Account - if a, err := d.db.GetAccountByURL(ctx, targetAccountURI.String()); err == nil { - targetAccount = a - } else if a, _, err := d.GetRemoteAccount(ctx, requestingUsername, targetAccountURI, false); err == nil { - targetAccount = a - } else { - // we can't find the target account so bail - l.Debug("can't retrieve account targeted by mention") - continue + var found bool + errs := []string{} + + if !found { + a, err := d.db.GetAccountByURL(ctx, targetAccountURI.String()) + aaaaaaaaaaaaaif err == nil && a != nil { + targetAccount = a + found = true + } else { + errs = append(errs, err.Error()) + } } + 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() if err != nil { return err @@ -373,8 +391,10 @@ func (d *deref) populateStatusFields(ctx context.Context, status *gtsmodel.Statu return fmt.Errorf("error creating mention: %s", err) } mentionIDs = append(mentionIDs, m.ID) + newMentions = append(newMentions, m) } status.MentionIDs = mentionIDs + status.Mentions = newMentions // status has replyToURI but we don't have an ID yet for the status it replies to if status.InReplyToURI != "" && status.InReplyToID == "" {