|
@@ -49,7 +49,8 @@ namespace MTWorkHR.API.Chat
|
|
|
{
|
|
|
var employees = await _userManager.GetUsersInRoleAsync("Employee");
|
|
|
var CompanyId = GetAuthenticatedCompanyId();
|
|
|
- var res = employees.Where(e => e.CompanyId == CompanyId).ToList();
|
|
|
+ var userId = Context.User.Identities.FirstOrDefault().FindFirst("uid")?.Value;
|
|
|
+ var res = employees.Where(e => e.CompanyId == CompanyId && e.Id != userId).ToList();
|
|
|
|
|
|
var response = MapperObject.Mapper.Map<List<ChatUserDto>>(res);
|
|
|
|
|
@@ -60,8 +61,9 @@ namespace MTWorkHR.API.Chat
|
|
|
{
|
|
|
var online = onlineUsers.FirstOrDefault(u=> u.UserId == emp.Id);
|
|
|
var profileImg = "";
|
|
|
- var lastMsg = "";
|
|
|
- var lastMsgDate = "";
|
|
|
+ var lastMessage = await GetLastMessage(emp.Id);
|
|
|
+ var lastMsg = lastMessage.Content;
|
|
|
+ var lastMsgDate = lastMessage.CreateDate;
|
|
|
var unseenCount = 0;
|
|
|
var chatUser = new ChatUserDto(emp.Id, emp.FirstName + " " + emp.LastName, online?.SignalrId, emp.Email, online != null ? true : false, profileImg, unseenCount,lastMsg,lastMsgDate);
|
|
|
}
|
|
@@ -125,10 +127,10 @@ namespace MTWorkHR.API.Chat
|
|
|
}
|
|
|
|
|
|
|
|
|
- public async Task<ChatMessage> GetLastMessage()
|
|
|
+ public async Task<ChatMessage> GetLastMessage(string contactId)
|
|
|
{
|
|
|
var userId = Context.User.Identities.FirstOrDefault().FindFirst("uid")?.Value;
|
|
|
- var allmessages = await _unitOfWork.ChatMessage.GetAllUserMessagesAsync(userId);
|
|
|
+ var allmessages = await _unitOfWork.ChatMessage.GetAllWithChildrenAsync(userId, contactId);
|
|
|
// Ensure the query is fully materialized before passing it to SignalR
|
|
|
var lastOne = allmessages.Item1.LastOrDefault();
|
|
|
|