Example #1
0
        private void RemoveUserFromAssociatedChatsInGroup(Models.User user, Guid groupId)
        {
            IEnumerable <ChatUser> chatUsers = _chatUserRepository.GetAllByUserIdAndGroupId(user.Id, groupId);

            if (chatUsers == null || !chatUsers.Any())
            {
                return;
            }

            var group = _groupRepository.Get(groupId);

            foreach (var chatUser in chatUsers)
            {
                var chatId      = chatUser.ChatId;
                var usersInChat = _chatUserRepository.CountByChatId(chatId);

                if (usersInChat <= 3)
                {
                    _chatService.RemoveChatByChatId(chatId);
                }
                else // remove only one chatUser
                {
                    _chatUserRepository.Remove(chatUser);
                    _chatUserStore.RemoveByUserIdAndChatId(user.Id, chatId);
                    _chatEventService.AddUserRemovedFromChatEvent(group, _authorizedUser, user, chatUser.Chat);
                }
            }
        }
Example #2
0
        private void RemoveAllChatUsers(Models.Chat chat, Models.Group group)
        {
            var chatUsers = _chatUserRepository.GetAllByChatId(chat.Id);

            _chatUserRepository.RemoveAllByChatId(chat.Id);
            _chatUserStore.RemoveAllByChatId(chat.Id);

            foreach (var chatUser in chatUsers)
            {
                _chatEventService.AddUserRemovedFromChatEvent(group, _authorizedUser, chatUser.User, chat);
            }
        }