前端:

新增添加好友功能
修复给联系人发消息时跳转空会话的情况
修复了已知问题
后端:
修复了已知问题
This commit is contained in:
2026-01-21 22:30:51 +08:00
parent 77744015de
commit f7e68555b1
22 changed files with 1281 additions and 430 deletions
+13 -20
View File
@@ -73,22 +73,14 @@ namespace IM_API.Services
}
#endregion
#region
public async Task<List<FriendRequest>> GetFriendRequestListAsync(int userId, bool isReceived, int page, int limit, bool desc)
public async Task<List<FriendRequest>> GetFriendRequestListAsync(int userId, int page, int limit, bool desc)
{
var query = _context.FriendRequests.AsQueryable();
//是否为请求方
if (isReceived)
{
query = _context.FriendRequests.Where(x => x.ResponseUser == userId);
}
else
{
query = _context.FriendRequests.Where(x => x.RequestUser == userId);
}
if (desc)
{
query = query.OrderByDescending(x => x.Id);
}
var query = _context.FriendRequests
.Where(
x => (x.ResponseUser == userId) ||
x.RequestUser == userId
);
query = query.OrderByDescending(x => x.Id);
var friendRequestList = await query.Skip((page - 1 * limit)).Take(limit).ToListAsync();
return friendRequestList;
}
@@ -154,16 +146,17 @@ namespace IM_API.Services
if (alreadyExists)
throw new BaseException(CodeDefine.FRIEND_REQUEST_EXISTS);
var friendShip = await _context.Friends.FirstOrDefaultAsync(x => x.UserId == dto.FromUserId && x.FriendId == dto.ToUserId);
//检查是否被对方拉黑
bool isBlocked = await _context.Friends.AnyAsync(x =>
x.UserId == dto.FromUserId && x.FriendId == dto.ToUserId && x.Status == (sbyte)FriendStatus.Blocked
);
bool isBlocked = friendShip != null && friendShip.StatusEnum == FriendStatus.Blocked;
if (isBlocked)
throw new BaseException(CodeDefine.FRIEND_REQUEST_REJECTED);
if (friendShip != null)
throw new BaseException(CodeDefine.ALREADY_FRIENDS);
//生成实体
var friendRequst = _mapper.Map<FriendRequest>(dto);
var friend = _mapper.Map<Friend>(friendRequst);
var friend = _mapper.Map<Friend>(dto);
_context.FriendRequests.Add(friendRequst);
_context.Friends.Add(friend);
await _context.SaveChangesAsync();