MM-20681 Fix custom post types not marking channel unread when using Mark as Unread (#13247)
* MM-20681 Fix custom post types not marking channel unread when using Mark as Unread * Fix inverted if statements
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
df95748e86
Коммит
4a23d4b282
@@ -57,6 +57,7 @@ func TestChannelStore(t *testing.T, ss store.Store, s SqlSupplier) {
|
||||
t.Run("GetChannelCounts", func(t *testing.T) { testChannelStoreGetChannelCounts(t, ss) })
|
||||
t.Run("GetMembersForUser", func(t *testing.T) { testChannelStoreGetMembersForUser(t, ss) })
|
||||
t.Run("GetMembersForUserWithPagination", func(t *testing.T) { testChannelStoreGetMembersForUserWithPagination(t, ss) })
|
||||
t.Run("CountPostsAfter", func(t *testing.T) { testCountPostsAfter(t, ss) })
|
||||
t.Run("UpdateLastViewedAt", func(t *testing.T) { testChannelStoreUpdateLastViewedAt(t, ss) })
|
||||
t.Run("IncrementMentionCount", func(t *testing.T) { testChannelStoreIncrementMentionCount(t, ss) })
|
||||
t.Run("UpdateChannelMember", func(t *testing.T) { testUpdateChannelMember(t, ss) })
|
||||
@@ -1594,6 +1595,150 @@ func testChannelStoreGetMembersForUserWithPagination(t *testing.T, ss store.Stor
|
||||
assert.Len(t, *members, 1)
|
||||
}
|
||||
|
||||
func testCountPostsAfter(t *testing.T, ss store.Store) {
|
||||
t.Run("should count all posts with or without the given user ID", func(t *testing.T) {
|
||||
userId1 := model.NewId()
|
||||
userId2 := model.NewId()
|
||||
|
||||
channelId := model.NewId()
|
||||
|
||||
p1, err := ss.Post().Save(&model.Post{
|
||||
UserId: userId1,
|
||||
ChannelId: channelId,
|
||||
CreateAt: 1000,
|
||||
})
|
||||
require.Nil(t, err)
|
||||
|
||||
_, err = ss.Post().Save(&model.Post{
|
||||
UserId: userId1,
|
||||
ChannelId: channelId,
|
||||
CreateAt: 1001,
|
||||
})
|
||||
require.Nil(t, err)
|
||||
|
||||
_, err = ss.Post().Save(&model.Post{
|
||||
UserId: userId2,
|
||||
ChannelId: channelId,
|
||||
CreateAt: 1002,
|
||||
})
|
||||
require.Nil(t, err)
|
||||
|
||||
count, err := ss.Channel().CountPostsAfter(channelId, p1.CreateAt-1, "")
|
||||
require.Nil(t, err)
|
||||
assert.Equal(t, 3, count)
|
||||
|
||||
count, err = ss.Channel().CountPostsAfter(channelId, p1.CreateAt, "")
|
||||
require.Nil(t, err)
|
||||
assert.Equal(t, 2, count)
|
||||
|
||||
count, err = ss.Channel().CountPostsAfter(channelId, p1.CreateAt-1, userId1)
|
||||
require.Nil(t, err)
|
||||
assert.Equal(t, 2, count)
|
||||
|
||||
count, err = ss.Channel().CountPostsAfter(channelId, p1.CreateAt, userId1)
|
||||
require.Nil(t, err)
|
||||
assert.Equal(t, 1, count)
|
||||
})
|
||||
|
||||
t.Run("should not count deleted posts", func(t *testing.T) {
|
||||
userId1 := model.NewId()
|
||||
|
||||
channelId := model.NewId()
|
||||
|
||||
p1, err := ss.Post().Save(&model.Post{
|
||||
UserId: userId1,
|
||||
ChannelId: channelId,
|
||||
CreateAt: 1000,
|
||||
})
|
||||
require.Nil(t, err)
|
||||
|
||||
_, err = ss.Post().Save(&model.Post{
|
||||
UserId: userId1,
|
||||
ChannelId: channelId,
|
||||
CreateAt: 1001,
|
||||
DeleteAt: 1001,
|
||||
})
|
||||
require.Nil(t, err)
|
||||
|
||||
count, err := ss.Channel().CountPostsAfter(channelId, p1.CreateAt-1, "")
|
||||
require.Nil(t, err)
|
||||
assert.Equal(t, 1, count)
|
||||
|
||||
count, err = ss.Channel().CountPostsAfter(channelId, p1.CreateAt, "")
|
||||
require.Nil(t, err)
|
||||
assert.Equal(t, 0, count)
|
||||
})
|
||||
|
||||
t.Run("should count system/bot messages, but not join/leave messages", func(t *testing.T) {
|
||||
userId1 := model.NewId()
|
||||
|
||||
channelId := model.NewId()
|
||||
|
||||
p1, err := ss.Post().Save(&model.Post{
|
||||
UserId: userId1,
|
||||
ChannelId: channelId,
|
||||
CreateAt: 1000,
|
||||
})
|
||||
require.Nil(t, err)
|
||||
|
||||
_, err = ss.Post().Save(&model.Post{
|
||||
UserId: userId1,
|
||||
ChannelId: channelId,
|
||||
CreateAt: 1001,
|
||||
Type: model.POST_JOIN_CHANNEL,
|
||||
})
|
||||
require.Nil(t, err)
|
||||
|
||||
_, err = ss.Post().Save(&model.Post{
|
||||
UserId: userId1,
|
||||
ChannelId: channelId,
|
||||
CreateAt: 1002,
|
||||
Type: model.POST_REMOVE_FROM_CHANNEL,
|
||||
})
|
||||
require.Nil(t, err)
|
||||
|
||||
_, err = ss.Post().Save(&model.Post{
|
||||
UserId: userId1,
|
||||
ChannelId: channelId,
|
||||
CreateAt: 1003,
|
||||
Type: model.POST_LEAVE_TEAM,
|
||||
})
|
||||
require.Nil(t, err)
|
||||
|
||||
p5, err := ss.Post().Save(&model.Post{
|
||||
UserId: userId1,
|
||||
ChannelId: channelId,
|
||||
CreateAt: 1004,
|
||||
Type: model.POST_HEADER_CHANGE,
|
||||
})
|
||||
require.Nil(t, err)
|
||||
|
||||
_, err = ss.Post().Save(&model.Post{
|
||||
UserId: userId1,
|
||||
ChannelId: channelId,
|
||||
CreateAt: 1005,
|
||||
Type: "custom_nps_survey",
|
||||
})
|
||||
require.Nil(t, err)
|
||||
|
||||
count, err := ss.Channel().CountPostsAfter(channelId, p1.CreateAt-1, "")
|
||||
require.Nil(t, err)
|
||||
assert.Equal(t, 3, count)
|
||||
|
||||
count, err = ss.Channel().CountPostsAfter(channelId, p1.CreateAt, "")
|
||||
require.Nil(t, err)
|
||||
assert.Equal(t, 2, count)
|
||||
|
||||
count, err = ss.Channel().CountPostsAfter(channelId, p5.CreateAt-1, "")
|
||||
require.Nil(t, err)
|
||||
assert.Equal(t, 2, count)
|
||||
|
||||
count, err = ss.Channel().CountPostsAfter(channelId, p5.CreateAt, "")
|
||||
require.Nil(t, err)
|
||||
assert.Equal(t, 1, count)
|
||||
})
|
||||
}
|
||||
|
||||
func testChannelStoreUpdateLastViewedAt(t *testing.T, ss store.Store) {
|
||||
o1 := model.Channel{}
|
||||
o1.TeamId = model.NewId()
|
||||
|
||||
@@ -133,14 +133,14 @@ func (_m *ChannelStore) ClearCaches() {
|
||||
}
|
||||
|
||||
// CountPostsAfter provides a mock function with given fields: channelId, timestamp, userId
|
||||
func (_m *ChannelStore) CountPostsAfter(channelId string, timestamp int64, userId string) (int64, *model.AppError) {
|
||||
func (_m *ChannelStore) CountPostsAfter(channelId string, timestamp int64, userId string) (int, *model.AppError) {
|
||||
ret := _m.Called(channelId, timestamp, userId)
|
||||
|
||||
var r0 int64
|
||||
if rf, ok := ret.Get(0).(func(string, int64, string) int64); ok {
|
||||
var r0 int
|
||||
if rf, ok := ret.Get(0).(func(string, int64, string) int); ok {
|
||||
r0 = rf(channelId, timestamp, userId)
|
||||
} else {
|
||||
r0 = ret.Get(0).(int64)
|
||||
r0 = ret.Get(0).(int)
|
||||
}
|
||||
|
||||
var r1 *model.AppError
|
||||
|
||||
Ссылка в новой задаче
Block a user