Luski.Net/Luski.net/Structures/Main/MainSocketUserBase.cs

53 lines
2.0 KiB
C#
Raw Permalink Normal View History

2024-03-20 23:18:34 -04:00
using System;
using System.IO;
using System.Text.Json.Serialization;
using System.Threading;
using System.Threading.Tasks;
using Luski.net.Enums;
using Luski.net.Interfaces;
2024-03-20 23:18:34 -04:00
using Luski.net.Structures.Public;
using Luski.Shared.PublicServers.V1.Enums;
using Luski.Shared.PublicServers.V1.ServerToClient.HTTP;
namespace Luski.net.Structures.Main;
2024-03-20 23:18:34 -04:00
public class MainSocketUserBase : STC, IUser
{
public MainServer 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!;
2024-11-18 23:24:23 -05:00
public async Task<Stream> 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.GetResourceStream(StorageDirectory.Avatars, Id.ToString());
}
public Task<PublicKeyInfo[]> GetUserKeys(CancellationToken CancellationToken)
{
string data = Server.GetFromServer($"Keys/GetUserKey/{Id}", CancellationToken).Content.ReadAsStringAsync().Result;
return Task.FromResult(new[] { new PublicKeyInfo() { Id = long.Parse(data) }});
}
}
[JsonSerializable(typeof(MainSocketUserBase))]
[JsonSourceGenerationOptions(
GenerationMode = JsonSourceGenerationMode.Default,
PropertyNamingPolicy = JsonKnownNamingPolicy.Unspecified,
WriteIndented = false,
DefaultIgnoreCondition = JsonIgnoreCondition.Never)]
internal partial class MainSocketUserBaseContext : JsonSerializerContext
{
}