summaryrefslogtreecommitdiff
path: root/internal/util/statustools.go
diff options
context:
space:
mode:
authorLibravatar kim <89579420+NyaaaWhatsUpDoc@users.noreply.github.com>2021-10-17 13:19:49 +0100
committerLibravatar GitHub <noreply@github.com>2021-10-17 14:19:49 +0200
commit7e4c3fa5c7374363a28e9b0d028b6d71700607c7 (patch)
treea723ea4c9534d4bd88b09d0f287b4e8b79804a0e /internal/util/statustools.go
parentFollow request improvements (#282) (diff)
downloadgotosocial-7e4c3fa5c7374363a28e9b0d028b6d71700607c7.tar.xz
fix mention extracting when no domain exists (usually intra-instance mentions) (#272)
* fix mention extracting when no domain exists (usually when intra-instance mentions) Signed-off-by: kim <grufwub@gmail.com> * fix search logic to match new mention matching logic Signed-off-by: kim <grufwub@gmail.com> * appease the linter :p Signed-off-by: kim <grufwub@gmail.com>
Diffstat (limited to 'internal/util/statustools.go')
-rw-r--r--internal/util/statustools.go18
1 files changed, 7 insertions, 11 deletions
diff --git a/internal/util/statustools.go b/internal/util/statustools.go
index 95ce63a5b..030372b50 100644
--- a/internal/util/statustools.go
+++ b/internal/util/statustools.go
@@ -68,16 +68,12 @@ func DeriveEmojisFromText(text string) []string {
// If nothing is matched, it will return an error.
func ExtractMentionParts(mention string) (username, domain string, err error) {
matches := regexes.MentionName.FindStringSubmatch(mention)
- if matches == nil || len(matches) != 3 {
- err = fmt.Errorf("could't match mention %s", mention)
- return
+ switch len(matches) {
+ case 2:
+ return matches[1], "", nil
+ case 3:
+ return matches[1], matches[2], nil
+ default:
+ return "", "", fmt.Errorf("couldn't match mention %s", mention)
}
- username = matches[1]
- domain = matches[2]
- return
-}
-
-// IsMention returns true if the passed string looks like @whatever@example.org
-func IsMention(mention string) bool {
- return regexes.MentionName.MatchString(strings.ToLower(mention))
}