Ejemplo 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);
 }