add(conversation):完善私聊好友会话服务
This commit is contained in:
@@ -24,9 +24,48 @@ namespace IM_API.Services
|
||||
|
||||
#endregion
|
||||
#region 获取用户会话列表
|
||||
public async Task<List<Conversation>> GetConversationsAsync(int userId)
|
||||
public async Task<List<ConversationDto>> GetConversationsAsync(int userId)
|
||||
{
|
||||
return await _context.Conversations.Where(x => x.UserId == userId)
|
||||
var privateQuery = from c in _context.Conversations
|
||||
join f in _context.Friends on new { c.UserId, c.TargetId}
|
||||
equals new { UserId = f.UserId, TargetId = f.FriendId}
|
||||
where c.UserId == userId && c.ChatType == (int)ChatType.PRIVATE
|
||||
select new ConversationDto
|
||||
{
|
||||
Id = c.Id,
|
||||
UserId = c.UserId,
|
||||
TargetId = c.TargetId,
|
||||
LastReadMessageId = c.LastReadMessageId,
|
||||
LastReadMessage = c.LastReadMessage,
|
||||
UnreadCount = c.UnreadCount,
|
||||
ChatType = c.ChatType,
|
||||
LastMessage = c.LastMessage,
|
||||
TargetAvatar = f.Avatar,
|
||||
TargetName = f.RemarkName,
|
||||
DateTime = c.LastMessageTime
|
||||
|
||||
};
|
||||
|
||||
var groupQuery = from c in _context.Conversations
|
||||
join g in _context.Groups on c.TargetId equals g.Id
|
||||
where c.UserId == userId && c.ChatType == (int)ChatType.GROUP
|
||||
select new ConversationDto
|
||||
{
|
||||
Id = c.Id,
|
||||
UserId = c.UserId,
|
||||
TargetId = c.TargetId,
|
||||
LastReadMessageId = c.LastReadMessageId,
|
||||
LastReadMessage = c.LastReadMessage,
|
||||
UnreadCount = c.UnreadCount,
|
||||
ChatType = c.ChatType,
|
||||
LastMessage = c.LastMessage,
|
||||
TargetAvatar = g.Avatar,
|
||||
TargetName = g.Name,
|
||||
DateTime = c.LastMessageTime
|
||||
};
|
||||
return await privateQuery
|
||||
.Concat(groupQuery)
|
||||
.OrderByDescending(x => x.DateTime)
|
||||
.ToListAsync();
|
||||
}
|
||||
#endregion
|
||||
@@ -39,6 +78,15 @@ namespace IM_API.Services
|
||||
await _context.SaveChangesAsync();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
public async Task<List<string>> GetUserAllStreamKeyAsync(int userId)
|
||||
{
|
||||
return await _context.Conversations.Where(x => x.UserId == userId)
|
||||
.Select(x => x.StreamKey)
|
||||
.Distinct()
|
||||
.ToListAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user