github.com/gigforks/mattermost-server@v4.9.1-0.20180619094218-800d97fa55d0+incompatible/model/channel_list.go (about) 1 // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. 2 // See License.txt for license information. 3 4 package model 5 6 import ( 7 "encoding/json" 8 "io" 9 ) 10 11 type ChannelList []*Channel 12 13 func (o *ChannelList) ToJson() string { 14 if b, err := json.Marshal(o); err != nil { 15 return "[]" 16 } else { 17 return string(b) 18 } 19 } 20 21 func (o *ChannelList) Etag() string { 22 23 id := "0" 24 var t int64 = 0 25 var delta int64 = 0 26 27 for _, v := range *o { 28 if v.LastPostAt > t { 29 t = v.LastPostAt 30 id = v.Id 31 } 32 33 if v.UpdateAt > t { 34 t = v.UpdateAt 35 id = v.Id 36 } 37 38 } 39 40 return Etag(id, t, delta, len(*o)) 41 } 42 43 func ChannelListFromJson(data io.Reader) *ChannelList { 44 var o *ChannelList 45 json.NewDecoder(data).Decode(&o) 46 return o 47 } 48 49 func ChannelSliceFromJson(data io.Reader) []*Channel { 50 var o []*Channel 51 json.NewDecoder(data).Decode(&o) 52 return o 53 }