added getChannelCounts service and refactored the client to more intelligently pull channel data

Этот коммит содержится в:
JoramWilander
2015-08-10 14:47:45 -04:00
родитель 1c0ee4d2f6
Коммит 6c0fefad15
10 изменённых файлов: 343 добавлений и 168 удалений

Просмотреть файл

@@ -281,6 +281,39 @@ func (s SqlChannelStore) GetMoreChannels(teamId string, userId string) StoreChan
return storeChannel
}
type channelIdWithCount struct {
Id string
TotalMsgCount int64
}
func (s SqlChannelStore) GetChannelCounts(teamId string, userId string) StoreChannel {
storeChannel := make(StoreChannel)
go func() {
result := StoreResult{}
var data []channelIdWithCount
_, err := s.GetReplica().Select(&data, "SELECT Id, TotalMsgCount FROM Channels WHERE Id IN (SELECT ChannelId FROM ChannelMembers WHERE UserId = :UserId) AND TeamId = :TeamId AND DeleteAt = 0 ORDER BY DisplayName", map[string]interface{}{"TeamId": teamId, "UserId": userId})
if err != nil {
result.Err = model.NewAppError("SqlChannelStore.GetChannelCounts", "We couldn't get the channel counts", "teamId="+teamId+", userId="+userId+", err="+err.Error())
} else {
counts := &model.ChannelCounts{Counts: make(map[string]int64)}
for i := range data {
v := data[i]
counts.Counts[v.Id] = v.TotalMsgCount
}
result.Data = counts
}
storeChannel <- result
close(storeChannel)
}()
return storeChannel
}
func (s SqlChannelStore) GetByName(teamId string, name string) StoreChannel {
storeChannel := make(StoreChannel)

Просмотреть файл

@@ -50,6 +50,7 @@ type ChannelStore interface {
GetByName(team_id string, domain string) StoreChannel
GetChannels(teamId string, userId string) StoreChannel
GetMoreChannels(teamId string, userId string) StoreChannel
GetChannelCounts(teamId string, userId string) StoreChannel
SaveMember(member *model.ChannelMember) StoreChannel
GetMembers(channelId string) StoreChannel