@@ -7,6 +7,7 @@ import 'package:firebase_messaging/firebase_messaging.dart';
77import 'package:flutter/foundation.dart' ;
88import 'package:http/http.dart' as http;
99import 'package:nostr/nostr.dart' as nostr;
10+ import 'package:package_info_plus/package_info_plus.dart' ;
1011import 'package:shared_preferences/shared_preferences.dart' ;
1112
1213import '../../features/auth/domain/repositories/auth_repository.dart' ;
@@ -323,7 +324,7 @@ class MobilePushSubscriptionServiceImpl
323324 token: token,
324325 );
325326
326- final payload = _buildPayload (
327+ final payload = await _buildPayload (
327328 messageAuthorPubkeysHex: messageAuthors,
328329 token: token,
329330 );
@@ -451,27 +452,39 @@ class MobilePushSubscriptionServiceImpl
451452 containsToken (subscription['apns_tokens' ], token.apnsToken);
452453 }
453454
454- Map <String , dynamic > _buildPayload ({
455+ Future < Map <String , dynamic > > _buildPayload ({
455456 required List <String > messageAuthorPubkeysHex,
456457 required MobilePushToken token,
457- }) {
458+ }) async {
458459 final usesFcm = _tokenProvider.platformKey == 'android' ;
459460 final usesApns = _tokenProvider.platformKey == 'ios' ;
460461 final fcmToken = usesFcm ? token.fcmToken : null ;
461462 final apnsToken = usesApns ? token.apnsToken : null ;
463+ final apnsTopic = usesApns ? await _resolveIosBundleId () : null ;
462464
463465 return < String , dynamic > {
464466 'webhooks' : const < String > [],
465467 'web_push_subscriptions' : const < Object > [],
466468 'fcm_tokens' : fcmToken == null ? const < String > [] : < String > [fcmToken],
467469 'apns_tokens' : apnsToken == null ? const < String > [] : < String > [apnsToken],
470+ if (apnsTopic != null ) 'apns_topic' : apnsTopic,
468471 'filter' : < String , dynamic > {
469472 'kinds' : < int > [_dmEventKind],
470473 'authors' : messageAuthorPubkeysHex,
471474 },
472475 };
473476 }
474477
478+ Future <String ?> _resolveIosBundleId () async {
479+ try {
480+ final packageName = (await PackageInfo .fromPlatform ()).packageName.trim ();
481+ if (packageName.isEmpty) return null ;
482+ return packageName;
483+ } catch (_) {
484+ return null ;
485+ }
486+ }
487+
475488 Future <http.Response > _authedRequest ({
476489 required String method,
477490 required String path,
0 commit comments