✨ Realm and chat with status listing member API
This commit is contained in:
55
DysonNetwork.Shared/Data/AccountStatus.cs
Normal file
55
DysonNetwork.Shared/Data/AccountStatus.cs
Normal file
@@ -0,0 +1,55 @@
|
||||
using DysonNetwork.Shared.Proto;
|
||||
using NodaTime;
|
||||
using NodaTime.Serialization.Protobuf;
|
||||
|
||||
namespace DysonNetwork.Shared.Data;
|
||||
|
||||
public class AccountStatusReference : ModelBase
|
||||
{
|
||||
public Guid Id { get; set; } = Guid.NewGuid();
|
||||
public StatusAttitude Attitude { get; set; }
|
||||
public bool IsOnline { get; set; }
|
||||
public bool IsCustomized { get; set; } = true;
|
||||
public bool IsInvisible { get; set; }
|
||||
public bool IsNotDisturb { get; set; }
|
||||
public string? Label { get; set; }
|
||||
public Instant? ClearedAt { get; set; }
|
||||
|
||||
public Guid AccountId { get; set; }
|
||||
|
||||
public AccountStatus ToProtoValue()
|
||||
{
|
||||
var proto = new AccountStatus
|
||||
{
|
||||
Id = Id.ToString(),
|
||||
Attitude = Attitude,
|
||||
IsOnline = IsOnline,
|
||||
IsCustomized = IsCustomized,
|
||||
IsInvisible = IsInvisible,
|
||||
IsNotDisturb = IsNotDisturb,
|
||||
Label = Label ?? string.Empty,
|
||||
ClearedAt = ClearedAt?.ToTimestamp(),
|
||||
AccountId = AccountId.ToString()
|
||||
};
|
||||
|
||||
return proto;
|
||||
}
|
||||
|
||||
public static AccountStatusReference FromProtoValue(AccountStatus proto)
|
||||
{
|
||||
var status = new AccountStatusReference
|
||||
{
|
||||
Id = Guid.Parse(proto.Id),
|
||||
Attitude = proto.Attitude,
|
||||
IsOnline = proto.IsOnline,
|
||||
IsCustomized = proto.IsCustomized,
|
||||
IsInvisible = proto.IsInvisible,
|
||||
IsNotDisturb = proto.IsNotDisturb,
|
||||
Label = proto.Label,
|
||||
ClearedAt = proto.ClearedAt?.ToInstant(),
|
||||
AccountId = Guid.Parse(proto.AccountId)
|
||||
};
|
||||
|
||||
return status;
|
||||
}
|
||||
}
|
@@ -52,6 +52,7 @@ message AccountStatus {
|
||||
bool is_not_disturb = 6;
|
||||
google.protobuf.StringValue label = 7;
|
||||
google.protobuf.Timestamp cleared_at = 8;
|
||||
string account_id = 9;
|
||||
}
|
||||
|
||||
// Profile contains detailed information about a user
|
||||
|
@@ -1,3 +1,4 @@
|
||||
using DysonNetwork.Shared.Data;
|
||||
using DysonNetwork.Shared.Proto;
|
||||
|
||||
namespace DysonNetwork.Shared.Registry;
|
||||
@@ -10,7 +11,7 @@ public class AccountClientHelper(AccountService.AccountServiceClient accounts)
|
||||
var response = await accounts.GetAccountAsync(request);
|
||||
return response;
|
||||
}
|
||||
|
||||
|
||||
public async Task<List<Account>> GetAccountBatch(List<Guid> ids)
|
||||
{
|
||||
var request = new GetAccountBatchRequest();
|
||||
@@ -18,4 +19,14 @@ public class AccountClientHelper(AccountService.AccountServiceClient accounts)
|
||||
var response = await accounts.GetAccountBatchAsync(request);
|
||||
return response.Accounts.ToList();
|
||||
}
|
||||
|
||||
public async Task<Dictionary<Guid, AccountStatusReference>> GetAccountStatusBatch(List<Guid> ids)
|
||||
{
|
||||
var request = new GetAccountBatchRequest();
|
||||
request.Id.AddRange(ids.Select(id => id.ToString()));
|
||||
var response = await accounts.GetAccountStatusBatchAsync(request);
|
||||
return response.Statuses
|
||||
.Select(AccountStatusReference.FromProtoValue)
|
||||
.ToDictionary(s => s.AccountId, s => s);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user