setupPushNotifications function

Future<bool> setupPushNotifications(
  1. dynamic client, {
  2. dynamic forced = false,
})

Implementation

Future<bool> setupPushNotifications(
  Client client, {
  forced = false,
}) async {
  if ((Platform.isAndroid || Platform.isIOS)) {
    if (pushServer.isEmpty) {
      // no server given. Ignoring
      _log.warning(
        'No push server configured. Skipping push notification setup.',
      );
      return false;
    }
  } else if (Platform.isLinux || Platform.isMacOS || Platform.isWindows) {
    if (ntfyServer.isEmpty) {
      // no server given. Ignoring
      _log.warning(
        'No NTFY server configured. Skipping notification setup.',
      );
      return false;
    }
  } else {
    // not supported
    _log.warning('Notifications not supported on this platform');
    return false;
  }

  final deviceId = client.deviceId().toString();
  if (!forced && await wasRejected(deviceId)) {
    // If the user rejected and we aren’t asked to force, don’t bother them again.
    return false;
  }

  // this show some extra dialog here on devices where necessary
  final requested = await setupNotificationsForDevice(
    client,
    appName: appName,
    appIdPrefix: appIdPrefix,
    pushServer: pushServer,
    ntfyServer: ntfyServer,
  );
  if (requested == false) {
    // we were bluntly rejected, save and don’t bother them again:
    await setRejected(deviceId, true);
  }
  return requested != null;
}