Beispiel #1
0
        public async Task OnChatCreateAsync(Chat chat)
        {
            if (chat == null)
            {
                throw new ArgumentNullException(nameof(chat));
            }

            await ChatRepository.AddAsync(chat);

            await NotifyClients(chat.Id, client => client.onChatCreateAsync(chat));
        }
Beispiel #2
0
        public async Task <ChatActionResult> RemoveUserAsync(string title, string username, User actionUser)
        {
            var user = await _userService.FindUserByUsernameAsync(username);

            var chats = actionUser.IsGlobalAdmin
                        ? await _chatRepository.FindByTitleAsync(title)
                        : (await _chatRepository.GetUserChats(actionUser.UserId)).Where(c => c.Title.Contains(title)).ToList();

            if (chats.Count == 0)
            {
                chats = await _chatTL.FindByTitleAsync(title);

                foreach (var chat in chats)
                {
                    await _chatRepository.AddAsync(chat);
                }
            }

            if (chats.Count == 0)
            {
                throw new ArgumentException($"Chat {title} doesnot exists");
            }
            if (chats.Count > 1)
            {
                return new ChatActionResult
                       {
                           Success = false,
                           Chats   = chats,
                           User    = user
                       }
            }
            ;

            await _chatTL.RemoveUserAsync(chats[0], user);

            return(new ChatActionResult {
                Success = true
            });
        }
Beispiel #3
0
        public async Task AddChatAsync(Message message)
        {
            var foundChat = await _chatRepository.GetByTelegramId(message.chat.id);

            if (foundChat != null)
            {
                ChatDb newChat = new ChatDb
                {
                    TelegramId = message.chat.id,
                    Title      = message.chat.title,
                    Type       = message.chat.type
                };

                await _chatRepository.AddAsync(newChat);

                await _chatRepository.SaveAsync();
            }
        }