feat: enhance message decryption for IRC clients and improve attachment handling

This commit is contained in:
HueByte
2026-07-16 16:35:34 +02:00
parent aae788028e
commit b62729dc95
6 changed files with 63 additions and 4 deletions
+12 -1
View File
@@ -1,7 +1,9 @@
using System.Text;
using System.Text.RegularExpressions;
using EchoHub.Core.Contracts;
using EchoHub.Core.DTOs;
using EchoHub.Core.Models;
using EchoHub.Core.Security;
namespace EchoHub.Server.Irc;
@@ -34,7 +36,7 @@ public static partial class IrcMessageFormatter
{
case AttachmentKind.Image:
lines.Add($"{prefix} PRIVMSG {ircChannel} :[Image: {attachment.FileName}] {attachment.Url}");
if (attachment.AsciiPreview is not null)
if (attachment.AsciiPreview is not null && !IsCiphertext(attachment.AsciiPreview))
{
foreach (var line in attachment.AsciiPreview.Split('\n'))
{
@@ -66,6 +68,15 @@ public static partial class IrcMessageFormatter
return lines;
}
/// <summary>
/// True when a preview is still encrypted — transport ($ENC$v1$) if a broadcast path
/// forgot to decrypt it, or E2E room ciphertext ($RC1$) the server cannot decrypt.
/// Emitting it would flood IRC clients with a multi-KB base64 blob.
/// </summary>
private static bool IsCiphertext(string text) =>
text.StartsWith(IMessageEncryptionService.CiphertextPrefix, StringComparison.Ordinal)
|| text.StartsWith(RoomCrypto.CiphertextPrefix, StringComparison.Ordinal);
/// <summary>
/// Format a link embed as IRC PRIVMSG lines (text-only, no ASCII thumbnail).
/// </summary>