2023-01-01 22:50:39 -05:00
|
|
|
|
using Luski.net.Interfaces;
|
|
|
|
|
using Luski.net.JsonTypes.BaseTypes;
|
|
|
|
|
using System;
|
2023-07-03 23:24:35 -04:00
|
|
|
|
using System.Text;
|
2023-01-01 22:50:39 -05:00
|
|
|
|
using System.Text.Json.Serialization;
|
2023-07-03 23:24:35 -04:00
|
|
|
|
using System.Threading;
|
2023-01-01 22:50:39 -05:00
|
|
|
|
using System.Threading.Tasks;
|
2023-07-03 23:24:35 -04:00
|
|
|
|
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
|
|
|
|
|
2023-07-08 09:06:13 -04: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
|
|
|
|
{
|
2023-07-08 09:06:13 -04: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!;
|
2023-07-03 23:24:35 -04:00
|
|
|
|
public async Task<IUser> GetAuthor(CancellationToken CancellationToken)
|
2023-01-01 22:50:39 -05:00
|
|
|
|
{
|
2023-07-08 09:06:13 -04: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
|
|
|
|
}
|
|
|
|
|
|
2023-07-03 23:24:35 -04: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));
|
2023-07-03 23:24:35 -04:00
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-08 09:06:13 -04:00
|
|
|
|
[JsonSerializable(typeof(MainSocketMessage))]
|
2023-01-01 22:50:39 -05:00
|
|
|
|
[JsonSourceGenerationOptions(
|
|
|
|
|
GenerationMode = JsonSourceGenerationMode.Default,
|
|
|
|
|
PropertyNamingPolicy = JsonKnownNamingPolicy.CamelCase,
|
|
|
|
|
WriteIndented = false)]
|
2023-07-08 09:06:13 -04:00
|
|
|
|
public partial class MainSocketMessageContext : JsonSerializerContext
|
2023-01-01 22:50:39 -05:00
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|