MM-49845: fixes acknowledgements in getpostsince (#22124)
* MM-49845: fixes acknowledgements in getpostsince GetPostsSince returns posts updated after a user requested date. If a user acknowledges a post the post's update at won't change thus not getting that post returned from GetPostsSince. This is troublesome particularly for the mobile client since it relies a lot to GetPostsSince for keeping the data up to date. This commit updates the post's update_at when a user acknowledges/un-acknowledges a post fixing this way the issue above. * Fixes linter * Apply suggestions from code review style changes Co-authored-by: Jesse Hallam <jesse@thehallams.ca> * Rename ack to acknowledgement Co-authored-by: Jesse Hallam <jesse@thehallams.ca>
Этот коммит содержится в:
@@ -42,6 +42,9 @@ func (a *App) SaveAcknowledgementForPost(c *request.Context, postID, userID stri
|
||||
}
|
||||
}
|
||||
|
||||
// The post is always modified since the UpdateAt always changes
|
||||
a.invalidateCacheForChannelPosts(channel.Id)
|
||||
|
||||
a.Srv().Go(func() {
|
||||
a.sendAcknowledgementEvent(model.WebsocketEventAcknowledgementAdded, acknowledgement, post)
|
||||
})
|
||||
@@ -85,6 +88,9 @@ func (a *App) DeleteAcknowledgementForPost(c *request.Context, postID, userID st
|
||||
return model.NewAppError("DeleteAcknowledgementForPost", "app.acknowledgement.delete.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr)
|
||||
}
|
||||
|
||||
// The post is always modified since the UpdateAt always changes
|
||||
a.invalidateCacheForChannelPosts(channel.Id)
|
||||
|
||||
a.Srv().Go(func() {
|
||||
a.sendAcknowledgementEvent(model.WebsocketEventAcknowledgementRemoved, oldAck, post)
|
||||
})
|
||||
|
||||
@@ -36,21 +36,41 @@ func testSaveAcknowledgementForPost(t *testing.T) {
|
||||
require.Equal(t, post.Id, acknowledgment.PostId)
|
||||
require.Equal(t, th.BasicUser.Id, acknowledgment.UserId)
|
||||
})
|
||||
|
||||
t.Run("saving acknowledgment should update the post's update_at", func(t *testing.T) {
|
||||
post, err := th.App.CreatePostAsUser(th.Context, &model.Post{
|
||||
UserId: th.BasicUser.Id,
|
||||
ChannelId: th.BasicChannel.Id,
|
||||
Message: "message",
|
||||
}, "", true)
|
||||
|
||||
require.Nil(t, err)
|
||||
|
||||
oldUpdateAt := post.UpdateAt
|
||||
|
||||
_, err = th.App.SaveAcknowledgementForPost(th.Context, post.Id, th.BasicUser.Id)
|
||||
require.Nil(t, err)
|
||||
|
||||
post, err = th.App.GetSinglePost(post.Id, false)
|
||||
require.Nil(t, err)
|
||||
|
||||
require.Greater(t, post.UpdateAt, oldUpdateAt)
|
||||
})
|
||||
}
|
||||
|
||||
func testDeleteAcknowledgementForPost(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
post, err := th.App.CreatePostAsUser(th.Context, &model.Post{
|
||||
post, err1 := th.App.CreatePostAsUser(th.Context, &model.Post{
|
||||
UserId: th.BasicUser.Id,
|
||||
ChannelId: th.BasicChannel.Id,
|
||||
CreateAt: model.GetMillis(),
|
||||
Message: "message",
|
||||
}, "", true)
|
||||
require.Nil(t, err)
|
||||
require.Nil(t, err1)
|
||||
|
||||
t.Run("delete acknowledgment for post should delete acknowledgement", func(t *testing.T) {
|
||||
_, err = th.App.SaveAcknowledgementForPost(th.Context, post.Id, th.BasicUser.Id)
|
||||
_, err := th.App.SaveAcknowledgementForPost(th.Context, post.Id, th.BasicUser.Id)
|
||||
require.Nil(t, err)
|
||||
|
||||
acknowledgments, err := th.App.GetAcknowledgementsForPost(post.Id)
|
||||
@@ -66,6 +86,24 @@ func testDeleteAcknowledgementForPost(t *testing.T) {
|
||||
require.Empty(t, acknowledgments)
|
||||
})
|
||||
|
||||
t.Run("deleting acknowledgment should update the post's update_at", func(t *testing.T) {
|
||||
_, err := th.App.SaveAcknowledgementForPost(th.Context, post.Id, th.BasicUser.Id)
|
||||
require.Nil(t, err)
|
||||
|
||||
post, err = th.App.GetSinglePost(post.Id, false)
|
||||
require.Nil(t, err)
|
||||
|
||||
oldUpdateAt := post.UpdateAt
|
||||
|
||||
err = th.App.DeleteAcknowledgementForPost(th.Context, post.Id, th.BasicUser.Id)
|
||||
require.Nil(t, err)
|
||||
|
||||
post, err = th.App.GetSinglePost(post.Id, false)
|
||||
require.Nil(t, err)
|
||||
|
||||
require.Greater(t, post.UpdateAt, oldUpdateAt)
|
||||
})
|
||||
|
||||
t.Run("delete acknowledgment for post after 5 min after acknowledged should not delete", func(t *testing.T) {
|
||||
_, nErr := th.App.Srv().Store().PostAcknowledgement().Save(post.Id, th.BasicUser.Id, model.GetMillis()-int64(6*60*1000))
|
||||
require.NoError(t, nErr)
|
||||
|
||||
Ссылка в новой задаче
Block a user