From dc09b7781ac310646014f05db23844ab2c6d63f4 Mon Sep 17 00:00:00 2001 From: Dmitri Aizenberg Date: Wed, 31 Aug 2016 06:24:14 -0700 Subject: 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 --- api/status.go | 40 ++++++++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 10 deletions(-) (limited to 'api/status.go') 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) -- cgit v1.2.3-1-g7c22