summaryrefslogtreecommitdiff
path: root/internal/util
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/util
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/util')
-rw-r--r--internal/util/statustools.go12
-rw-r--r--internal/util/statustools_test.go8
2 files changed, 9 insertions, 11 deletions
diff --git a/internal/util/statustools.go b/internal/util/statustools.go
index bb87c23fa..08032a8f4 100644
--- a/internal/util/statustools.go
+++ b/internal/util/statustools.go
@@ -25,13 +25,11 @@ import (
"github.com/superseriousbusiness/gotosocial/internal/regexes"
)
-// DeriveMentionsFromText takes a plaintext (ie., not html-formatted) text,
-// and applies a regex to it to return a deduplicated list of accounts
-// mentioned in that text.
-//
-// It will look for fully-qualified account names in the form "@user@example.org".
-// or the form "@username" for local users.
-func DeriveMentionsFromText(text string) []string {
+// DeriveMentionNamesFromText takes a plaintext (ie., not html-formatted) text,
+// and applies a regex to it to return a deduplicated list of account names
+// mentioned in that text, in the format "@user@example.org" or "@username" for
+// local users.
+func DeriveMentionNamesFromText(text string) []string {
mentionedAccounts := []string{}
for _, m := range regexes.MentionFinder.FindAllStringSubmatch(text, -1) {
mentionedAccounts = append(mentionedAccounts, m[1])
diff --git a/internal/util/statustools_test.go b/internal/util/statustools_test.go
index bcd9a4883..bea89158a 100644
--- a/internal/util/statustools_test.go
+++ b/internal/util/statustools_test.go
@@ -37,7 +37,7 @@ https://localhost:8080/@the_mighty_zork/statuses/01FGVP55XMF2K6316MQRX6PFG1
that link shouldn't come out formatted as a mention!`
- menchies := util.DeriveMentionsFromText(statusText)
+ menchies := util.DeriveMentionNamesFromText(statusText)
suite.Empty(menchies)
}
@@ -56,7 +56,7 @@ func (suite *StatusTestSuite) TestDeriveMentionsOK() {
`
- menchies := util.DeriveMentionsFromText(statusText)
+ menchies := util.DeriveMentionNamesFromText(statusText)
assert.Len(suite.T(), menchies, 6)
assert.Equal(suite.T(), "@dumpsterqueer@example.org", menchies[0])
assert.Equal(suite.T(), "@someone_else@testing.best-horse.com", menchies[1])
@@ -68,7 +68,7 @@ func (suite *StatusTestSuite) TestDeriveMentionsOK() {
func (suite *StatusTestSuite) TestDeriveMentionsEmpty() {
statusText := ``
- menchies := util.DeriveMentionsFromText(statusText)
+ menchies := util.DeriveMentionNamesFromText(statusText)
assert.Len(suite.T(), menchies, 0)
}
@@ -126,7 +126,7 @@ func (suite *StatusTestSuite) TestDeriveMultiple() {
Text`
- ms := util.DeriveMentionsFromText(statusText)
+ ms := util.DeriveMentionNamesFromText(statusText)
hs := util.DeriveHashtagsFromText(statusText)
es := util.DeriveEmojisFromText(statusText)