added re-broadcast to the notifications with action buttons, added some regular notifcations to broadcast service
This commit is contained in:
@@ -23,6 +23,7 @@ public class NotificationService : DisposableMediatorSubscriberBase, IHostedServ
|
||||
private readonly INotificationManager _notificationManager;
|
||||
private readonly IChatGui _chatGui;
|
||||
private readonly PairRequestService _pairRequestService;
|
||||
private readonly BroadcastService _broadcastService;
|
||||
private readonly HashSet<string> _shownPairRequestNotifications = new();
|
||||
|
||||
public NotificationService(
|
||||
@@ -32,7 +33,8 @@ public class NotificationService : DisposableMediatorSubscriberBase, IHostedServ
|
||||
INotificationManager notificationManager,
|
||||
IChatGui chatGui,
|
||||
LightlessMediator mediator,
|
||||
PairRequestService pairRequestService) : base(logger, mediator)
|
||||
PairRequestService pairRequestService,
|
||||
BroadcastService broadcastService) : base(logger, mediator)
|
||||
{
|
||||
_logger = logger;
|
||||
_configService = configService;
|
||||
@@ -40,6 +42,7 @@ public class NotificationService : DisposableMediatorSubscriberBase, IHostedServ
|
||||
_notificationManager = notificationManager;
|
||||
_chatGui = chatGui;
|
||||
_pairRequestService = pairRequestService;
|
||||
_broadcastService = broadcastService;
|
||||
}
|
||||
|
||||
public Task StartAsync(CancellationToken cancellationToken)
|
||||
@@ -47,6 +50,7 @@ public class NotificationService : DisposableMediatorSubscriberBase, IHostedServ
|
||||
Mediator.Subscribe<NotificationMessage>(this, HandleNotificationMessage);
|
||||
Mediator.Subscribe<PairRequestsUpdatedMessage>(this, HandlePairRequestsUpdated);
|
||||
Mediator.Subscribe<PerformanceNotificationMessage>(this, HandlePerformanceNotification);
|
||||
Mediator.Subscribe<BroadcastExpiredMessage>(this, HandleBroadcastExpired);
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
@@ -750,4 +754,73 @@ public class NotificationService : DisposableMediatorSubscriberBase, IHostedServ
|
||||
}
|
||||
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