MM-22706: pass along set_online flag in websocket response (#14591)
* MM-22706: pass along set_online flag in websocket response To let the client know whether a user has created a post without being online or not, we get the set_online query param and pass it down to the websocket event being passed down to the client. With this PR, the "data" field of the `posted` event will contain a `set_online` boolean field set to true/false depending on the query_param set_online value set in the createPost call. * Setting to false for auto responder Co-authored-by: mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
b9309b2af1
Коммит
14f7118dde
17
api4/post.go
17
api4/post.go
@@ -67,14 +67,6 @@ func createPost(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
post.CreateAt = 0
|
||||
}
|
||||
|
||||
rp, err := c.App.CreatePostAsUser(c.App.PostWithProxyRemovedFromImageURLs(post), c.App.Session().Id)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
auditRec.Success()
|
||||
auditRec.AddMeta("post", rp) // overwrite meta
|
||||
|
||||
setOnline := r.URL.Query().Get("set_online")
|
||||
setOnlineBool := true // By default, always set online.
|
||||
var err2 error
|
||||
@@ -85,6 +77,15 @@ func createPost(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
setOnlineBool = true // Set online nevertheless.
|
||||
}
|
||||
}
|
||||
|
||||
rp, err := c.App.CreatePostAsUser(c.App.PostWithProxyRemovedFromImageURLs(post), c.App.Session().Id, setOnlineBool)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
auditRec.Success()
|
||||
auditRec.AddMeta("post", rp) // overwrite meta
|
||||
|
||||
if setOnlineBool {
|
||||
c.App.SetStatusOnline(c.App.Session().UserId, false)
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ import (
|
||||
"reflect"
|
||||
"sort"
|
||||
"strings"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -593,6 +594,38 @@ func TestCreatePostCheckOnlineStatus(t *testing.T) {
|
||||
api := Init(th.Server, th.Server.AppOptions, th.Server.Router)
|
||||
session, _ := th.App.GetSession(th.Client.AuthToken)
|
||||
|
||||
cli := th.CreateClient()
|
||||
_, loginResp := cli.Login(th.BasicUser2.Username, th.BasicUser2.Password)
|
||||
require.Nil(t, loginResp.Error)
|
||||
|
||||
var wg sync.WaitGroup
|
||||
wsClient, err := th.CreateWebSocketClientWithClient(cli)
|
||||
require.Nil(t, err)
|
||||
defer func() {
|
||||
wsClient.Close()
|
||||
wg.Wait()
|
||||
|
||||
}()
|
||||
|
||||
wsClient.Listen()
|
||||
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
i := 0
|
||||
for ev := range wsClient.EventChannel {
|
||||
if ev.EventType() == model.WEBSOCKET_EVENT_POSTED {
|
||||
if i == 0 {
|
||||
assert.False(t, ev.GetData()["set_online"].(bool))
|
||||
} else {
|
||||
assert.True(t, ev.GetData()["set_online"].(bool))
|
||||
}
|
||||
i++
|
||||
}
|
||||
}
|
||||
assert.Equal(t, 2, i, "unexpected number of posted events")
|
||||
}()
|
||||
|
||||
handler := api.ApiHandler(createPost)
|
||||
resp := httptest.NewRecorder()
|
||||
post := &model.Post{
|
||||
@@ -606,7 +639,7 @@ func TestCreatePostCheckOnlineStatus(t *testing.T) {
|
||||
handler.ServeHTTP(resp, req)
|
||||
assert.Equal(t, http.StatusCreated, resp.Code)
|
||||
|
||||
_, err := th.App.GetStatus(th.BasicUser.Id)
|
||||
_, err = th.App.GetStatus(th.BasicUser.Id)
|
||||
require.NotNil(t, err)
|
||||
assert.Equal(t, "store.sql_status.get.missing.app_error", err.Id)
|
||||
|
||||
@@ -643,7 +676,7 @@ func TestUpdatePost(t *testing.T) {
|
||||
ChannelId: channel.Id,
|
||||
Message: "zz" + model.NewId() + "a",
|
||||
FileIds: fileIds,
|
||||
}, channel, false)
|
||||
}, channel, false, true)
|
||||
require.Nil(t, err)
|
||||
|
||||
assert.Equal(t, rpost.Message, rpost.Message, "full name didn't match")
|
||||
@@ -699,7 +732,7 @@ func TestUpdatePost(t *testing.T) {
|
||||
Message: "zz" + model.NewId() + "a",
|
||||
Type: model.POST_JOIN_LEAVE,
|
||||
UserId: th.BasicUser.Id,
|
||||
}, channel, false)
|
||||
}, channel, false, true)
|
||||
require.Nil(t, err)
|
||||
|
||||
up2 := &model.Post{
|
||||
@@ -715,7 +748,7 @@ func TestUpdatePost(t *testing.T) {
|
||||
ChannelId: channel.Id,
|
||||
Message: "zz" + model.NewId() + "a",
|
||||
UserId: th.BasicUser.Id,
|
||||
}, channel, false)
|
||||
}, channel, false, true)
|
||||
require.Nil(t, err)
|
||||
|
||||
t.Run("new message, add files", func(t *testing.T) {
|
||||
|
||||
@@ -414,8 +414,8 @@ type AppIface interface {
|
||||
CreateOAuthUser(service string, userData io.Reader, teamId string) (*model.User, *model.AppError)
|
||||
CreateOutgoingWebhook(hook *model.OutgoingWebhook) (*model.OutgoingWebhook, *model.AppError)
|
||||
CreatePasswordRecoveryToken(userId, email string) (*model.Token, *model.AppError)
|
||||
CreatePost(post *model.Post, channel *model.Channel, triggerWebhooks bool) (savedPost *model.Post, err *model.AppError)
|
||||
CreatePostAsUser(post *model.Post, currentSessionId string) (*model.Post, *model.AppError)
|
||||
CreatePost(post *model.Post, channel *model.Channel, triggerWebhooks, setOnline bool) (savedPost *model.Post, err *model.AppError)
|
||||
CreatePostAsUser(post *model.Post, currentSessionId string, setOnline bool) (*model.Post, *model.AppError)
|
||||
CreatePostMissingChannel(post *model.Post, triggerWebhooks bool) (*model.Post, *model.AppError)
|
||||
CreateRole(role *model.Role) (*model.Role, *model.AppError)
|
||||
CreateScheme(scheme *model.Scheme) (*model.Scheme, *model.AppError)
|
||||
@@ -859,7 +859,7 @@ type AppIface interface {
|
||||
SendEmailVerification(user *model.User, newEmail string) *model.AppError
|
||||
SendEphemeralPost(userId string, post *model.Post) *model.Post
|
||||
SendInviteEmails(team *model.Team, senderName string, senderUserId string, invites []string, siteURL string)
|
||||
SendNotifications(post *model.Post, team *model.Team, channel *model.Channel, sender *model.User, parentPostList *model.PostList) ([]string, error)
|
||||
SendNotifications(post *model.Post, team *model.Team, channel *model.Channel, sender *model.User, parentPostList *model.PostList, setOnline bool) ([]string, error)
|
||||
SendPasswordReset(email string, siteURL string) (bool, *model.AppError)
|
||||
SendPasswordResetEmail(email string, token *model.Token, locale, siteURL string) (bool, *model.AppError)
|
||||
SendRemoveExpiredLicenseEmail(email string, locale, siteURL string, licenseId string) *model.AppError
|
||||
|
||||
@@ -52,7 +52,7 @@ func (a *App) SendAutoResponse(channel *model.Channel, receiver *model.User) (bo
|
||||
UserId: receiver.Id,
|
||||
}
|
||||
|
||||
if _, err := a.CreatePost(autoResponderPost, channel, false); err != nil {
|
||||
if _, err := a.CreatePost(autoResponderPost, channel, false, false); err != nil {
|
||||
mlog.Error(err.Error())
|
||||
return false, err
|
||||
}
|
||||
|
||||
@@ -190,7 +190,7 @@ func TestSendAutoResponseSuccess(t *testing.T) {
|
||||
Message: "zz" + model.NewId() + "a",
|
||||
UserId: th.BasicUser.Id},
|
||||
th.BasicChannel,
|
||||
false)
|
||||
false, true)
|
||||
|
||||
sent, err := th.App.SendAutoResponse(th.BasicChannel, userUpdated1)
|
||||
|
||||
@@ -230,7 +230,7 @@ func TestSendAutoResponseFailure(t *testing.T) {
|
||||
Message: "zz" + model.NewId() + "a",
|
||||
UserId: th.BasicUser.Id},
|
||||
th.BasicChannel,
|
||||
false)
|
||||
false, true)
|
||||
|
||||
sent, err := th.App.SendAutoResponse(th.BasicChannel, userUpdated1)
|
||||
|
||||
|
||||
@@ -57,7 +57,7 @@ func (a *App) CreateBot(bot *model.Bot) (*model.Bot, *model.AppError) {
|
||||
Message: T("api.bot.teams_channels.add_message_mobile"),
|
||||
}
|
||||
|
||||
if _, err := a.CreatePostAsUser(botAddPost, a.Session().Id); err != nil {
|
||||
if _, err := a.CreatePostAsUser(botAddPost, a.Session().Id, true); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
@@ -342,7 +342,7 @@ func (a *App) notifySysadminsBotOwnerDeactivated(userId string) *model.AppError
|
||||
Type: model.POST_SYSTEM_GENERIC,
|
||||
}
|
||||
|
||||
_, appErr = a.CreatePost(post, channel, false)
|
||||
_, appErr = a.CreatePost(post, channel, false, true)
|
||||
if appErr != nil {
|
||||
return appErr
|
||||
}
|
||||
|
||||
@@ -621,7 +621,7 @@ func (a *App) postChannelPrivacyMessage(user *model.User, channel *model.Channel
|
||||
},
|
||||
}
|
||||
|
||||
if _, err := a.CreatePost(post, channel, false); err != nil {
|
||||
if _, err := a.CreatePost(post, channel, false, true); err != nil {
|
||||
return model.NewAppError("postChannelPrivacyMessage", "api.channel.post_channel_privacy_message.error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
@@ -661,7 +661,7 @@ func (a *App) RestoreChannel(channel *model.Channel, userId string) (*model.Chan
|
||||
},
|
||||
}
|
||||
|
||||
if _, err := a.CreatePost(post, channel, false); err != nil {
|
||||
if _, err := a.CreatePost(post, channel, false, true); err != nil {
|
||||
mlog.Error("Failed to post unarchive message", mlog.Err(err))
|
||||
}
|
||||
}
|
||||
@@ -1158,7 +1158,7 @@ func (a *App) DeleteChannel(channel *model.Channel, userId string) *model.AppErr
|
||||
},
|
||||
}
|
||||
|
||||
if _, err := a.CreatePost(post, channel, false); err != nil {
|
||||
if _, err := a.CreatePost(post, channel, false, true); err != nil {
|
||||
mlog.Error("Failed to post archive message", mlog.Err(err))
|
||||
}
|
||||
}
|
||||
@@ -1386,7 +1386,7 @@ func (a *App) PostUpdateChannelHeaderMessage(userId string, channel *model.Chann
|
||||
},
|
||||
}
|
||||
|
||||
if _, err := a.CreatePost(post, channel, false); err != nil {
|
||||
if _, err := a.CreatePost(post, channel, false, true); err != nil {
|
||||
return model.NewAppError("", "api.channel.post_update_channel_header_message_and_forget.post.error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
@@ -1419,7 +1419,7 @@ func (a *App) PostUpdateChannelPurposeMessage(userId string, channel *model.Chan
|
||||
"new_purpose": newChannelPurpose,
|
||||
},
|
||||
}
|
||||
if _, err := a.CreatePost(post, channel, false); err != nil {
|
||||
if _, err := a.CreatePost(post, channel, false, true); err != nil {
|
||||
return model.NewAppError("", "app.channel.post_update_channel_purpose_message.post.error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
@@ -1446,7 +1446,7 @@ func (a *App) PostUpdateChannelDisplayNameMessage(userId string, channel *model.
|
||||
},
|
||||
}
|
||||
|
||||
if _, err := a.CreatePost(post, channel, false); err != nil {
|
||||
if _, err := a.CreatePost(post, channel, false, true); err != nil {
|
||||
return model.NewAppError("PostUpdateChannelDisplayNameMessage", "api.channel.post_update_channel_displayname_message_and_forget.create_post.error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
@@ -1726,7 +1726,7 @@ func (a *App) postJoinChannelMessage(user *model.User, channel *model.Channel) *
|
||||
},
|
||||
}
|
||||
|
||||
if _, err := a.CreatePost(post, channel, false); err != nil {
|
||||
if _, err := a.CreatePost(post, channel, false, true); err != nil {
|
||||
return model.NewAppError("postJoinChannelMessage", "api.channel.post_user_add_remove_message_and_forget.error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
@@ -1744,7 +1744,7 @@ func (a *App) postJoinTeamMessage(user *model.User, channel *model.Channel) *mod
|
||||
},
|
||||
}
|
||||
|
||||
if _, err := a.CreatePost(post, channel, false); err != nil {
|
||||
if _, err := a.CreatePost(post, channel, false, true); err != nil {
|
||||
return model.NewAppError("postJoinTeamMessage", "api.channel.post_user_add_remove_message_and_forget.error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
@@ -1829,7 +1829,7 @@ func (a *App) postLeaveChannelMessage(user *model.User, channel *model.Channel)
|
||||
},
|
||||
}
|
||||
|
||||
if _, err := a.CreatePost(post, channel, false); err != nil {
|
||||
if _, err := a.CreatePost(post, channel, false, true); err != nil {
|
||||
return model.NewAppError("postLeaveChannelMessage", "api.channel.post_user_add_remove_message_and_forget.error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
@@ -1859,7 +1859,7 @@ func (a *App) PostAddToChannelMessage(user *model.User, addedUser *model.User, c
|
||||
},
|
||||
}
|
||||
|
||||
if _, err := a.CreatePost(post, channel, false); err != nil {
|
||||
if _, err := a.CreatePost(post, channel, false, true); err != nil {
|
||||
return model.NewAppError("postAddToChannelMessage", "api.channel.post_user_add_remove_message_and_forget.error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
@@ -1881,7 +1881,7 @@ func (a *App) postAddToTeamMessage(user *model.User, addedUser *model.User, chan
|
||||
},
|
||||
}
|
||||
|
||||
if _, err := a.CreatePost(post, channel, false); err != nil {
|
||||
if _, err := a.CreatePost(post, channel, false, true); err != nil {
|
||||
return model.NewAppError("postAddToTeamMessage", "api.channel.post_user_add_remove_message_and_forget.error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
@@ -1903,7 +1903,7 @@ func (a *App) postRemoveFromChannelMessage(removerUserId string, removedUser *mo
|
||||
},
|
||||
}
|
||||
|
||||
if _, err := a.CreatePost(post, channel, false); err != nil {
|
||||
if _, err := a.CreatePost(post, channel, false, true); err != nil {
|
||||
return model.NewAppError("postRemoveFromChannelMessage", "api.channel.post_user_add_remove_message_and_forget.error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
@@ -2337,7 +2337,7 @@ func (a *App) postChannelMoveMessage(user *model.User, channel *model.Channel, p
|
||||
},
|
||||
}
|
||||
|
||||
if _, err := a.CreatePost(post, channel, false); err != nil {
|
||||
if _, err := a.CreatePost(post, channel, false, true); err != nil {
|
||||
return model.NewAppError("postChannelMoveMessage", "api.team.move_channel.post.error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
|
||||
@@ -1142,7 +1142,7 @@ func TestMarkChannelAsUnreadFromPost(t *testing.T) {
|
||||
UserId: u2.Id,
|
||||
ChannelId: c2.Id,
|
||||
Message: "@" + u1.Username,
|
||||
}, c2, false)
|
||||
}, c2, false, true)
|
||||
require.Nil(t, err)
|
||||
th.CreatePost(c2)
|
||||
|
||||
|
||||
@@ -388,14 +388,14 @@ func TestExportDMandGMPost(t *testing.T) {
|
||||
Message: "aa" + model.NewId() + "a",
|
||||
UserId: th1.BasicUser.Id,
|
||||
}
|
||||
th1.App.CreatePost(p1, dmChannel, false)
|
||||
th1.App.CreatePost(p1, dmChannel, false, true)
|
||||
|
||||
p2 := &model.Post{
|
||||
ChannelId: dmChannel.Id,
|
||||
Message: "bb" + model.NewId() + "a",
|
||||
UserId: th1.BasicUser.Id,
|
||||
}
|
||||
th1.App.CreatePost(p2, dmChannel, false)
|
||||
th1.App.CreatePost(p2, dmChannel, false, true)
|
||||
|
||||
// GM posts
|
||||
p3 := &model.Post{
|
||||
@@ -403,14 +403,14 @@ func TestExportDMandGMPost(t *testing.T) {
|
||||
Message: "cc" + model.NewId() + "a",
|
||||
UserId: th1.BasicUser.Id,
|
||||
}
|
||||
th1.App.CreatePost(p3, gmChannel, false)
|
||||
th1.App.CreatePost(p3, gmChannel, false, true)
|
||||
|
||||
p4 := &model.Post{
|
||||
ChannelId: gmChannel.Id,
|
||||
Message: "dd" + model.NewId() + "a",
|
||||
UserId: th1.BasicUser.Id,
|
||||
}
|
||||
th1.App.CreatePost(p4, gmChannel, false)
|
||||
th1.App.CreatePost(p4, gmChannel, false, true)
|
||||
|
||||
posts, err := th1.App.Srv().Store.Post().GetDirectPostParentsForExportAfter(1000, "0000000")
|
||||
require.Nil(t, err)
|
||||
@@ -473,7 +473,7 @@ func TestExportPostWithProps(t *testing.T) {
|
||||
},
|
||||
UserId: th1.BasicUser.Id,
|
||||
}
|
||||
th1.App.CreatePost(p1, dmChannel, false)
|
||||
th1.App.CreatePost(p1, dmChannel, false, true)
|
||||
|
||||
p2 := &model.Post{
|
||||
ChannelId: gmChannel.Id,
|
||||
@@ -483,7 +483,7 @@ func TestExportPostWithProps(t *testing.T) {
|
||||
},
|
||||
UserId: th1.BasicUser.Id,
|
||||
}
|
||||
th1.App.CreatePost(p2, gmChannel, false)
|
||||
th1.App.CreatePost(p2, gmChannel, false, true)
|
||||
|
||||
posts, err := th1.App.Srv().Store.Post().GetDirectPostParentsForExportAfter(1000, "0000000")
|
||||
require.Nil(t, err)
|
||||
|
||||
@@ -249,13 +249,13 @@ func TestMigrateFilenamesToFileInfos(t *testing.T) {
|
||||
fpath := fmt.Sprintf("/teams/%v/channels/%v/users/%v/%v/test.png", th.BasicTeam.Id, th.BasicChannel.Id, th.BasicUser.Id, fileId)
|
||||
_, err := th.App.WriteFile(file, fpath)
|
||||
require.Nil(t, err)
|
||||
rpost, err := th.App.CreatePost(&model.Post{UserId: th.BasicUser.Id, ChannelId: th.BasicChannel.Id, Filenames: []string{fmt.Sprintf("/%v/%v/%v/test.png", th.BasicChannel.Id, th.BasicUser.Id, fileId)}}, th.BasicChannel, false)
|
||||
rpost, err := th.App.CreatePost(&model.Post{UserId: th.BasicUser.Id, ChannelId: th.BasicChannel.Id, Filenames: []string{fmt.Sprintf("/%v/%v/%v/test.png", th.BasicChannel.Id, th.BasicUser.Id, fileId)}}, th.BasicChannel, false, true)
|
||||
require.Nil(t, err)
|
||||
|
||||
infos = th.App.MigrateFilenamesToFileInfos(rpost)
|
||||
assert.Equal(t, 1, len(infos))
|
||||
|
||||
rpost, err = th.App.CreatePost(&model.Post{UserId: th.BasicUser.Id, ChannelId: th.BasicChannel.Id, Filenames: []string{fmt.Sprintf("/%v/%v/%v/../../test.png", th.BasicChannel.Id, th.BasicUser.Id, fileId)}}, th.BasicChannel, false)
|
||||
rpost, err = th.App.CreatePost(&model.Post{UserId: th.BasicUser.Id, ChannelId: th.BasicChannel.Id, Filenames: []string{fmt.Sprintf("/%v/%v/%v/../../test.png", th.BasicChannel.Id, th.BasicUser.Id, fileId)}}, th.BasicChannel, false, true)
|
||||
require.Nil(t, err)
|
||||
|
||||
infos = th.App.MigrateFilenamesToFileInfos(rpost)
|
||||
|
||||
@@ -395,7 +395,7 @@ func (me *TestHelper) CreatePost(channel *model.Channel) *model.Post {
|
||||
|
||||
utils.DisableDebugLogForTest()
|
||||
var err *model.AppError
|
||||
if post, err = me.App.CreatePost(post, channel, false); err != nil {
|
||||
if post, err = me.App.CreatePost(post, channel, false, true); err != nil {
|
||||
mlog.Error(err.Error())
|
||||
|
||||
time.Sleep(time.Second)
|
||||
@@ -415,7 +415,7 @@ func (me *TestHelper) CreateMessagePost(channel *model.Channel, message string)
|
||||
|
||||
utils.DisableDebugLogForTest()
|
||||
var err *model.AppError
|
||||
if post, err = me.App.CreatePost(post, channel, false); err != nil {
|
||||
if post, err = me.App.CreatePost(post, channel, false, true); err != nil {
|
||||
mlog.Error(err.Error())
|
||||
|
||||
time.Sleep(time.Second)
|
||||
|
||||
@@ -55,7 +55,7 @@ func TestPostActionInvalidURL(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
post, err := th.App.CreatePostAsUser(&interactivePost, "")
|
||||
post, err := th.App.CreatePostAsUser(&interactivePost, "", true)
|
||||
require.Nil(t, err)
|
||||
attachments, ok := post.GetProp("attachments").([]*model.SlackAttachment)
|
||||
require.True(t, ok)
|
||||
@@ -155,7 +155,7 @@ func TestPostAction(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
post, err := th.App.CreatePostAsUser(&interactivePost, "")
|
||||
post, err := th.App.CreatePostAsUser(&interactivePost, "", true)
|
||||
require.Nil(t, err)
|
||||
|
||||
attachments, ok := post.GetProp("attachments").([]*model.SlackAttachment)
|
||||
@@ -192,7 +192,7 @@ func TestPostAction(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
post2, err := th.App.CreatePostAsUser(&menuPost, "")
|
||||
post2, err := th.App.CreatePostAsUser(&menuPost, "", true)
|
||||
require.Nil(t, err)
|
||||
|
||||
attachments2, ok := post2.GetProp("attachments").([]*model.SlackAttachment)
|
||||
@@ -250,7 +250,7 @@ func TestPostAction(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
postplugin, err := th.App.CreatePostAsUser(&interactivePostPlugin, "")
|
||||
postplugin, err := th.App.CreatePostAsUser(&interactivePostPlugin, "", true)
|
||||
require.Nil(t, err)
|
||||
|
||||
attachmentsPlugin, ok := postplugin.GetProp("attachments").([]*model.SlackAttachment)
|
||||
@@ -291,7 +291,7 @@ func TestPostAction(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
postSiteURL, err := th.App.CreatePostAsUser(&interactivePostSiteURL, "")
|
||||
postSiteURL, err := th.App.CreatePostAsUser(&interactivePostSiteURL, "", true)
|
||||
require.Nil(t, err)
|
||||
|
||||
attachmentsSiteURL, ok := postSiteURL.GetProp("attachments").([]*model.SlackAttachment)
|
||||
@@ -333,7 +333,7 @@ func TestPostAction(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
postSubpath, err := th.App.CreatePostAsUser(&interactivePostSubpath, "")
|
||||
postSubpath, err := th.App.CreatePostAsUser(&interactivePostSubpath, "", true)
|
||||
require.Nil(t, err)
|
||||
|
||||
attachmentsSubpath, ok := postSubpath.GetProp("attachments").([]*model.SlackAttachment)
|
||||
@@ -408,7 +408,7 @@ func TestPostActionProps(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
post, err := th.App.CreatePostAsUser(&interactivePost, "")
|
||||
post, err := th.App.CreatePostAsUser(&interactivePost, "", true)
|
||||
require.Nil(t, err)
|
||||
attachments, ok := post.GetProp("attachments").([]*model.SlackAttachment)
|
||||
require.True(t, ok)
|
||||
@@ -576,7 +576,7 @@ func TestPostActionRelativeURL(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
post, err := th.App.CreatePostAsUser(&interactivePost, "")
|
||||
post, err := th.App.CreatePostAsUser(&interactivePost, "", true)
|
||||
require.Nil(t, err)
|
||||
attachments, ok := post.GetProp("attachments").([]*model.SlackAttachment)
|
||||
require.True(t, ok)
|
||||
@@ -616,7 +616,7 @@ func TestPostActionRelativeURL(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
post, err := th.App.CreatePostAsUser(&interactivePost, "")
|
||||
post, err := th.App.CreatePostAsUser(&interactivePost, "", true)
|
||||
require.Nil(t, err)
|
||||
attachments, ok := post.GetProp("attachments").([]*model.SlackAttachment)
|
||||
require.True(t, ok)
|
||||
@@ -656,7 +656,7 @@ func TestPostActionRelativeURL(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
post, err := th.App.CreatePostAsUser(&interactivePost, "")
|
||||
post, err := th.App.CreatePostAsUser(&interactivePost, "", true)
|
||||
require.Nil(t, err)
|
||||
attachments, ok := post.GetProp("attachments").([]*model.SlackAttachment)
|
||||
require.True(t, ok)
|
||||
@@ -697,7 +697,7 @@ func TestPostActionRelativeURL(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
post, err := th.App.CreatePostAsUser(&interactivePost, "")
|
||||
post, err := th.App.CreatePostAsUser(&interactivePost, "", true)
|
||||
require.Nil(t, err)
|
||||
attachments, ok := post.GetProp("attachments").([]*model.SlackAttachment)
|
||||
require.True(t, ok)
|
||||
@@ -737,7 +737,7 @@ func TestPostActionRelativeURL(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
post, err := th.App.CreatePostAsUser(&interactivePost, "")
|
||||
post, err := th.App.CreatePostAsUser(&interactivePost, "", true)
|
||||
require.Nil(t, err)
|
||||
attachments, ok := post.GetProp("attachments").([]*model.SlackAttachment)
|
||||
require.True(t, ok)
|
||||
@@ -811,7 +811,7 @@ func TestPostActionRelativePluginURL(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
post, err := th.App.CreatePostAsUser(&interactivePost, "")
|
||||
post, err := th.App.CreatePostAsUser(&interactivePost, "", true)
|
||||
require.Nil(t, err)
|
||||
attachments, ok := post.GetProp("attachments").([]*model.SlackAttachment)
|
||||
require.True(t, ok)
|
||||
@@ -851,7 +851,7 @@ func TestPostActionRelativePluginURL(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
post, err := th.App.CreatePostAsUser(&interactivePost, "")
|
||||
post, err := th.App.CreatePostAsUser(&interactivePost, "", true)
|
||||
require.Nil(t, err)
|
||||
attachments, ok := post.GetProp("attachments").([]*model.SlackAttachment)
|
||||
require.True(t, ok)
|
||||
@@ -891,7 +891,7 @@ func TestPostActionRelativePluginURL(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
post, err := th.App.CreatePostAsUser(&interactivePost, "")
|
||||
post, err := th.App.CreatePostAsUser(&interactivePost, "", true)
|
||||
require.Nil(t, err)
|
||||
attachments, ok := post.GetProp("attachments").([]*model.SlackAttachment)
|
||||
require.True(t, ok)
|
||||
@@ -931,7 +931,7 @@ func TestPostActionRelativePluginURL(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
post, err := th.App.CreatePostAsUser(&interactivePost, "")
|
||||
post, err := th.App.CreatePostAsUser(&interactivePost, "", true)
|
||||
require.Nil(t, err)
|
||||
attachments, ok := post.GetProp("attachments").([]*model.SlackAttachment)
|
||||
require.True(t, ok)
|
||||
|
||||
@@ -16,7 +16,7 @@ import (
|
||||
"github.com/mattermost/mattermost-server/v5/utils/markdown"
|
||||
)
|
||||
|
||||
func (a *App) SendNotifications(post *model.Post, team *model.Team, channel *model.Channel, sender *model.User, parentPostList *model.PostList) ([]string, error) {
|
||||
func (a *App) SendNotifications(post *model.Post, team *model.Team, channel *model.Channel, sender *model.User, parentPostList *model.PostList, setOnline bool) ([]string, error) {
|
||||
// Do not send notifications in archived channels
|
||||
if channel.DeleteAt > 0 {
|
||||
return []string{}, nil
|
||||
@@ -343,6 +343,7 @@ func (a *App) SendNotifications(post *model.Post, team *model.Team, channel *mod
|
||||
message.Add("channel_name", channel.Name)
|
||||
message.Add("sender_name", notification.GetSenderName(model.SHOW_USERNAME, *a.Config().ServiceSettings.EnablePostUsernameOverride))
|
||||
message.Add("team_id", team.Id)
|
||||
message.Add("set_online", setOnline)
|
||||
|
||||
if len(post.FileIds) != 0 && fchan != nil {
|
||||
message.Add("otherFile", "true")
|
||||
|
||||
@@ -29,7 +29,7 @@ func TestSendNotifications(t *testing.T) {
|
||||
}, true)
|
||||
require.Nil(t, appErr)
|
||||
|
||||
mentions, err := th.App.SendNotifications(post1, th.BasicTeam, th.BasicChannel, th.BasicUser, nil)
|
||||
mentions, err := th.App.SendNotifications(post1, th.BasicTeam, th.BasicChannel, th.BasicUser, nil, true)
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, mentions)
|
||||
require.True(t, utils.StringInSlice(th.BasicUser2.Id, mentions), "mentions", mentions)
|
||||
@@ -44,7 +44,7 @@ func TestSendNotifications(t *testing.T) {
|
||||
}, true)
|
||||
require.Nil(t, appErr)
|
||||
|
||||
mentions, err = th.App.SendNotifications(post2, th.BasicTeam, dm, th.BasicUser, nil)
|
||||
mentions, err = th.App.SendNotifications(post2, th.BasicTeam, dm, th.BasicUser, nil, true)
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, mentions)
|
||||
|
||||
@@ -60,12 +60,12 @@ func TestSendNotifications(t *testing.T) {
|
||||
}, true)
|
||||
require.Nil(t, appErr)
|
||||
|
||||
mentions, err = th.App.SendNotifications(post3, th.BasicTeam, dm, th.BasicUser, nil)
|
||||
mentions, err = th.App.SendNotifications(post3, th.BasicTeam, dm, th.BasicUser, nil, true)
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, mentions)
|
||||
|
||||
th.BasicChannel.DeleteAt = 1
|
||||
mentions, err = th.App.SendNotifications(post1, th.BasicTeam, th.BasicChannel, th.BasicUser, nil)
|
||||
mentions, err = th.App.SendNotifications(post1, th.BasicTeam, th.BasicChannel, th.BasicUser, nil, true)
|
||||
require.NoError(t, err)
|
||||
require.Empty(t, mentions)
|
||||
}
|
||||
|
||||
@@ -1928,7 +1928,7 @@ func (a *OpenTracingAppLayer) CreatePasswordRecoveryToken(userId string, email s
|
||||
return resultVar0, resultVar1
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) CreatePost(post *model.Post, channel *model.Channel, triggerWebhooks bool) (savedPost *model.Post, err *model.AppError) {
|
||||
func (a *OpenTracingAppLayer) CreatePost(post *model.Post, channel *model.Channel, triggerWebhooks bool, setOnline bool) (savedPost *model.Post, err *model.AppError) {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.CreatePost")
|
||||
|
||||
@@ -1940,7 +1940,7 @@ func (a *OpenTracingAppLayer) CreatePost(post *model.Post, channel *model.Channe
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
resultVar0, resultVar1 := a.app.CreatePost(post, channel, triggerWebhooks)
|
||||
resultVar0, resultVar1 := a.app.CreatePost(post, channel, triggerWebhooks, setOnline)
|
||||
|
||||
if resultVar1 != nil {
|
||||
span.LogFields(spanlog.Error(resultVar1))
|
||||
@@ -1950,7 +1950,7 @@ func (a *OpenTracingAppLayer) CreatePost(post *model.Post, channel *model.Channe
|
||||
return resultVar0, resultVar1
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) CreatePostAsUser(post *model.Post, currentSessionId string) (*model.Post, *model.AppError) {
|
||||
func (a *OpenTracingAppLayer) CreatePostAsUser(post *model.Post, currentSessionId string, setOnline bool) (*model.Post, *model.AppError) {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.CreatePostAsUser")
|
||||
|
||||
@@ -1962,7 +1962,7 @@ func (a *OpenTracingAppLayer) CreatePostAsUser(post *model.Post, currentSessionI
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
resultVar0, resultVar1 := a.app.CreatePostAsUser(post, currentSessionId)
|
||||
resultVar0, resultVar1 := a.app.CreatePostAsUser(post, currentSessionId, setOnline)
|
||||
|
||||
if resultVar1 != nil {
|
||||
span.LogFields(spanlog.Error(resultVar1))
|
||||
@@ -12518,7 +12518,7 @@ func (a *OpenTracingAppLayer) SendInviteEmails(team *model.Team, senderName stri
|
||||
a.app.SendInviteEmails(team, senderName, senderUserId, invites, siteURL)
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) SendNotifications(post *model.Post, team *model.Team, channel *model.Channel, sender *model.User, parentPostList *model.PostList) ([]string, error) {
|
||||
func (a *OpenTracingAppLayer) SendNotifications(post *model.Post, team *model.Team, channel *model.Channel, sender *model.User, parentPostList *model.PostList, setOnline bool) ([]string, error) {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.SendNotifications")
|
||||
|
||||
@@ -12530,7 +12530,7 @@ func (a *OpenTracingAppLayer) SendNotifications(post *model.Post, team *model.Te
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
resultVar0, resultVar1 := a.app.SendNotifications(post, team, channel, sender, parentPostList)
|
||||
resultVar0, resultVar1 := a.app.SendNotifications(post, team, channel, sender, parentPostList, setOnline)
|
||||
|
||||
if resultVar1 != nil {
|
||||
span.LogFields(spanlog.Error(resultVar1))
|
||||
|
||||
@@ -97,7 +97,7 @@ func TestHookMessageWillBePosted(t *testing.T) {
|
||||
Message: "message_",
|
||||
CreateAt: model.GetMillis() - 10000,
|
||||
}
|
||||
_, err := th.App.CreatePost(post, th.BasicChannel, false)
|
||||
_, err := th.App.CreatePost(post, th.BasicChannel, false, true)
|
||||
if assert.NotNil(t, err) {
|
||||
assert.Equal(t, "Post rejected by plugin. rejected", err.Message)
|
||||
}
|
||||
@@ -138,7 +138,7 @@ func TestHookMessageWillBePosted(t *testing.T) {
|
||||
Message: "message_",
|
||||
CreateAt: model.GetMillis() - 10000,
|
||||
}
|
||||
_, err := th.App.CreatePost(post, th.BasicChannel, false)
|
||||
_, err := th.App.CreatePost(post, th.BasicChannel, false, true)
|
||||
if assert.NotNil(t, err) {
|
||||
assert.Equal(t, "Post rejected by plugin. rejected", err.Message)
|
||||
}
|
||||
@@ -178,7 +178,7 @@ func TestHookMessageWillBePosted(t *testing.T) {
|
||||
Message: "message",
|
||||
CreateAt: model.GetMillis() - 10000,
|
||||
}
|
||||
post, err := th.App.CreatePost(post, th.BasicChannel, false)
|
||||
post, err := th.App.CreatePost(post, th.BasicChannel, false, true)
|
||||
require.Nil(t, err)
|
||||
|
||||
assert.Equal(t, "message", post.Message)
|
||||
@@ -222,7 +222,7 @@ func TestHookMessageWillBePosted(t *testing.T) {
|
||||
Message: "message",
|
||||
CreateAt: model.GetMillis() - 10000,
|
||||
}
|
||||
post, err := th.App.CreatePost(post, th.BasicChannel, false)
|
||||
post, err := th.App.CreatePost(post, th.BasicChannel, false, true)
|
||||
require.Nil(t, err)
|
||||
|
||||
assert.Equal(t, "message_fromplugin", post.Message)
|
||||
@@ -288,7 +288,7 @@ func TestHookMessageWillBePosted(t *testing.T) {
|
||||
Message: "message",
|
||||
CreateAt: model.GetMillis() - 10000,
|
||||
}
|
||||
post, err := th.App.CreatePost(post, th.BasicChannel, false)
|
||||
post, err := th.App.CreatePost(post, th.BasicChannel, false, true)
|
||||
require.Nil(t, err)
|
||||
assert.Equal(t, "prefix_message_suffix", post.Message)
|
||||
})
|
||||
@@ -332,7 +332,7 @@ func TestHookMessageHasBeenPosted(t *testing.T) {
|
||||
Message: "message",
|
||||
CreateAt: model.GetMillis() - 10000,
|
||||
}
|
||||
_, err := th.App.CreatePost(post, th.BasicChannel, false)
|
||||
_, err := th.App.CreatePost(post, th.BasicChannel, false, true)
|
||||
require.Nil(t, err)
|
||||
}
|
||||
|
||||
@@ -371,7 +371,7 @@ func TestHookMessageWillBeUpdated(t *testing.T) {
|
||||
Message: "message_",
|
||||
CreateAt: model.GetMillis() - 10000,
|
||||
}
|
||||
post, err := th.App.CreatePost(post, th.BasicChannel, false)
|
||||
post, err := th.App.CreatePost(post, th.BasicChannel, false, true)
|
||||
require.Nil(t, err)
|
||||
assert.Equal(t, "message_", post.Message)
|
||||
post.Message = post.Message + "edited_"
|
||||
@@ -419,7 +419,7 @@ func TestHookMessageHasBeenUpdated(t *testing.T) {
|
||||
Message: "message_",
|
||||
CreateAt: model.GetMillis() - 10000,
|
||||
}
|
||||
post, err := th.App.CreatePost(post, th.BasicChannel, false)
|
||||
post, err := th.App.CreatePost(post, th.BasicChannel, false, true)
|
||||
require.Nil(t, err)
|
||||
assert.Equal(t, "message_", post.Message)
|
||||
post.Message = post.Message + "edited"
|
||||
@@ -958,7 +958,7 @@ func TestHookContext(t *testing.T) {
|
||||
Message: "not this",
|
||||
CreateAt: model.GetMillis() - 10000,
|
||||
}
|
||||
_, err := th.App.CreatePost(post, th.BasicChannel, false)
|
||||
_, err := th.App.CreatePost(post, th.BasicChannel, false, true)
|
||||
require.Nil(t, err)
|
||||
}
|
||||
|
||||
|
||||
@@ -663,7 +663,7 @@ func TestPluginPanicLogs(t *testing.T) {
|
||||
Message: "message_",
|
||||
CreateAt: model.GetMillis() - 10000,
|
||||
}
|
||||
_, err := th.App.CreatePost(post, th.BasicChannel, false)
|
||||
_, err := th.App.CreatePost(post, th.BasicChannel, false, true)
|
||||
assert.Nil(t, err)
|
||||
|
||||
testlib.AssertLog(t, th.LogBuffer, mlog.LevelDebug, "panic: some text from panic")
|
||||
|
||||
14
app/post.go
14
app/post.go
@@ -24,7 +24,7 @@ const (
|
||||
PAGE_DEFAULT = 0
|
||||
)
|
||||
|
||||
func (a *App) CreatePostAsUser(post *model.Post, currentSessionId string) (*model.Post, *model.AppError) {
|
||||
func (a *App) CreatePostAsUser(post *model.Post, currentSessionId string, setOnline bool) (*model.Post, *model.AppError) {
|
||||
// Check that channel has not been deleted
|
||||
channel, errCh := a.Srv().Store.Channel().Get(post.ChannelId, true)
|
||||
if errCh != nil {
|
||||
@@ -42,7 +42,7 @@ func (a *App) CreatePostAsUser(post *model.Post, currentSessionId string) (*mode
|
||||
return nil, err
|
||||
}
|
||||
|
||||
rp, err := a.CreatePost(post, channel, true)
|
||||
rp, err := a.CreatePost(post, channel, true, setOnline)
|
||||
if err != nil {
|
||||
if err.Id == "api.post.create_post.root_id.app_error" ||
|
||||
err.Id == "api.post.create_post.channel_root_id.app_error" ||
|
||||
@@ -96,7 +96,7 @@ func (a *App) CreatePostMissingChannel(post *model.Post, triggerWebhooks bool) (
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return a.CreatePost(post, channel, triggerWebhooks)
|
||||
return a.CreatePost(post, channel, triggerWebhooks, true)
|
||||
}
|
||||
|
||||
// deduplicateCreatePost attempts to make posting idempotent within a caching window.
|
||||
@@ -140,7 +140,7 @@ func (a *App) deduplicateCreatePost(post *model.Post) (foundPost *model.Post, er
|
||||
return actualPost, nil
|
||||
}
|
||||
|
||||
func (a *App) CreatePost(post *model.Post, channel *model.Channel, triggerWebhooks bool) (savedPost *model.Post, err *model.AppError) {
|
||||
func (a *App) CreatePost(post *model.Post, channel *model.Channel, triggerWebhooks, setOnline bool) (savedPost *model.Post, err *model.AppError) {
|
||||
foundPost, err := a.deduplicateCreatePost(post)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -318,7 +318,7 @@ func (a *App) CreatePost(post *model.Post, channel *model.Channel, triggerWebhoo
|
||||
// to be done when we send the post over the websocket in handlePostEvents
|
||||
rpost = a.PreparePostForClient(rpost, true, false)
|
||||
|
||||
if err := a.handlePostEvents(rpost, user, channel, triggerWebhooks, parentPostList); err != nil {
|
||||
if err := a.handlePostEvents(rpost, user, channel, triggerWebhooks, parentPostList, setOnline); err != nil {
|
||||
mlog.Error("Failed to handle post events", mlog.Err(err))
|
||||
}
|
||||
|
||||
@@ -404,7 +404,7 @@ func (a *App) FillInPostProps(post *model.Post, channel *model.Channel) *model.A
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *App) handlePostEvents(post *model.Post, user *model.User, channel *model.Channel, triggerWebhooks bool, parentPostList *model.PostList) error {
|
||||
func (a *App) handlePostEvents(post *model.Post, user *model.User, channel *model.Channel, triggerWebhooks bool, parentPostList *model.PostList, setOnline bool) error {
|
||||
var team *model.Team
|
||||
if len(channel.TeamId) > 0 {
|
||||
t, err := a.Srv().Store.Team().Get(channel.TeamId)
|
||||
@@ -420,7 +420,7 @@ func (a *App) handlePostEvents(post *model.Post, user *model.User, channel *mode
|
||||
a.invalidateCacheForChannel(channel)
|
||||
a.invalidateCacheForChannelPosts(channel.Id)
|
||||
|
||||
if _, err := a.SendNotifications(post, team, channel, user, parentPostList); err != nil {
|
||||
if _, err := a.SendNotifications(post, team, channel, user, parentPostList, setOnline); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
@@ -182,7 +182,7 @@ func TestPreparePostForClient(t *testing.T) {
|
||||
UserId: th.BasicUser.Id,
|
||||
ChannelId: th.BasicChannel.Id,
|
||||
FileIds: []string{fileInfo.Id},
|
||||
}, th.BasicChannel, false)
|
||||
}, th.BasicChannel, false, true)
|
||||
require.Nil(t, err)
|
||||
|
||||
fileInfo.PostId = post.Id
|
||||
@@ -213,7 +213,7 @@ func TestPreparePostForClient(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
}, th.BasicChannel, false)
|
||||
}, th.BasicChannel, false, true)
|
||||
require.Nil(t, err)
|
||||
|
||||
th.AddReactionToPost(post, th.BasicUser, "smile")
|
||||
@@ -257,7 +257,7 @@ func TestPreparePostForClient(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
}, th.BasicChannel, false)
|
||||
}, th.BasicChannel, false, true)
|
||||
require.Nil(t, err)
|
||||
|
||||
th.AddReactionToPost(post, th.BasicUser, emoji1.Name)
|
||||
@@ -291,7 +291,7 @@ func TestPreparePostForClient(t *testing.T) {
|
||||
UserId: th.BasicUser.Id,
|
||||
ChannelId: th.BasicChannel.Id,
|
||||
Message: "Test",
|
||||
}, th.BasicChannel, false)
|
||||
}, th.BasicChannel, false, true)
|
||||
|
||||
require.Nil(t, err)
|
||||
|
||||
@@ -337,7 +337,7 @@ func TestPreparePostForClient(t *testing.T) {
|
||||
UserId: th.BasicUser.Id,
|
||||
ChannelId: th.BasicChannel.Id,
|
||||
Message: fmt.Sprintf("This is  and ", server.URL, server.URL),
|
||||
}, th.BasicChannel, false)
|
||||
}, th.BasicChannel, false, true)
|
||||
require.Nil(t, err)
|
||||
|
||||
clientPost := th.App.PreparePostForClient(post, false, false)
|
||||
@@ -381,7 +381,7 @@ func TestPreparePostForClient(t *testing.T) {
|
||||
ChannelId: th.BasicChannel.Id,
|
||||
Message: `This is our logo: ` + server.URL + `/test-image2.png
|
||||
And this is our icon: ` + server.URL + `/test-image1.png`,
|
||||
}, th.BasicChannel, false)
|
||||
}, th.BasicChannel, false, true)
|
||||
require.Nil(t, err)
|
||||
|
||||
clientPost := th.App.PreparePostForClient(post, false, false)
|
||||
@@ -416,7 +416,7 @@ func TestPreparePostForClient(t *testing.T) {
|
||||
UserId: th.BasicUser.Id,
|
||||
ChannelId: th.BasicChannel.Id,
|
||||
Message: `This is our web page: ` + server.URL,
|
||||
}, th.BasicChannel, false)
|
||||
}, th.BasicChannel, false, true)
|
||||
require.Nil(t, err)
|
||||
|
||||
clientPost := th.App.PreparePostForClient(post, false, false)
|
||||
@@ -459,7 +459,7 @@ func TestPreparePostForClient(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
}, th.BasicChannel, false)
|
||||
}, th.BasicChannel, false, true)
|
||||
require.Nil(t, err)
|
||||
|
||||
clientPost := th.App.PreparePostForClient(post, false, false)
|
||||
@@ -495,7 +495,7 @@ func TestPreparePostForClient(t *testing.T) {
|
||||
FileIds: []string{fileInfo.Id},
|
||||
UserId: th.BasicUser.Id,
|
||||
ChannelId: th.BasicChannel.Id,
|
||||
}, th.BasicChannel, false)
|
||||
}, th.BasicChannel, false, true)
|
||||
require.Nil(t, err)
|
||||
|
||||
th.AddReactionToPost(post, th.BasicUser, "taco")
|
||||
@@ -601,7 +601,7 @@ func testProxyOpenGraphImage(t *testing.T, th *TestHelper, shouldProxy bool) {
|
||||
UserId: th.BasicUser.Id,
|
||||
ChannelId: th.BasicChannel.Id,
|
||||
Message: `This is our web page: ` + server.URL,
|
||||
}, th.BasicChannel, false)
|
||||
}, th.BasicChannel, false, true)
|
||||
require.Nil(t, err)
|
||||
|
||||
embeds := th.App.PreparePostForClient(post, false, false).Metadata.Embeds
|
||||
|
||||
150
app/post_test.go
150
app/post_test.go
@@ -33,7 +33,7 @@ func TestCreatePostDeduplicate(t *testing.T) {
|
||||
ChannelId: th.BasicChannel.Id,
|
||||
Message: "message",
|
||||
PendingPostId: pendingPostId,
|
||||
}, "")
|
||||
}, "", true)
|
||||
require.Nil(t, err)
|
||||
require.Equal(t, "message", post.Message)
|
||||
|
||||
@@ -42,7 +42,7 @@ func TestCreatePostDeduplicate(t *testing.T) {
|
||||
ChannelId: th.BasicChannel.Id,
|
||||
Message: "message",
|
||||
PendingPostId: pendingPostId,
|
||||
}, "")
|
||||
}, "", true)
|
||||
require.Nil(t, err)
|
||||
require.Equal(t, post.Id, duplicatePost.Id, "should have returned previously created post id")
|
||||
require.Equal(t, "message", duplicatePost.Message)
|
||||
@@ -82,7 +82,7 @@ func TestCreatePostDeduplicate(t *testing.T) {
|
||||
ChannelId: th.BasicChannel.Id,
|
||||
Message: "message",
|
||||
PendingPostId: pendingPostId,
|
||||
}, "")
|
||||
}, "", true)
|
||||
require.NotNil(t, err)
|
||||
require.Equal(t, "Post rejected by plugin. rejected", err.Id)
|
||||
require.Nil(t, post)
|
||||
@@ -92,7 +92,7 @@ func TestCreatePostDeduplicate(t *testing.T) {
|
||||
ChannelId: th.BasicChannel.Id,
|
||||
Message: "message",
|
||||
PendingPostId: pendingPostId,
|
||||
}, "")
|
||||
}, "", true)
|
||||
require.Nil(t, err)
|
||||
require.Equal(t, "message", duplicatePost.Message)
|
||||
})
|
||||
@@ -142,7 +142,7 @@ func TestCreatePostDeduplicate(t *testing.T) {
|
||||
ChannelId: th.BasicChannel.Id,
|
||||
Message: "plugin delayed",
|
||||
PendingPostId: pendingPostId,
|
||||
}, "")
|
||||
}, "", true)
|
||||
require.Nil(t, err)
|
||||
require.Equal(t, post.Message, "plugin delayed")
|
||||
}()
|
||||
@@ -156,7 +156,7 @@ func TestCreatePostDeduplicate(t *testing.T) {
|
||||
ChannelId: th.BasicChannel.Id,
|
||||
Message: "plugin delayed",
|
||||
PendingPostId: pendingPostId,
|
||||
}, "")
|
||||
}, "", true)
|
||||
require.NotNil(t, err)
|
||||
require.Equal(t, "api.post.deduplicate_create_post.pending", err.Id)
|
||||
require.Nil(t, duplicatePost)
|
||||
@@ -172,7 +172,7 @@ func TestCreatePostDeduplicate(t *testing.T) {
|
||||
ChannelId: th.BasicChannel.Id,
|
||||
Message: "message",
|
||||
PendingPostId: pendingPostId,
|
||||
}, "")
|
||||
}, "", true)
|
||||
require.Nil(t, err)
|
||||
require.Equal(t, "message", post.Message)
|
||||
|
||||
@@ -183,7 +183,7 @@ func TestCreatePostDeduplicate(t *testing.T) {
|
||||
ChannelId: th.BasicChannel.Id,
|
||||
Message: "message",
|
||||
PendingPostId: pendingPostId,
|
||||
}, "")
|
||||
}, "", true)
|
||||
require.Nil(t, err)
|
||||
require.NotEqual(t, post.Id, duplicatePost.Id, "should have created new post id")
|
||||
require.Equal(t, "message", duplicatePost.Message)
|
||||
@@ -350,7 +350,7 @@ func TestPostReplyToPostWhereRootPosterLeftChannel(t *testing.T) {
|
||||
CreateAt: 0,
|
||||
}
|
||||
|
||||
_, err = th.App.CreatePostAsUser(&replyPost, "")
|
||||
_, err = th.App.CreatePostAsUser(&replyPost, "", true)
|
||||
require.Nil(t, err)
|
||||
}
|
||||
|
||||
@@ -372,7 +372,7 @@ func TestPostAttachPostToChildPost(t *testing.T) {
|
||||
CreateAt: 0,
|
||||
}
|
||||
|
||||
res1, err := th.App.CreatePostAsUser(&replyPost1, "")
|
||||
res1, err := th.App.CreatePostAsUser(&replyPost1, "", true)
|
||||
require.Nil(t, err)
|
||||
|
||||
replyPost2 := model.Post{
|
||||
@@ -385,7 +385,7 @@ func TestPostAttachPostToChildPost(t *testing.T) {
|
||||
CreateAt: 0,
|
||||
}
|
||||
|
||||
_, err = th.App.CreatePostAsUser(&replyPost2, "")
|
||||
_, err = th.App.CreatePostAsUser(&replyPost2, "", true)
|
||||
assert.Equalf(t, err.StatusCode, http.StatusBadRequest, "Expected BadRequest error, got %v", err)
|
||||
|
||||
replyPost3 := model.Post{
|
||||
@@ -398,7 +398,7 @@ func TestPostAttachPostToChildPost(t *testing.T) {
|
||||
CreateAt: 0,
|
||||
}
|
||||
|
||||
_, err = th.App.CreatePostAsUser(&replyPost3, "")
|
||||
_, err = th.App.CreatePostAsUser(&replyPost3, "", true)
|
||||
assert.Nil(t, err)
|
||||
}
|
||||
|
||||
@@ -429,7 +429,7 @@ func TestPostChannelMentions(t *testing.T) {
|
||||
CreateAt: 0,
|
||||
}
|
||||
|
||||
result, err := th.App.CreatePostAsUser(post, "")
|
||||
result, err := th.App.CreatePostAsUser(post, "", true)
|
||||
require.Nil(t, err)
|
||||
assert.Equal(t, map[string]interface{}{
|
||||
"mention-test": map[string]interface{}{
|
||||
@@ -632,7 +632,7 @@ func TestDeletePostWithFileAttachments(t *testing.T) {
|
||||
FileIds: []string{info1.Id},
|
||||
}
|
||||
|
||||
post, err = th.App.CreatePost(post, th.BasicChannel, false)
|
||||
post, err = th.App.CreatePost(post, th.BasicChannel, false, true)
|
||||
assert.Nil(t, err)
|
||||
|
||||
// Delete the post.
|
||||
@@ -682,7 +682,7 @@ func TestCreatePost(t *testing.T) {
|
||||
UserId: th.BasicUser.Id,
|
||||
}
|
||||
|
||||
rpost, err := th.App.CreatePost(post, th.BasicChannel, false)
|
||||
rpost, err := th.App.CreatePost(post, th.BasicChannel, false, true)
|
||||
require.Nil(t, err)
|
||||
assert.Equal(t, "", rpost.Message)
|
||||
})
|
||||
@@ -698,7 +698,7 @@ func TestCreatePost(t *testing.T) {
|
||||
Message: "This post does not have mentions",
|
||||
UserId: th.BasicUser.Id,
|
||||
}
|
||||
rpost, err := th.App.CreatePost(postWithNoMention, th.BasicChannel, false)
|
||||
rpost, err := th.App.CreatePost(postWithNoMention, th.BasicChannel, false, true)
|
||||
require.Nil(t, err)
|
||||
assert.Equal(t, rpost.GetProps(), model.StringInterface{})
|
||||
|
||||
@@ -707,7 +707,7 @@ func TestCreatePost(t *testing.T) {
|
||||
Message: "This post has @here mention @all",
|
||||
UserId: th.BasicUser.Id,
|
||||
}
|
||||
rpost, err = th.App.CreatePost(postWithMention, th.BasicChannel, false)
|
||||
rpost, err = th.App.CreatePost(postWithMention, th.BasicChannel, false, true)
|
||||
require.Nil(t, err)
|
||||
assert.Equal(t, rpost.GetProps(), model.StringInterface{})
|
||||
})
|
||||
@@ -721,7 +721,7 @@ func TestCreatePost(t *testing.T) {
|
||||
Message: "This post does not have mentions",
|
||||
UserId: th.BasicUser.Id,
|
||||
}
|
||||
rpost, err := th.App.CreatePost(postWithNoMention, th.BasicChannel, false)
|
||||
rpost, err := th.App.CreatePost(postWithNoMention, th.BasicChannel, false, true)
|
||||
require.Nil(t, err)
|
||||
assert.Equal(t, rpost.GetProps(), model.StringInterface{})
|
||||
|
||||
@@ -730,7 +730,7 @@ func TestCreatePost(t *testing.T) {
|
||||
Message: "This post has @here mention @all",
|
||||
UserId: th.BasicUser.Id,
|
||||
}
|
||||
rpost, err = th.App.CreatePost(postWithMention, th.BasicChannel, false)
|
||||
rpost, err = th.App.CreatePost(postWithMention, th.BasicChannel, false, true)
|
||||
require.Nil(t, err)
|
||||
assert.Equal(t, rpost.GetProp(model.POST_PROPS_MENTION_HIGHLIGHT_DISABLED), true)
|
||||
|
||||
@@ -762,7 +762,7 @@ func TestPatchPost(t *testing.T) {
|
||||
UserId: th.BasicUser.Id,
|
||||
}
|
||||
|
||||
rpost, err := th.App.CreatePost(post, th.BasicChannel, false)
|
||||
rpost, err := th.App.CreatePost(post, th.BasicChannel, false, true)
|
||||
require.Nil(t, err)
|
||||
assert.NotEqual(t, "", rpost.Message)
|
||||
|
||||
@@ -787,7 +787,7 @@ func TestPatchPost(t *testing.T) {
|
||||
UserId: th.BasicUser.Id,
|
||||
}
|
||||
|
||||
rpost, err := th.App.CreatePost(post, th.BasicChannel, false)
|
||||
rpost, err := th.App.CreatePost(post, th.BasicChannel, false, true)
|
||||
require.Nil(t, err)
|
||||
|
||||
t.Run("Does not set prop when user has USE_CHANNEL_MENTIONS", func(t *testing.T) {
|
||||
@@ -840,7 +840,7 @@ func TestCreatePostAsUser(t *testing.T) {
|
||||
require.Nil(t, appErr)
|
||||
|
||||
time.Sleep(1 * time.Millisecond)
|
||||
_, appErr = th.App.CreatePostAsUser(post, "")
|
||||
_, appErr = th.App.CreatePostAsUser(post, "", true)
|
||||
require.Nil(t, appErr)
|
||||
|
||||
channelMemberAfter, appErr := th.App.Srv().Store.Channel().GetMember(th.BasicChannel.Id, th.BasicUser.Id)
|
||||
@@ -864,7 +864,7 @@ func TestCreatePostAsUser(t *testing.T) {
|
||||
require.Nil(t, appErr)
|
||||
|
||||
time.Sleep(1 * time.Millisecond)
|
||||
_, appErr = th.App.CreatePostAsUser(post, "")
|
||||
_, appErr = th.App.CreatePostAsUser(post, "", true)
|
||||
require.Nil(t, appErr)
|
||||
|
||||
channelMemberAfter, appErr := th.App.Srv().Store.Channel().GetMember(th.BasicChannel.Id, th.BasicUser.Id)
|
||||
@@ -895,7 +895,7 @@ func TestCreatePostAsUser(t *testing.T) {
|
||||
require.Nil(t, appErr)
|
||||
|
||||
time.Sleep(1 * time.Millisecond)
|
||||
_, appErr = th.App.CreatePostAsUser(post, "")
|
||||
_, appErr = th.App.CreatePostAsUser(post, "", true)
|
||||
require.Nil(t, appErr)
|
||||
|
||||
channelMemberAfter, appErr := th.App.Srv().Store.Channel().GetMember(th.BasicChannel.Id, th.BasicUser.Id)
|
||||
@@ -917,7 +917,7 @@ func TestCreatePostAsUser(t *testing.T) {
|
||||
UserId: user.Id,
|
||||
}
|
||||
|
||||
_, appErr := th.App.CreatePostAsUser(post, "")
|
||||
_, appErr := th.App.CreatePostAsUser(post, "", true)
|
||||
require.Nil(t, appErr)
|
||||
|
||||
testlib.AssertLog(t, th.LogBuffer, mlog.LevelWarn, "Failed to get membership")
|
||||
@@ -940,7 +940,7 @@ func TestCreatePostAsUser(t *testing.T) {
|
||||
UserId: bot.UserId,
|
||||
}
|
||||
|
||||
_, appErr = th.App.CreatePostAsUser(post, "")
|
||||
_, appErr = th.App.CreatePostAsUser(post, "", true)
|
||||
require.Nil(t, appErr)
|
||||
|
||||
testlib.AssertNoLog(t, th.LogBuffer, mlog.LevelWarn, "Failed to get membership")
|
||||
@@ -982,7 +982,7 @@ func TestUpdatePost(t *testing.T) {
|
||||
UserId: th.BasicUser.Id,
|
||||
}
|
||||
|
||||
rpost, err := th.App.CreatePost(post, th.BasicChannel, false)
|
||||
rpost, err := th.App.CreatePost(post, th.BasicChannel, false, true)
|
||||
require.Nil(t, err)
|
||||
assert.NotEqual(t, "", rpost.Message)
|
||||
|
||||
@@ -1008,7 +1008,7 @@ func TestSearchPostsInTeamForUser(t *testing.T) {
|
||||
UserId: th.BasicUser.Id,
|
||||
ChannelId: th.BasicChannel.Id,
|
||||
Message: searchTerm,
|
||||
}, th.BasicChannel, false)
|
||||
}, th.BasicChannel, false, true)
|
||||
|
||||
require.Nil(t, err)
|
||||
|
||||
@@ -1194,19 +1194,19 @@ func TestCountMentionsFromPost(t *testing.T) {
|
||||
UserId: user1.Id,
|
||||
ChannelId: channel.Id,
|
||||
Message: "test",
|
||||
}, channel, false)
|
||||
}, channel, false, true)
|
||||
require.Nil(t, err)
|
||||
_, err = th.App.CreatePost(&model.Post{
|
||||
UserId: user1.Id,
|
||||
ChannelId: channel.Id,
|
||||
Message: "test2",
|
||||
}, channel, false)
|
||||
}, channel, false, true)
|
||||
require.Nil(t, err)
|
||||
_, err = th.App.CreatePost(&model.Post{
|
||||
UserId: user1.Id,
|
||||
ChannelId: channel.Id,
|
||||
Message: "test3",
|
||||
}, channel, false)
|
||||
}, channel, false, true)
|
||||
require.Nil(t, err)
|
||||
|
||||
count, err := th.App.countMentionsFromPost(user2, post1)
|
||||
@@ -1231,19 +1231,19 @@ func TestCountMentionsFromPost(t *testing.T) {
|
||||
UserId: user1.Id,
|
||||
ChannelId: channel.Id,
|
||||
Message: fmt.Sprintf("@%s", user2.Username),
|
||||
}, channel, false)
|
||||
}, channel, false, true)
|
||||
require.Nil(t, err)
|
||||
_, err = th.App.CreatePost(&model.Post{
|
||||
UserId: user1.Id,
|
||||
ChannelId: channel.Id,
|
||||
Message: "test2",
|
||||
}, channel, false)
|
||||
}, channel, false, true)
|
||||
require.Nil(t, err)
|
||||
_, err = th.App.CreatePost(&model.Post{
|
||||
UserId: user1.Id,
|
||||
ChannelId: channel.Id,
|
||||
Message: "apple",
|
||||
}, channel, false)
|
||||
}, channel, false, true)
|
||||
require.Nil(t, err)
|
||||
|
||||
// post1 and post3 should mention the user
|
||||
@@ -1270,19 +1270,19 @@ func TestCountMentionsFromPost(t *testing.T) {
|
||||
UserId: user1.Id,
|
||||
ChannelId: channel.Id,
|
||||
Message: "test",
|
||||
}, channel, false)
|
||||
}, channel, false, true)
|
||||
require.Nil(t, err)
|
||||
_, err = th.App.CreatePost(&model.Post{
|
||||
UserId: user1.Id,
|
||||
ChannelId: channel.Id,
|
||||
Message: "@channel",
|
||||
}, channel, false)
|
||||
}, channel, false, true)
|
||||
require.Nil(t, err)
|
||||
_, err = th.App.CreatePost(&model.Post{
|
||||
UserId: user1.Id,
|
||||
ChannelId: channel.Id,
|
||||
Message: "@all",
|
||||
}, channel, false)
|
||||
}, channel, false, true)
|
||||
require.Nil(t, err)
|
||||
|
||||
// post2 and post3 should mention the user
|
||||
@@ -1309,19 +1309,19 @@ func TestCountMentionsFromPost(t *testing.T) {
|
||||
UserId: user1.Id,
|
||||
ChannelId: channel.Id,
|
||||
Message: "test",
|
||||
}, channel, false)
|
||||
}, channel, false, true)
|
||||
require.Nil(t, err)
|
||||
_, err = th.App.CreatePost(&model.Post{
|
||||
UserId: user1.Id,
|
||||
ChannelId: channel.Id,
|
||||
Message: "@channel",
|
||||
}, channel, false)
|
||||
}, channel, false, true)
|
||||
require.Nil(t, err)
|
||||
_, err = th.App.CreatePost(&model.Post{
|
||||
UserId: user1.Id,
|
||||
ChannelId: channel.Id,
|
||||
Message: "@all",
|
||||
}, channel, false)
|
||||
}, channel, false, true)
|
||||
require.Nil(t, err)
|
||||
|
||||
count, err := th.App.countMentionsFromPost(user2, post1)
|
||||
@@ -1351,19 +1351,19 @@ func TestCountMentionsFromPost(t *testing.T) {
|
||||
UserId: user1.Id,
|
||||
ChannelId: channel.Id,
|
||||
Message: "test",
|
||||
}, channel, false)
|
||||
}, channel, false, true)
|
||||
require.Nil(t, err)
|
||||
_, err = th.App.CreatePost(&model.Post{
|
||||
UserId: user1.Id,
|
||||
ChannelId: channel.Id,
|
||||
Message: "@channel",
|
||||
}, channel, false)
|
||||
}, channel, false, true)
|
||||
require.Nil(t, err)
|
||||
_, err = th.App.CreatePost(&model.Post{
|
||||
UserId: user1.Id,
|
||||
ChannelId: channel.Id,
|
||||
Message: "@all",
|
||||
}, channel, false)
|
||||
}, channel, false, true)
|
||||
require.Nil(t, err)
|
||||
|
||||
count, err := th.App.countMentionsFromPost(user2, post1)
|
||||
@@ -1388,34 +1388,34 @@ func TestCountMentionsFromPost(t *testing.T) {
|
||||
UserId: user2.Id,
|
||||
ChannelId: channel.Id,
|
||||
Message: "test",
|
||||
}, channel, false)
|
||||
}, channel, false, true)
|
||||
require.Nil(t, err)
|
||||
_, err = th.App.CreatePost(&model.Post{
|
||||
UserId: user1.Id,
|
||||
ChannelId: channel.Id,
|
||||
RootId: post1.Id,
|
||||
Message: "test2",
|
||||
}, channel, false)
|
||||
}, channel, false, true)
|
||||
require.Nil(t, err)
|
||||
post3, err := th.App.CreatePost(&model.Post{
|
||||
UserId: user1.Id,
|
||||
ChannelId: channel.Id,
|
||||
Message: "test3",
|
||||
}, channel, false)
|
||||
}, channel, false, true)
|
||||
require.Nil(t, err)
|
||||
_, err = th.App.CreatePost(&model.Post{
|
||||
UserId: user2.Id,
|
||||
ChannelId: channel.Id,
|
||||
RootId: post3.Id,
|
||||
Message: "test4",
|
||||
}, channel, false)
|
||||
}, channel, false, true)
|
||||
require.Nil(t, err)
|
||||
_, err = th.App.CreatePost(&model.Post{
|
||||
UserId: user1.Id,
|
||||
ChannelId: channel.Id,
|
||||
RootId: post3.Id,
|
||||
Message: "test5",
|
||||
}, channel, false)
|
||||
}, channel, false, true)
|
||||
require.Nil(t, err)
|
||||
|
||||
// post2 should mention the user
|
||||
@@ -1442,34 +1442,34 @@ func TestCountMentionsFromPost(t *testing.T) {
|
||||
UserId: user2.Id,
|
||||
ChannelId: channel.Id,
|
||||
Message: "test",
|
||||
}, channel, false)
|
||||
}, channel, false, true)
|
||||
require.Nil(t, err)
|
||||
_, err = th.App.CreatePost(&model.Post{
|
||||
UserId: user1.Id,
|
||||
ChannelId: channel.Id,
|
||||
RootId: post1.Id,
|
||||
Message: "test2",
|
||||
}, channel, false)
|
||||
}, channel, false, true)
|
||||
require.Nil(t, err)
|
||||
post3, err := th.App.CreatePost(&model.Post{
|
||||
UserId: user1.Id,
|
||||
ChannelId: channel.Id,
|
||||
Message: "test3",
|
||||
}, channel, false)
|
||||
}, channel, false, true)
|
||||
require.Nil(t, err)
|
||||
_, err = th.App.CreatePost(&model.Post{
|
||||
UserId: user2.Id,
|
||||
ChannelId: channel.Id,
|
||||
RootId: post3.Id,
|
||||
Message: "test4",
|
||||
}, channel, false)
|
||||
}, channel, false, true)
|
||||
require.Nil(t, err)
|
||||
_, err = th.App.CreatePost(&model.Post{
|
||||
UserId: user1.Id,
|
||||
ChannelId: channel.Id,
|
||||
RootId: post3.Id,
|
||||
Message: "test5",
|
||||
}, channel, false)
|
||||
}, channel, false, true)
|
||||
require.Nil(t, err)
|
||||
|
||||
// post2 and post5 should mention the user
|
||||
@@ -1498,7 +1498,7 @@ func TestCountMentionsFromPost(t *testing.T) {
|
||||
Props: map[string]interface{}{
|
||||
model.POST_PROPS_ADDED_USER_ID: model.NewId(),
|
||||
},
|
||||
}, channel, false)
|
||||
}, channel, false, true)
|
||||
require.Nil(t, err)
|
||||
_, err = th.App.CreatePost(&model.Post{
|
||||
UserId: user1.Id,
|
||||
@@ -1508,7 +1508,7 @@ func TestCountMentionsFromPost(t *testing.T) {
|
||||
Props: map[string]interface{}{
|
||||
model.POST_PROPS_ADDED_USER_ID: user2.Id,
|
||||
},
|
||||
}, channel, false)
|
||||
}, channel, false, true)
|
||||
require.Nil(t, err)
|
||||
_, err = th.App.CreatePost(&model.Post{
|
||||
UserId: user1.Id,
|
||||
@@ -1518,7 +1518,7 @@ func TestCountMentionsFromPost(t *testing.T) {
|
||||
Props: map[string]interface{}{
|
||||
model.POST_PROPS_ADDED_USER_ID: user2.Id,
|
||||
},
|
||||
}, channel, false)
|
||||
}, channel, false, true)
|
||||
require.Nil(t, err)
|
||||
|
||||
// should be mentioned by post2 and post3
|
||||
@@ -1543,14 +1543,14 @@ func TestCountMentionsFromPost(t *testing.T) {
|
||||
UserId: user1.Id,
|
||||
ChannelId: channel.Id,
|
||||
Message: "test",
|
||||
}, channel, false)
|
||||
}, channel, false, true)
|
||||
require.Nil(t, err)
|
||||
|
||||
_, err = th.App.CreatePost(&model.Post{
|
||||
UserId: user1.Id,
|
||||
ChannelId: channel.Id,
|
||||
Message: "test2",
|
||||
}, channel, false)
|
||||
}, channel, false, true)
|
||||
require.Nil(t, err)
|
||||
|
||||
count, err := th.App.countMentionsFromPost(user2, post1)
|
||||
@@ -1578,19 +1578,19 @@ func TestCountMentionsFromPost(t *testing.T) {
|
||||
UserId: user1.Id,
|
||||
ChannelId: channel.Id,
|
||||
Message: fmt.Sprintf("@%s", user2.Username),
|
||||
}, channel, false)
|
||||
}, channel, false, true)
|
||||
require.Nil(t, err)
|
||||
post2, err := th.App.CreatePost(&model.Post{
|
||||
UserId: user1.Id,
|
||||
ChannelId: channel.Id,
|
||||
Message: "test2",
|
||||
}, channel, false)
|
||||
}, channel, false, true)
|
||||
require.Nil(t, err)
|
||||
_, err = th.App.CreatePost(&model.Post{
|
||||
UserId: user1.Id,
|
||||
ChannelId: channel.Id,
|
||||
Message: fmt.Sprintf("@%s", user2.Username),
|
||||
}, channel, false)
|
||||
}, channel, false, true)
|
||||
require.Nil(t, err)
|
||||
|
||||
// post1 and post3 should mention the user, but we only count post3
|
||||
@@ -1615,13 +1615,13 @@ func TestCountMentionsFromPost(t *testing.T) {
|
||||
UserId: user1.Id,
|
||||
ChannelId: channel.Id,
|
||||
Message: fmt.Sprintf("@%s", user2.Username),
|
||||
}, channel, false)
|
||||
}, channel, false, true)
|
||||
require.Nil(t, err)
|
||||
_, err = th.App.CreatePost(&model.Post{
|
||||
UserId: user2.Id,
|
||||
ChannelId: channel.Id,
|
||||
Message: fmt.Sprintf("@%s", user2.Username),
|
||||
}, channel, false)
|
||||
}, channel, false, true)
|
||||
require.Nil(t, err)
|
||||
|
||||
// post2 should mention the user
|
||||
@@ -1648,27 +1648,27 @@ func TestCountMentionsFromPost(t *testing.T) {
|
||||
UserId: user1.Id,
|
||||
ChannelId: channel.Id,
|
||||
Message: "test1",
|
||||
}, channel, false)
|
||||
}, channel, false, true)
|
||||
require.Nil(t, err)
|
||||
_, err = th.App.CreatePost(&model.Post{
|
||||
UserId: user2.Id,
|
||||
ChannelId: channel.Id,
|
||||
RootId: post1.Id,
|
||||
Message: "test2",
|
||||
}, channel, false)
|
||||
}, channel, false, true)
|
||||
require.Nil(t, err)
|
||||
post3, err := th.App.CreatePost(&model.Post{
|
||||
UserId: user1.Id,
|
||||
ChannelId: channel.Id,
|
||||
Message: "test3",
|
||||
}, channel, false)
|
||||
}, channel, false, true)
|
||||
require.Nil(t, err)
|
||||
_, err = th.App.CreatePost(&model.Post{
|
||||
UserId: user1.Id,
|
||||
ChannelId: channel.Id,
|
||||
RootId: post1.Id,
|
||||
Message: "test4",
|
||||
}, channel, false)
|
||||
}, channel, false, true)
|
||||
require.Nil(t, err)
|
||||
|
||||
// post4 should mention the user
|
||||
@@ -1693,13 +1693,13 @@ func TestCountMentionsFromPost(t *testing.T) {
|
||||
UserId: user1.Id,
|
||||
ChannelId: channel.Id,
|
||||
Message: "test1",
|
||||
}, channel, false)
|
||||
}, channel, false, true)
|
||||
require.Nil(t, err)
|
||||
_, err = th.App.CreatePost(&model.Post{
|
||||
UserId: user2.Id,
|
||||
ChannelId: channel.Id,
|
||||
Message: fmt.Sprintf("@%s", user2.Username),
|
||||
}, channel, false)
|
||||
}, channel, false, true)
|
||||
require.Nil(t, err)
|
||||
_, err = th.App.CreatePost(&model.Post{
|
||||
UserId: user2.Id,
|
||||
@@ -1708,7 +1708,7 @@ func TestCountMentionsFromPost(t *testing.T) {
|
||||
Props: map[string]interface{}{
|
||||
"from_webhook": "true",
|
||||
},
|
||||
}, channel, false)
|
||||
}, channel, false, true)
|
||||
require.Nil(t, err)
|
||||
|
||||
// post3 should mention the user
|
||||
@@ -1735,7 +1735,7 @@ func TestCountMentionsFromPost(t *testing.T) {
|
||||
UserId: user1.Id,
|
||||
ChannelId: channel.Id,
|
||||
Message: fmt.Sprintf("@%s", user2.Username),
|
||||
}, channel, false)
|
||||
}, channel, false, true)
|
||||
require.Nil(t, err)
|
||||
|
||||
for i := 0; i < numPosts-1; i++ {
|
||||
@@ -1743,7 +1743,7 @@ func TestCountMentionsFromPost(t *testing.T) {
|
||||
UserId: user1.Id,
|
||||
ChannelId: channel.Id,
|
||||
Message: fmt.Sprintf("@%s", user2.Username),
|
||||
}, channel, false)
|
||||
}, channel, false, true)
|
||||
require.Nil(t, err)
|
||||
}
|
||||
|
||||
@@ -1770,7 +1770,7 @@ func TestFillInPostProps(t *testing.T) {
|
||||
UserId: user1.Id,
|
||||
ChannelId: channel.Id,
|
||||
Message: "test123123 @group1 @group2 blah blah blah",
|
||||
}, channel, false)
|
||||
}, channel, false, true)
|
||||
require.Nil(t, err)
|
||||
|
||||
err = th.App.FillInPostProps(post1, channel)
|
||||
@@ -1802,7 +1802,7 @@ func TestFillInPostProps(t *testing.T) {
|
||||
UserId: guest.Id,
|
||||
ChannelId: channel.Id,
|
||||
Message: "test123123 @group1 @group2 blah blah blah",
|
||||
}, channel, false)
|
||||
}, channel, false, true)
|
||||
require.Nil(t, err)
|
||||
|
||||
err = th.App.FillInPostProps(post1, channel)
|
||||
@@ -1835,7 +1835,7 @@ func TestFillInPostProps(t *testing.T) {
|
||||
UserId: guest.Id,
|
||||
ChannelId: channel.Id,
|
||||
Message: "test123123 @group1 @group2 blah blah blah",
|
||||
}, channel, false)
|
||||
}, channel, false, true)
|
||||
require.Nil(t, err)
|
||||
|
||||
err = th.App.FillInPostProps(post1, channel)
|
||||
|
||||
@@ -1041,7 +1041,7 @@ func (a *App) postLeaveTeamMessage(user *model.User, channel *model.Channel) *mo
|
||||
},
|
||||
}
|
||||
|
||||
if _, err := a.CreatePost(post, channel, false); err != nil {
|
||||
if _, err := a.CreatePost(post, channel, false, true); err != nil {
|
||||
return model.NewAppError("postRemoveFromChannelMessage", "api.channel.post_user_add_remove_message_and_forget.error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
@@ -1059,7 +1059,7 @@ func (a *App) postRemoveFromTeamMessage(user *model.User, channel *model.Channel
|
||||
},
|
||||
}
|
||||
|
||||
if _, err := a.CreatePost(post, channel, false); err != nil {
|
||||
if _, err := a.CreatePost(post, channel, false, true); err != nil {
|
||||
return model.NewAppError("postRemoveFromTeamMessage", "api.channel.post_user_add_remove_message_and_forget.error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
|
||||
@@ -206,7 +206,7 @@ func (me *TestHelper) CreatePost(channel *model.Channel) *model.Post {
|
||||
|
||||
utils.DisableDebugLogForTest()
|
||||
var err *model.AppError
|
||||
if post, err = me.App.CreatePost(post, channel, false); err != nil {
|
||||
if post, err = me.App.CreatePost(post, channel, false, true); err != nil {
|
||||
mlog.Error(err.Error())
|
||||
|
||||
time.Sleep(time.Second)
|
||||
|
||||
Ссылка в новой задаче
Block a user