Add-ish support for tags and mentions in new messages
Some checks failed
/ docker (push) Has been cancelled

This commit is contained in:
Melody Becker 2025-06-05 17:07:04 +02:00
parent 94106bb82f
commit b0f041e7b0
Signed by: mstar
SSH key fingerprint: SHA256:9VAo09aaVNTWKzPW7Hq2LW+ox9OdwmTSHRoD4mlz1yI
14 changed files with 242 additions and 53 deletions

View file

@ -1,8 +1,11 @@
package webshared
import (
"regexp"
"time"
"git.mstar.dev/mstar/goutils/sliceutils"
"git.mstar.dev/mstar/linstrom/shared"
"git.mstar.dev/mstar/linstrom/storage-new/models"
)
@ -24,6 +27,8 @@ type Note struct {
var _ shared.Clonable = &Note{}
var _ shared.Sanitisable = &Note{}
var mentionsRegex = regexp.MustCompile(`@([a-zA-Z@\._0-9]+)`)
// No test, does nothing currently
func (note *Note) Sanitize() {
}
@ -58,3 +63,17 @@ func (n *Note) FromModel(m *models.Note) {
}
n.AccessLevel = uint8(m.AccessLevel)
}
func MentionsFromContent(content string) []string {
matches := mentionsRegex.FindAllStringSubmatch(content, -1)
if len(matches) == 0 {
return []string{}
}
return sliceutils.Map(matches, func(t []string) string {
if len(t) != 2 {
return ""
} else {
return t[1]
}
})
}

View file

@ -1,7 +1,9 @@
package webshared
import (
"fmt"
"slices"
"strings"
"time"
"git.mstar.dev/mstar/linstrom/config"
@ -118,3 +120,11 @@ func (u *User) FromModel(m *models.User) {
u.Verified = &m.Verified
u.FinishedRegistration = &m.FinishedRegistration
}
func UserPublicUrl(id string) string {
if strings.HasPrefix(id, "http") {
return id
} else {
return fmt.Sprintf("%s/api/activitypub/user/%s", config.GlobalConfig.General.GetFullPublicUrl(), id)
}
}