set update_at on bookmarks return when changing sort order (#28807)

* set update_at on bookmarks return when changing sort order

* update bookmarks sort order test
This commit is contained in:
Elias Nahum 2024-10-17 13:42:19 +08:00 committed by GitHub
parent 48cde8c0bf
commit f8f998bfcb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 18 additions and 2 deletions

View file

@ -963,8 +963,7 @@ func TestUpdateChannelBookmarkSortOrder(t *testing.T) {
})
t.Run("a websockets event should be fired as part of editing a bookmark's sort order", func(t *testing.T) {
t.Skip("MM-60499")
now := model.GetMillis()
webSocketClient, err := th.CreateWebSocketClient()
require.NoError(t, err)
webSocketClient.Listen()
@ -978,6 +977,14 @@ func TestUpdateChannelBookmarkSortOrder(t *testing.T) {
Emoji: ":smile:",
}
bookmark2 := &model.ChannelBookmark{
ChannelId: th.BasicChannel.Id,
DisplayName: "Link bookmark test 2",
LinkUrl: "https://mattermost.com",
Type: model.ChannelBookmarkLink,
Emoji: ":smile:",
}
// set the user for the session
originalSessionUserId := th.Context.Session().UserId
th.Context.Session().UserId = th.BasicUser.Id
@ -987,6 +994,10 @@ func TestUpdateChannelBookmarkSortOrder(t *testing.T) {
require.Nil(t, appErr)
require.NotNil(t, cb)
cb, appErr = th.App.CreateChannelBookmark(th.Context, bookmark2, "")
require.Nil(t, appErr)
require.NotNil(t, cb)
bookmarks, resp, err := th.Client.UpdateChannelBookmarkSortOrder(context.Background(), th.BasicChannel.Id, cb.Id, 0)
require.NoError(t, err)
CheckOKStatus(t, resp)
@ -1001,6 +1012,10 @@ func TestUpdateChannelBookmarkSortOrder(t *testing.T) {
if event.EventType() == model.WebsocketEventChannelBookmarkSorted {
err := json.Unmarshal([]byte(event.GetData()["bookmarks"].(string)), &bl)
require.NoError(t, err)
for _, b := range bl {
require.Greater(t, b.UpdateAt, now)
}
}
case <-timeout:
waiting = false

View file

@ -270,6 +270,7 @@ func (s *SqlChannelBookmarkStore) UpdateSortOrder(bookmarkId, channelId string,
ids := []string{}
for index, b := range bookmarks {
b.SortOrder = int64(index)
b.UpdateAt = now
caseStmt = caseStmt.When(sq.Eq{"Id": b.Id}, strconv.FormatInt(int64(index), 10))
ids = append(ids, b.Id)
}