added re-broadcast to the notifications with action buttons, added some regular notifcations to broadcast service
This commit is contained in:
@@ -190,7 +190,8 @@ public sealed class Plugin : IDalamudPlugin
|
|||||||
notificationManager,
|
notificationManager,
|
||||||
chatGui,
|
chatGui,
|
||||||
s.GetRequiredService<LightlessMediator>(),
|
s.GetRequiredService<LightlessMediator>(),
|
||||||
s.GetRequiredService<PairRequestService>()));
|
s.GetRequiredService<PairRequestService>(),
|
||||||
|
s.GetRequiredService<BroadcastService>()));
|
||||||
collection.AddSingleton((s) =>
|
collection.AddSingleton((s) =>
|
||||||
{
|
{
|
||||||
var httpClient = new HttpClient();
|
var httpClient = new HttpClient();
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
using LightlessSync.API.Dto.Group;
|
using LightlessSync.API.Dto.Group;
|
||||||
using LightlessSync.API.Dto.User;
|
using LightlessSync.API.Dto.User;
|
||||||
using LightlessSync.LightlessConfiguration;
|
using LightlessSync.LightlessConfiguration;
|
||||||
using LightlessSync.Services.Mediator;
|
using LightlessSync.Services.Mediator;
|
||||||
@@ -394,6 +394,10 @@ public class BroadcastService : IHostedService, IMediatorSubscriber
|
|||||||
if (!IsLightFinderAvailable)
|
if (!IsLightFinderAvailable)
|
||||||
{
|
{
|
||||||
_logger.LogWarning("ToggleBroadcast - Lightfinder is not available.");
|
_logger.LogWarning("ToggleBroadcast - Lightfinder is not available.");
|
||||||
|
_mediator.Publish(new NotificationMessage(
|
||||||
|
"Broadcast Unavailable",
|
||||||
|
"Lightfinder is not available on this server.",
|
||||||
|
LightlessConfiguration.Models.NotificationType.Error));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -403,6 +407,10 @@ public class BroadcastService : IHostedService, IMediatorSubscriber
|
|||||||
if (!_config.Current.BroadcastEnabled && cooldown is { } cd && cd > TimeSpan.Zero)
|
if (!_config.Current.BroadcastEnabled && cooldown is { } cd && cd > TimeSpan.Zero)
|
||||||
{
|
{
|
||||||
_logger.LogWarning("Cooldown active. Must wait {Remaining}s before re-enabling.", cd.TotalSeconds);
|
_logger.LogWarning("Cooldown active. Must wait {Remaining}s before re-enabling.", cd.TotalSeconds);
|
||||||
|
_mediator.Publish(new NotificationMessage(
|
||||||
|
"Broadcast Cooldown",
|
||||||
|
$"Please wait {cd.TotalSeconds:F0} seconds before re-enabling broadcast.",
|
||||||
|
LightlessConfiguration.Models.NotificationType.Warning));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -427,10 +435,19 @@ public class BroadcastService : IHostedService, IMediatorSubscriber
|
|||||||
_logger.LogDebug("Toggling broadcast. Server currently broadcasting: {ServerStatus}, setting to: {NewStatus}", isCurrentlyBroadcasting, newStatus);
|
_logger.LogDebug("Toggling broadcast. Server currently broadcasting: {ServerStatus}, setting to: {NewStatus}", isCurrentlyBroadcasting, newStatus);
|
||||||
|
|
||||||
_mediator.Publish(new EnableBroadcastMessage(hashedCid, newStatus));
|
_mediator.Publish(new EnableBroadcastMessage(hashedCid, newStatus));
|
||||||
|
|
||||||
|
_mediator.Publish(new NotificationMessage(
|
||||||
|
newStatus ? "Broadcast Enabled" : "Broadcast Disabled",
|
||||||
|
newStatus ? "Your Lightfinder broadcast has been enabled." : "Your Lightfinder broadcast has been disabled.",
|
||||||
|
LightlessConfiguration.Models.NotificationType.Info));
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
_logger.LogError(ex, "Failed to determine current broadcast status for toggle");
|
_logger.LogError(ex, "Failed to determine current broadcast status for toggle");
|
||||||
|
_mediator.Publish(new NotificationMessage(
|
||||||
|
"Broadcast Failed",
|
||||||
|
$"Failed to toggle broadcast: {ex.Message}",
|
||||||
|
LightlessConfiguration.Models.NotificationType.Error));
|
||||||
}
|
}
|
||||||
}).ConfigureAwait(false);
|
}).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
@@ -493,6 +510,7 @@ public class BroadcastService : IHostedService, IMediatorSubscriber
|
|||||||
{
|
{
|
||||||
_logger.LogDebug("Broadcast TTL expired. Disabling broadcast locally.");
|
_logger.LogDebug("Broadcast TTL expired. Disabling broadcast locally.");
|
||||||
ApplyBroadcastDisabled(forcePublish: true);
|
ApplyBroadcastDisabled(forcePublish: true);
|
||||||
|
_mediator.Publish(new BroadcastExpiredMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -108,6 +108,7 @@ public record EnableBroadcastMessage(string HashedCid, bool Enabled) : MessageBa
|
|||||||
public record BroadcastStatusChangedMessage(bool Enabled, TimeSpan? Ttl) : MessageBase;
|
public record BroadcastStatusChangedMessage(bool Enabled, TimeSpan? Ttl) : MessageBase;
|
||||||
public record SyncshellBroadcastsUpdatedMessage : MessageBase;
|
public record SyncshellBroadcastsUpdatedMessage : MessageBase;
|
||||||
public record PairRequestsUpdatedMessage : MessageBase;
|
public record PairRequestsUpdatedMessage : MessageBase;
|
||||||
|
public record BroadcastExpiredMessage : MessageBase;
|
||||||
public record VisibilityChange : MessageBase;
|
public record VisibilityChange : MessageBase;
|
||||||
#pragma warning restore S2094
|
#pragma warning restore S2094
|
||||||
#pragma warning restore MA0048 // File name must match type name
|
#pragma warning restore MA0048 // File name must match type name
|
||||||
@@ -23,6 +23,7 @@ public class NotificationService : DisposableMediatorSubscriberBase, IHostedServ
|
|||||||
private readonly INotificationManager _notificationManager;
|
private readonly INotificationManager _notificationManager;
|
||||||
private readonly IChatGui _chatGui;
|
private readonly IChatGui _chatGui;
|
||||||
private readonly PairRequestService _pairRequestService;
|
private readonly PairRequestService _pairRequestService;
|
||||||
|
private readonly BroadcastService _broadcastService;
|
||||||
private readonly HashSet<string> _shownPairRequestNotifications = new();
|
private readonly HashSet<string> _shownPairRequestNotifications = new();
|
||||||
|
|
||||||
public NotificationService(
|
public NotificationService(
|
||||||
@@ -32,7 +33,8 @@ public class NotificationService : DisposableMediatorSubscriberBase, IHostedServ
|
|||||||
INotificationManager notificationManager,
|
INotificationManager notificationManager,
|
||||||
IChatGui chatGui,
|
IChatGui chatGui,
|
||||||
LightlessMediator mediator,
|
LightlessMediator mediator,
|
||||||
PairRequestService pairRequestService) : base(logger, mediator)
|
PairRequestService pairRequestService,
|
||||||
|
BroadcastService broadcastService) : base(logger, mediator)
|
||||||
{
|
{
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_configService = configService;
|
_configService = configService;
|
||||||
@@ -40,6 +42,7 @@ public class NotificationService : DisposableMediatorSubscriberBase, IHostedServ
|
|||||||
_notificationManager = notificationManager;
|
_notificationManager = notificationManager;
|
||||||
_chatGui = chatGui;
|
_chatGui = chatGui;
|
||||||
_pairRequestService = pairRequestService;
|
_pairRequestService = pairRequestService;
|
||||||
|
_broadcastService = broadcastService;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task StartAsync(CancellationToken cancellationToken)
|
public Task StartAsync(CancellationToken cancellationToken)
|
||||||
@@ -47,6 +50,7 @@ public class NotificationService : DisposableMediatorSubscriberBase, IHostedServ
|
|||||||
Mediator.Subscribe<NotificationMessage>(this, HandleNotificationMessage);
|
Mediator.Subscribe<NotificationMessage>(this, HandleNotificationMessage);
|
||||||
Mediator.Subscribe<PairRequestsUpdatedMessage>(this, HandlePairRequestsUpdated);
|
Mediator.Subscribe<PairRequestsUpdatedMessage>(this, HandlePairRequestsUpdated);
|
||||||
Mediator.Subscribe<PerformanceNotificationMessage>(this, HandlePerformanceNotification);
|
Mediator.Subscribe<PerformanceNotificationMessage>(this, HandlePerformanceNotification);
|
||||||
|
Mediator.Subscribe<BroadcastExpiredMessage>(this, HandleBroadcastExpired);
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -750,4 +754,73 @@ public class NotificationService : DisposableMediatorSubscriberBase, IHostedServ
|
|||||||
}
|
}
|
||||||
return $"{playerName} ({userData.UID})";
|
return $"{playerName} ({userData.UID})";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void HandleBroadcastExpired(BroadcastExpiredMessage _)
|
||||||
|
{
|
||||||
|
var location = GetNotificationLocation(NotificationType.Warning);
|
||||||
|
|
||||||
|
if (location == NotificationLocation.Chat || location == NotificationLocation.ChatAndLightlessUi)
|
||||||
|
{
|
||||||
|
ShowChat(new NotificationMessage("Broadcast Expired", "Your Lightfinder broadcast has expired after 3 hours.", NotificationType.Warning));
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((location == NotificationLocation.LightlessUi || location == NotificationLocation.ChatAndLightlessUi)
|
||||||
|
&& _configService.Current.UseLightlessNotifications)
|
||||||
|
{
|
||||||
|
var notification = new LightlessNotification
|
||||||
|
{
|
||||||
|
Id = "broadcast_expired",
|
||||||
|
Title = "Broadcast Expired",
|
||||||
|
Message = "Your Lightfinder broadcast has expired after 3 hours. Would you like to re-enable it?",
|
||||||
|
Type = NotificationType.Warning,
|
||||||
|
Duration = TimeSpan.FromSeconds(_configService.Current.WarningNotificationDurationSeconds),
|
||||||
|
SoundEffectId = GetSoundEffectId(NotificationType.Warning, null),
|
||||||
|
Actions = CreateBroadcastExpiredActions()
|
||||||
|
};
|
||||||
|
|
||||||
|
if (notification.SoundEffectId.HasValue)
|
||||||
|
{
|
||||||
|
PlayNotificationSound(notification.SoundEffectId.Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
Mediator.Publish(new LightlessNotificationMessage(notification));
|
||||||
|
}
|
||||||
|
else if (location != NotificationLocation.Nowhere && location != NotificationLocation.Chat)
|
||||||
|
{
|
||||||
|
HandleNotificationMessage(new NotificationMessage("Broadcast Expired", "Your Lightfinder broadcast has expired after 3 hours.", NotificationType.Warning));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<LightlessNotificationAction> CreateBroadcastExpiredActions()
|
||||||
|
{
|
||||||
|
return new List<LightlessNotificationAction>
|
||||||
|
{
|
||||||
|
new()
|
||||||
|
{
|
||||||
|
Id = "re_enable",
|
||||||
|
Label = "Re-enable Broadcast",
|
||||||
|
Icon = FontAwesomeIcon.Plus,
|
||||||
|
Color = UIColors.Get("LightlessGreen"),
|
||||||
|
IsPrimary = true,
|
||||||
|
OnClick = (n) =>
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Re-enabling broadcast from notification");
|
||||||
|
_broadcastService.ToggleBroadcast();
|
||||||
|
DismissNotification(n);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
new()
|
||||||
|
{
|
||||||
|
Id = "close",
|
||||||
|
Label = "Close",
|
||||||
|
Icon = FontAwesomeIcon.Times,
|
||||||
|
Color = UIColors.Get("DimRed"),
|
||||||
|
OnClick = (n) =>
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Broadcast expiration notification dismissed");
|
||||||
|
DismissNotification(n);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user