mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
Do not update channel message count for team add/remove message (#10225)
This commit is contained in:
@@ -117,7 +117,8 @@ func (s *SqlPostStore) Save(post *model.Post) store.StoreChannel {
|
||||
if post.Type != model.POST_JOIN_LEAVE && post.Type != model.POST_ADD_REMOVE &&
|
||||
post.Type != model.POST_JOIN_CHANNEL && post.Type != model.POST_LEAVE_CHANNEL &&
|
||||
post.Type != model.POST_JOIN_TEAM && post.Type != model.POST_LEAVE_TEAM &&
|
||||
post.Type != model.POST_ADD_TO_CHANNEL && post.Type != model.POST_REMOVE_FROM_CHANNEL {
|
||||
post.Type != model.POST_ADD_TO_CHANNEL && post.Type != model.POST_REMOVE_FROM_CHANNEL &&
|
||||
post.Type != model.POST_ADD_TO_TEAM && post.Type != model.POST_REMOVE_FROM_TEAM {
|
||||
s.GetMaster().Exec("UPDATE Channels SET LastPostAt = :LastPostAt, TotalMsgCount = TotalMsgCount + 1 WHERE Id = :ChannelId", map[string]interface{}{"LastPostAt": time, "ChannelId": post.ChannelId})
|
||||
} else {
|
||||
// don't update TotalMsgCount for unimportant messages so that the channel isn't marked as unread
|
||||
|
||||
@@ -18,6 +18,7 @@ import (
|
||||
|
||||
func TestPostStore(t *testing.T, ss store.Store) {
|
||||
t.Run("Save", func(t *testing.T) { testPostStoreSave(t, ss) })
|
||||
t.Run("SaveAndUpdateChannelMsgCounts", func(t *testing.T) { testPostStoreSaveChannelMsgCounts(t, ss) })
|
||||
t.Run("Get", func(t *testing.T) { testPostStoreGet(t, ss) })
|
||||
t.Run("GetSingle", func(t *testing.T) { testPostStoreGetSingle(t, ss) })
|
||||
t.Run("GetEtagCache", func(t *testing.T) { testGetEtagCache(t, ss) })
|
||||
@@ -63,6 +64,37 @@ func testPostStoreSave(t *testing.T, ss store.Store) {
|
||||
}
|
||||
}
|
||||
|
||||
func testPostStoreSaveChannelMsgCounts(t *testing.T, ss store.Store) {
|
||||
c1 := &model.Channel{Name: model.NewId(), DisplayName: "posttestchannel", Type: model.CHANNEL_OPEN}
|
||||
res := <-ss.Channel().Save(c1, 1000000)
|
||||
require.Nil(t, res.Err)
|
||||
|
||||
o1 := model.Post{}
|
||||
o1.ChannelId = c1.Id
|
||||
o1.UserId = model.NewId()
|
||||
o1.Message = "zz" + model.NewId() + "b"
|
||||
|
||||
require.Nil(t, (<-ss.Post().Save(&o1)).Err)
|
||||
|
||||
res = <-ss.Channel().Get(c1.Id, false)
|
||||
require.Nil(t, res.Err)
|
||||
c1 = res.Data.(*model.Channel)
|
||||
assert.Equal(t, int64(1), c1.TotalMsgCount, "Message count should update by 1")
|
||||
|
||||
o1.Id = ""
|
||||
o1.Type = model.POST_ADD_TO_TEAM
|
||||
require.Nil(t, (<-ss.Post().Save(&o1)).Err)
|
||||
|
||||
o1.Id = ""
|
||||
o1.Type = model.POST_REMOVE_FROM_TEAM
|
||||
require.Nil(t, (<-ss.Post().Save(&o1)).Err)
|
||||
|
||||
res = <-ss.Channel().Get(c1.Id, false)
|
||||
require.Nil(t, res.Err)
|
||||
c1 = res.Data.(*model.Channel)
|
||||
assert.Equal(t, int64(1), c1.TotalMsgCount, "Message count should not update for team add/removed message")
|
||||
}
|
||||
|
||||
func testPostStoreGet(t *testing.T, ss store.Store) {
|
||||
o1 := &model.Post{}
|
||||
o1.ChannelId = model.NewId()
|
||||
|
||||
Reference in New Issue
Block a user