From 79e4959d022114e26ea6349143c37ace708003a4 Mon Sep 17 00:00:00 2001 From: Zubair Ahmed Date: Wed, 2 Nov 2022 15:10:51 +0530 Subject: [PATCH] Return empty list of channels when requesting more channels at the end of cursor (#21557) --- api4/resolver_channel_test.go | 2 +- app/channel.go | 9 +-------- store/sqlstore/channel_store.go | 4 ---- store/storetest/channel_store.go | 16 ++++++++++++++++ 4 files changed, 18 insertions(+), 13 deletions(-) diff --git a/api4/resolver_channel_test.go b/api4/resolver_channel_test.go index d5a55dee16..7ecc12f06b 100644 --- a/api4/resolver_channel_test.go +++ b/api4/resolver_channel_test.go @@ -310,7 +310,7 @@ func TestGraphQLChannels(t *testing.T) { resp, err = th.MakeGraphQLRequest(&input) require.NoError(t, err) - require.Len(t, resp.Errors, 1) // no channels found + require.Len(t, resp.Errors, 0) // no errors for no channels found th.BasicChannel.Purpose = "newpurpose" _, _, err = th.Client.UpdateChannel(th.BasicChannel) diff --git a/app/channel.go b/app/channel.go index 504c7265d6..64d61c20aa 100644 --- a/app/channel.go +++ b/app/channel.go @@ -1876,15 +1876,8 @@ func (a *App) GetChannelsForTeamForUser(c request.CTX, teamID string, userID str func (a *App) GetChannelsForTeamForUserWithCursor(c request.CTX, teamID string, userID string, opts *model.ChannelSearchOpts, afterChannelID string) (model.ChannelList, *model.AppError) { list, err := a.Srv().Store().Channel().GetChannelsWithCursor(teamID, userID, opts, afterChannelID) if err != nil { - var nfErr *store.ErrNotFound - switch { - case errors.As(err, &nfErr): - return nil, model.NewAppError("GetChannelsForUser", "app.channel.get_channels.not_found.app_error", nil, "", http.StatusNotFound).Wrap(err) - default: - return nil, model.NewAppError("GetChannelsForUser", "app.channel.get_channels.get.app_error", nil, "", http.StatusInternalServerError).Wrap(err) - } + return nil, model.NewAppError("GetChannelsForUser", "app.channel.get_channels.get.app_error", nil, "", http.StatusInternalServerError).Wrap(err) } - return list, nil } diff --git a/store/sqlstore/channel_store.go b/store/sqlstore/channel_store.go index 78db001082..cfd30c85c2 100644 --- a/store/sqlstore/channel_store.go +++ b/store/sqlstore/channel_store.go @@ -1110,10 +1110,6 @@ func (s SqlChannelStore) GetChannelsWithCursor(teamId string, userId string, opt return nil, errors.Wrapf(err, "failed to get channels with TeamId=%s and UserId=%s", teamId, userId) } - if len(channels) == 0 { - return nil, store.NewErrNotFound("Channel", "userId="+userId) - } - return channels, nil } diff --git a/store/storetest/channel_store.go b/store/storetest/channel_store.go index 2138f011ed..c1843bc8be 100644 --- a/store/storetest/channel_store.go +++ b/store/storetest/channel_store.go @@ -3566,6 +3566,22 @@ func testChannelStoreGetChannelsWithCursor(t *testing.T, ss store.Store) { require.Len(t, list, 1) require.Equal(t, teamID, list[0].TeamId, "incorrect teamID") + // all channels should be returned + list, nErr = ss.Channel().GetChannelsWithCursor(o1.TeamId, m1.UserId, &model.ChannelSearchOpts{ + IncludeDeleted: false, + LastDeleteAt: 0, + }, "") + require.NoError(t, nErr) + require.Len(t, list, 3) + + // should return empty list + list, nErr = ss.Channel().GetChannelsWithCursor(o1.TeamId, m1.UserId, &model.ChannelSearchOpts{ + IncludeDeleted: false, + LastDeleteAt: 0, + }, list[2].Id) + require.NoError(t, nErr) + require.Len(t, list, 0) + // Sleeping to guarantee that the // UpdateAt is different. // The proper way would be to set UpdateAt during channel creation itself,