github.com/adacta-ru/mattermost-server/v6@v6.0.0/wsapi/user.go (about)

     1  // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
     2  // See LICENSE.txt for license information.
     3  
     4  package wsapi
     5  
     6  import (
     7  	"github.com/adacta-ru/mattermost-server/v6/model"
     8  )
     9  
    10  func (api *API) InitUser() {
    11  	api.Router.Handle("user_typing", api.ApiWebSocketHandler(api.userTyping))
    12  	api.Router.Handle("user_update_active_status", api.ApiWebSocketHandler(api.userUpdateActiveStatus))
    13  }
    14  
    15  func (api *API) userTyping(req *model.WebSocketRequest) (map[string]interface{}, *model.AppError) {
    16  	api.App.ExtendSessionExpiryIfNeeded(&req.Session)
    17  
    18  	if api.App.Srv().Busy.IsBusy() {
    19  		// this is considered a non-critical service and will be disabled when server busy.
    20  		return nil, NewServerBusyWebSocketError(req.Action)
    21  	}
    22  
    23  	var ok bool
    24  	var channelId string
    25  	if channelId, ok = req.Data["channel_id"].(string); !ok || !model.IsValidId(channelId) {
    26  		return nil, NewInvalidWebSocketParamError(req.Action, "channel_id")
    27  	}
    28  
    29  	if !api.App.SessionHasPermissionToChannel(req.Session, channelId, model.PERMISSION_CREATE_POST) {
    30  		return nil, NewInvalidWebSocketParamError(req.Action, "channel_id")
    31  	}
    32  
    33  	var parentId string
    34  	if parentId, ok = req.Data["parent_id"].(string); !ok {
    35  		parentId = ""
    36  	}
    37  
    38  	appErr := api.App.PublishUserTyping(req.Session.UserId, channelId, parentId)
    39  
    40  	return nil, appErr
    41  }
    42  
    43  func (api *API) userUpdateActiveStatus(req *model.WebSocketRequest) (map[string]interface{}, *model.AppError) {
    44  	var ok bool
    45  	var userIsActive bool
    46  	if userIsActive, ok = req.Data["user_is_active"].(bool); !ok {
    47  		return nil, NewInvalidWebSocketParamError(req.Action, "user_is_active")
    48  	}
    49  
    50  	var manual bool
    51  	if manual, ok = req.Data["manual"].(bool); !ok {
    52  		manual = false
    53  	}
    54  
    55  	if userIsActive {
    56  		api.App.SetStatusOnline(req.Session.UserId, manual)
    57  	} else {
    58  		api.App.SetStatusAwayIfNeeded(req.Session.UserId, manual)
    59  	}
    60  
    61  	return nil, nil
    62  }