Esempio n. 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);
                }
            }
        }