From f8f998bfcbeffed8ef6e11244855e205e07e750a Mon Sep 17 00:00:00 2001 From: Elias Nahum Date: Thu, 17 Oct 2024 13:42:19 +0800 Subject: [PATCH] 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 --- server/channels/api4/channel_bookmark_test.go | 19 +++++++++++++++++-- .../store/sqlstore/channel_bookmark_store.go | 1 + 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/server/channels/api4/channel_bookmark_test.go b/server/channels/api4/channel_bookmark_test.go index 4f323d06237..4b9486ea651 100644 --- a/server/channels/api4/channel_bookmark_test.go +++ b/server/channels/api4/channel_bookmark_test.go @@ -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 diff --git a/server/channels/store/sqlstore/channel_bookmark_store.go b/server/channels/store/sqlstore/channel_bookmark_store.go index f0a7a5baa77..cd16b24b803 100644 --- a/server/channels/store/sqlstore/channel_bookmark_store.go +++ b/server/channels/store/sqlstore/channel_bookmark_store.go @@ -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) }