diff options
author | Joram Wilander <jwawilander@gmail.com> | 2017-03-28 04:58:19 -0400 |
---|---|---|
committer | George Goldberg <george@gberg.me> | 2017-03-28 09:58:19 +0100 |
commit | daca0d93f621bcb1daae149c178af0631bcd120a (patch) | |
tree | 6127936c76dbc6fd20a7377385469980e5bd72e3 /wsapi/user.go | |
parent | ca8b8d1245026672b1a56d256bb8ff3c8bb1bba9 (diff) | |
download | chat-daca0d93f621bcb1daae149c178af0631bcd120a.tar.gz chat-daca0d93f621bcb1daae149c178af0631bcd120a.tar.bz2 chat-daca0d93f621bcb1daae149c178af0631bcd120a.zip |
Move WebSocket API to it's own package and add websocket v4 endpoint (#5881)
Diffstat (limited to 'wsapi/user.go')
-rw-r--r-- | wsapi/user.go | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/wsapi/user.go b/wsapi/user.go new file mode 100644 index 000000000..a89bf1118 --- /dev/null +++ b/wsapi/user.go @@ -0,0 +1,40 @@ +// Copyright (c) 2017 Mattermost, Inc. All Rights Reserved. +// See License.txt for license information. + +package wsapi + +import ( + l4g "github.com/alecthomas/log4go" + "github.com/mattermost/platform/app" + "github.com/mattermost/platform/model" + "github.com/mattermost/platform/utils" +) + +func InitUser() { + l4g.Debug(utils.T("wsapi.user.init.debug")) + + app.Srv.WebSocketRouter.Handle("user_typing", ApiWebSocketHandler(userTyping)) +} + +func 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 app.Publish(event) + + return nil, nil +} |