From 9d495410f6b78aa00f4acf9227ab20f07b366968 Mon Sep 17 00:00:00 2001 From: Henry-Hiles Date: Wed, 2 Dec 2026 13:50:34 -0500 Subject: [PATCH] make webpush enabled check better Because Continuwuity sends a VAPID even when webpush is disabled. --- lib/controllers/unified_push.dart | 5 +++-- lib/controllers/unified_push_allowed.dart | 2 +- lib/models/capabilities.dart | 8 ++++++++ 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/controllers/unified_push.dart b/lib/controllers/unified_push.dart index 1fa3a2e..d6f3777 100644 --- a/lib/controllers/unified_push.dart +++ b/lib/controllers/unified_push.dart @@ -225,7 +225,8 @@ class UnifiedPushController extends AsyncNotifier { CapabilitiesController.provider.future, ); - if (capabilities.webpush?.vapid == null) { + final vapid = capabilities.webPushVapid; + if (vapid == null) { throw UnsupportedError( "Your homeserver does not support MSC4174 (Web Push), and therefore cannot send notifications to Nexus.", ); @@ -243,7 +244,7 @@ class UnifiedPushController extends AsyncNotifier { await Future.wait([ UnifiedPush.register( instance: deviceId, - vapid: capabilities.webpush?.vapid, + vapid: vapid, ), endpoint.future, ], eagerError: true); diff --git a/lib/controllers/unified_push_allowed.dart b/lib/controllers/unified_push_allowed.dart index 6dd1cf7..978f4ab 100644 --- a/lib/controllers/unified_push_allowed.dart +++ b/lib/controllers/unified_push_allowed.dart @@ -23,7 +23,7 @@ class UnifiedPushAllowedController extends AsyncNotifier { CapabilitiesController.provider.future, ); - if (capabilities.webpush?.vapid == null) { + if (capabilities.webPushVapid == null) { return "Your homeserver does not support MSC4174 (Web Push), and therefore cannot send notifications to Nexus."; } diff --git a/lib/models/capabilities.dart b/lib/models/capabilities.dart index cdf86b7..9224cf5 100644 --- a/lib/models/capabilities.dart +++ b/lib/models/capabilities.dart @@ -10,6 +10,14 @@ class const Capabilities({ @JsonKey(name: "org.matrix.msc4174.webpush") final WebPush? webpush, @JsonKey(name: "m.room_versions") final RoomVersions? roomVersions, }) with _$Capabilities { + /// The VAPID key to register Web Push pushers with, or null if the + /// homeserver can't send Web Push. Continuwuity sends a key even when the + /// feature is disabled, so `enabled` must be checked too. + String? get webPushVapid => switch (webpush) { + WebPush(enabled: true, :final vapid) => vapid, + _ => null, + }; + Map toJson() => _$CapabilitiesToJson(this); factory Capabilities.fromJson(Map json) =>