2019-11-29 06:59:40 -05:00
|
|
|
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
|
|
|
// See LICENSE.txt for license information.
|
2016-07-18 11:10:03 -04:00
|
|
|
|
|
|
|
|
package model
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"encoding/json"
|
2025-02-25 16:20:00 -05:00
|
|
|
"time"
|
2016-07-18 11:10:03 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
const (
|
2021-07-12 14:05:36 -04:00
|
|
|
StatusOutOfOffice = "ooo"
|
|
|
|
|
StatusOffline = "offline"
|
|
|
|
|
StatusAway = "away"
|
|
|
|
|
StatusDnd = "dnd"
|
|
|
|
|
StatusOnline = "online"
|
|
|
|
|
StatusCacheSize = SessionCacheSize
|
|
|
|
|
StatusChannelTimeout = 20000 // 20 seconds
|
|
|
|
|
StatusMinUpdateTime = 120000 // 2 minutes
|
2025-02-25 16:20:00 -05:00
|
|
|
|
|
|
|
|
// DNDExpiryInterval is how often the job to expire temporary DND statuses runs.
|
|
|
|
|
DNDExpiryInterval = 1 * time.Minute
|
2016-07-18 11:10:03 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type Status struct {
|
|
|
|
|
UserId string `json:"user_id"`
|
|
|
|
|
Status string `json:"status"`
|
2016-08-31 09:24:14 -04:00
|
|
|
Manual bool `json:"manual"`
|
2016-07-18 11:10:03 -04:00
|
|
|
LastActivityAt int64 `json:"last_activity_at"`
|
2018-06-21 13:42:20 -04:00
|
|
|
ActiveChannel string `json:"active_channel,omitempty" db:"-"`
|
2025-02-25 16:20:00 -05:00
|
|
|
|
|
|
|
|
// DNDEndTime is the time that the user's DND status will expire. Unlike other timestamps in Mattermost, this value
|
|
|
|
|
// is in seconds instead of milliseconds.
|
|
|
|
|
DNDEndTime int64 `json:"dnd_end_time"`
|
|
|
|
|
|
|
|
|
|
PrevStatus string `json:"-"`
|
2016-07-18 11:10:03 -04:00
|
|
|
}
|
|
|
|
|
|
2021-09-01 08:43:12 -04:00
|
|
|
func (s *Status) ToJSON() ([]byte, error) {
|
|
|
|
|
sCopy := *s
|
|
|
|
|
sCopy.ActiveChannel = ""
|
|
|
|
|
return json.Marshal(sCopy)
|
2018-06-21 13:42:20 -04:00
|
|
|
}
|
|
|
|
|
|
2021-09-01 08:43:12 -04:00
|
|
|
func StatusListToJSON(u []*Status) ([]byte, error) {
|
|
|
|
|
list := make([]Status, len(u))
|
2020-03-27 06:40:52 -04:00
|
|
|
for i, s := range u {
|
2021-09-01 08:43:12 -04:00
|
|
|
list[i] = *s
|
|
|
|
|
list[i].ActiveChannel = ""
|
2018-06-21 13:42:20 -04:00
|
|
|
}
|
2021-09-01 08:43:12 -04:00
|
|
|
return json.Marshal(list)
|
2017-03-30 11:09:39 -04:00
|
|
|
}
|
|
|
|
|
|
2022-07-05 02:46:50 -04:00
|
|
|
func StatusMapToInterfaceMap(statusMap map[string]*Status) map[string]any {
|
|
|
|
|
interfaceMap := map[string]any{}
|
2017-01-10 11:38:03 -05:00
|
|
|
for _, s := range statusMap {
|
|
|
|
|
// Omitted statues mean offline
|
2021-07-12 14:05:36 -04:00
|
|
|
if s.Status != StatusOffline {
|
2017-01-10 11:38:03 -05:00
|
|
|
interfaceMap[s.UserId] = s.Status
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return interfaceMap
|
|
|
|
|
}
|