mirror of
https://github.com/DorkSquadRR/DorkNet.git
synced 2026-10-25 23:18:44 -07:00
Enhance global friends functionality: suppress auto-generated placeholder accounts in synthesized friend lists and update documentation for clarity.
This commit is contained in:
@@ -31,9 +31,30 @@ public static class RelationshipQueries
|
||||
/// friend in anyone's list.</summary>
|
||||
public const long SystemAccountId = 1;
|
||||
|
||||
/// <summary>True when <paramref name="username"/> is still an
|
||||
/// auto-generated placeholder name (<c>Player_</c> followed by digits
|
||||
/// only — see <c>PlayerService.GenerateUsername</c>). These are accounts
|
||||
/// that never set a real username; the global-friends toggle hides them
|
||||
/// from the synthesized "everyone" list so they don't clutter it. A
|
||||
/// genuine Friend row still surfaces them — only the synthetic pairing is
|
||||
/// suppressed.</summary>
|
||||
public static bool IsPlaceholderUsername(string? username)
|
||||
{
|
||||
const string prefix = "Player_";
|
||||
if (string.IsNullOrEmpty(username) ||
|
||||
!username.StartsWith(prefix, StringComparison.Ordinal)) return false;
|
||||
var suffix = username.AsSpan(prefix.Length);
|
||||
if (suffix.IsEmpty) return false;
|
||||
foreach (var c in suffix)
|
||||
if (!char.IsAsciiDigit(c)) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>The effective friend ids for <paramref name="me"/>. With the
|
||||
/// global-friends toggle off this is the real Friend graph; with it on
|
||||
/// it's every other (non-system, non-blocked) account.</summary>
|
||||
/// it's every other (non-system, non-blocked) account, excluding
|
||||
/// placeholder <c>Player_NNN</c> accounts that aren't already real
|
||||
/// friends.</summary>
|
||||
public static async Task<List<long>> EffectiveFriendIdsAsync(
|
||||
DorkNetDbContext db, ServerSettingsService settings, long me)
|
||||
{
|
||||
@@ -53,10 +74,21 @@ public static class RelationshipQueries
|
||||
(r.RequesterId == me || r.TargetId == me))
|
||||
.Select(r => r.RequesterId == me ? r.TargetId : r.RequesterId)
|
||||
.ToListAsync();
|
||||
var realFriendSet = (await db.Relationships
|
||||
.Where(r => r.Status == RelationshipStatus.Friend &&
|
||||
(r.RequesterId == me || r.TargetId == me))
|
||||
.Select(r => r.RequesterId == me ? r.TargetId : r.RequesterId)
|
||||
.ToListAsync()).ToHashSet();
|
||||
|
||||
return await db.Players
|
||||
var candidates = await db.Players
|
||||
.Where(p => p.Id != me && p.Id != SystemAccountId && !blocked.Contains(p.Id))
|
||||
.Select(p => p.Id)
|
||||
.Select(p => new { p.Id, p.Username })
|
||||
.ToListAsync();
|
||||
|
||||
// Suppress placeholder accounts unless they're an actual friend.
|
||||
return candidates
|
||||
.Where(p => realFriendSet.Contains(p.Id) || !IsPlaceholderUsername(p.Username))
|
||||
.Select(p => p.Id)
|
||||
.ToList();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user