🐛 Fix publisher members has no account info

This commit is contained in:
2025-07-19 12:10:43 +08:00
parent 4398984551
commit 921a10f7ab
3 changed files with 27 additions and 4 deletions

View File

@@ -1,6 +1,7 @@
using DysonNetwork.Shared.Cache;
using DysonNetwork.Shared.Data;
using DysonNetwork.Shared.Proto;
using DysonNetwork.Shared.Registry;
using DysonNetwork.Sphere.Post;
using Microsoft.EntityFrameworkCore;
using NodaTime;
@@ -10,7 +11,8 @@ namespace DysonNetwork.Sphere.Publisher;
public class PublisherService(
AppDatabase db,
FileReferenceService.FileReferenceServiceClient fileRefs,
ICacheService cache
ICacheService cache,
AccountClientHelper accountsHelper
)
{
public async Task<Publisher?> GetPublisherByName(string name)
@@ -376,4 +378,24 @@ public class PublisherService(
return member != null && member.Role >= requiredRole;
}
public async Task<PublisherMember> LoadMemberAccount(PublisherMember member)
{
var account = await accountsHelper.GetAccount(member.AccountId);
member.Account = Pass.Account.Account.FromProtoValue(account);
return member;
}
public async Task<List<PublisherMember>> LoadMemberAccounts(ICollection<PublisherMember> members)
{
var accountIds = members.Select(m => m.AccountId).ToList();
var accounts = (await accountsHelper.GetAccountBatch(accountIds)).ToDictionary(a => Guid.Parse(a.Id), a => a);
return members.Select(m =>
{
if (accounts.TryGetValue(m.AccountId, out var account))
m.Account = Pass.Account.Account.FromProtoValue(account);
return m;
}).ToList();
}
}