🐛 Fixes of accounts mentioned messages unable to send

This commit is contained in:
2025-07-22 21:52:44 +08:00
parent 5f64236b59
commit be589aed1d
3 changed files with 27 additions and 2 deletions

View File

@@ -57,6 +57,19 @@ public class AccountServiceGrpc(
return response;
}
public override async Task<GetAccountBatchResponse> 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<ListAccountsResponse> ListAccounts(ListAccountsRequest request,
ServerCallContext context)
{

View File

@@ -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
}

View File

@@ -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;