@@ -15,6 +15,7 @@ public interface INotificationSettingsService
|
||||
{
|
||||
SmtpOptions GetSmtp();
|
||||
LineOptions GetLine();
|
||||
WebPushOptions GetWebPush();
|
||||
void Reload();
|
||||
}
|
||||
|
||||
@@ -27,6 +28,7 @@ public sealed class NotificationSettingsService : INotificationSettingsService
|
||||
|
||||
private SmtpOptions? _smtp;
|
||||
private LineOptions? _line;
|
||||
private WebPushOptions? _webPush;
|
||||
|
||||
public NotificationSettingsService(
|
||||
IServiceScopeFactory scopeFactory,
|
||||
@@ -50,12 +52,19 @@ public sealed class NotificationSettingsService : INotificationSettingsService
|
||||
return _line!;
|
||||
}
|
||||
|
||||
public WebPushOptions GetWebPush()
|
||||
{
|
||||
EnsureLoaded();
|
||||
return _webPush!;
|
||||
}
|
||||
|
||||
public void Reload()
|
||||
{
|
||||
lock (_gate)
|
||||
{
|
||||
_smtp = null;
|
||||
_line = null;
|
||||
_webPush = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,7 +72,7 @@ public sealed class NotificationSettingsService : INotificationSettingsService
|
||||
{
|
||||
lock (_gate)
|
||||
{
|
||||
if (_smtp is not null && _line is not null)
|
||||
if (_smtp is not null && _line is not null && _webPush is not null)
|
||||
return;
|
||||
|
||||
using var scope = _scopeFactory.CreateScope();
|
||||
@@ -72,9 +81,11 @@ public sealed class NotificationSettingsService : INotificationSettingsService
|
||||
|
||||
if (row is null)
|
||||
{
|
||||
// Not seeded yet — use the appsettings values so sends still work.
|
||||
// Not seeded yet — use the appsettings values so sends still work. Web push has no
|
||||
// appsettings fallback; it stays disabled until the row exists with VAPID keys.
|
||||
_smtp = _smtpFallback.Value;
|
||||
_line = _lineFallback.Value;
|
||||
_webPush = new WebPushOptions();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -93,6 +104,12 @@ public sealed class NotificationSettingsService : INotificationSettingsService
|
||||
ChannelAccessToken = row.LineChannelAccessToken,
|
||||
ChannelSecret = row.LineChannelSecret,
|
||||
};
|
||||
_webPush = new WebPushOptions
|
||||
{
|
||||
PublicKey = row.VapidPublicKey,
|
||||
PrivateKey = row.VapidPrivateKey,
|
||||
Subject = row.VapidSubject,
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user