mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
Channel.GetChannelCounts to sync by default (#11210)
This commit is contained in:
committed by
Jesús Espino
parent
5a3fed4534
commit
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) {
|
||||
result := <-a.Srv.Store.Channel().GetChannelCounts(teamId, userId)
|
||||
if result.Err != nil {
|
||||
return nil, result.Err
|
||||
}
|
||||
return result.Data.(*model.ChannelCounts), nil
|
||||
return a.Srv.Store.Channel().GetChannelCounts(teamId, userId)
|
||||
}
|
||||
|
||||
func (a *App) GetChannelUnread(channelId, userId string) (*model.ChannelUnread, *model.AppError) {
|
||||
|
||||
@@ -1115,25 +1115,22 @@ type channelIdWithCountAndUpdateAt struct {
|
||||
UpdateAt int64
|
||||
}
|
||||
|
||||
func (s SqlChannelStore) GetChannelCounts(teamId string, userId string) store.StoreChannel {
|
||||
return store.Do(func(result *store.StoreResult) {
|
||||
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})
|
||||
func (s SqlChannelStore) GetChannelCounts(teamId string, userId string) (*model.ChannelCounts, *model.AppError) {
|
||||
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})
|
||||
|
||||
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
|
||||
}
|
||||
if err != nil {
|
||||
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)
|
||||
}
|
||||
|
||||
counts := &model.ChannelCounts{Counts: make(map[string]int64), UpdateTimes: make(map[string]int64)}
|
||||
for i := range data {
|
||||
v := data[i]
|
||||
counts.Counts[v.Id] = v.TotalMsgCount
|
||||
counts.UpdateTimes[v.Id] = v.UpdateAt
|
||||
}
|
||||
counts := &model.ChannelCounts{Counts: make(map[string]int64), UpdateTimes: make(map[string]int64)}
|
||||
for i := range data {
|
||||
v := data[i]
|
||||
counts.Counts[v.Id] = v.TotalMsgCount
|
||||
counts.UpdateTimes[v.Id] = v.UpdateAt
|
||||
}
|
||||
|
||||
result.Data = counts
|
||||
})
|
||||
return counts, nil
|
||||
}
|
||||
|
||||
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)
|
||||
GetPublicChannelsForTeam(teamId string, offset int, limit int) 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
|
||||
GetAll(teamId string) StoreChannel
|
||||
GetChannelsByIds(channelIds []string) StoreChannel
|
||||
|
||||
@@ -1540,8 +1540,7 @@ func testChannelStoreGetChannelCounts(t *testing.T, ss store.Store) {
|
||||
m3.NotifyProps = model.GetDefaultChannelNotifyProps()
|
||||
store.Must(ss.Channel().SaveMember(&m3))
|
||||
|
||||
cresult := <-ss.Channel().GetChannelCounts(o1.TeamId, m1.UserId)
|
||||
counts := cresult.Data.(*model.ChannelCounts)
|
||||
counts, _ := ss.Channel().GetChannelCounts(o1.TeamId, m1.UserId)
|
||||
|
||||
if len(counts.Counts) != 1 {
|
||||
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
|
||||
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)
|
||||
|
||||
var r0 store.StoreChannel
|
||||
if rf, ok := ret.Get(0).(func(string, string) store.StoreChannel); ok {
|
||||
var r0 *model.ChannelCounts
|
||||
if rf, ok := ret.Get(0).(func(string, string) *model.ChannelCounts); ok {
|
||||
r0 = rf(teamId, userId)
|
||||
} else {
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user