summaryrefslogtreecommitdiff
path: root/internal/processing/status/util.go
diff options
context:
space:
mode:
authorLibravatar tobi <31960611+tsmethurst@users.noreply.github.com>2022-03-29 11:54:56 +0200
committerLibravatar GitHub <noreply@github.com>2022-03-29 11:54:56 +0200
commit37d310f981f3e26bc643aeabac134b591c84455a (patch)
tree041f5db16254b5257471bcac0730ac9d93ce13d5 /internal/processing/status/util.go
parent[feature/security] Add systemd sandboxing options to harden security (#440) (diff)
downloadgotosocial-37d310f981f3e26bc643aeabac134b591c84455a.tar.xz
[feature] Dereference remote mentions when the account is not already known (#442)v0.2.2
* remove mention util function from db * add ParseMentionFunc to gtsmodel * add parseMentionFunc to processor * refactor search to simplify it a bit * add parseMentionFunc to account * add parseMentionFunc to status * some renaming for clarity * test dereference of unknown mentioned account
Diffstat (limited to 'internal/processing/status/util.go')
-rw-r--r--internal/processing/status/util.go33
1 files changed, 18 insertions, 15 deletions
diff --git a/internal/processing/status/util.go b/internal/processing/status/util.go
index f2640929d..5de66af8a 100644
--- a/internal/processing/status/util.go
+++ b/internal/processing/status/util.go
@@ -23,10 +23,10 @@ import (
"errors"
"fmt"
+ "github.com/sirupsen/logrus"
apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model"
"github.com/superseriousbusiness/gotosocial/internal/db"
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
- "github.com/superseriousbusiness/gotosocial/internal/id"
"github.com/superseriousbusiness/gotosocial/internal/text"
"github.com/superseriousbusiness/gotosocial/internal/util"
)
@@ -192,27 +192,30 @@ func (p *processor) ProcessLanguage(ctx context.Context, form *apimodel.Advanced
}
func (p *processor) ProcessMentions(ctx context.Context, form *apimodel.AdvancedStatusCreateForm, accountID string, status *gtsmodel.Status) error {
- menchies := []string{}
- gtsMenchies, err := p.db.MentionStringsToMentions(ctx, util.DeriveMentionsFromText(form.Status), accountID, status.ID)
- if err != nil {
- return fmt.Errorf("error generating mentions from status: %s", err)
- }
- for _, menchie := range gtsMenchies {
- menchieID, err := id.NewRandomULID()
+ mentionedAccountNames := util.DeriveMentionNamesFromText(form.Status)
+ mentions := []*gtsmodel.Mention{}
+ mentionIDs := []string{}
+
+ for _, mentionedAccountName := range mentionedAccountNames {
+ gtsMention, err := p.parseMention(ctx, mentionedAccountName, accountID, status.ID)
if err != nil {
- return err
+ logrus.Errorf("ProcessMentions: error parsing mention %s from status: %s", mentionedAccountName, err)
+ continue
}
- menchie.ID = menchieID
- if err := p.db.Put(ctx, menchie); err != nil {
- return fmt.Errorf("error putting mentions in db: %s", err)
+ if err := p.db.Put(ctx, gtsMention); err != nil {
+ logrus.Errorf("ProcessMentions: error putting mention in db: %s", err)
}
- menchies = append(menchies, menchie.ID)
+
+ mentions = append(mentions, gtsMention)
+ mentionIDs = append(mentionIDs, gtsMention.ID)
}
+
// add full populated gts menchies to the status for passing them around conveniently
- status.Mentions = gtsMenchies
+ status.Mentions = mentions
// add just the ids of the mentioned accounts to the status for putting in the db
- status.MentionIDs = menchies
+ status.MentionIDs = mentionIDs
+
return nil
}