From be589aed1d8a5d47a884596d281f5b9fd29f5a01 Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Tue, 22 Jul 2025 21:52:44 +0800 Subject: [PATCH] :bug: Fixes of accounts mentioned messages unable to send --- DysonNetwork.Pass/Account/AccountServiceGrpc.cs | 13 +++++++++++++ DysonNetwork.Shared/Proto/account.proto | 5 +++++ DysonNetwork.Sphere/Chat/ChatController.cs | 11 +++++++++-- 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/DysonNetwork.Pass/Account/AccountServiceGrpc.cs b/DysonNetwork.Pass/Account/AccountServiceGrpc.cs index d7bda39..e0d6173 100644 --- a/DysonNetwork.Pass/Account/AccountServiceGrpc.cs +++ b/DysonNetwork.Pass/Account/AccountServiceGrpc.cs @@ -57,6 +57,19 @@ public class AccountServiceGrpc( return response; } + public override async Task LookupAccountBatch(LookupAccountBatchRequest request, ServerCallContext context) + { + var accountNames = request.Names.ToList(); + var accounts = await _db.Accounts + .AsNoTracking() + .Where(a => accountNames.Contains(a.Name)) + .Include(a => a.Profile) + .ToListAsync(); + var response = new GetAccountBatchResponse(); + response.Accounts.AddRange(accounts.Select(a => a.ToProtoValue())); + return response; + } + public override async Task ListAccounts(ListAccountsRequest request, ServerCallContext context) { diff --git a/DysonNetwork.Shared/Proto/account.proto b/DysonNetwork.Shared/Proto/account.proto index bad0af4..91a5a9a 100644 --- a/DysonNetwork.Shared/Proto/account.proto +++ b/DysonNetwork.Shared/Proto/account.proto @@ -218,6 +218,7 @@ service AccountService { // Account Operations rpc GetAccount(GetAccountRequest) returns (Account) {} rpc GetAccountBatch(GetAccountBatchRequest) returns (GetAccountBatchResponse) {} + rpc LookupAccountBatch(LookupAccountBatchRequest) returns (GetAccountBatchResponse) {} rpc ListAccounts(ListAccountsRequest) returns (ListAccountsResponse) {} // Profile Operations @@ -292,6 +293,10 @@ message GetAccountBatchRequest { repeated string id = 1; // Account ID to retrieve } +message LookupAccountBatchRequest { + repeated string names = 1; +} + message GetAccountBatchResponse { repeated Account accounts = 1; // List of accounts } diff --git a/DysonNetwork.Sphere/Chat/ChatController.cs b/DysonNetwork.Sphere/Chat/ChatController.cs index d0ab923..bb33c16 100644 --- a/DysonNetwork.Sphere/Chat/ChatController.cs +++ b/DysonNetwork.Sphere/Chat/ChatController.cs @@ -16,7 +16,8 @@ public partial class ChatController( AppDatabase db, ChatService cs, ChatRoomService crs, - FileService.FileServiceClient files + FileService.FileServiceClient files, + AccountService.AccountServiceClient accounts ) : ControllerBase { public class MarkMessageReadRequest @@ -213,8 +214,14 @@ public partial class ChatController( .ToList(); if (mentioned.Count > 0) { + var queryRequest = new LookupAccountBatchRequest(); + queryRequest.Names.AddRange(mentioned); + var queryResponse = (await accounts.LookupAccountBatchAsync(queryRequest)).Accounts; + var mentionedId = queryResponse + .Select(a => Guid.Parse(a.Id)) + .ToList(); var mentionedMembers = await db.ChatMembers - .Where(m => mentioned.Contains(m.Account.Name)) + .Where(m => mentionedId.Contains(m.AccountId)) .Select(m => m.Id) .ToListAsync(); message.MembersMentioned = mentionedMembers;