diff options
Diffstat (limited to 'internal')
| -rw-r--r-- | internal/ap/extract.go | 5 | ||||
| -rw-r--r-- | internal/processing/search.go | 31 | ||||
| -rw-r--r-- | internal/regexes/regexes.go | 2 | ||||
| -rw-r--r-- | internal/util/statustools.go | 18 | 
4 files changed, 22 insertions, 34 deletions
diff --git a/internal/ap/extract.go b/internal/ap/extract.go index 8a1d99ce9..f6ba555a8 100644 --- a/internal/ap/extract.go +++ b/internal/ap/extract.go @@ -565,13 +565,10 @@ func ExtractMention(i Mentionable) (*gtsmodel.Mention, error) {  	}  	// just make sure the mention string is valid so we can handle it properly later on... -	username, domain, err := util.ExtractMentionParts(mentionString) +	_, _, err = util.ExtractMentionParts(mentionString)  	if err != nil {  		return nil, err  	} -	if username == "" || domain == "" { -		return nil, errors.New("username or domain was empty") -	}  	mention.NameString = mentionString  	// the href prop should be the AP URI of a user we know, eg https://example.org/users/whatever_user diff --git a/internal/processing/search.go b/internal/processing/search.go index a73315396..fbcfb02be 100644 --- a/internal/processing/search.go +++ b/internal/processing/search.go @@ -53,7 +53,7 @@ func (p *processor) SearchGet(ctx context.Context, authed *oauth.Auth, searchQue  	var foundOne bool  	// check if the query is something like @whatever_username@example.org -- this means it's a remote account -	if !foundOne && util.IsMention(searchQuery.Query) { +	if _, domain, err := util.ExtractMentionParts(searchQuery.Query); err == nil && domain != "" {  		l.Debug("search term is a mention, looking it up...")  		foundAccount, err := p.searchAccountByMention(ctx, authed, searchQuery.Query, searchQuery.Resolve)  		if err == nil && foundAccount != nil { @@ -64,27 +64,22 @@ func (p *processor) SearchGet(ctx context.Context, authed *oauth.Auth, searchQue  	}  	// check if the query is a URI and just do a lookup for that, straight up -	if uri, err := url.Parse(query); err == nil && !foundOne { -		// 1. check if it's a status -		if foundStatus, err := p.searchStatusByURI(ctx, authed, uri, searchQuery.Resolve); err == nil && foundStatus != nil { -			foundStatuses = append(foundStatuses, foundStatus) -			foundOne = true -			l.Debug("got a status by searching by URI") -		} +	if !foundOne { +		if uri, err := url.Parse(query); err == nil { +			// 1. check if it's a status +			if foundStatus, err := p.searchStatusByURI(ctx, authed, uri, searchQuery.Resolve); err == nil && foundStatus != nil { +				foundStatuses = append(foundStatuses, foundStatus) +				l.Debug("got a status by searching by URI") +			} -		// 2. check if it's an account -		if foundAccount, err := p.searchAccountByURI(ctx, authed, uri, searchQuery.Resolve); err == nil && foundAccount != nil { -			foundAccounts = append(foundAccounts, foundAccount) -			foundOne = true -			l.Debug("got an account by searching by URI") +			// 2. check if it's an account +			if foundAccount, err := p.searchAccountByURI(ctx, authed, uri, searchQuery.Resolve); err == nil && foundAccount != nil { +				foundAccounts = append(foundAccounts, foundAccount) +				l.Debug("got an account by searching by URI") +			}  		}  	} -	if !foundOne { -		// we haven't found anything yet so search for text now -		l.Debug("nothing found by mention or by URI, will fall back to searching by text now") -	} -  	/*  		FROM HERE ON we have our search results, it's just a matter of filtering them according to what this user is allowed to see,  		and then converting them into our frontend format. diff --git a/internal/regexes/regexes.go b/internal/regexes/regexes.go index 93d672d3c..3dabb92af 100644 --- a/internal/regexes/regexes.go +++ b/internal/regexes/regexes.go @@ -47,7 +47,7 @@ const (  )  var ( -	mentionName = `^@(\w+)(?:@([a-zA-Z0-9_\-\.:]+)?)$` +	mentionName = `^@(\w+)(?:@([a-zA-Z0-9_\-\.:]+))?$`  	// MentionName captures the username and domain part from a mention string  	// such as @whatever_user@example.org, returning whatever_user and example.org (without the @ symbols)  	MentionName = regexp.MustCompile(mentionName) 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))  }  | 
