clearNotifications static method

Future<void> clearNotifications(
  1. ChatId chatId
)

Clears notifications identified by the provided ChatId via registered ServiceWorkers.

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',
    );
  }
}