mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-10-29 15:02:25 -05:00
[chore] status dereferencing improvements (#3255)
* search for mentions also by username,domain in status deref, handle deleted statuses in enrichStatusSafely() * return d.enrichStatusSafely() directly
This commit is contained in:
parent
540edef0c2
commit
3254ef1923
4 changed files with 113 additions and 63 deletions
|
|
@ -49,15 +49,16 @@ type Mention struct {
|
|||
//
|
||||
// This will not be put in the database, it's just for convenience.
|
||||
NameString string `bun:"-"`
|
||||
|
||||
// TargetAccountURI is the AP ID (uri) of the user mentioned.
|
||||
//
|
||||
// This will not be put in the database, it's just for convenience.
|
||||
TargetAccountURI string `bun:"-"`
|
||||
|
||||
// TargetAccountURL is the web url of the user mentioned.
|
||||
//
|
||||
// This will not be put in the database, it's just for convenience.
|
||||
TargetAccountURL string `bun:"-"`
|
||||
// A pointer to the gtsmodel account of the mentioned account.
|
||||
}
|
||||
|
||||
// ParseMentionFunc describes a function that takes a lowercase account namestring
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue