예제 #1
0
        public async Task AddUserToConversation(string conversationId, string userName)
        {
            string userId = _httpContextAccessor.HttpContext.Request.Query["userId"];
            if(long.TryParse(conversationId, out long convId))
            {
                await _chatService.AddUserToConversation(convId, userName, userId);

                List<string> conversationUsers = _chatService.GetConversationUsers(convId);
                await conversationUsers.ForEachAsync(async (x) =>
                {
                    string recieverConnectionId = await _chatService.GetUserConnectionId(x);
                    if (recieverConnectionId != null)
                    {
                        await Clients.Client(recieverConnectionId).SendAsync("RecievePrivateMessage", "system", "New user added!");
                    }
                });
            }
        }