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