MM-54778 Fix mark as unread on GMs (#24880)

* Fix mark as unread on GMs

* Don't count own messages in gms when marking as unread

* Change argument name

* Rename userId

---------

Co-authored-by: Mattermost Build <build@mattermost.com>
Этот коммит содержится в:
Daniel Espino García
2023-10-24 15:27:30 +02:00
коммит произвёл GitHub
родитель 5d3ba7483b
Коммит 6125b0ca7f
9 изменённых файлов: 115 добавлений и 49 удалений

Просмотреть файл

@@ -4479,6 +4479,7 @@ 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()
userId3 := model.NewId()
channelId := model.NewId()
@@ -4503,21 +4504,28 @@ func testCountPostsAfter(t *testing.T, ss store.Store) {
})
require.NoError(t, err)
_, err = ss.Post().Save(&model.Post{
UserId: userId3,
ChannelId: channelId,
CreateAt: 1003,
})
require.NoError(t, err)
count, _, err := ss.Channel().CountPostsAfter(channelId, p1.CreateAt-1, "")
require.NoError(t, err)
assert.Equal(t, 3, count)
assert.Equal(t, 4, count)
count, _, err = ss.Channel().CountPostsAfter(channelId, p1.CreateAt, "")
require.NoError(t, err)
assert.Equal(t, 2, count)
assert.Equal(t, 3, count)
count, _, err = ss.Channel().CountPostsAfter(channelId, p1.CreateAt-1, userId1)
count, _, err = ss.Channel().CountPostsAfter(channelId, p1.CreateAt-1, userId2)
require.NoError(t, err)
assert.Equal(t, 3, count)
count, _, err = ss.Channel().CountPostsAfter(channelId, p1.CreateAt, userId2)
require.NoError(t, err)
assert.Equal(t, 2, count)
count, _, err = ss.Channel().CountPostsAfter(channelId, p1.CreateAt, userId1)
require.NoError(t, err)
assert.Equal(t, 1, count)
})
t.Run("should not count deleted posts", func(t *testing.T) {
@@ -4623,6 +4631,7 @@ func testCountUrgentPostsAfter(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()
userId3 := model.NewId()
channelId := model.NewId()
@@ -4661,19 +4670,33 @@ func testCountUrgentPostsAfter(t *testing.T, ss store.Store) {
})
require.NoError(t, err)
_, err = ss.Post().Save(&model.Post{
UserId: userId3,
ChannelId: channelId,
CreateAt: 1003,
Metadata: &model.PostMetadata{
Priority: &model.PostPriority{
Priority: model.NewString(model.PostPriorityUrgent),
RequestedAck: model.NewBool(false),
PersistentNotifications: model.NewBool(false),
},
},
})
require.NoError(t, err)
count, err := ss.Channel().CountUrgentPostsAfter(channelId, p1.CreateAt-1, "")
require.NoError(t, err)
assert.Equal(t, 1, count)
assert.Equal(t, 2, count)
count, err = ss.Channel().CountUrgentPostsAfter(channelId, p1.CreateAt, "")
require.NoError(t, err)
assert.Equal(t, 0, count)
assert.Equal(t, 1, count)
count, err = ss.Channel().CountUrgentPostsAfter(channelId, p1.CreateAt-1, userId1)
count, err = ss.Channel().CountUrgentPostsAfter(channelId, p1.CreateAt-1, userId3)
require.NoError(t, err)
assert.Equal(t, 1, count)
count, err = ss.Channel().CountUrgentPostsAfter(channelId, p1.CreateAt, userId1)
count, err = ss.Channel().CountUrgentPostsAfter(channelId, p1.CreateAt, userId3)
require.NoError(t, err)
assert.Equal(t, 0, count)
})

Просмотреть файл

@@ -184,30 +184,30 @@ func (_m *ChannelStore) ClearSidebarOnTeamLeave(userID string, teamID string) er
return r0
}
// CountPostsAfter provides a mock function with given fields: channelID, timestamp, userID
func (_m *ChannelStore) CountPostsAfter(channelID string, timestamp int64, userID string) (int, int, error) {
ret := _m.Called(channelID, timestamp, userID)
// CountPostsAfter provides a mock function with given fields: channelID, timestamp, excludedUserID
func (_m *ChannelStore) CountPostsAfter(channelID string, timestamp int64, excludedUserID string) (int, int, error) {
ret := _m.Called(channelID, timestamp, excludedUserID)
var r0 int
var r1 int
var r2 error
if rf, ok := ret.Get(0).(func(string, int64, string) (int, int, error)); ok {
return rf(channelID, timestamp, userID)
return rf(channelID, timestamp, excludedUserID)
}
if rf, ok := ret.Get(0).(func(string, int64, string) int); ok {
r0 = rf(channelID, timestamp, userID)
r0 = rf(channelID, timestamp, excludedUserID)
} else {
r0 = ret.Get(0).(int)
}
if rf, ok := ret.Get(1).(func(string, int64, string) int); ok {
r1 = rf(channelID, timestamp, userID)
r1 = rf(channelID, timestamp, excludedUserID)
} else {
r1 = ret.Get(1).(int)
}
if rf, ok := ret.Get(2).(func(string, int64, string) error); ok {
r2 = rf(channelID, timestamp, userID)
r2 = rf(channelID, timestamp, excludedUserID)
} else {
r2 = ret.Error(2)
}
@@ -215,23 +215,23 @@ func (_m *ChannelStore) CountPostsAfter(channelID string, timestamp int64, userI
return r0, r1, r2
}
// CountUrgentPostsAfter provides a mock function with given fields: channelID, timestamp, userID
func (_m *ChannelStore) CountUrgentPostsAfter(channelID string, timestamp int64, userID string) (int, error) {
ret := _m.Called(channelID, timestamp, userID)
// CountUrgentPostsAfter provides a mock function with given fields: channelID, timestamp, excludedUserID
func (_m *ChannelStore) CountUrgentPostsAfter(channelID string, timestamp int64, excludedUserID string) (int, error) {
ret := _m.Called(channelID, timestamp, excludedUserID)
var r0 int
var r1 error
if rf, ok := ret.Get(0).(func(string, int64, string) (int, error)); ok {
return rf(channelID, timestamp, userID)
return rf(channelID, timestamp, excludedUserID)
}
if rf, ok := ret.Get(0).(func(string, int64, string) int); ok {
r0 = rf(channelID, timestamp, userID)
r0 = rf(channelID, timestamp, excludedUserID)
} else {
r0 = ret.Get(0).(int)
}
if rf, ok := ret.Get(1).(func(string, int64, string) error); ok {
r1 = rf(channelID, timestamp, userID)
r1 = rf(channelID, timestamp, excludedUserID)
} else {
r1 = ret.Error(1)
}