Add-ish support for tags and mentions in new messages
Some checks failed
/ docker (push) Has been cancelled
Some checks failed
/ docker (push) Has been cancelled
This commit is contained in:
parent
94106bb82f
commit
b0f041e7b0
14 changed files with 242 additions and 53 deletions
|
@ -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]
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue