Exemplo n.º 1
0
 private ChanelEvent HandleChanelActions(ChanelAct act)
 {
     if (act is GetAllChanels)
     {
         return(new ChanelsRetrieved(_channelService.Channels));
     }
     if (act is RemoveUserFromChannel removeUserAct)
     {
         _channelService.RemoveUserFromChannel(removeUserAct.SocketId);
     }
     if (act is FindUserChannel findUserChannelAct)
     {
         return(new UserChannelFounded(_channelService.FindUserChannel(findUserChannelAct.SocketId)));
     }
     if (act is GetChanelDetails channelDetailAct)
     {
         return(new ChanelDetailsRetrieved(_channelService.GetChannel(channelDetailAct.ChanelName)));
     }
     if (act is CreateChannel createChannelAct)
     {
         if (_channelService.CreateChannel(createChannelAct.ChannelName))
         {
             _databaseAdapter.CreateChannel(_channelService.GetChannel(createChannelAct.ChannelName));
         }
     }
     if (act is AddUserToChanel addUserToChannel)
     {
         _channelService.AddUserToChannel(addUserToChannel.ChanelName, addUserToChannel.UserId, addUserToChannel.UserSocketId);
         _channelService.MatchSubscribedUsersWithChannelUsers(_userService.Users);
     }
     if (act is AddMessageToChannel addMessageAct)
     {
         //RetrieveSavedSubscribedUsers();
         _channelService.MatchSubscribedUsersWithChannelUsers(_userService.Users);
         _channelService.AddMessageToChannel(addMessageAct.ChannelName, addMessageAct.Message);
         _databaseAdapter.AddMessageToChannel(addMessageAct.ChannelName, addMessageAct.Message);
         var channelUsers =
             _channelService.GetChannelUsersWithoutTheSender(addMessageAct.ChannelName,
                                                             addMessageAct.Message.UserId);
         _pushNotificationAdapter.SendNewMessageNotification(channelUsers, addMessageAct.Message.UserId);
     }
     return(null);
 }
Exemplo n.º 2
0
        public IActionResult CreateChannel([FromBody] CreateChannelRequest request)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(new
                {
                    Errors = ModelState.Values.SelectMany(x => x.Errors.Select(xx => xx.ErrorMessage))
                }));
            }

            if (_userService.CheckIfUserIsAdminOrOwner(_user.Id, request.WorkspaceId))
            {
                var result = _channelService.CreateChannel(request.Name, request.WorkspaceId, request.ChannelType);
                if (result.Success)
                {
                    return(StatusCode(201, new { Meassage = "Channel added successful" }));
                }
                return(BadRequest(new { Error = result.Errors }));
            }

            return(StatusCode(403, new { Error = "User doesn't have permission to adding channels" }));
        }
Exemplo n.º 3
0
        private async void FeedCategoryTree_CreateChannel(NewChannelData newChannelData)
        {
            var channel         = newChannelData.Channel;
            var parentComponent = newChannelData.ParentTreeComponent;
            var category        = (parentComponent?.Item as Category);

            if (channel == null || parentComponent == null || category == null)
            {
                return;
            }

            channel.CategoryId = category.CategoryId;

            var createdChannel = _channelService.CreateChannel(channel);

            var treeComponent = new TreeComponent(createdChannel);

            parentComponent.SubComponents.Add(treeComponent);
            parentComponent.IsExpanded = true;

            await _feedUpdater.UpdateFeedAsync(createdChannel.ChannelId);

            UpdateChannelStats(createdChannel.ChannelId, treeComponent);
        }
Exemplo n.º 4
0
        public string CreateChannel([FromBody] JsonElement json)
        {
            var request = ToObject <RequestCreateChannel>(json);

            return(PrepareResponse(_channelService.CreateChannel(request)));
        }