too many changes to name honestly
This commit is contained in:
@ -21,8 +21,8 @@ package util
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/superseriousbusiness/gotosocial/internal/db/model"
|
||||
"github.com/superseriousbusiness/gotosocial/pkg/mastotypes"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/db/gtsmodel"
|
||||
mastotypes "github.com/superseriousbusiness/gotosocial/internal/mastotypes/mastomodel"
|
||||
)
|
||||
|
||||
type URIs struct {
|
||||
@ -64,16 +64,16 @@ func GenerateURIs(username string, protocol string, host string) *URIs {
|
||||
}
|
||||
|
||||
// ParseGTSVisFromMastoVis converts a mastodon visibility into its gts equivalent.
|
||||
func ParseGTSVisFromMastoVis(m mastotypes.Visibility) model.Visibility {
|
||||
func ParseGTSVisFromMastoVis(m mastotypes.Visibility) gtsmodel.Visibility {
|
||||
switch m {
|
||||
case mastotypes.VisibilityPublic:
|
||||
return model.VisibilityPublic
|
||||
return gtsmodel.VisibilityPublic
|
||||
case mastotypes.VisibilityUnlisted:
|
||||
return model.VisibilityUnlocked
|
||||
return gtsmodel.VisibilityUnlocked
|
||||
case mastotypes.VisibilityPrivate:
|
||||
return model.VisibilityFollowersOnly
|
||||
return gtsmodel.VisibilityFollowersOnly
|
||||
case mastotypes.VisibilityDirect:
|
||||
return model.VisibilityDirect
|
||||
return gtsmodel.VisibilityDirect
|
||||
default:
|
||||
break
|
||||
}
|
||||
@ -81,15 +81,15 @@ func ParseGTSVisFromMastoVis(m mastotypes.Visibility) model.Visibility {
|
||||
}
|
||||
|
||||
// ParseMastoVisFromGTSVis converts a gts visibility into its mastodon equivalent
|
||||
func ParseMastoVisFromGTSVis(m model.Visibility) mastotypes.Visibility {
|
||||
func ParseMastoVisFromGTSVis(m gtsmodel.Visibility) mastotypes.Visibility {
|
||||
switch m {
|
||||
case model.VisibilityPublic:
|
||||
case gtsmodel.VisibilityPublic:
|
||||
return mastotypes.VisibilityPublic
|
||||
case model.VisibilityUnlocked:
|
||||
case gtsmodel.VisibilityUnlocked:
|
||||
return mastotypes.VisibilityUnlisted
|
||||
case model.VisibilityFollowersOnly, model.VisibilityMutualsOnly:
|
||||
case gtsmodel.VisibilityFollowersOnly, gtsmodel.VisibilityMutualsOnly:
|
||||
return mastotypes.VisibilityPrivate
|
||||
case model.VisibilityDirect:
|
||||
case gtsmodel.VisibilityDirect:
|
||||
return mastotypes.VisibilityDirect
|
||||
default:
|
||||
break
|
||||
|
||||
@ -19,16 +19,13 @@
|
||||
package util
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// To play around with these regexes, see: https://regex101.com/r/2km2EK/1
|
||||
var (
|
||||
// mention regex can be played around with here: https://regex101.com/r/2km2EK/1
|
||||
hostnameRegexString = `(?:(?:[a-zA-Z]{1})|(?:[a-zA-Z]{1}[a-zA-Z]{1})|(?:[a-zA-Z]{1}[0-9]{1})|(?:[0-9]{1}[a-zA-Z]{1})|(?:[a-zA-Z0-9][a-zA-Z0-9-_]{1,61}[a-zA-Z0-9]))\.(?:[a-zA-Z]{2,6}|[a-zA-Z0-9-]{2,30}\.[a-zA-Z]{2,5}))`
|
||||
mentionRegexString = fmt.Sprintf(`(?: |^|\W)(@[a-zA-Z0-9_]+@%s(?: |\n)`, hostnameRegexString)
|
||||
// mention regex can be played around with here: https://regex101.com/r/qwM9D3/1
|
||||
mentionRegexString = `(?: |^|\W)(@[a-zA-Z0-9_]+(?:@[a-zA-Z0-9_\-\.]+)?)(?: |\n)`
|
||||
mentionRegex = regexp.MustCompile(mentionRegexString)
|
||||
// hashtag regex can be played with here: https://regex101.com/r/Vhy8pg/1
|
||||
hashtagRegexString = `(?: |^|\W)?#([a-zA-Z0-9]{1,30})(?:\b|\r)`
|
||||
@ -43,7 +40,7 @@ var (
|
||||
// mentioned in that status.
|
||||
//
|
||||
// It will look for fully-qualified account names in the form "@user@example.org".
|
||||
// Mentions that are just in the form "@username" will not be detected.
|
||||
// or the form "@username" for local users.
|
||||
// The case of the returned mentions will be lowered, for consistency.
|
||||
func DeriveMentions(status string) []string {
|
||||
mentionedAccounts := []string{}
|
||||
|
||||
@ -36,16 +36,17 @@ func (suite *StatusTestSuite) TestDeriveMentionsOK() {
|
||||
|
||||
@someone_else@testing.best-horse.com can you confirm? @hello@test.lgbt
|
||||
|
||||
@thiswontwork though! @NORWILL@THIS.one!!
|
||||
@thisisalocaluser ! @NORWILL@THIS.one!!
|
||||
|
||||
here is a duplicate mention: @hello@test.lgbt
|
||||
`
|
||||
|
||||
menchies := DeriveMentions(statusText)
|
||||
assert.Len(suite.T(), menchies, 3)
|
||||
assert.Len(suite.T(), menchies, 4)
|
||||
assert.Equal(suite.T(), "@dumpsterqueer@example.org", menchies[0])
|
||||
assert.Equal(suite.T(), "@someone_else@testing.best-horse.com", menchies[1])
|
||||
assert.Equal(suite.T(), "@hello@test.lgbt", menchies[2])
|
||||
assert.Equal(suite.T(), "@thisisalocaluser", menchies[3])
|
||||
}
|
||||
|
||||
func (suite *StatusTestSuite) TestDeriveMentionsEmpty() {
|
||||
|
||||
Reference in New Issue
Block a user