summaryrefslogtreecommitdiffstats
path: root/model/channel_count.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 /model/channel_count.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 'model/channel_count.go')
-rw-r--r--model/channel_count.go46
1 files changed, 46 insertions, 0 deletions
diff --git a/model/channel_count.go b/model/channel_count.go
new file mode 100644
index 000000000..05d8401e1
--- /dev/null
+++ b/model/channel_count.go
@@ -0,0 +1,46 @@
+// Copyright (c) 2015 Spinpunch, Inc. All Rights Reserved.
+// See License.txt for license information.
+
+package model
+
+import (
+ "crypto/md5"
+ "encoding/json"
+ "io"
+ "strconv"
+)
+
+type ChannelCounts struct {
+ Counts map[string]int64 `json:"counts"`
+}
+
+func (o *ChannelCounts) Etag() string {
+ str := ""
+ for id, count := range o.Counts {
+ str += id + strconv.FormatInt(count, 10)
+ }
+
+ data := []byte(str)
+
+ return Etag(md5.Sum(data))
+}
+
+func (o *ChannelCounts) ToJson() string {
+ b, err := json.Marshal(o)
+ if err != nil {
+ return ""
+ } else {
+ return string(b)
+ }
+}
+
+func ChannelCountsFromJson(data io.Reader) *ChannelCounts {
+ decoder := json.NewDecoder(data)
+ var o ChannelCounts
+ err := decoder.Decode(&o)
+ if err == nil {
+ return &o
+ } else {
+ return nil
+ }
+}