روشن/خاموشکردن این کانال در بخش «کانالهای اعلان» بالا. (در صورت خاموش بودن، کد ورود روی صفحه نمایش داده میشود.)
@@ -182,12 +203,7 @@
اعلانها (Web Push / PWA)
-
-
-
+
روشن/خاموشکردن این کانال در بخش «کانالهای اعلان» بالا. اینجا فقط کلیدهای VAPID را وارد کن.
diff --git a/src/JobsMedical.Web/Pages/Admin/Settings.cshtml.cs b/src/JobsMedical.Web/Pages/Admin/Settings.cshtml.cs
index 4caef51..88007e7 100644
--- a/src/JobsMedical.Web/Pages/Admin/Settings.cshtml.cs
+++ b/src/JobsMedical.Web/Pages/Admin/Settings.cshtml.cs
@@ -46,6 +46,7 @@ public class SettingsModel : PageModel
[BindProperty] public string? SmsTemplate { get; set; }
[BindProperty] public string? SmsSender { get; set; }
[BindProperty] public string? NeshanMapKey { get; set; }
+ [BindProperty] public bool WebNotificationsEnabled { get; set; }
[BindProperty] public bool PushEnabled { get; set; }
[BindProperty] public string? VapidPublicKey { get; set; }
[BindProperty] public string? VapidPrivateKey { get; set; }
@@ -88,6 +89,7 @@ public class SettingsModel : PageModel
DemoMode = s.DemoMode;
WebsitesEnabled = s.WebsitesEnabled;
WebsiteUrls = s.WebsiteUrls;
+ WebNotificationsEnabled = s.WebNotificationsEnabled;
PushEnabled = s.PushEnabled;
VapidPublicKey = s.VapidPublicKey;
VapidPrivateKey = s.VapidPrivateKey;
@@ -125,6 +127,7 @@ public class SettingsModel : PageModel
DemoMode = DemoMode,
WebsitesEnabled = WebsitesEnabled,
WebsiteUrls = WebsiteUrls,
+ WebNotificationsEnabled = WebNotificationsEnabled,
PushEnabled = PushEnabled,
VapidPublicKey = VapidPublicKey,
VapidPrivateKey = VapidPrivateKey,
diff --git a/src/JobsMedical.Web/Services/NotificationService.cs b/src/JobsMedical.Web/Services/NotificationService.cs
index 0a0fbe3..a1b55ee 100644
--- a/src/JobsMedical.Web/Services/NotificationService.cs
+++ b/src/JobsMedical.Web/Services/NotificationService.cs
@@ -78,18 +78,26 @@ public class NotificationService
private async Task AddAsync(List userIds, string title, string? body, string url)
{
if (userIds.Count == 0) return;
- foreach (var uid in userIds)
- _db.Notifications.Add(new Notification { UserId = uid, Title = title, Body = body, Url = url });
- await _db.SaveChangesAsync();
- _log.LogInformation("Notified {Count} users: {Title}", userIds.Count, title);
- // Live: stream to any open tab/PWA over SSE (our own origin — works in Iran).
- // The browser updates the bell instantly + shows a local toast/OS notification.
- var notice = new LiveNotice(title, body, url);
- foreach (var uid in userIds) _hub.Publish(uid, notice);
+ var settings = await _db.AppSettings.FindAsync(1);
+ var webOn = settings?.WebNotificationsEnabled ?? true; // master toggle for the in-app/web channel
- // Also push to the lock screen for users who subscribed (best-effort; Web Push
- // depends on the browser's push service, which is filtered in Iran for Chromium).
+ // Web / in-app notifications channel (bell list + live SSE). Admin can turn it off.
+ if (webOn)
+ {
+ foreach (var uid in userIds)
+ _db.Notifications.Add(new Notification { UserId = uid, Title = title, Body = body, Url = url });
+ await _db.SaveChangesAsync();
+ _log.LogInformation("Notified {Count} users: {Title}", userIds.Count, title);
+
+ // Live: stream to any open tab/PWA over SSE (our own origin — works in Iran).
+ // The browser updates the bell instantly + shows a local toast/OS notification.
+ var notice = new LiveNotice(title, body, url);
+ foreach (var uid in userIds) _hub.Publish(uid, notice);
+ }
+
+ // Web Push channel (lock screen). Self-gates on PushEnabled + VAPID keys; best-effort
+ // since Web Push depends on the browser's push service, which is filtered in Iran.
try { await _push.PushToUsersAsync(userIds, title, body, url); }
catch (Exception ex) { _log.LogWarning(ex, "Web push fan-out failed"); }
}
diff --git a/src/JobsMedical.Web/Services/Scraping/SettingsService.cs b/src/JobsMedical.Web/Services/Scraping/SettingsService.cs
index efc8aa5..01d1f5c 100644
--- a/src/JobsMedical.Web/Services/Scraping/SettingsService.cs
+++ b/src/JobsMedical.Web/Services/Scraping/SettingsService.cs
@@ -54,6 +54,7 @@ public class SettingsService
s.SmsTemplate = incoming.SmsTemplate?.Trim();
s.SmsSender = incoming.SmsSender?.Trim();
s.NeshanMapKey = incoming.NeshanMapKey?.Trim();
+ s.WebNotificationsEnabled = incoming.WebNotificationsEnabled;
s.PushEnabled = incoming.PushEnabled;
s.VapidPublicKey = incoming.VapidPublicKey?.Trim();
s.VapidPrivateKey = incoming.VapidPrivateKey?.Trim();