MM42267: Add member count in the browse channel modal (#23800)
* add base for calling the endpoint * add endpoint and handler * update store and layers * call the endpoint * align types * update app layers * generate mocks * complete handler * finish store query * add todos * add ui for member count * add selector * add a todo * add cache layer * optimize calls in FE * handle invalidation of the cache * fix go style * fix test * use existing channel layer count * fix import error * delete unnecessary code * write tests for channel cache layer * fix testname * fix mocks * fix cache layer test * fix a test * really fix the test * write more tests for server * address PR comments * remove comment * rename more_channels to browse_channels * fix style * update snapshot * add translations * Revert "add translations" This reverts commit 56476a5dabe357703ef02be9a38b3e88f5c8b1e7. * add only related translations * address PR review points * add test * fix test --------- Co-authored-by: Mattermost Build <build@mattermost.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
4803889158
Коммит
628273d98d
@@ -625,6 +625,7 @@ type AppIface interface {
|
||||
GetChannelsForTeamForUser(c request.CTX, teamID string, userID string, opts *model.ChannelSearchOpts) (model.ChannelList, *model.AppError)
|
||||
GetChannelsForTeamForUserWithCursor(c request.CTX, teamID string, userID string, opts *model.ChannelSearchOpts, afterChannelID string) (model.ChannelList, *model.AppError)
|
||||
GetChannelsForUser(c request.CTX, userID string, includeDeleted bool, lastDeleteAt, pageSize int, fromChannelID string) (model.ChannelList, *model.AppError)
|
||||
GetChannelsMemberCount(c request.CTX, channelIDs []string) (map[string]int64, *model.AppError)
|
||||
GetChannelsUserNotIn(c request.CTX, teamID string, userID string, offset int, limit int) (model.ChannelList, *model.AppError)
|
||||
GetCloudSession(token string) (*model.Session, *model.AppError)
|
||||
GetClusterId() string
|
||||
|
||||
@@ -1834,6 +1834,20 @@ func (a *App) GetChannels(c request.CTX, channelIDs []string) ([]*model.Channel,
|
||||
return channels, nil
|
||||
}
|
||||
|
||||
func (a *App) GetChannelsMemberCount(c request.CTX, channelIDs []string) (map[string]int64, *model.AppError) {
|
||||
channelsCount, err := a.Srv().Store().Channel().GetChannelsMemberCount(channelIDs)
|
||||
if err != nil {
|
||||
var nfErr *store.ErrNotFound
|
||||
switch {
|
||||
case errors.As(err, &nfErr):
|
||||
return nil, model.NewAppError("GetChannelsMemberCount", "app.channel.get_channels_member_count.existing.app_error", nil, "", http.StatusNotFound).Wrap(err)
|
||||
default:
|
||||
return nil, model.NewAppError("GetChannelsMemberCount", "app.channel.get_channels_member_count.find.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
}
|
||||
}
|
||||
return channelsCount, nil
|
||||
}
|
||||
|
||||
func (a *App) GetChannelByName(c request.CTX, channelName, teamID string, includeDeleted bool) (*model.Channel, *model.AppError) {
|
||||
var channel *model.Channel
|
||||
var err error
|
||||
|
||||
@@ -2195,6 +2195,24 @@ func TestGetMemberCountsByGroup(t *testing.T) {
|
||||
require.ElementsMatch(t, cmc, resp)
|
||||
}
|
||||
|
||||
func TestGetChannelsMemberCount(t *testing.T) {
|
||||
th := SetupWithStoreMock(t)
|
||||
defer th.TearDown()
|
||||
|
||||
mockStore := th.App.Srv().Store().(*mocks.Store)
|
||||
mockChannelStore := mocks.ChannelStore{}
|
||||
channelsMemberCount := map[string]int64{
|
||||
"channel1": int64(10),
|
||||
"channel2": int64(20),
|
||||
}
|
||||
mockChannelStore.On("GetChannelsMemberCount", []string{"channel1", "channel2"}).Return(channelsMemberCount, nil)
|
||||
mockStore.On("Channel").Return(&mockChannelStore)
|
||||
mockStore.On("GetDBSchemaVersion").Return(1, nil)
|
||||
resp, err := th.App.GetChannelsMemberCount(th.Context, []string{"channel1", "channel2"})
|
||||
require.Nil(t, err)
|
||||
require.Equal(t, channelsMemberCount, resp)
|
||||
}
|
||||
|
||||
func TestViewChannelCollapsedThreadsTurnedOff(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
@@ -5612,6 +5612,28 @@ func (a *OpenTracingAppLayer) GetChannelsForUser(c request.CTX, userID string, i
|
||||
return resultVar0, resultVar1
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) GetChannelsMemberCount(c request.CTX, channelIDs []string) (map[string]int64, *model.AppError) {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.GetChannelsMemberCount")
|
||||
|
||||
a.ctx = newCtx
|
||||
a.app.Srv().Store().SetContext(newCtx)
|
||||
defer func() {
|
||||
a.app.Srv().Store().SetContext(origCtx)
|
||||
a.ctx = origCtx
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
resultVar0, resultVar1 := a.app.GetChannelsMemberCount(c, channelIDs)
|
||||
|
||||
if resultVar1 != nil {
|
||||
span.LogFields(spanlog.Error(resultVar1))
|
||||
ext.Error.Set(span, true)
|
||||
}
|
||||
|
||||
return resultVar0, resultVar1
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) GetChannelsUserNotIn(c request.CTX, teamID string, userID string, offset int, limit int) (model.ChannelList, *model.AppError) {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.GetChannelsUserNotIn")
|
||||
|
||||
Ссылка в новой задаче
Block a user