diff options
Diffstat (limited to 'internal/gtsmodel/status.go')
-rw-r--r-- | internal/gtsmodel/status.go | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/internal/gtsmodel/status.go b/internal/gtsmodel/status.go index 9ebbc18c7..91c0ada61 100644 --- a/internal/gtsmodel/status.go +++ b/internal/gtsmodel/status.go @@ -184,6 +184,35 @@ func (s *Status) GetMentionByTargetURI(uri string) (*Mention, bool) { return nil, false } +// GetMentionByUsernameDomain fetches the Mention associated with given +// username and domains, typically extracted from a mention Namestring. +func (s *Status) GetMentionByUsernameDomain(username, domain string) (*Mention, bool) { + for _, mention := range s.Mentions { + + // We can only check if target + // account is set on the mention. + account := mention.TargetAccount + if account == nil { + continue + } + + // Usernames must always match. + if account.Username != username { + continue + } + + // Finally, either domains must + // match or an empty domain may + // be permitted if account local. + if account.Domain == domain || + (domain == "" && account.IsLocal()) { + return mention, true + } + } + + return nil, false +} + // GetTagByName searches status for Tag{} with name. func (s *Status) GetTagByName(name string) (*Tag, bool) { for _, tag := range s.Tags { |