tags, emoji
This commit is contained in:
@ -188,10 +188,29 @@ type DB interface {
|
||||
// In other words, this is the public record that the server has of an account.
|
||||
AccountToMastoPublic(account *model.Account) (*mastotypes.Account, error)
|
||||
|
||||
// AccountStringsToMentions takes a slice of deduplicated account names in the form "@test@whatever.example.org", which have been
|
||||
// MentionStringsToMentions takes a slice of deduplicated, lowercase account names in the form "@test@whatever.example.org", which have been
|
||||
// mentioned in a status. It takes the id of the account that wrote the status, and the id of the status itself, and then
|
||||
// checks in the database for the mentioned accounts, and returns a slice of mentions generated based on the given parameters.
|
||||
AccountStringsToMentions(targetAccounts []string, originAccountID string, statusID string) ([]*model.Mention, error)
|
||||
//
|
||||
// Note: this func doesn't/shouldn't do any manipulation of the accounts in the DB, it's just for checking if they exist
|
||||
// and conveniently returning them.
|
||||
MentionStringsToMentions(targetAccounts []string, originAccountID string, statusID string) ([]*model.Mention, error)
|
||||
|
||||
// TagStringsToTags takes a slice of deduplicated, lowercase tags in the form "somehashtag", which have been
|
||||
// used in a status. It takes the id of the account that wrote the status, and the id of the status itself, and then
|
||||
// returns a slice of *model.Tag corresponding to the given tags.
|
||||
//
|
||||
// Note: this func doesn't/shouldn't do any manipulation of the tags in the DB, it's just for checking if they exist
|
||||
// and conveniently returning them.
|
||||
TagStringsToTags(tags []string, originAccountID string, statusID string) ([]*model.Tag, error)
|
||||
|
||||
// EmojiStringsToEmojis takes a slice of deduplicated, lowercase emojis in the form ":emojiname:", which have been
|
||||
// used in a status. It takes the id of the account that wrote the status, and the id of the status itself, and then
|
||||
// returns a slice of *model.Emoji corresponding to the given emojis.
|
||||
//
|
||||
// Note: this func doesn't/shouldn't do any manipulation of the emoji in the DB, it's just for checking if they exist
|
||||
// and conveniently returning them.
|
||||
EmojiStringsToEmojis(emojis []string, originAccountID string, statusID string) ([]*model.Emoji, error)
|
||||
}
|
||||
|
||||
// New returns a new database service that satisfies the DB interface and, by extension,
|
||||
|
||||
@ -665,7 +665,7 @@ func (ps *postgresService) AccountToMastoPublic(a *model.Account) (*mastotypes.A
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (ps *postgresService) AccountStringsToMentions(targetAccounts []string, originAccountID string, statusID string) ([]*model.Mention, error) {
|
||||
func (ps *postgresService) MentionStringsToMentions(targetAccounts []string, originAccountID string, statusID string) ([]*model.Mention, error) {
|
||||
menchies := []*model.Mention{}
|
||||
for _, a := range targetAccounts {
|
||||
// A mentioned account looks like "@test@example.org" -- we can guarantee this from the regex that targetAccounts should have been derived from.
|
||||
@ -710,7 +710,7 @@ func (ps *postgresService) AccountStringsToMentions(targetAccounts []string, ori
|
||||
return nil, fmt.Errorf("error getting account with username %s and domain %s: %s", username, domain, err)
|
||||
}
|
||||
|
||||
// id, createdat and updatedat will be populated by the db, so we have everything we need!
|
||||
// id, createdAt and updatedAt will be populated by the db, so we have everything we need!
|
||||
menchies = append(menchies, &model.Mention{
|
||||
StatusID: statusID,
|
||||
OriginAccountID: originAccountID,
|
||||
@ -719,3 +719,35 @@ func (ps *postgresService) AccountStringsToMentions(targetAccounts []string, ori
|
||||
}
|
||||
return menchies, nil
|
||||
}
|
||||
|
||||
// for now this function doesn't really use the database, but it's here because:
|
||||
// A) it might later and
|
||||
// B) it's v. similar to MentionStringsToMentions
|
||||
func (ps *postgresService) TagStringsToTags(tags []string, originAccountID string, statusID string) ([]*model.Tag, error) {
|
||||
newTags := []*model.Tag{}
|
||||
for _, t := range tags {
|
||||
newTags = append(newTags, &model.Tag{
|
||||
Name: t,
|
||||
})
|
||||
}
|
||||
return newTags, nil
|
||||
}
|
||||
|
||||
func (ps *postgresService) EmojiStringsToEmojis(emojis []string, originAccountID string, statusID string) ([]*model.Emoji, error) {
|
||||
newEmojis := []*model.Emoji{}
|
||||
for _, e := range emojis {
|
||||
emoji := &model.Emoji{}
|
||||
err := ps.conn.Model(emoji).Where("shortcode = ?", e).Where("visible_in_picker = true").Where("disabled = false").Select()
|
||||
if err != nil {
|
||||
if err == pg.ErrNoRows {
|
||||
// no result found for this username/domain so just don't include it as a mencho and carry on about our business
|
||||
ps.log.Debugf("no emoji found with shortcode %s, skipping it", e)
|
||||
continue
|
||||
}
|
||||
// a serious error has happened so bail
|
||||
return nil, fmt.Errorf("error getting emoji with shortcode %s: %s",e, err)
|
||||
}
|
||||
newEmojis = append(newEmojis, emoji)
|
||||
}
|
||||
return newEmojis, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user