48 lines
1.9 KiB
C#
48 lines
1.9 KiB
C#
using System.Text.Json.Serialization;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using Luski.net.Enums;
|
|
using Luski.net.Interfaces;
|
|
using Luski.net.JsonTypes.BaseTypes;
|
|
|
|
namespace Luski.net.Structures.Public;
|
|
|
|
public class PublicSocketUserBase : IncomingHTTP, IUser
|
|
{
|
|
public PublicServer Server { get; internal set; } = default!;
|
|
[JsonPropertyName("id")]
|
|
[JsonInclude]
|
|
public long Id { get; internal set; } = default!;
|
|
[JsonPropertyName("username")]
|
|
[JsonInclude]
|
|
public string DisplayName { get; internal set; } = default!;
|
|
[JsonPropertyName("status")]
|
|
[JsonInclude]
|
|
public UserStatus Status { get; internal set; } = default!;
|
|
[JsonPropertyName("picture_type")]
|
|
[JsonInclude]
|
|
public PictureType PictureType { get; internal set; } = default!;
|
|
public async Task<byte[]> GetAvatar(CancellationToken CancellationToken)
|
|
{
|
|
bool isc = System.IO.File.Exists(Server.Storage.GetStorageDirectory(StorageDirectory.Avatars) + Id.ToString());
|
|
if (!isc) await Server.GetFromServer($"socketuserprofile/Avatar/{Id}", Server.Storage.GetStorageDirectory(StorageDirectory.Avatars) + Id.ToString(), CancellationToken);
|
|
return Server.Storage.GetResourceBytes(StorageDirectory.Avatars, Id.ToString());
|
|
}
|
|
|
|
public Task<long> GetUserKey(CancellationToken CancellationToken)
|
|
{
|
|
string data = Server.GetFromServer($"Keys/GetUserKey/{Id}", CancellationToken).Content.ReadAsStringAsync().Result;
|
|
return Task.FromResult(long.Parse(data));
|
|
}
|
|
}
|
|
|
|
[JsonSerializable(typeof(PublicSocketUserBase))]
|
|
[JsonSourceGenerationOptions(
|
|
GenerationMode = JsonSourceGenerationMode.Default,
|
|
PropertyNamingPolicy = JsonKnownNamingPolicy.Unspecified,
|
|
WriteIndented = false,
|
|
DefaultIgnoreCondition = JsonIgnoreCondition.Never)]
|
|
internal partial class PublicSocketUserBaseContext : JsonSerializerContext
|
|
{
|
|
|
|
} |