Procházet zdrojové kódy

SendMessage : empty receiver conn

zinab_elgendy před 2 týdny
rodič
revize
2780903cd5
1 změnil soubory, kde provedl 14 přidání a 14 odebrání
  1. 14 14
      MTWorkHR.Application/Chat/ChatHub.cs

+ 14 - 14
MTWorkHR.Application/Chat/ChatHub.cs

@@ -95,11 +95,20 @@ namespace MTWorkHR.API.Chat
             return CompanyIdLong;
         }
 
-      
 
-      
+        // Get previous messages between two users
+        public async Task GetPreviousMessages(string contactId)
+        {
+            var userId = Context.User.Identities.FirstOrDefault().FindFirst("uid")?.Value;
+            var allmessages = await _unitOfWork.ChatMessage.GetAllWithChildrenAsync(userId, contactId);
+            // Ensure the query is fully materialized before passing it to SignalR
+            var messagesList = await allmessages.Item1.ToListAsync();
+
+            await Clients.Caller.SendAsync("PreviousMessages", messagesList);
+        }
+
         // Send a message from one user to another
-       
+
         public async Task SendMessage(string receiverUserId, string msg)
         {
             try
@@ -113,7 +122,7 @@ namespace MTWorkHR.API.Chat
                 ChatMessage messag = new ChatMessage { 
                     Content = msg, 
                     ReceiverId = receiverUserId, 
-                    ReceiverName = receiverUser.UserName ?? "", 
+                    ReceiverName = receiverUser?.UserName ?? "", 
                     SenderId = userId, 
                     SenderName = userName, 
                     IsSeen = false 
@@ -126,16 +135,7 @@ namespace MTWorkHR.API.Chat
             catch (Exception e) { _logger.LogError(e, e.Message); }
         }
 
-        // Get previous messages between two users
-        public async Task GetPreviousMessages(string contactId)
-        {
-            var userId = Context.User.Identities.FirstOrDefault().FindFirst("uid")?.Value;
-            var allmessages = await _unitOfWork.ChatMessage.GetAllWithChildrenAsync(userId, contactId);
-            // Ensure the query is fully materialized before passing it to SignalR
-            var messagesList = await allmessages.Item1.ToListAsync();
-
-            await Clients.Caller.SendAsync("PreviousMessages", messagesList);
-        }
+      
 
 
         public async Task<Tuple<ChatMessage, int>> GetLastMessage(string contactId)