2023-08-21 10:58:17 -04:00
|
|
|
using System.IO;
|
2023-07-03 23:24:35 -04:00
|
|
|
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;
|
|
|
|
|
2023-07-08 09:06:13 -04:00
|
|
|
namespace Luski.net.Structures.Main;
|
2023-07-03 23:24:35 -04:00
|
|
|
|
2023-07-08 09:06:13 -04:00
|
|
|
public class MainSocketUserBase : IncomingHTTP, IUser
|
2023-07-03 23:24:35 -04:00
|
|
|
{
|
2023-07-08 09:06:13 -04:00
|
|
|
public MainServer Server { get; internal set; } = default!;
|
2023-07-03 23:24:35 -04:00
|
|
|
[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!;
|
2023-08-21 10:58:17 -04:00
|
|
|
public async Task<Stream> GetAvatar(CancellationToken CancellationToken)
|
2023-07-03 23:24:35 -04:00
|
|
|
{
|
2023-07-10 07:35:05 -04:00
|
|
|
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);
|
2023-08-21 10:58:17 -04:00
|
|
|
return Server.Storage.GetResourceStream(StorageDirectory.Avatars, Id.ToString());
|
2023-07-03 23:24:35 -04:00
|
|
|
}
|
|
|
|
|
2023-08-21 10:58:17 -04:00
|
|
|
public Task<PublicKeyInfo[]> GetUserKeys(CancellationToken CancellationToken)
|
2023-07-03 23:24:35 -04:00
|
|
|
{
|
|
|
|
string data = Server.GetFromServer($"Keys/GetUserKey/{Id}", CancellationToken).Content.ReadAsStringAsync().Result;
|
2023-08-21 10:58:17 -04:00
|
|
|
return Task.FromResult(new[] { new PublicKeyInfo() { Id = long.Parse(data) }});
|
2023-07-03 23:24:35 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-08 09:06:13 -04:00
|
|
|
[JsonSerializable(typeof(MainSocketUserBase))]
|
2023-07-03 23:24:35 -04:00
|
|
|
[JsonSourceGenerationOptions(
|
|
|
|
GenerationMode = JsonSourceGenerationMode.Default,
|
|
|
|
PropertyNamingPolicy = JsonKnownNamingPolicy.Unspecified,
|
|
|
|
WriteIndented = false,
|
|
|
|
DefaultIgnoreCondition = JsonIgnoreCondition.Never)]
|
2023-07-08 09:06:13 -04:00
|
|
|
internal partial class MainSocketUserBaseContext : JsonSerializerContext
|
2023-07-03 23:24:35 -04:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|