using Luski.net.Interfaces; using Luski.net.JsonTypes.BaseTypes; using System; using System.Text; using System.Text.Json.Serialization; using System.Threading; using System.Threading.Tasks; using JacobTechEncryption; using Luski.Shared.PublicServers.V1.ServerToClient.HTTP; namespace Luski.net.Structures.Main; public class MainSocketMessage : STC { public MainServer Server { get; internal set; } = default!; [JsonPropertyName("id")] [JsonInclude] public long Id { get; internal set; } = default!; [JsonPropertyName("user_id")] [JsonInclude] public long AuthorID { get; internal set; } = default!; [JsonPropertyName("content")] [JsonInclude] public string Context { get; internal set; } = default!; [JsonPropertyName("channel_id")] [JsonInclude] public long ChannelID { get; internal set; } = default!; [JsonPropertyName("files")] [JsonInclude] public File[]? Files { get; internal set; } = default!; public async Task GetAuthor(CancellationToken CancellationToken) { if (Server.User.Id != AuthorID) return await Server.GetUser(AuthorID, CancellationToken); else return Server.User; } internal void decrypt(string? key, CancellationToken CancellationToken) { if (string.IsNullOrEmpty(key)) throw new ArgumentNullException(nameof(key)); Context = Encoding.UTF8.GetString(Encryption.AES.Decrypt(Convert.FromBase64String(Context), key)); if (Files is not null && Files.Length > 0) { for (int i = 0; i < Files.Length; i++) { Files[i].key = key; Files[i].decrypt(); } } } } [JsonSerializable(typeof(MainSocketMessage))] [JsonSourceGenerationOptions( GenerationMode = JsonSourceGenerationMode.Default, PropertyNamingPolicy = JsonKnownNamingPolicy.CamelCase, WriteIndented = false)] public partial class MainSocketMessageContext : JsonSerializerContext { }