mattermost/wsapi/user.go
Chris 91bfc72a99 Reduce logging data races, fix MySQL test race condition (#7994)
* fix races

* revert unintentional change

* fix test as intended
2017-12-22 12:09:33 +00:00

35 lines
981 B
Go

// Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
package wsapi
import (
"github.com/mattermost/mattermost-server/model"
)
func (api *API) InitUser() {
api.Router.Handle("user_typing", api.ApiWebSocketHandler(api.userTyping))
}
func (api *API) userTyping(req *model.WebSocketRequest) (map[string]interface{}, *model.AppError) {
var ok bool
var channelId string
if channelId, ok = req.Data["channel_id"].(string); !ok || len(channelId) != 26 {
return nil, NewInvalidWebSocketParamError(req.Action, "channel_id")
}
var parentId string
if parentId, ok = req.Data["parent_id"].(string); !ok {
parentId = ""
}
omitUsers := make(map[string]bool, 1)
omitUsers[req.Session.UserId] = true
event := model.NewWebSocketEvent(model.WEBSOCKET_EVENT_TYPING, "", channelId, "", omitUsers)
event.Add("parent_id", parentId)
event.Add("user_id", req.Session.UserId)
go api.App.Publish(event)
return nil, nil
}