Channel.GetTeamChannels to sync by default (#11211)
Этот коммит содержится в:
коммит произвёл
Hanzei
родитель
7d08efc335
Коммит
a7278169d2
@@ -1697,11 +1697,11 @@ func (a *App) RemoveUserFromChannel(userIdToRemove string, removerUserId string,
|
||||
|
||||
func (a *App) GetNumberOfChannelsOnTeam(teamId string) (int, *model.AppError) {
|
||||
// Get total number of channels on current team
|
||||
result := <-a.Srv.Store.Channel().GetTeamChannels(teamId)
|
||||
if result.Err != nil {
|
||||
return 0, result.Err
|
||||
list, err := a.Srv.Store.Channel().GetTeamChannels(teamId)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return len(*result.Data.(*model.ChannelList)), nil
|
||||
return len(*list), nil
|
||||
}
|
||||
|
||||
func (a *App) SetActiveChannel(userId string, channelId string) *model.AppError {
|
||||
|
||||
@@ -1070,12 +1070,11 @@ func (a *App) PermanentDeleteTeam(team *model.Team) *model.AppError {
|
||||
return err
|
||||
}
|
||||
|
||||
if result := <-a.Srv.Store.Channel().GetTeamChannels(team.Id); result.Err != nil {
|
||||
if result.Err.Id != "store.sql_channel.get_channels.not_found.app_error" {
|
||||
return result.Err
|
||||
if channels, err := a.Srv.Store.Channel().GetTeamChannels(team.Id); err != nil {
|
||||
if err.Id != "store.sql_channel.get_channels.not_found.app_error" {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
channels := result.Data.(*model.ChannelList)
|
||||
for _, c := range *channels {
|
||||
a.PermanentDeleteChannel(c)
|
||||
}
|
||||
|
||||
@@ -2142,12 +2142,12 @@ func (a *App) GetViewUsersRestrictionsForTeam(userId string, teamId string) ([]s
|
||||
func (a *App) getListOfAllowedChannelsForTeam(teamId string, viewRestrictions *model.ViewUsersRestrictions) ([]string, *model.AppError) {
|
||||
var listOfAllowedChannels []string
|
||||
if viewRestrictions == nil || strings.Contains(strings.Join(viewRestrictions.Teams, "."), teamId) {
|
||||
result := <-a.Srv.Store.Channel().GetTeamChannels(teamId)
|
||||
if result.Err != nil {
|
||||
return nil, result.Err
|
||||
channels, err := a.Srv.Store.Channel().GetTeamChannels(teamId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
channelIds := []string{}
|
||||
for _, channel := range *result.Data.(*model.ChannelList) {
|
||||
for _, channel := range *channels {
|
||||
channelIds = append(channelIds, channel.Id)
|
||||
}
|
||||
|
||||
|
||||
@@ -1133,23 +1133,19 @@ func (s SqlChannelStore) GetChannelCounts(teamId string, userId string) (*model.
|
||||
return counts, nil
|
||||
}
|
||||
|
||||
func (s SqlChannelStore) GetTeamChannels(teamId string) store.StoreChannel {
|
||||
return store.Do(func(result *store.StoreResult) {
|
||||
data := &model.ChannelList{}
|
||||
_, err := s.GetReplica().Select(data, "SELECT * FROM Channels WHERE TeamId = :TeamId And Type != 'D' ORDER BY DisplayName", map[string]interface{}{"TeamId": teamId})
|
||||
func (s SqlChannelStore) GetTeamChannels(teamId string) (*model.ChannelList, *model.AppError) {
|
||||
data := &model.ChannelList{}
|
||||
_, err := s.GetReplica().Select(data, "SELECT * FROM Channels WHERE TeamId = :TeamId And Type != 'D' ORDER BY DisplayName", map[string]interface{}{"TeamId": teamId})
|
||||
|
||||
if err != nil {
|
||||
result.Err = model.NewAppError("SqlChannelStore.GetTeamChannels", "store.sql_channel.get_channels.get.app_error", nil, "teamId="+teamId+", err="+err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
return nil, model.NewAppError("SqlChannelStore.GetTeamChannels", "store.sql_channel.get_channels.get.app_error", nil, "teamId="+teamId+", err="+err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
if len(*data) == 0 {
|
||||
result.Err = model.NewAppError("SqlChannelStore.GetTeamChannels", "store.sql_channel.get_channels.not_found.app_error", nil, "teamId="+teamId, http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
if len(*data) == 0 {
|
||||
return nil, model.NewAppError("SqlChannelStore.GetTeamChannels", "store.sql_channel.get_channels.not_found.app_error", nil, "teamId="+teamId, http.StatusNotFound)
|
||||
}
|
||||
|
||||
result.Data = data
|
||||
})
|
||||
return data, nil
|
||||
}
|
||||
|
||||
func (s SqlChannelStore) GetByName(teamId string, name string, allowFromCache bool) store.StoreChannel {
|
||||
|
||||
@@ -153,7 +153,7 @@ type ChannelStore interface {
|
||||
GetPublicChannelsForTeam(teamId string, offset int, limit int) StoreChannel
|
||||
GetPublicChannelsByIdsForTeam(teamId string, channelIds []string) StoreChannel
|
||||
GetChannelCounts(teamId string, userId string) (*model.ChannelCounts, *model.AppError)
|
||||
GetTeamChannels(teamId string) StoreChannel
|
||||
GetTeamChannels(teamId string) (*model.ChannelList, *model.AppError)
|
||||
GetAll(teamId string) StoreChannel
|
||||
GetChannelsByIds(channelIds []string) ([]*model.Channel, *model.AppError)
|
||||
GetForPost(postId string) StoreChannel
|
||||
|
||||
@@ -432,10 +432,9 @@ func testChannelStoreGet(t *testing.T, ss store.Store, s SqlSupplier) {
|
||||
}
|
||||
}
|
||||
|
||||
if r3 := <-ss.Channel().GetTeamChannels(o1.TeamId); r3.Err != nil {
|
||||
t.Fatal(r3.Err)
|
||||
if channels, err := ss.Channel().GetTeamChannels(o1.TeamId); err != nil {
|
||||
t.Fatal(err)
|
||||
} else {
|
||||
channels := r3.Data.(*model.ChannelList)
|
||||
if len(*channels) == 0 {
|
||||
t.Fatal("too little")
|
||||
}
|
||||
|
||||
@@ -779,19 +779,28 @@ func (_m *ChannelStore) GetPublicChannelsForTeam(teamId string, offset int, limi
|
||||
}
|
||||
|
||||
// GetTeamChannels provides a mock function with given fields: teamId
|
||||
func (_m *ChannelStore) GetTeamChannels(teamId string) store.StoreChannel {
|
||||
func (_m *ChannelStore) GetTeamChannels(teamId string) (*model.ChannelList, *model.AppError) {
|
||||
ret := _m.Called(teamId)
|
||||
|
||||
var r0 store.StoreChannel
|
||||
if rf, ok := ret.Get(0).(func(string) store.StoreChannel); ok {
|
||||
var r0 *model.ChannelList
|
||||
if rf, ok := ret.Get(0).(func(string) *model.ChannelList); ok {
|
||||
r0 = rf(teamId)
|
||||
} 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) *model.AppError); ok {
|
||||
r1 = rf(teamId)
|
||||
} else {
|
||||
if ret.Get(1) != nil {
|
||||
r1 = ret.Get(1).(*model.AppError)
|
||||
}
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// IncrementMentionCount provides a mock function with given fields: channelId, userId
|
||||
|
||||
Ссылка в новой задаче
Block a user