feat: Add notification sound functionality and embed support

- Introduced NotificationConfig to manage notification settings, including sound file.
- Added Notification.mp3 asset for notifications.
- Implemented NotificationSoundService to handle playing notification sounds.
- Enhanced ChatRenderer and MainWindow to support emoji rendering.
- Updated MessageDto to allow multiple embeds per message.
- Modified LinkEmbedService to fetch multiple embeds from message content.
- Added data migration for legacy embed JSON format to new array format.
- Adjusted embed handling in ChatService and IrcMessageFormatter to accommodate multiple embeds.
- Updated HubConstants for new embed dimensions and limits.
This commit is contained in:
HueByte
2026-02-19 21:52:18 +01:00
parent 7167b40013
commit b508a5854a
14 changed files with 746 additions and 156 deletions
@@ -1,5 +1,6 @@
using System.Text.RegularExpressions;
using EchoHub.Core.Constants;
using EchoHub.Core.DTOs;
using EchoHub.Server.Data;
using Microsoft.EntityFrameworkCore;
@@ -16,6 +17,7 @@ public static partial class DataMigrationService
await EnsureDefaultChannelsPublicAsync(db, logger);
await MigrateAnsiMessagesAsync(db, logger);
await MigrateEmbedJsonToArrayAsync(db, logger);
}
/// <summary>
@@ -91,4 +93,47 @@ public static partial class DataMigrationService
[GeneratedRegex(@"\x1b\[(?:(0)|(?:(38;2|48;2);(\d{1,3});(\d{1,3});(\d{1,3})))m")]
private static partial Regex AnsiColorRegex();
/// <summary>
/// Migrate old single-object EmbedJson ("{...}") to array format ("[{...}]").
/// </summary>
private static async Task MigrateEmbedJsonToArrayAsync(EchoHubDbContext db, ILogger logger)
{
var messages = await db.Messages
.Where(m => m.EmbedJson != null)
.ToListAsync();
var toMigrate = messages
.Where(m => m.EmbedJson!.TrimStart().StartsWith('{'))
.ToList();
if (toMigrate.Count == 0)
return;
logger.LogInformation("Found {Count} messages with legacy single-embed JSON. Migrating to array format...", toMigrate.Count);
var modified = 0;
foreach (var message in toMigrate)
{
try
{
var single = System.Text.Json.JsonSerializer.Deserialize<EmbedDto>(message.EmbedJson!);
if (single is not null)
{
message.EmbedJson = System.Text.Json.JsonSerializer.Serialize(new[] { single });
modified++;
}
}
catch
{
// Skip malformed JSON
}
}
if (modified > 0)
{
await db.SaveChangesAsync();
logger.LogInformation("Migrated {Count} embed records from single-object to array format.", modified);
}
}
}