clearNotifications static method
- ChatId chatId
Clears notifications identified by the provided ChatId via registered
ServiceWorker
s.
Implementation
static Future<void> clearNotifications(ChatId chatId) async {
// Try to `postMessage` to active registrations, if any.
try {
final List<web.ServiceWorkerRegistration> registrations = await web
.window
.navigator
.serviceWorker
.getRegistrations()
.toDart
.then((js) => js.toDart);
for (var registration in registrations) {
registration.active?.postMessage('closeAll:$chatId'.toJS);
}
} catch (e) {
// Ignore errors; SW might not be available yet.
Log.debug(
'`clearNotifications($chatId)` has failed due to: $e',
'WebUtils',
);
}
}