summaryrefslogtreecommitdiffstats
path: root/store/sql_channel_store.go
diff options
context:
space:
mode:
authorJoramWilander <jwawilander@gmail.com>2015-08-10 14:47:45 -0400
committerJoramWilander <jwawilander@gmail.com>2015-08-11 12:11:35 -0400
commit6c0fefad152e1843bccf80fb675301b789f70dd5 (patch)
treee48b601f97cf9f7456e8783082fcb3974691785b /store/sql_channel_store.go
parent1c0ee4d2f65d1d4434a3a16070abe7d61a268ce6 (diff)
downloadchat-6c0fefad152e1843bccf80fb675301b789f70dd5.tar.gz
chat-6c0fefad152e1843bccf80fb675301b789f70dd5.tar.bz2
chat-6c0fefad152e1843bccf80fb675301b789f70dd5.zip
added getChannelCounts service and refactored the client to more intelligently pull channel data
Diffstat (limited to 'store/sql_channel_store.go')
-rw-r--r--store/sql_channel_store.go33
1 files changed, 33 insertions, 0 deletions
diff --git a/store/sql_channel_store.go b/store/sql_channel_store.go
index cac5c681b..6caa6fc70 100644
--- a/store/sql_channel_store.go
+++ b/store/sql_channel_store.go
@@ -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)