|
@@ -95,11 +95,20 @@ namespace MTWorkHR.API.Chat
|
|
return CompanyIdLong;
|
|
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
|
|
// Send a message from one user to another
|
|
-
|
|
|
|
|
|
+
|
|
public async Task SendMessage(string receiverUserId, string msg)
|
|
public async Task SendMessage(string receiverUserId, string msg)
|
|
{
|
|
{
|
|
try
|
|
try
|
|
@@ -113,7 +122,7 @@ namespace MTWorkHR.API.Chat
|
|
ChatMessage messag = new ChatMessage {
|
|
ChatMessage messag = new ChatMessage {
|
|
Content = msg,
|
|
Content = msg,
|
|
ReceiverId = receiverUserId,
|
|
ReceiverId = receiverUserId,
|
|
- ReceiverName = receiverUser.UserName ?? "",
|
|
|
|
|
|
+ ReceiverName = receiverUser?.UserName ?? "",
|
|
SenderId = userId,
|
|
SenderId = userId,
|
|
SenderName = userName,
|
|
SenderName = userName,
|
|
IsSeen = false
|
|
IsSeen = false
|
|
@@ -126,16 +135,7 @@ namespace MTWorkHR.API.Chat
|
|
catch (Exception e) { _logger.LogError(e, e.Message); }
|
|
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)
|
|
public async Task<Tuple<ChatMessage, int>> GetLastMessage(string contactId)
|