github.com/demisto/mattermost-server@v4.9.0-rc3+incompatible/wsapi/user.go (about)

     1  // Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved.
     2  // See License.txt for license information.
     3  
     4  package wsapi
     5  
     6  import (
     7  	"github.com/mattermost/mattermost-server/model"
     8  )
     9  
    10  func (api *API) InitUser() {
    11  	api.Router.Handle("user_typing", api.ApiWebSocketHandler(api.userTyping))
    12  }
    13  
    14  func (api *API) userTyping(req *model.WebSocketRequest) (map[string]interface{}, *model.AppError) {
    15  	var ok bool
    16  	var channelId string
    17  	if channelId, ok = req.Data["channel_id"].(string); !ok || len(channelId) != 26 {
    18  		return nil, NewInvalidWebSocketParamError(req.Action, "channel_id")
    19  	}
    20  
    21  	var parentId string
    22  	if parentId, ok = req.Data["parent_id"].(string); !ok {
    23  		parentId = ""
    24  	}
    25  
    26  	omitUsers := make(map[string]bool, 1)
    27  	omitUsers[req.Session.UserId] = true
    28  
    29  	event := model.NewWebSocketEvent(model.WEBSOCKET_EVENT_TYPING, "", channelId, "", omitUsers)
    30  	event.Add("parent_id", parentId)
    31  	event.Add("user_id", req.Session.UserId)
    32  	api.App.Publish(event)
    33  
    34  	return nil, nil
    35  }