diff options
author | Dmitri Aizenberg <dmitri.aiz@gmail.com> | 2016-08-31 06:24:14 -0700 |
---|---|---|
committer | Joram Wilander <jwawilander@gmail.com> | 2016-08-31 09:24:14 -0400 |
commit | dc09b7781ac310646014f05db23844ab2c6d63f4 (patch) | |
tree | 906f13501b8e30be3551fa18078429445e5ee094 /api/status.go | |
parent | db660bdf9cbea09197d8292a8ec8efda8ac41f38 (diff) | |
download | chat-dc09b7781ac310646014f05db23844ab2c6d63f4.tar.gz chat-dc09b7781ac310646014f05db23844ab2c6d63f4.tar.bz2 chat-dc09b7781ac310646014f05db23844ab2c6d63f4.zip |
PLT-1527 Add a slash command to set yourself away (#3752)
* added handlers for slash commands
* added manual status persistance
* added tests
* removed extra debug output and comments
* rebase - fixing the PR
* making echo messages after slash commands ephemeral
Diffstat (limited to 'api/status.go')
-rw-r--r-- | api/status.go | 40 |
1 files changed, 30 insertions, 10 deletions
diff --git a/api/status.go b/api/status.go index d19105e3b..d83eac033 100644 --- a/api/status.go +++ b/api/status.go @@ -65,19 +65,24 @@ func GetAllStatuses() (map[string]interface{}, *model.AppError) { } } -func SetStatusOnline(userId string, sessionId string) { +func SetStatusOnline(userId string, sessionId string, manual bool) { + l4g.Debug(userId, "online") broadcast := false var status *model.Status var err *model.AppError if status, err = GetStatus(userId); err != nil { - status = &model.Status{userId, model.STATUS_ONLINE, model.GetMillis()} + status = &model.Status{userId, model.STATUS_ONLINE, false, model.GetMillis()} broadcast = true } else { + if status.Manual && !manual { + return // manually set status always overrides non-manual one + } if status.Status != model.STATUS_ONLINE { broadcast = true } status.Status = model.STATUS_ONLINE + status.Manual = false // for "online" there's no manually or auto set status.LastActivityAt = model.GetMillis() } @@ -107,8 +112,14 @@ func SetStatusOnline(userId string, sessionId string) { } } -func SetStatusOffline(userId string) { - status := &model.Status{userId, model.STATUS_OFFLINE, model.GetMillis()} +func SetStatusOffline(userId string, manual bool) { + l4g.Debug(userId, "offline") + status, err := GetStatus(userId) + if err == nil && status.Manual && !manual { + return // manually set status always overrides non-manual one + } + + status = &model.Status{userId, model.STATUS_OFFLINE, manual, model.GetMillis()} AddStatusCache(status) @@ -121,21 +132,30 @@ func SetStatusOffline(userId string) { go Publish(event) } -func SetStatusAwayIfNeeded(userId string) { +func SetStatusAwayIfNeeded(userId string, manual bool) { + l4g.Debug(userId, "away") status, err := GetStatus(userId) + if err != nil { - status = &model.Status{userId, model.STATUS_OFFLINE, 0} + status = &model.Status{userId, model.STATUS_OFFLINE, manual, 0} } - if status.Status == model.STATUS_AWAY { - return + if !manual && status.Manual { + return // manually set status always overrides non-manual one } - if !IsUserAway(status.LastActivityAt) { - return + if !manual { + if status.Status == model.STATUS_AWAY { + return + } + + if !IsUserAway(status.LastActivityAt) { + return + } } status.Status = model.STATUS_AWAY + status.Manual = manual AddStatusCache(status) |