mirror of
https://github.com/superseriousbusiness/gotosocial
synced 2025-06-05 21:59:39 +02:00
kim is a reply guy (#208)
* bun debug * bun trace logging hooks * more tests * fix up some stuffffff * drop the frontend cache until a proper fix is made * go fmt
This commit is contained in:
@@ -25,38 +25,38 @@ import (
|
||||
"github.com/superseriousbusiness/gotosocial/internal/regexes"
|
||||
)
|
||||
|
||||
// DeriveMentionsFromStatus takes a plaintext (ie., not html-formatted) status,
|
||||
// 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 status.
|
||||
// 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 DeriveMentionsFromStatus(status string) []string {
|
||||
func DeriveMentionsFromText(text string) []string {
|
||||
mentionedAccounts := []string{}
|
||||
for _, m := range regexes.MentionFinder.FindAllStringSubmatch(status, -1) {
|
||||
for _, m := range regexes.MentionFinder.FindAllStringSubmatch(text, -1) {
|
||||
mentionedAccounts = append(mentionedAccounts, m[1])
|
||||
}
|
||||
return UniqueStrings(mentionedAccounts)
|
||||
}
|
||||
|
||||
// DeriveHashtagsFromStatus takes a plaintext (ie., not html-formatted) status,
|
||||
// DeriveHashtagsFromText takes a plaintext (ie., not html-formatted) text,
|
||||
// and applies a regex to it to return a deduplicated list of hashtags
|
||||
// used in that status, without the leading #. The case of the returned
|
||||
// used in that text, without the leading #. The case of the returned
|
||||
// tags will be lowered, for consistency.
|
||||
func DeriveHashtagsFromStatus(status string) []string {
|
||||
func DeriveHashtagsFromText(text string) []string {
|
||||
tags := []string{}
|
||||
for _, m := range regexes.HashtagFinder.FindAllStringSubmatch(status, -1) {
|
||||
for _, m := range regexes.HashtagFinder.FindAllStringSubmatch(text, -1) {
|
||||
tags = append(tags, strings.TrimPrefix(m[1], "#"))
|
||||
}
|
||||
return UniqueStrings(tags)
|
||||
}
|
||||
|
||||
// DeriveEmojisFromStatus takes a plaintext (ie., not html-formatted) status,
|
||||
// DeriveEmojisFromText takes a plaintext (ie., not html-formatted) text,
|
||||
// and applies a regex to it to return a deduplicated list of emojis
|
||||
// used in that status, without the surround ::.
|
||||
func DeriveEmojisFromStatus(status string) []string {
|
||||
// used in that text, without the surrounding `::`
|
||||
func DeriveEmojisFromText(text string) []string {
|
||||
emojis := []string{}
|
||||
for _, m := range regexes.EmojiFinder.FindAllStringSubmatch(status, -1) {
|
||||
for _, m := range regexes.EmojiFinder.FindAllStringSubmatch(text, -1) {
|
||||
emojis = append(emojis, m[1])
|
||||
}
|
||||
return UniqueStrings(emojis)
|
||||
|
@@ -45,7 +45,7 @@ func (suite *StatusTestSuite) TestDeriveMentionsOK() {
|
||||
|
||||
`
|
||||
|
||||
menchies := util.DeriveMentionsFromStatus(statusText)
|
||||
menchies := util.DeriveMentionsFromText(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])
|
||||
@@ -57,7 +57,7 @@ func (suite *StatusTestSuite) TestDeriveMentionsOK() {
|
||||
|
||||
func (suite *StatusTestSuite) TestDeriveMentionsEmpty() {
|
||||
statusText := ``
|
||||
menchies := util.DeriveMentionsFromStatus(statusText)
|
||||
menchies := util.DeriveMentionsFromText(statusText)
|
||||
assert.Len(suite.T(), menchies, 0)
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ func (suite *StatusTestSuite) TestDeriveHashtagsOK() {
|
||||
|
||||
#111111 thisalsoshouldn'twork#### ##`
|
||||
|
||||
tags := util.DeriveHashtagsFromStatus(statusText)
|
||||
tags := util.DeriveHashtagsFromText(statusText)
|
||||
assert.Len(suite.T(), tags, 5)
|
||||
assert.Equal(suite.T(), "testing123", tags[0])
|
||||
assert.Equal(suite.T(), "also", tags[1])
|
||||
@@ -97,7 +97,7 @@ Here's some normal text with an :emoji: at the end
|
||||
:underscores_ok_too:
|
||||
`
|
||||
|
||||
tags := util.DeriveEmojisFromStatus(statusText)
|
||||
tags := util.DeriveEmojisFromText(statusText)
|
||||
assert.Len(suite.T(), tags, 7)
|
||||
assert.Equal(suite.T(), "test", tags[0])
|
||||
assert.Equal(suite.T(), "another", tags[1])
|
||||
@@ -115,9 +115,9 @@ func (suite *StatusTestSuite) TestDeriveMultiple() {
|
||||
|
||||
Text`
|
||||
|
||||
ms := util.DeriveMentionsFromStatus(statusText)
|
||||
hs := util.DeriveHashtagsFromStatus(statusText)
|
||||
es := util.DeriveEmojisFromStatus(statusText)
|
||||
ms := util.DeriveMentionsFromText(statusText)
|
||||
hs := util.DeriveHashtagsFromText(statusText)
|
||||
es := util.DeriveEmojisFromText(statusText)
|
||||
|
||||
assert.Len(suite.T(), ms, 1)
|
||||
assert.Equal(suite.T(), "@foss_satan@fossbros-anonymous.io", ms[0])
|
||||
|
Reference in New Issue
Block a user