MM-31339: Send only one direct message reply within one calendar day. (#17181)
* don't send auto response if already responded today * update query to get posts from channel for given user and Updatetime requires value in milli seconds * regenerate mocks and layers * update function to return true/false on existence of auto responded post in channel and add tests * add store tests * bubble up error and propagate upstream * fix error handling logic * use require instead of assert Co-authored-by: Ibrahim Serdar Acikgoz <serdaracikgoz86@gmail.com> * rename variable for better redability and logging fixes * update comment explaining function * use new function to generate test ids * add comments to clarify NewTestId copies * add translations for error id * fix translation Co-authored-by: Ibrahim Serdar Acikgoz <serdaracikgoz86@gmail.com> Co-authored-by: Mattermod <mattermod@users.noreply.github.com> Co-authored-by: Saturnino Abril <saturnino.abril@gmail.com>
Этот коммит содержится в:
@@ -11,6 +11,7 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
sq "github.com/Masterminds/squirrel"
|
||||
"github.com/mattermost/gorp"
|
||||
@@ -958,6 +959,36 @@ func (s *SqlPostStore) GetPostsSince(options model.GetPostsSinceOptions, allowFr
|
||||
return list, nil
|
||||
}
|
||||
|
||||
func (s *SqlPostStore) HasAutoResponsePostByUserSince(options model.GetPostsSinceOptions, userId string) (bool, error) {
|
||||
query := `
|
||||
SELECT 1
|
||||
FROM
|
||||
Posts
|
||||
WHERE
|
||||
UpdateAt >= :Time
|
||||
AND
|
||||
ChannelId = :ChannelId
|
||||
AND
|
||||
UserId = :UserId
|
||||
AND
|
||||
Type = :Type
|
||||
LIMIT 1`
|
||||
|
||||
exist, err := s.GetReplica().SelectInt(query, map[string]interface{}{
|
||||
"ChannelId": options.ChannelId,
|
||||
"Time": options.Time,
|
||||
"UserId": userId,
|
||||
"Type": model.POST_AUTO_RESPONDER,
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return false, errors.Wrapf(err,
|
||||
"failed to check if autoresponse posts in channelId=%s for userId=%s since %s", options.ChannelId, userId, time.Unix(options.Time, 0).Format(time.RFC3339))
|
||||
}
|
||||
|
||||
return exist > 0, nil
|
||||
}
|
||||
|
||||
func (s *SqlPostStore) GetPostsSinceForSync(options model.GetPostsSinceForSyncOptions, _ /* allowFromCache */ bool) ([]*model.Post, error) {
|
||||
if options.Limit < 0 || options.Limit > 1000 {
|
||||
return nil, store.NewErrInvalidInput("Post", "<options.Limit>", options.Limit)
|
||||
|
||||
Ссылка в новой задаче
Block a user