diff --git a/store/sqlstore/post_store.go b/store/sqlstore/post_store.go index 4317d968b0..08dcff879a 100644 --- a/store/sqlstore/post_store.go +++ b/store/sqlstore/post_store.go @@ -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 diff --git a/store/storetest/post_store.go b/store/storetest/post_store.go index b93eb6628d..d0fd363bde 100644 --- a/store/storetest/post_store.go +++ b/store/storetest/post_store.go @@ -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()