zinab_elgendy 2 veckor sedan
förälder
incheckning
f8256ddd16
1 ändrade filer med 6 tillägg och 6 borttagningar
  1. 6 6
      MTWorkHR.Application/Chat/ChatHub.cs

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

@@ -62,9 +62,9 @@ namespace MTWorkHR.API.Chat
                 var online = onlineUsers.FirstOrDefault(u=>  u.UserId == emp.Id);
                 var profileImg = "";
                 var lastMessage = await GetLastMessage(emp.Id);
-                var lastMsg = lastMessage?.Content;
-                var lastMsgDate = lastMessage?.CreateDate;
-                var unseenCount = 0;
+                var lastMsg = lastMessage.Item1?.Content;
+                var lastMsgDate = lastMessage.Item1?.CreateDate;
+                var unseenCount = lastMessage.Item2;
                 var chatUser = new ChatUserDto(emp.Id, emp.FirstName + " " + emp.LastName, online?.SignalrId, emp.Email, online != null ? true : false, profileImg, unseenCount,lastMsg,lastMsgDate);
             }
 
@@ -127,14 +127,14 @@ namespace MTWorkHR.API.Chat
         }
 
 
-        public async Task<ChatMessage> GetLastMessage(string contactId)
+        public async Task<Tuple<ChatMessage, int>> GetLastMessage(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 lastOne = allmessages.Item1.LastOrDefault();
-
-            return lastOne?? new ChatMessage();
+            var unseen = allmessages.Item1.Count(m=> m.IsSeen == false);
+            return new Tuple<ChatMessage, int>( lastOne?? new ChatMessage(), unseen);
         }
         //----------------------------------------------------------------------
         //----------------------------------------------------------------------