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

61 lines
2.0 KiB
C#
Raw Permalink Normal View History

2023-01-01 22:50:39 -05:00
using Luski.net.Interfaces;
using Luski.net.JsonTypes.BaseTypes;
using System;
using System.Text;
2023-01-01 22:50:39 -05:00
using System.Text.Json.Serialization;
using System.Threading;
2023-01-01 22:50:39 -05:00
using System.Threading.Tasks;
using JacobTechEncryption;
2024-03-20 23:18:34 -04:00
using Luski.Shared.PublicServers.V1.ServerToClient.HTTP;
2023-01-01 22:50:39 -05:00
namespace Luski.net.Structures.Main;
2023-01-01 22:50:39 -05:00
2024-03-20 23:18:34 -04:00
public class MainSocketMessage : STC
2023-01-01 22:50:39 -05:00
{
public MainServer Server { get; internal set; } = default!;
2023-01-01 22:50:39 -05:00
[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<IUser> GetAuthor(CancellationToken CancellationToken)
2023-01-01 22:50:39 -05:00
{
if (Server.User.Id != AuthorID) return await Server.GetUser<MainSocketUserBase>(AuthorID, CancellationToken);
else return Server.User;
2023-01-01 22:50:39 -05:00
}
internal void decrypt(string? key, CancellationToken CancellationToken)
2023-01-01 22:50:39 -05:00
{
if (string.IsNullOrEmpty(key)) throw new ArgumentNullException(nameof(key));
Context = Encoding.UTF8.GetString(Encryption.AES.Decrypt(Convert.FromBase64String(Context), key));
2023-01-01 22:50:39 -05:00
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))]
2023-01-01 22:50:39 -05:00
[JsonSourceGenerationOptions(
GenerationMode = JsonSourceGenerationMode.Default,
PropertyNamingPolicy = JsonKnownNamingPolicy.CamelCase,
WriteIndented = false)]
public partial class MainSocketMessageContext : JsonSerializerContext
2023-01-01 22:50:39 -05:00
{
}