2017-04-12 08:27:57 -04:00
|
|
|
// Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved.
|
2017-03-28 04:58:19 -04:00
|
|
|
// See License.txt for license information.
|
|
|
|
|
|
|
|
|
|
package wsapi
|
|
|
|
|
|
|
|
|
|
import (
|
2018-04-27 12:49:45 -07:00
|
|
|
"github.com/mattermost/mattermost-server/mlog"
|
2017-09-06 23:05:10 -07:00
|
|
|
"github.com/mattermost/mattermost-server/model"
|
2017-03-28 04:58:19 -04:00
|
|
|
)
|
|
|
|
|
|
2017-09-27 11:52:34 -05:00
|
|
|
func (api *API) InitStatus() {
|
2017-11-09 14:46:20 -06:00
|
|
|
api.Router.Handle("get_statuses", api.ApiWebSocketHandler(api.getStatuses))
|
2017-09-27 11:52:34 -05:00
|
|
|
api.Router.Handle("get_statuses_by_ids", api.ApiWebSocketHandler(api.getStatusesByIds))
|
2017-03-28 04:58:19 -04:00
|
|
|
}
|
|
|
|
|
|
2017-11-09 14:46:20 -06:00
|
|
|
func (api *API) getStatuses(req *model.WebSocketRequest) (map[string]interface{}, *model.AppError) {
|
|
|
|
|
statusMap := api.App.GetAllStatuses()
|
2017-03-28 04:58:19 -04:00
|
|
|
return model.StatusMapToInterfaceMap(statusMap), nil
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-27 11:52:34 -05:00
|
|
|
func (api *API) getStatusesByIds(req *model.WebSocketRequest) (map[string]interface{}, *model.AppError) {
|
2017-03-28 04:58:19 -04:00
|
|
|
var userIds []string
|
|
|
|
|
if userIds = model.ArrayFromInterface(req.Data["user_ids"]); len(userIds) == 0 {
|
2018-04-27 12:49:45 -07:00
|
|
|
mlog.Error(model.StringInterfaceToJson(req.Data))
|
2017-03-28 04:58:19 -04:00
|
|
|
return nil, NewInvalidWebSocketParamError(req.Action, "user_ids")
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-27 11:52:34 -05:00
|
|
|
statusMap, err := api.App.GetStatusesByIds(userIds)
|
2017-03-28 04:58:19 -04:00
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return statusMap, nil
|
|
|
|
|
}
|