[MM-17069]also unread the given post (#11932)

This commit is contained in:
Guillermo Vayá 2019-09-02 10:00:38 +02:00 committed by GitHub
parent 600cf71ee9
commit 3629f26bb9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 20 deletions

View file

@ -2686,7 +2686,7 @@ func TestSetChannelUnread(t *testing.T) {
checkHTTPStatus(t, r, 200, false)
unread, err := th.App.GetChannelUnread(c1.Id, u1.Id)
require.Nil(t, err)
assert.Equal(t, int64(1), unread.MsgCount)
assert.Equal(t, int64(2), unread.MsgCount)
})
t.Run("Unread on a private channel", func(t *testing.T) {
@ -2694,12 +2694,12 @@ func TestSetChannelUnread(t *testing.T) {
assert.Equal(t, 200, r.StatusCode)
unread, err := th.App.GetChannelUnread(th.BasicPrivateChannel.Id, u1.Id)
require.Nil(t, err)
assert.Equal(t, int64(0), unread.MsgCount)
assert.Equal(t, int64(1), unread.MsgCount)
r = th.Client.SetPostUnread(u1.Id, pp1.Id)
assert.Equal(t, 200, r.StatusCode)
unread, err = th.App.GetChannelUnread(th.BasicPrivateChannel.Id, u1.Id)
require.Nil(t, err)
assert.Equal(t, int64(1), unread.MsgCount)
assert.Equal(t, int64(2), unread.MsgCount)
})
t.Run("Can't unread an imaginary post", func(t *testing.T) {

View file

@ -1080,33 +1080,33 @@ func TestMarkChannelAsUnreadFromPost(t *testing.T) {
response, err := th.App.MarkChannelAsUnreadFromPost(p2.Id, u1.Id)
require.Nil(t, err)
require.NotNil(t, response)
assert.Equal(t, int64(3), response.MsgCount)
assert.Equal(t, int64(2), response.MsgCount)
unread, err := th.App.GetChannelUnread(c1.Id, u1.Id)
require.Nil(t, err)
assert.Equal(t, int64(1), unread.MsgCount)
assert.Equal(t, p2.CreateAt, response.LastViewedAt)
assert.Equal(t, int64(2), unread.MsgCount)
assert.Equal(t, p2.CreateAt-1, response.LastViewedAt)
})
t.Run("Unread last one", func(t *testing.T) {
response, err := th.App.MarkChannelAsUnreadFromPost(p3.Id, u1.Id)
require.Nil(t, err)
require.NotNil(t, response)
assert.Equal(t, int64(4), response.MsgCount)
assert.Equal(t, int64(3), response.MsgCount)
unread, err := th.App.GetChannelUnread(c1.Id, u1.Id)
require.Nil(t, err)
assert.Equal(t, int64(0), unread.MsgCount)
assert.Equal(t, p3.CreateAt, response.LastViewedAt)
assert.Equal(t, int64(1), unread.MsgCount)
assert.Equal(t, p3.CreateAt-1, response.LastViewedAt)
})
t.Run("Unread first one", func(t *testing.T) {
response, err := th.App.MarkChannelAsUnreadFromPost(p1.Id, u1.Id)
require.Nil(t, err)
require.NotNil(t, response)
assert.Equal(t, int64(2), response.MsgCount)
assert.Equal(t, int64(1), response.MsgCount)
unread, err := th.App.GetChannelUnread(c1.Id, u1.Id)
require.Nil(t, err)
assert.Equal(t, int64(2), unread.MsgCount)
assert.Equal(t, p1.CreateAt, response.LastViewedAt)
assert.Equal(t, int64(3), unread.MsgCount)
assert.Equal(t, p1.CreateAt-1, response.LastViewedAt)
})
t.Run("Other users are unaffected", func(t *testing.T) {
@ -1120,19 +1120,19 @@ func TestMarkChannelAsUnreadFromPost(t *testing.T) {
response, err := th.App.MarkChannelAsUnreadFromPost(pp1.Id, u1.Id)
require.Nil(t, err)
require.NotNil(t, response)
assert.Equal(t, int64(1), response.MsgCount)
assert.Equal(t, int64(0), response.MsgCount)
unread, err := th.App.GetChannelUnread(pc1.Id, u1.Id)
require.Nil(t, err)
assert.Equal(t, int64(1), unread.MsgCount)
assert.Equal(t, pp1.CreateAt, response.LastViewedAt)
assert.Equal(t, int64(2), unread.MsgCount)
assert.Equal(t, pp1.CreateAt-1, response.LastViewedAt)
response, err = th.App.MarkChannelAsUnreadFromPost(pp2.Id, u1.Id)
assert.Nil(t, err)
assert.Equal(t, int64(2), response.MsgCount)
assert.Equal(t, int64(1), response.MsgCount)
unread, err = th.App.GetChannelUnread(pc1.Id, u1.Id)
require.Nil(t, err)
assert.Equal(t, int64(0), unread.MsgCount)
assert.Equal(t, pp2.CreateAt, response.LastViewedAt)
assert.Equal(t, int64(1), unread.MsgCount)
assert.Equal(t, pp2.CreateAt-1, response.LastViewedAt)
})
t.Run("Can't unread an imaginary post", func(t *testing.T) {

View file

@ -1841,7 +1841,9 @@ func (s SqlChannelStore) CountPostsSince(channelID string, since int64) (int64,
// it returns a channelunread so redux can update the apps easily.
func (s SqlChannelStore) UpdateLastViewedAtPost(unreadPost *model.Post, userID string, mentionCount int) (*model.ChannelUnreadAt, *model.AppError) {
unread, appErr := s.CountPostsSince(unreadPost.ChannelId, unreadPost.CreateAt)
unreadDate := unreadPost.CreateAt - 1
unread, appErr := s.CountPostsSince(unreadPost.ChannelId, unreadDate)
if appErr != nil {
return nil, appErr
}
@ -1849,7 +1851,7 @@ func (s SqlChannelStore) UpdateLastViewedAtPost(unreadPost *model.Post, userID s
params := map[string]interface{}{
"mentions": mentionCount,
"unreadCount": unread,
"lastViewedAt": unreadPost.CreateAt,
"lastViewedAt": unreadDate,
"userId": userID,
"channelId": unreadPost.ChannelId,
"updatedAt": model.GetMillis(),