Channel.GetChannelCounts to sync by default (#11210)
Этот коммит содержится в:
коммит произвёл
Jesús Espino
родитель
5a3fed4534
Коммит
27a88b7868
@@ -1355,11 +1355,7 @@ func (a *App) GetChannelMemberCount(channelId string) (int64, *model.AppError) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) GetChannelCounts(teamId string, userId string) (*model.ChannelCounts, *model.AppError) {
|
func (a *App) GetChannelCounts(teamId string, userId string) (*model.ChannelCounts, *model.AppError) {
|
||||||
result := <-a.Srv.Store.Channel().GetChannelCounts(teamId, userId)
|
return a.Srv.Store.Channel().GetChannelCounts(teamId, userId)
|
||||||
if result.Err != nil {
|
|
||||||
return nil, result.Err
|
|
||||||
}
|
|
||||||
return result.Data.(*model.ChannelCounts), nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) GetChannelUnread(channelId, userId string) (*model.ChannelUnread, *model.AppError) {
|
func (a *App) GetChannelUnread(channelId, userId string) (*model.ChannelUnread, *model.AppError) {
|
||||||
|
|||||||
@@ -1115,25 +1115,22 @@ type channelIdWithCountAndUpdateAt struct {
|
|||||||
UpdateAt int64
|
UpdateAt int64
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s SqlChannelStore) GetChannelCounts(teamId string, userId string) store.StoreChannel {
|
func (s SqlChannelStore) GetChannelCounts(teamId string, userId string) (*model.ChannelCounts, *model.AppError) {
|
||||||
return store.Do(func(result *store.StoreResult) {
|
var data []channelIdWithCountAndUpdateAt
|
||||||
var data []channelIdWithCountAndUpdateAt
|
_, err := s.GetReplica().Select(&data, "SELECT Id, TotalMsgCount, UpdateAt FROM Channels WHERE Id IN (SELECT ChannelId FROM ChannelMembers WHERE UserId = :UserId) AND (TeamId = :TeamId OR TeamId = '') AND DeleteAt = 0 ORDER BY DisplayName", map[string]interface{}{"TeamId": teamId, "UserId": userId})
|
||||||
_, err := s.GetReplica().Select(&data, "SELECT Id, TotalMsgCount, UpdateAt FROM Channels WHERE Id IN (SELECT ChannelId FROM ChannelMembers WHERE UserId = :UserId) AND (TeamId = :TeamId OR TeamId = '') AND DeleteAt = 0 ORDER BY DisplayName", map[string]interface{}{"TeamId": teamId, "UserId": userId})
|
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
result.Err = model.NewAppError("SqlChannelStore.GetChannelCounts", "store.sql_channel.get_channel_counts.get.app_error", nil, "teamId="+teamId+", userId="+userId+", err="+err.Error(), http.StatusInternalServerError)
|
return nil, model.NewAppError("SqlChannelStore.GetChannelCounts", "store.sql_channel.get_channel_counts.get.app_error", nil, "teamId="+teamId+", userId="+userId+", err="+err.Error(), http.StatusInternalServerError)
|
||||||
return
|
}
|
||||||
}
|
|
||||||
|
|
||||||
counts := &model.ChannelCounts{Counts: make(map[string]int64), UpdateTimes: make(map[string]int64)}
|
counts := &model.ChannelCounts{Counts: make(map[string]int64), UpdateTimes: make(map[string]int64)}
|
||||||
for i := range data {
|
for i := range data {
|
||||||
v := data[i]
|
v := data[i]
|
||||||
counts.Counts[v.Id] = v.TotalMsgCount
|
counts.Counts[v.Id] = v.TotalMsgCount
|
||||||
counts.UpdateTimes[v.Id] = v.UpdateAt
|
counts.UpdateTimes[v.Id] = v.UpdateAt
|
||||||
}
|
}
|
||||||
|
|
||||||
result.Data = counts
|
return counts, nil
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s SqlChannelStore) GetTeamChannels(teamId string) store.StoreChannel {
|
func (s SqlChannelStore) GetTeamChannels(teamId string) store.StoreChannel {
|
||||||
|
|||||||
@@ -152,7 +152,7 @@ type ChannelStore interface {
|
|||||||
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) StoreChannel
|
||||||
GetChannelCounts(teamId string, userId string) StoreChannel
|
GetChannelCounts(teamId string, userId string) (*model.ChannelCounts, *model.AppError)
|
||||||
GetTeamChannels(teamId string) StoreChannel
|
GetTeamChannels(teamId string) StoreChannel
|
||||||
GetAll(teamId string) StoreChannel
|
GetAll(teamId string) StoreChannel
|
||||||
GetChannelsByIds(channelIds []string) StoreChannel
|
GetChannelsByIds(channelIds []string) StoreChannel
|
||||||
|
|||||||
@@ -1540,8 +1540,7 @@ func testChannelStoreGetChannelCounts(t *testing.T, ss store.Store) {
|
|||||||
m3.NotifyProps = model.GetDefaultChannelNotifyProps()
|
m3.NotifyProps = model.GetDefaultChannelNotifyProps()
|
||||||
store.Must(ss.Channel().SaveMember(&m3))
|
store.Must(ss.Channel().SaveMember(&m3))
|
||||||
|
|
||||||
cresult := <-ss.Channel().GetChannelCounts(o1.TeamId, m1.UserId)
|
counts, _ := ss.Channel().GetChannelCounts(o1.TeamId, m1.UserId)
|
||||||
counts := cresult.Data.(*model.ChannelCounts)
|
|
||||||
|
|
||||||
if len(counts.Counts) != 1 {
|
if len(counts.Counts) != 1 {
|
||||||
t.Fatal("wrong number of counts")
|
t.Fatal("wrong number of counts")
|
||||||
|
|||||||
@@ -316,19 +316,28 @@ func (_m *ChannelStore) GetByNames(team_id string, names []string, allowFromCach
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetChannelCounts provides a mock function with given fields: teamId, userId
|
// GetChannelCounts provides a mock function with given fields: teamId, userId
|
||||||
func (_m *ChannelStore) GetChannelCounts(teamId string, userId string) store.StoreChannel {
|
func (_m *ChannelStore) GetChannelCounts(teamId string, userId string) (*model.ChannelCounts, *model.AppError) {
|
||||||
ret := _m.Called(teamId, userId)
|
ret := _m.Called(teamId, userId)
|
||||||
|
|
||||||
var r0 store.StoreChannel
|
var r0 *model.ChannelCounts
|
||||||
if rf, ok := ret.Get(0).(func(string, string) store.StoreChannel); ok {
|
if rf, ok := ret.Get(0).(func(string, string) *model.ChannelCounts); ok {
|
||||||
r0 = rf(teamId, userId)
|
r0 = rf(teamId, userId)
|
||||||
} else {
|
} else {
|
||||||
if ret.Get(0) != nil {
|
if ret.Get(0) != nil {
|
||||||
r0 = ret.Get(0).(store.StoreChannel)
|
r0 = ret.Get(0).(*model.ChannelCounts)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return r0
|
var r1 *model.AppError
|
||||||
|
if rf, ok := ret.Get(1).(func(string, string) *model.AppError); ok {
|
||||||
|
r1 = rf(teamId, userId)
|
||||||
|
} else {
|
||||||
|
if ret.Get(1) != nil {
|
||||||
|
r1 = ret.Get(1).(*model.AppError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return r0, r1
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetChannelMembersForExport provides a mock function with given fields: userId, teamId
|
// GetChannelMembersForExport provides a mock function with given fields: userId, teamId
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user