mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
Channel.GetPublicChannelsForTeam to sync by default (#11208)
* Channel.GetPublicChannelsForTeam to sync by default * var rename
This commit is contained in:
committed by
Jesús Espino
parent
be5c962913
commit
de8a60225b
@@ -1258,11 +1258,7 @@ func (a *App) GetPublicChannelsByIdsForTeam(teamId string, channelIds []string)
|
||||
}
|
||||
|
||||
func (a *App) GetPublicChannelsForTeam(teamId string, offset int, limit int) (*model.ChannelList, *model.AppError) {
|
||||
result := <-a.Srv.Store.Channel().GetPublicChannelsForTeam(teamId, offset, limit)
|
||||
if result.Err != nil {
|
||||
return nil, result.Err
|
||||
}
|
||||
return result.Data.(*model.ChannelList), nil
|
||||
return a.Srv.Store.Channel().GetPublicChannelsForTeam(teamId, offset, limit)
|
||||
}
|
||||
|
||||
func (a *App) GetChannelMember(channelId string, userId string) (*model.ChannelMember, *model.AppError) {
|
||||
|
||||
@@ -1031,35 +1031,32 @@ func (s SqlChannelStore) GetMoreChannels(teamId string, userId string, offset in
|
||||
return channels, nil
|
||||
}
|
||||
|
||||
func (s SqlChannelStore) GetPublicChannelsForTeam(teamId string, offset int, limit int) store.StoreChannel {
|
||||
return store.Do(func(result *store.StoreResult) {
|
||||
data := &model.ChannelList{}
|
||||
_, err := s.GetReplica().Select(data, `
|
||||
SELECT
|
||||
Channels.*
|
||||
FROM
|
||||
Channels
|
||||
JOIN
|
||||
PublicChannels pc ON (pc.Id = Channels.Id)
|
||||
WHERE
|
||||
pc.TeamId = :TeamId
|
||||
AND pc.DeleteAt = 0
|
||||
ORDER BY pc.DisplayName
|
||||
LIMIT :Limit
|
||||
OFFSET :Offset
|
||||
func (s SqlChannelStore) GetPublicChannelsForTeam(teamId string, offset int, limit int) (*model.ChannelList, *model.AppError) {
|
||||
channels := &model.ChannelList{}
|
||||
_, err := s.GetReplica().Select(channels, `
|
||||
SELECT
|
||||
Channels.*
|
||||
FROM
|
||||
Channels
|
||||
JOIN
|
||||
PublicChannels pc ON (pc.Id = Channels.Id)
|
||||
WHERE
|
||||
pc.TeamId = :TeamId
|
||||
AND pc.DeleteAt = 0
|
||||
ORDER BY pc.DisplayName
|
||||
LIMIT :Limit
|
||||
OFFSET :Offset
|
||||
`, map[string]interface{}{
|
||||
"TeamId": teamId,
|
||||
"Limit": limit,
|
||||
"Offset": offset,
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
result.Err = model.NewAppError("SqlChannelStore.GetPublicChannelsForTeam", "store.sql_channel.get_public_channels.get.app_error", nil, "teamId="+teamId+", err="+err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
result.Data = data
|
||||
"TeamId": teamId,
|
||||
"Limit": limit,
|
||||
"Offset": offset,
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return nil, model.NewAppError("SqlChannelStore.GetPublicChannelsForTeam", "store.sql_channel.get_public_channels.get.app_error", nil, "teamId="+teamId+", err="+err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
return channels, nil
|
||||
}
|
||||
|
||||
func (s SqlChannelStore) GetPublicChannelsByIdsForTeam(teamId string, channelIds []string) (*model.ChannelList, *model.AppError) {
|
||||
|
||||
@@ -150,7 +150,7 @@ type ChannelStore interface {
|
||||
GetChannels(teamId string, userId string, includeDeleted bool) (*model.ChannelList, *model.AppError)
|
||||
GetAllChannels(page, perPage int, opts ChannelSearchOpts) StoreChannel
|
||||
GetMoreChannels(teamId string, userId string, offset int, limit int) (*model.ChannelList, *model.AppError)
|
||||
GetPublicChannelsForTeam(teamId string, offset int, limit int) StoreChannel
|
||||
GetPublicChannelsForTeam(teamId string, offset int, limit int) (*model.ChannelList, *model.AppError)
|
||||
GetPublicChannelsByIdsForTeam(teamId string, channelIds []string) (*model.ChannelList, *model.AppError)
|
||||
GetChannelCounts(teamId string, userId string) (*model.ChannelCounts, *model.AppError)
|
||||
GetTeamChannels(teamId string) (*model.ChannelList, *model.AppError)
|
||||
|
||||
@@ -1359,9 +1359,9 @@ func testChannelStoreGetPublicChannelsForTeam(t *testing.T, ss store.Store) {
|
||||
require.Nil(t, err)
|
||||
|
||||
t.Run("only o1 initially listed in public channels", func(t *testing.T) {
|
||||
result := <-ss.Channel().GetPublicChannelsForTeam(teamId, 0, 100)
|
||||
require.Nil(t, result.Err)
|
||||
require.Equal(t, &model.ChannelList{&o1}, result.Data.(*model.ChannelList))
|
||||
list, channelErr := ss.Channel().GetPublicChannelsForTeam(teamId, 0, 100)
|
||||
require.Nil(t, channelErr)
|
||||
require.Equal(t, &model.ChannelList{&o1}, list)
|
||||
})
|
||||
|
||||
// o4 is another public channel on the team
|
||||
@@ -1387,21 +1387,21 @@ func testChannelStoreGetPublicChannelsForTeam(t *testing.T, ss store.Store) {
|
||||
require.Nil(t, err, "channel should have been deleted")
|
||||
|
||||
t.Run("both o1 and o4 listed in public channels", func(t *testing.T) {
|
||||
cresult := <-ss.Channel().GetPublicChannelsForTeam(teamId, 0, 100)
|
||||
require.Nil(t, cresult.Err)
|
||||
require.Equal(t, &model.ChannelList{&o1, &o4}, cresult.Data.(*model.ChannelList))
|
||||
list, err := ss.Channel().GetPublicChannelsForTeam(teamId, 0, 100)
|
||||
require.Nil(t, err)
|
||||
require.Equal(t, &model.ChannelList{&o1, &o4}, list)
|
||||
})
|
||||
|
||||
t.Run("only o1 listed in public channels with offset 0, limit 1", func(t *testing.T) {
|
||||
result := <-ss.Channel().GetPublicChannelsForTeam(teamId, 0, 1)
|
||||
require.Nil(t, result.Err)
|
||||
require.Equal(t, &model.ChannelList{&o1}, result.Data.(*model.ChannelList))
|
||||
list, err := ss.Channel().GetPublicChannelsForTeam(teamId, 0, 1)
|
||||
require.Nil(t, err)
|
||||
require.Equal(t, &model.ChannelList{&o1}, list)
|
||||
})
|
||||
|
||||
t.Run("only o4 listed in public channels with offset 1, limit 1", func(t *testing.T) {
|
||||
result := <-ss.Channel().GetPublicChannelsForTeam(teamId, 1, 1)
|
||||
require.Nil(t, result.Err)
|
||||
require.Equal(t, &model.ChannelList{&o4}, result.Data.(*model.ChannelList))
|
||||
list, err := ss.Channel().GetPublicChannelsForTeam(teamId, 1, 1)
|
||||
require.Nil(t, err)
|
||||
require.Equal(t, &model.ChannelList{&o4}, list)
|
||||
})
|
||||
|
||||
t.Run("verify analytics for open channels", func(t *testing.T) {
|
||||
|
||||
@@ -878,19 +878,28 @@ func (_m *ChannelStore) GetPublicChannelsByIdsForTeam(teamId string, channelIds
|
||||
}
|
||||
|
||||
// GetPublicChannelsForTeam provides a mock function with given fields: teamId, offset, limit
|
||||
func (_m *ChannelStore) GetPublicChannelsForTeam(teamId string, offset int, limit int) store.StoreChannel {
|
||||
func (_m *ChannelStore) GetPublicChannelsForTeam(teamId string, offset int, limit int) (*model.ChannelList, *model.AppError) {
|
||||
ret := _m.Called(teamId, offset, limit)
|
||||
|
||||
var r0 store.StoreChannel
|
||||
if rf, ok := ret.Get(0).(func(string, int, int) store.StoreChannel); ok {
|
||||
var r0 *model.ChannelList
|
||||
if rf, ok := ret.Get(0).(func(string, int, int) *model.ChannelList); ok {
|
||||
r0 = rf(teamId, offset, limit)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(store.StoreChannel)
|
||||
r0 = ret.Get(0).(*model.ChannelList)
|
||||
}
|
||||
}
|
||||
|
||||
return r0
|
||||
var r1 *model.AppError
|
||||
if rf, ok := ret.Get(1).(func(string, int, int) *model.AppError); ok {
|
||||
r1 = rf(teamId, offset, limit)
|
||||
} else {
|
||||
if ret.Get(1) != nil {
|
||||
r1 = ret.Get(1).(*model.AppError)
|
||||
}
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// GetTeamChannels provides a mock function with given fields: teamId
|
||||
|
||||
Reference in New Issue
Block a user