Ejemplo n.º 1
0
        public async Task <IActionResult> JoinChannel([FromHeader] string authToken, [FromBody] ChannelRequestModel model)
        {
            var errMsg = string.Empty;

            try
            {
                var channel = ServerContext.Current.Chat.Join(UserContext.User, model.Id);
                return(await SuccessResponse(channel));
            }
            catch (Exception ex)
            {
                errMsg = ex.Message;
            }

            return(await ErrorResponse(errMsg, ResponseType.InvalidModel));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> CreateChannel([FromHeader] string authToken, [FromBody] ChannelRequestModel model)
        {
            var errMsg = string.Empty;

            try
            {
                var channel = ServerContext.Current.Chat.AddChannel(UserContext.User, ChatChannelType.Custom, name: model.Name);

                return(await SuccessResponse(new ChannelModel(channel, true)
                                             .GetInfo(new ChannelModelViewOptions(true))));
            }
            catch (Exception ex)
            {
                errMsg = ex.Message;
            }
            return(await ErrorResponse(errMsg, ResponseType.InvalidModel));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> CloseChannel([FromHeader] string authToken, [FromBody] ChannelRequestModel model)
        {
            var channel = ServerContext.Current.Chat.LookupChannel(UserContext.User, model.Id, ChatChannelType.Custom, CheckAccessRule.IsSubscribed);

            if (channel == null)
            {
                return(await GenericResponse(ResponseType.InvalidModel, string.Format(ChatNetworkModule.ErrMsg_NoSuchChannelOrNotAllow, "close it")));
            }

            var errMsg = string.Empty;

            try
            {
                ServerContext.Current.Chat.DropChannel(UserContext.User, channel);
                return(await SuccessResponse(true));
            }
            catch (Exception ex)
            {
                errMsg = ex.Message;
            }

            return(await ErrorResponse(errMsg, ResponseType.InvalidModel));
        }