fix(guild): emit is_friend / is_friend_apply in /guild/info members
GuildMemberInfo.cs:48-49 re-reads json["is_friend"] / json["is_friend_apply"] UNGUARDED on top of the base-class UserInfoBase's guarded read. Our DTO had them as int? with global WhenWritingNull → keys omitted → LitJson threw KeyNotFoundException, crashing the client right after guild create. Flip the fields to non-nullable int with JsonIgnoreCondition.Never so they always ship, and wire a batched IFriendService.GetFriendRelationsAsync lookup so the values are actually populated (single Contains-batched query per relation table). Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -313,6 +313,36 @@ public sealed class FriendService : IFriendService, IPlayedTogetherWriter
|
||||
await _db.SaveChangesAsync(ct);
|
||||
}
|
||||
|
||||
public async Task<IReadOnlyDictionary<long, FriendRelation>> GetFriendRelationsAsync(
|
||||
long viewerId, IReadOnlyList<long> otherViewerIds, CancellationToken ct)
|
||||
{
|
||||
if (otherViewerIds.Count == 0)
|
||||
return new Dictionary<long, FriendRelation>();
|
||||
|
||||
var idSet = otherViewerIds.Where(id => id != viewerId).Distinct().ToList();
|
||||
var friendSet = idSet.Count == 0
|
||||
? new HashSet<long>()
|
||||
: (await _db.ViewerFriends.AsNoTracking()
|
||||
.Where(f => f.OwnerViewerId == viewerId && idSet.Contains(f.FriendViewerId))
|
||||
.Select(f => f.FriendViewerId)
|
||||
.ToListAsync(ct)).ToHashSet();
|
||||
var applySet = idSet.Count == 0
|
||||
? new HashSet<long>()
|
||||
: (await _db.ViewerFriendApplies.AsNoTracking()
|
||||
.Where(a => a.FromViewerId == viewerId && idSet.Contains(a.ToViewerId))
|
||||
.Select(a => a.ToViewerId)
|
||||
.ToListAsync(ct)).ToHashSet();
|
||||
|
||||
var result = new Dictionary<long, FriendRelation>(otherViewerIds.Count);
|
||||
foreach (var id in otherViewerIds)
|
||||
{
|
||||
result[id] = id == viewerId
|
||||
? new FriendRelation(false, false)
|
||||
: new FriendRelation(friendSet.Contains(id), applySet.Contains(id));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// --- helpers ---
|
||||
|
||||
private sealed record ViewerProjection(
|
||||
|
||||
Reference in New Issue
Block a user