github.com/rajatvaryani/mattermost-server@v5.11.1+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 } 54 55 type ChannelListWithTeamData []*ChannelWithTeamData 56 57 func (o *ChannelListWithTeamData) ToJson() string { 58 if b, err := json.Marshal(o); err != nil { 59 return "[]" 60 } else { 61 return string(b) 62 } 63 } 64 65 func (o *ChannelListWithTeamData) Etag() string { 66 67 id := "0" 68 var t int64 = 0 69 var delta int64 = 0 70 71 for _, v := range *o { 72 if v.LastPostAt > t { 73 t = v.LastPostAt 74 id = v.Id 75 } 76 77 if v.UpdateAt > t { 78 t = v.UpdateAt 79 id = v.Id 80 } 81 82 if v.TeamUpdateAt > t { 83 t = v.TeamUpdateAt 84 id = v.Id 85 } 86 } 87 88 return Etag(id, t, delta, len(*o)) 89 } 90 91 func ChannelListWithTeamDataFromJson(data io.Reader) *ChannelListWithTeamData { 92 var o *ChannelListWithTeamData 93 json.NewDecoder(data).Decode(&o) 94 return o 95 }