github.com/gigforks/mattermost-server@v4.9.1-0.20180619094218-800d97fa55d0+incompatible/model/status.go (about) 1 // Copyright (c) 2016-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 const ( 12 STATUS_OUT_OF_OFFICE = "ooo" 13 STATUS_OFFLINE = "offline" 14 STATUS_AWAY = "away" 15 STATUS_DND = "dnd" 16 STATUS_ONLINE = "online" 17 STATUS_CACHE_SIZE = SESSION_CACHE_SIZE 18 STATUS_CHANNEL_TIMEOUT = 20000 // 20 seconds 19 STATUS_MIN_UPDATE_TIME = 120000 // 2 minutes 20 ) 21 22 type Status struct { 23 UserId string `json:"user_id"` 24 Status string `json:"status"` 25 Manual bool `json:"manual"` 26 LastActivityAt int64 `json:"last_activity_at"` 27 ActiveChannel string `json:"-" db:"-"` 28 } 29 30 func (o *Status) ToJson() string { 31 b, _ := json.Marshal(o) 32 return string(b) 33 } 34 35 func StatusFromJson(data io.Reader) *Status { 36 var o *Status 37 json.NewDecoder(data).Decode(&o) 38 return o 39 } 40 41 func StatusListToJson(u []*Status) string { 42 b, _ := json.Marshal(u) 43 return string(b) 44 } 45 46 func StatusListFromJson(data io.Reader) []*Status { 47 var statuses []*Status 48 json.NewDecoder(data).Decode(&statuses) 49 return statuses 50 } 51 52 func StatusMapToInterfaceMap(statusMap map[string]*Status) map[string]interface{} { 53 interfaceMap := map[string]interface{}{} 54 for _, s := range statusMap { 55 // Omitted statues mean offline 56 if s.Status != STATUS_OFFLINE { 57 interfaceMap[s.UserId] = s.Status 58 } 59 } 60 return interfaceMap 61 }