Esempio n. 1
0
        public async Task SendMessage(string conversationId, string message, long? fileId)
        {
            long convId = long.Parse(conversationId);
            string senderId = _httpContextAccessor.HttpContext.Request.Query["userId"];
            await _chatService.AddMessageToDb(convId, senderId, message, fileId);
            List<string> conversationUsers = _chatService.GetConversationUsers(convId);
            string senderConnectionId = Context.ConnectionId;
            await conversationUsers.ForEachAsync(async (x) =>
            {
                string recieverConnectionId = await _chatService.GetUserConnectionId(x);
                if(recieverConnectionId != null)
                {
                    await Clients.Client(recieverConnectionId).SendAsync("RecievePrivateMessage", convId, message, senderId);
                }
            });
            //if(recieverConnectionId == null)
            //{

            //}
            //else
            //{
            //    //Clients.Client(senderConnectionId).SendAsync("SendPrivateMessage", recieverConnectionId, message);
            //}
        }