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:
gamer147
2026-07-04 16:18:22 -04:00
parent 1bdcd8397b
commit 7a13e99df7
5 changed files with 64 additions and 8 deletions

View File

@@ -396,17 +396,19 @@ public sealed class GuildController : SVSimController
var viewerIds = members.Select(m => m.ViewerId).ToList();
var profiles = await _viewers.LoadGuildProfileBatchAsync(viewerIds, ct);
var relations = await _friends.GetFriendRelationsAsync(callerViewerId, viewerIds, ct);
var result = new List<GuildMemberInfoDto>(members.Count);
foreach (var m in members)
{
profiles.TryGetValue(m.ViewerId, out var p);
result.Add(ToMemberDto(m, p));
relations.TryGetValue(m.ViewerId, out var r);
result.Add(ToMemberDto(m, p, r));
}
return result;
}
private static GuildMemberInfoDto ToMemberDto(GuildMember member, GuildMemberProfile? profile) => new()
private static GuildMemberInfoDto ToMemberDto(GuildMember member, GuildMemberProfile? profile, FriendRelation? relation) => new()
{
ViewerId = member.ViewerId,
Name = profile?.Name ?? "",
@@ -414,6 +416,8 @@ public sealed class GuildController : SVSimController
CountryCode = profile?.CountryCode ?? "",
Rank = profile?.Rank ?? 1,
DegreeId = profile?.DegreeId ?? 0,
IsFriend = relation?.IsFriend == true ? 1 : 0,
IsFriendApply = relation?.HasOutgoingApply == true ? 1 : 0,
IsOfficialMarkDisplayed = profile?.IsOfficialMarkDisplayed == true ? 1 : 0,
Role = (int)member.Role,
};

View File

@@ -30,13 +30,21 @@ public class GuildMemberInfoDto
[JsonPropertyName("degree_id"), Key("degree_id"), JsonConverter(typeof(StringifiedIntConverter))]
public int DegreeId { get; set; }
/// <summary>Optional — omit when the caller has no friend relationship with this member.</summary>
[JsonPropertyName("is_friend"), Key("is_friend")]
public int? IsFriend { get; set; }
/// <summary>
/// Client reads unconditionally in GuildMemberInfo.cs:48 (json["is_friend"].ToBoolean()) — always emit.
/// Base UserInfoBase guards this, but GuildMemberInfo re-reads it on top, unguarded. 0 = not a friend.
/// </summary>
[JsonPropertyName("is_friend"), Key("is_friend"),
JsonIgnore(Condition = JsonIgnoreCondition.Never)]
public int IsFriend { get; set; }
/// <summary>Optional — omit when no pending friend apply.</summary>
[JsonPropertyName("is_friend_apply"), Key("is_friend_apply")]
public int? IsFriendApply { get; set; }
/// <summary>
/// Client reads unconditionally in GuildMemberInfo.cs:49 (json["is_friend_apply"].ToBoolean()) — always emit.
/// 0 = no pending friend apply.
/// </summary>
[JsonPropertyName("is_friend_apply"), Key("is_friend_apply"),
JsonIgnore(Condition = JsonIgnoreCondition.Never)]
public int IsFriendApply { get; set; }
/// <summary>
/// Whether the official-account badge is shown for this member.