summaryrefslogtreecommitdiffstats
path: root/app/status.go
diff options
context:
space:
mode:
authorCarlos Tadeu Panato Junior <ctadeu@gmail.com>2017-03-24 18:23:32 +0100
committerGeorge Goldberg <george@gberg.me>2017-03-24 17:23:32 +0000
commit5bf6ae04dfedc2e504ea8af5c71b2e9a8287e2b5 (patch)
tree19445c4de5d31670ede7429a97e292b72c022368 /app/status.go
parent28ad645153b206ba84ddc4935280eaed94bb0138 (diff)
downloadchat-5bf6ae04dfedc2e504ea8af5c71b2e9a8287e2b5.tar.gz
chat-5bf6ae04dfedc2e504ea8af5c71b2e9a8287e2b5.tar.bz2
chat-5bf6ae04dfedc2e504ea8af5c71b2e9a8287e2b5.zip
[APIV4] GET /users/{user_id}/status - user status endpoint for apiV4 (#5824)
Diffstat (limited to 'app/status.go')
-rw-r--r--app/status.go53
1 files changed, 53 insertions, 0 deletions
diff --git a/app/status.go b/app/status.go
index 51e7d1ed8..3adf643f8 100644
--- a/app/status.go
+++ b/app/status.go
@@ -90,6 +90,59 @@ func GetStatusesByIds(userIds []string) (map[string]interface{}, *model.AppError
return statusMap, nil
}
+//GetUserStatusesByIds used by apiV4
+func GetUserStatusesByIds(userIds []string) ([]*model.Status, *model.AppError) {
+ var statusMap []*model.Status
+ metrics := einterfaces.GetMetricsInterface()
+
+ missingUserIds := []string{}
+ for _, userId := range userIds {
+ if result, ok := statusCache.Get(userId); ok {
+ statusMap = append(statusMap, result.(*model.Status))
+ if metrics != nil {
+ metrics.IncrementMemCacheHitCounter("Status")
+ }
+ } else {
+ missingUserIds = append(missingUserIds, userId)
+ if metrics != nil {
+ metrics.IncrementMemCacheMissCounter("Status")
+ }
+ }
+ }
+
+ if len(missingUserIds) > 0 {
+ if result := <-Srv.Store.Status().GetByIds(missingUserIds); result.Err != nil {
+ return nil, result.Err
+ } else {
+ statuses := result.Data.([]*model.Status)
+
+ for _, s := range statuses {
+ AddStatusCache(s)
+ }
+
+ statusMap = append(statusMap, statuses...)
+ }
+ }
+
+ // For the case where the user does not have a row in the Status table and cache
+ // remove the existing ids from missingUserIds and then create a offline state for the missing ones
+ for i := 0; i < len(missingUserIds); i++ {
+ missingUserId := missingUserIds[i]
+ for _, userMap := range statusMap {
+ if missingUserId == userMap.UserId {
+ missingUserIds = append(missingUserIds[:i], missingUserIds[i+1:]...)
+ i--
+ break
+ }
+ }
+ }
+ for _, userId := range missingUserIds {
+ statusMap = append(statusMap, &model.Status{UserId: userId, Status: "offline"})
+ }
+
+ return statusMap, nil
+}
+
func SetStatusOnline(userId string, sessionId string, manual bool) {
broadcast := false