2017-04-12 08:27:57 -04:00
|
|
|
// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
|
2016-07-18 11:10:03 -04:00
|
|
|
// See License.txt for license information.
|
|
|
|
|
|
|
|
|
|
package api
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
|
|
l4g "github.com/alecthomas/log4go"
|
2016-08-04 09:25:37 -08:00
|
|
|
|
2017-09-06 23:05:10 -07:00
|
|
|
"github.com/mattermost/mattermost-server/app"
|
|
|
|
|
"github.com/mattermost/mattermost-server/model"
|
|
|
|
|
"github.com/mattermost/mattermost-server/utils"
|
2016-07-18 11:10:03 -04:00
|
|
|
)
|
|
|
|
|
|
2017-09-22 12:54:27 -05:00
|
|
|
func (api *API) InitStatus() {
|
2016-07-18 11:10:03 -04:00
|
|
|
l4g.Debug(utils.T("api.status.init.debug"))
|
|
|
|
|
|
2017-09-22 12:54:27 -05:00
|
|
|
api.BaseRoutes.Users.Handle("/status", api.ApiUserRequired(getStatusesHttp)).Methods("GET")
|
|
|
|
|
api.BaseRoutes.Users.Handle("/status/ids", api.ApiUserRequired(getStatusesByIdsHttp)).Methods("POST")
|
2016-07-18 11:10:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func getStatusesHttp(c *Context, w http.ResponseWriter, r *http.Request) {
|
2017-01-13 13:53:37 -05:00
|
|
|
statusMap := model.StatusMapToInterfaceMap(app.GetAllStatuses())
|
2016-07-18 11:10:03 -04:00
|
|
|
w.Write([]byte(model.StringInterfaceToJson(statusMap)))
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-19 14:49:25 -04:00
|
|
|
func getStatusesByIdsHttp(c *Context, w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
userIds := model.ArrayFromJson(r.Body)
|
|
|
|
|
|
|
|
|
|
if len(userIds) == 0 {
|
|
|
|
|
c.SetInvalidParam("getStatusesByIdsHttp", "user_ids")
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-06 17:12:54 -05:00
|
|
|
statusMap, err := c.App.GetStatusesByIds(userIds)
|
2016-10-19 14:49:25 -04:00
|
|
|
if err != nil {
|
|
|
|
|
c.Err = err
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
w.Write([]byte(model.StringInterfaceToJson(statusMap)))
|
|
|
|
|
}
|