github.com/vnforks/kid/v5@v5.22.1-0.20200408055009-b89d99c65676/wsapi/status.go (about) 1 // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. 2 // See LICENSE.txt for license information. 3 4 package wsapi 5 6 import ( 7 "github.com/vnforks/kid/v5/mlog" 8 "github.com/vnforks/kid/v5/model" 9 ) 10 11 func (api *API) InitStatus() { 12 api.Router.Handle("get_statuses", api.ApiWebSocketHandler(api.getStatuses)) 13 api.Router.Handle("get_statuses_by_ids", api.ApiWebSocketHandler(api.getStatusesByIds)) 14 } 15 16 func (api *API) getStatuses(req *model.WebSocketRequest) (map[string]interface{}, *model.AppError) { 17 statusMap := api.App.GetAllStatuses() 18 return model.StatusMapToInterfaceMap(statusMap), nil 19 } 20 21 func (api *API) getStatusesByIds(req *model.WebSocketRequest) (map[string]interface{}, *model.AppError) { 22 var userIds []string 23 if userIds = model.ArrayFromInterface(req.Data["user_ids"]); len(userIds) == 0 { 24 mlog.Error(model.StringInterfaceToJson(req.Data)) 25 return nil, NewInvalidWebSocketParamError(req.Action, "user_ids") 26 } 27 28 statusMap, err := api.App.GetStatusesByIds(userIds) 29 if err != nil { 30 return nil, err 31 } 32 33 return statusMap, nil 34 }