[MM-55143] Disallow reacting with an emoji that does not exist, limit the total number of unique reactions per post (#25331)

* [MM-55143] Disallow reacting with an emoji that does not exist

* WIP for server limit on emoji reactions

* WIP

* Implement default limit of 25 unique emoji reactions

* Add modal for reaction limit

* Fix test

* PR feedback

* Fix i18n

* Update admin string

* Merge'd

* Fixing some issues, check limits correctly based on other users reactions

* Fix typos

* Fix lint/test

* Add tests, fix other tests

---------

Co-authored-by: Mattermost Build <build@mattermost.com>
Этот коммит содержится в:
Devin Binnie
2023-11-27 09:11:04 -05:00
коммит произвёл GitHub
родитель 0a38042d58
Коммит eaa5cce3ce
24 изменённых файлов: 652 добавлений и 29 удалений

Просмотреть файл

@@ -4,6 +4,7 @@
package sqlstore
import (
"database/sql"
"time"
sq "github.com/mattermost/squirrel"
@@ -107,6 +108,25 @@ func (s *SqlReactionStore) GetForPost(postId string, allowFromCache bool) ([]*mo
return reactions, nil
}
func (s *SqlReactionStore) ExistsOnPost(postId string, emojiName string) (bool, error) {
query := s.getQueryBuilder().
Select("1").
From("Reactions").
Where(sq.Eq{"PostId": postId}).
Where(sq.Eq{"EmojiName": emojiName}).
Where(sq.Eq{"COALESCE(DeleteAt, 0)": 0})
var hasRows bool
if err := s.GetReplicaX().GetBuilder(&hasRows, query); err != nil {
if err == sql.ErrNoRows {
return false, nil
}
return false, errors.Wrap(err, "failed to check for existing reaction")
}
return hasRows, nil
}
// GetForPostSince returns all reactions associated with `postId` updated after `since`.
func (s *SqlReactionStore) GetForPostSince(postId string, since int64, excludeRemoteId string, inclDeleted bool) ([]*model.Reaction, error) {
query := s.getQueryBuilder().
@@ -138,6 +158,21 @@ func (s *SqlReactionStore) GetForPostSince(postId string, since int64, excludeRe
return reactions, nil
}
func (s *SqlReactionStore) GetUniqueCountForPost(postId string) (int, error) {
query := s.getQueryBuilder().
Select("COUNT(DISTINCT EmojiName)").
From("Reactions").
Where(sq.Eq{"PostId": postId}).
Where(sq.Eq{"DeleteAt": 0})
var count int64
err := s.GetReplicaX().GetBuilder(&count, query)
if err != nil {
return 0, errors.Wrap(err, "failed to count Reactions")
}
return int(count), nil
}
func (s *SqlReactionStore) BulkGetForPosts(postIds []string) ([]*model.Reaction, error) {
placeholder, values := constructArrayArgs(postIds)
var reactions []*model.Reaction