Channel.GetPublicChannelsByIdsForTeam to sync by default (#11209)
Этот коммит содержится в:
коммит произвёл
Gabe Jackson
родитель
e92ecf6696
Коммит
c8f334ab1c
@@ -1258,11 +1258,7 @@ func (a *App) GetChannelsUserNotIn(teamId string, userId string, offset int, lim
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) GetPublicChannelsByIdsForTeam(teamId string, channelIds []string) (*model.ChannelList, *model.AppError) {
|
func (a *App) GetPublicChannelsByIdsForTeam(teamId string, channelIds []string) (*model.ChannelList, *model.AppError) {
|
||||||
result := <-a.Srv.Store.Channel().GetPublicChannelsByIdsForTeam(teamId, channelIds)
|
return a.Srv.Store.Channel().GetPublicChannelsByIdsForTeam(teamId, channelIds)
|
||||||
if result.Err != nil {
|
|
||||||
return nil, result.Err
|
|
||||||
}
|
|
||||||
return result.Data.(*model.ChannelList), nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) GetPublicChannelsForTeam(teamId string, offset int, limit int) (*model.ChannelList, *model.AppError) {
|
func (a *App) GetPublicChannelsForTeam(teamId string, offset int, limit int) (*model.ChannelList, *model.AppError) {
|
||||||
|
|||||||
@@ -1066,47 +1066,45 @@ func (s SqlChannelStore) GetPublicChannelsForTeam(teamId string, offset int, lim
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s SqlChannelStore) GetPublicChannelsByIdsForTeam(teamId string, channelIds []string) store.StoreChannel {
|
func (s SqlChannelStore) GetPublicChannelsByIdsForTeam(teamId string, channelIds []string) (*model.ChannelList, *model.AppError) {
|
||||||
return store.Do(func(result *store.StoreResult) {
|
props := make(map[string]interface{})
|
||||||
props := make(map[string]interface{})
|
props["teamId"] = teamId
|
||||||
props["teamId"] = teamId
|
|
||||||
|
|
||||||
idQuery := ""
|
idQuery := ""
|
||||||
|
|
||||||
for index, channelId := range channelIds {
|
for index, channelId := range channelIds {
|
||||||
if len(idQuery) > 0 {
|
if len(idQuery) > 0 {
|
||||||
idQuery += ", "
|
idQuery += ", "
|
||||||
}
|
|
||||||
|
|
||||||
props["channelId"+strconv.Itoa(index)] = channelId
|
|
||||||
idQuery += ":channelId" + strconv.Itoa(index)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
data := &model.ChannelList{}
|
props["channelId"+strconv.Itoa(index)] = channelId
|
||||||
_, err := s.GetReplica().Select(data, `
|
idQuery += ":channelId" + strconv.Itoa(index)
|
||||||
SELECT
|
}
|
||||||
Channels.*
|
|
||||||
FROM
|
data := &model.ChannelList{}
|
||||||
Channels
|
_, err := s.GetReplica().Select(data, `
|
||||||
JOIN
|
SELECT
|
||||||
PublicChannels pc ON (pc.Id = Channels.Id)
|
Channels.*
|
||||||
WHERE
|
FROM
|
||||||
pc.TeamId = :teamId
|
Channels
|
||||||
AND pc.DeleteAt = 0
|
JOIN
|
||||||
AND pc.Id IN (`+idQuery+`)
|
PublicChannels pc ON (pc.Id = Channels.Id)
|
||||||
ORDER BY pc.DisplayName
|
WHERE
|
||||||
|
pc.TeamId = :teamId
|
||||||
|
AND pc.DeleteAt = 0
|
||||||
|
AND pc.Id IN (`+idQuery+`)
|
||||||
|
ORDER BY pc.DisplayName
|
||||||
`, props)
|
`, props)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
result.Err = model.NewAppError("SqlChannelStore.GetPublicChannelsByIdsForTeam", "store.sql_channel.get_channels_by_ids.get.app_error", nil, err.Error(), http.StatusInternalServerError)
|
return nil, model.NewAppError("SqlChannelStore.GetPublicChannelsByIdsForTeam", "store.sql_channel.get_channels_by_ids.get.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(*data) == 0 {
|
if len(*data) == 0 {
|
||||||
result.Err = model.NewAppError("SqlChannelStore.GetPublicChannelsByIdsForTeam", "store.sql_channel.get_channels_by_ids.not_found.app_error", nil, "", http.StatusNotFound)
|
return nil, model.NewAppError("SqlChannelStore.GetPublicChannelsByIdsForTeam", "store.sql_channel.get_channels_by_ids.not_found.app_error", nil, "", http.StatusNotFound)
|
||||||
}
|
}
|
||||||
|
|
||||||
result.Data = data
|
return data, nil
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type channelIdWithCountAndUpdateAt struct {
|
type channelIdWithCountAndUpdateAt struct {
|
||||||
|
|||||||
@@ -151,7 +151,7 @@ type ChannelStore interface {
|
|||||||
GetAllChannels(page, perPage int, opts ChannelSearchOpts) StoreChannel
|
GetAllChannels(page, perPage int, opts ChannelSearchOpts) StoreChannel
|
||||||
GetMoreChannels(teamId string, userId string, offset int, limit int) (*model.ChannelList, *model.AppError)
|
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) StoreChannel
|
||||||
GetPublicChannelsByIdsForTeam(teamId string, channelIds []string) StoreChannel
|
GetPublicChannelsByIdsForTeam(teamId string, channelIds []string) (*model.ChannelList, *model.AppError)
|
||||||
GetChannelCounts(teamId string, userId string) (*model.ChannelCounts, *model.AppError)
|
GetChannelCounts(teamId string, userId string) (*model.ChannelCounts, *model.AppError)
|
||||||
GetTeamChannels(teamId string) (*model.ChannelList, *model.AppError)
|
GetTeamChannels(teamId string) (*model.ChannelList, *model.AppError)
|
||||||
GetAll(teamId string) StoreChannel
|
GetAll(teamId string) StoreChannel
|
||||||
|
|||||||
@@ -1450,15 +1450,15 @@ func testChannelStoreGetPublicChannelsByIdsForTeam(t *testing.T, ss store.Store)
|
|||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
|
|
||||||
t.Run("oc1 by itself should be found as a public channel in the team", func(t *testing.T) {
|
t.Run("oc1 by itself should be found as a public channel in the team", func(t *testing.T) {
|
||||||
result := <-ss.Channel().GetPublicChannelsByIdsForTeam(teamId, []string{oc1.Id})
|
list, channelErr := ss.Channel().GetPublicChannelsByIdsForTeam(teamId, []string{oc1.Id})
|
||||||
require.Nil(t, result.Err)
|
require.Nil(t, channelErr)
|
||||||
require.Equal(t, &model.ChannelList{&oc1}, result.Data.(*model.ChannelList))
|
require.Equal(t, &model.ChannelList{&oc1}, list)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("only oc1, among others, should be found as a public channel in the team", func(t *testing.T) {
|
t.Run("only oc1, among others, should be found as a public channel in the team", func(t *testing.T) {
|
||||||
result := <-ss.Channel().GetPublicChannelsByIdsForTeam(teamId, []string{oc1.Id, oc2.Id, model.NewId(), pc3.Id})
|
list, channelErr := ss.Channel().GetPublicChannelsByIdsForTeam(teamId, []string{oc1.Id, oc2.Id, model.NewId(), pc3.Id})
|
||||||
require.Nil(t, result.Err)
|
require.Nil(t, channelErr)
|
||||||
require.Equal(t, &model.ChannelList{&oc1}, result.Data.(*model.ChannelList))
|
require.Equal(t, &model.ChannelList{&oc1}, list)
|
||||||
})
|
})
|
||||||
|
|
||||||
// oc4 is another public channel on the team
|
// oc4 is another public channel on the team
|
||||||
@@ -1485,15 +1485,15 @@ func testChannelStoreGetPublicChannelsByIdsForTeam(t *testing.T, ss store.Store)
|
|||||||
require.Nil(t, err, "channel should have been deleted")
|
require.Nil(t, err, "channel should have been deleted")
|
||||||
|
|
||||||
t.Run("only oc1 and oc4, among others, should be found as a public channel in the team", func(t *testing.T) {
|
t.Run("only oc1 and oc4, among others, should be found as a public channel in the team", func(t *testing.T) {
|
||||||
result := <-ss.Channel().GetPublicChannelsByIdsForTeam(teamId, []string{oc1.Id, oc2.Id, model.NewId(), pc3.Id, oc4.Id})
|
list, err := ss.Channel().GetPublicChannelsByIdsForTeam(teamId, []string{oc1.Id, oc2.Id, model.NewId(), pc3.Id, oc4.Id})
|
||||||
require.Nil(t, result.Err)
|
require.Nil(t, err)
|
||||||
require.Equal(t, &model.ChannelList{&oc1, &oc4}, result.Data.(*model.ChannelList))
|
require.Equal(t, &model.ChannelList{&oc1, &oc4}, list)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("random channel id should not be found as a public channel in the team", func(t *testing.T) {
|
t.Run("random channel id should not be found as a public channel in the team", func(t *testing.T) {
|
||||||
result := <-ss.Channel().GetPublicChannelsByIdsForTeam(teamId, []string{model.NewId()})
|
_, err := ss.Channel().GetPublicChannelsByIdsForTeam(teamId, []string{model.NewId()})
|
||||||
require.NotNil(t, result.Err)
|
require.NotNil(t, err)
|
||||||
require.Equal(t, result.Err.Id, "store.sql_channel.get_channels_by_ids.not_found.app_error")
|
require.Equal(t, err.Id, "store.sql_channel.get_channels_by_ids.not_found.app_error")
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -774,19 +774,28 @@ func (_m *ChannelStore) GetPinnedPosts(channelId string) store.StoreChannel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetPublicChannelsByIdsForTeam provides a mock function with given fields: teamId, channelIds
|
// GetPublicChannelsByIdsForTeam provides a mock function with given fields: teamId, channelIds
|
||||||
func (_m *ChannelStore) GetPublicChannelsByIdsForTeam(teamId string, channelIds []string) store.StoreChannel {
|
func (_m *ChannelStore) GetPublicChannelsByIdsForTeam(teamId string, channelIds []string) (*model.ChannelList, *model.AppError) {
|
||||||
ret := _m.Called(teamId, channelIds)
|
ret := _m.Called(teamId, channelIds)
|
||||||
|
|
||||||
var r0 store.StoreChannel
|
var r0 *model.ChannelList
|
||||||
if rf, ok := ret.Get(0).(func(string, []string) store.StoreChannel); ok {
|
if rf, ok := ret.Get(0).(func(string, []string) *model.ChannelList); ok {
|
||||||
r0 = rf(teamId, channelIds)
|
r0 = rf(teamId, channelIds)
|
||||||
} else {
|
} else {
|
||||||
if ret.Get(0) != nil {
|
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, []string) *model.AppError); ok {
|
||||||
|
r1 = rf(teamId, channelIds)
|
||||||
|
} else {
|
||||||
|
if ret.Get(1) != nil {
|
||||||
|
r1 = ret.Get(1).(*model.AppError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return r0, r1
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetPublicChannelsForTeam provides a mock function with given fields: teamId, offset, limit
|
// GetPublicChannelsForTeam provides a mock function with given fields: teamId, offset, limit
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user