notifications improvement, working pairs incoming request feature and working user logging in notif

This commit is contained in:
choco
2025-10-06 20:25:47 +02:00
parent 090b81c989
commit 83e4555e4b
7 changed files with 176 additions and 49 deletions

View File

@@ -6,7 +6,6 @@ using LightlessSync.UI;
using LightlessSync.UI.Models;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using System.Numerics;
namespace LightlessSync.Services;
public class LightlessNotificationService : DisposableMediatorSubscriberBase, IHostedService
{
@@ -37,7 +36,7 @@ public class LightlessNotificationService : DisposableMediatorSubscriberBase, IH
_notificationUI = notificationUI;
}
public void ShowNotification(string title, string message, NotificationType type = NotificationType.Info,
TimeSpan? duration = null, List<LightlessNotificationAction>? actions = null)
TimeSpan? duration = null, List<LightlessNotificationAction>? actions = null, uint? soundEffectId = null)
{
var notification = new LightlessNotification
{
@@ -45,8 +44,16 @@ public class LightlessNotificationService : DisposableMediatorSubscriberBase, IH
Message = message,
Type = type,
Duration = duration ?? TimeSpan.FromSeconds(10),
Actions = actions ?? new List<LightlessNotificationAction>()
Actions = actions ?? new List<LightlessNotificationAction>(),
SoundEffectId = soundEffectId ?? NotificationSounds.GetDefaultSound(type)
};
// Play sound effect if specified
if (notification.SoundEffectId.HasValue)
{
PlayNotificationSound(notification.SoundEffectId.Value);
}
Mediator.Publish(new LightlessNotificationMessage(notification));
}
public void ShowPairRequestNotification(string senderName, string senderId, Action onAccept, Action onDecline)
@@ -57,6 +64,7 @@ public class LightlessNotificationService : DisposableMediatorSubscriberBase, IH
Message = $"{senderName} wants to pair with you.",
Type = NotificationType.Info,
Duration = TimeSpan.FromSeconds(60),
SoundEffectId = NotificationSounds.PairRequest,
Actions = new List<LightlessNotificationAction>
{
new()
@@ -91,6 +99,13 @@ public class LightlessNotificationService : DisposableMediatorSubscriberBase, IH
}
}
};
// Play sound effect
if (notification.SoundEffectId.HasValue)
{
PlayNotificationSound(notification.SoundEffectId.Value);
}
Mediator.Publish(new LightlessNotificationMessage(notification));
}
public void ShowDownloadCompleteNotification(string fileName, int fileCount, Action? onOpenFolder = null)
@@ -121,8 +136,16 @@ public class LightlessNotificationService : DisposableMediatorSubscriberBase, IH
$"Downloaded {fileName} successfully.",
Type = NotificationType.Info,
Duration = TimeSpan.FromSeconds(8),
Actions = actions
Actions = actions,
SoundEffectId = NotificationSounds.DownloadComplete
};
// Play sound effect
if (notification.SoundEffectId.HasValue)
{
PlayNotificationSound(notification.SoundEffectId.Value);
}
Mediator.Publish(new LightlessNotificationMessage(notification));
}
public void ShowErrorNotification(string title, string message, Exception? exception = null, Action? onRetry = null, Action? onViewLog = null)
@@ -161,21 +184,47 @@ public class LightlessNotificationService : DisposableMediatorSubscriberBase, IH
Message = exception != null ? $"{message}\n\nError: {exception.Message}" : message,
Type = NotificationType.Error,
Duration = TimeSpan.FromSeconds(15),
Actions = actions
Actions = actions,
SoundEffectId = NotificationSounds.Error
};
// Play sound effect
if (notification.SoundEffectId.HasValue)
{
PlayNotificationSound(notification.SoundEffectId.Value);
}
Mediator.Publish(new LightlessNotificationMessage(notification));
}
public void ShowPairDownloadNotification(List<(string playerName, float progress, string status)> downloadStatus)
public void ShowPairDownloadNotification(List<(string playerName, float progress, string status)> downloadStatus, int queueWaiting = 0)
{
var totalProgress = downloadStatus.Count > 0 ? downloadStatus.Average(x => x.progress) : 0f;
var completedCount = downloadStatus.Count(x => x.progress >= 1.0f);
var totalCount = downloadStatus.Count;
// Filter out queue status from user downloads
var userDownloads = downloadStatus.Where(x => x.playerName != "Pair Queue").ToList();
var message = $"Progress: {completedCount}/{totalCount} completed";
if (downloadStatus.Any(x => x.progress < 1.0f))
var totalProgress = userDownloads.Count > 0 ? userDownloads.Average(x => x.progress) : 0f;
var completedCount = userDownloads.Count(x => x.progress >= 1.0f);
var totalCount = userDownloads.Count;
var message = "";
// Add queue status at the top if there are waiting items
if (queueWaiting > 0)
{
var activeDownloads = downloadStatus.Where(x => x.progress < 1.0f).Take(3);
message += "\n" + string.Join("\n", activeDownloads.Select(x =>
message = $"Queue: {queueWaiting} waiting";
}
// Add download progress if there are downloads
if (totalCount > 0)
{
var progressMessage = $"Progress: {completedCount}/{totalCount} completed";
message = string.IsNullOrEmpty(message) ? progressMessage : $"{message}\n{progressMessage}";
}
if (userDownloads.Any(x => x.progress < 1.0f))
{
var maxNamesToShow = _configService.Current.MaxConcurrentPairApplications;
var activeDownloads = userDownloads.Where(x => x.progress < 1.0f).Take(maxNamesToShow);
var downloadLines = string.Join("\n", activeDownloads.Select(x =>
{
var statusText = x.status switch
{
@@ -188,11 +237,12 @@ public class LightlessNotificationService : DisposableMediatorSubscriberBase, IH
return $"• {x.playerName}: {statusText}";
}));
if (downloadStatus.Count(x => x.progress < 1.0f) > 3)
{
message += $"\n• ... and {downloadStatus.Count(x => x.progress < 1.0f) - 3} more";
}
message += string.IsNullOrEmpty(message) ? downloadLines : $"\n{downloadLines}";
}
// Check if all downloads are completed
var allDownloadsCompleted = userDownloads.All(x => x.progress >= 1.0f) && userDownloads.Any();
var notification = new LightlessNotification
{
Id = "pair_download_progress",
@@ -204,9 +254,33 @@ public class LightlessNotificationService : DisposableMediatorSubscriberBase, IH
Progress = totalProgress
};
Mediator.Publish(new LightlessNotificationMessage(notification));
if (allDownloadsCompleted)
{
DismissPairDownloadNotification();
}
}
public void DismissPairDownloadNotification()
{
Mediator.Publish(new LightlessNotificationDismissMessage("pair_download_progress"));
}
private void PlayNotificationSound(uint soundEffectId)
{
try
{
// TODO: Implement proper sound playback
// The ChatGui.PlaySoundEffect method doesn't exist in the current Dalamud API
// For now, just log what sound would be played
_logger.LogDebug("Would play notification sound effect {SoundId}", soundEffectId);
// Future implementation options:
// 1. Use UIModule->PlaySound() with proper unsafe interop
// 2. Use game's sound system through SigScanner
// 3. Wait for official Dalamud sound API
}
catch (Exception ex)
{
_logger.LogWarning(ex, "Failed to play notification sound effect {SoundId}", soundEffectId);
}
}
}