Skip to content

Commit 082f95e

Browse files
notif [nfc]: Rename NotificationOpenPayload -> NotificationNavigationData
And rename it's methods to be clear that they are Android only.
1 parent de12464 commit 082f95e

File tree

2 files changed

+39
-39
lines changed

2 files changed

+39
-39
lines changed

lib/notifications/display.dart

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -294,15 +294,15 @@ class NotificationDisplayManager {
294294
name: data.senderFullName,
295295
iconBitmap: await _fetchBitmap(data.senderAvatarUrl))));
296296

297-
final intentDataUrl = NotificationOpenPayload(
297+
final intentDataUrl = NotificationNavigationData(
298298
realmUrl: data.realmUrl,
299299
userId: data.userId,
300300
narrow: switch (data.recipient) {
301301
FcmMessageChannelRecipient(:var streamId, :var topic) =>
302302
TopicNarrow(streamId, topic),
303303
FcmMessageDmRecipient(:var allRecipientIds) =>
304304
DmNarrow(allRecipientIds: allRecipientIds, selfUserId: data.userId),
305-
}).buildUrl();
305+
}).buildAndroidNotificationUrl();
306306

307307
await _androidHost.notify(
308308
id: kNotificationId,
@@ -498,7 +498,7 @@ class NotificationDisplayManager {
498498

499499
assert(debugLog('got notif: url: $url'));
500500
assert(url.scheme == 'zulip' && url.host == 'notification');
501-
final payload = NotificationOpenPayload.parseUrl(url);
501+
final payload = NotificationNavigationData.parseAndroidNotificationUrl(url);
502502

503503
final account = globalStore.accounts.firstWhereOrNull(
504504
(account) => account.realmUrl.origin == payload.realmUrl.origin
@@ -551,20 +551,21 @@ class NotificationDisplayManager {
551551
}
552552
}
553553

554-
/// The information contained in 'zulip://notification/…' internal
555-
/// Android intent data URL, used for notification-open flow.
556-
class NotificationOpenPayload {
554+
class NotificationNavigationData {
557555
final Uri realmUrl;
558556
final int userId;
559-
final Narrow narrow;
557+
final SendableNarrow narrow;
560558

561-
NotificationOpenPayload({
559+
NotificationNavigationData({
562560
required this.realmUrl,
563561
required this.userId,
564562
required this.narrow,
565563
});
566564

567-
factory NotificationOpenPayload.parseUrl(Uri url) {
565+
/// Parses the internal Android notification url, that was created using
566+
/// [buildAndroidNotificationUrl], and retrieves the information required
567+
/// for navigation.
568+
factory NotificationNavigationData.parseAndroidNotificationUrl(Uri url) {
568569
if (url case Uri(
569570
scheme: 'zulip',
570571
host: 'notification',
@@ -582,7 +583,7 @@ class NotificationOpenPayload {
582583
final realmUrl = Uri.parse(realmUrlStr);
583584
final userId = int.parse(userIdStr, radix: 10);
584585

585-
final Narrow narrow;
586+
final SendableNarrow narrow;
586587
switch (narrowType) {
587588
case 'topic':
588589
final channelIdStr = url.queryParameters['channel_id']!;
@@ -599,7 +600,7 @@ class NotificationOpenPayload {
599600
throw const FormatException();
600601
}
601602

602-
return NotificationOpenPayload(
603+
return NotificationNavigationData(
603604
realmUrl: realmUrl,
604605
userId: userId,
605606
narrow: narrow,
@@ -610,7 +611,7 @@ class NotificationOpenPayload {
610611
}
611612
}
612613

613-
Uri buildUrl() {
614+
Uri buildAndroidNotificationUrl() {
614615
return Uri(
615616
scheme: 'zulip',
616617
host: 'notification',
@@ -627,7 +628,6 @@ class NotificationOpenPayload {
627628
'narrow_type': 'dm',
628629
'all_recipient_ids': allRecipientIds.join(','),
629630
},
630-
_ => throw UnsupportedError('Found an unexpected Narrow of type ${narrow.runtimeType}.'),
631631
})
632632
},
633633
);

test/notifications/display_test.dart

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -346,15 +346,15 @@ void main() {
346346
const expectedPendingIntentFlags = PendingIntentFlag.immutable;
347347
const expectedIntentFlags = IntentFlag.activityClearTop | IntentFlag.activityNewTask;
348348
final expectedSelfUserKey = '${data.realmUrl}|${data.userId}';
349-
final expectedIntentDataUrl = NotificationOpenPayload(
349+
final expectedIntentDataUrl = NotificationNavigationData(
350350
realmUrl: data.realmUrl,
351351
userId: data.userId,
352352
narrow: switch (data.recipient) {
353353
FcmMessageChannelRecipient(:var streamId, :var topic) =>
354354
TopicNarrow(streamId, topic),
355355
FcmMessageDmRecipient(:var allRecipientIds) =>
356356
DmNarrow(allRecipientIds: allRecipientIds, selfUserId: data.userId),
357-
}).buildUrl();
357+
}).buildAndroidNotificationUrl();
358358

359359
final messageStyleMessagesChecks =
360360
messageStyleMessages.mapIndexed((i, messageData) {
@@ -1072,15 +1072,15 @@ void main() {
10721072

10731073
Future<void> openNotification(WidgetTester tester, Account account, Message message) async {
10741074
final data = messageFcmMessage(message, account: account);
1075-
final intentDataUrl = NotificationOpenPayload(
1075+
final intentDataUrl = NotificationNavigationData(
10761076
realmUrl: data.realmUrl,
10771077
userId: data.userId,
10781078
narrow: switch (data.recipient) {
10791079
FcmMessageChannelRecipient(:var streamId, :var topic) =>
10801080
TopicNarrow(streamId, topic),
10811081
FcmMessageDmRecipient(:var allRecipientIds) =>
10821082
DmNarrow(allRecipientIds: allRecipientIds, selfUserId: data.userId),
1083-
}).buildUrl();
1083+
}).buildAndroidNotificationUrl();
10841084
unawaited(
10851085
WidgetsBinding.instance.handlePushRoute(intentDataUrl.toString()));
10861086
await tester.idle(); // let navigateForNotification find navigator
@@ -1198,19 +1198,19 @@ void main() {
11981198
testWidgets('at app launch', (tester) async {
11991199
addTearDown(testBinding.reset);
12001200
// Set up a value for `PlatformDispatcher.defaultRouteName` to return,
1201-
// for determining the intial route.
1201+
// for determining the initial route.
12021202
final account = eg.selfAccount;
12031203
final message = eg.streamMessage();
12041204
final data = messageFcmMessage(message, account: account);
1205-
final intentDataUrl = NotificationOpenPayload(
1205+
final intentDataUrl = NotificationNavigationData(
12061206
realmUrl: data.realmUrl,
12071207
userId: data.userId,
12081208
narrow: switch (data.recipient) {
12091209
FcmMessageChannelRecipient(:var streamId, :var topic) =>
12101210
TopicNarrow(streamId, topic),
12111211
FcmMessageDmRecipient(:var allRecipientIds) =>
12121212
DmNarrow(allRecipientIds: allRecipientIds, selfUserId: data.userId),
1213-
}).buildUrl();
1213+
}).buildAndroidNotificationUrl();
12141214
addTearDown(tester.binding.platformDispatcher.clearDefaultRouteNameTestValue);
12151215
tester.binding.platformDispatcher.defaultRouteNameTestValue = intentDataUrl.toString();
12161216

@@ -1235,15 +1235,15 @@ void main() {
12351235
await testBinding.globalStore.add(accountA, eg.initialSnapshot());
12361236
await testBinding.globalStore.add(accountB, eg.initialSnapshot());
12371237

1238-
final intentDataUrl = NotificationOpenPayload(
1238+
final intentDataUrl = NotificationNavigationData(
12391239
realmUrl: data.realmUrl,
12401240
userId: data.userId,
12411241
narrow: switch (data.recipient) {
12421242
FcmMessageChannelRecipient(:var streamId, :var topic) =>
12431243
TopicNarrow(streamId, topic),
12441244
FcmMessageDmRecipient(:var allRecipientIds) =>
12451245
DmNarrow(allRecipientIds: allRecipientIds, selfUserId: data.userId),
1246-
}).buildUrl();
1246+
}).buildAndroidNotificationUrl();
12471247
addTearDown(tester.binding.platformDispatcher.clearDefaultRouteNameTestValue);
12481248
tester.binding.platformDispatcher.defaultRouteNameTestValue = intentDataUrl.toString();
12491249

@@ -1256,39 +1256,39 @@ void main() {
12561256
});
12571257
});
12581258

1259-
group('NotificationOpenPayload', () {
1259+
group('NotificationNavigationData', () {
12601260
test('smoke round-trip', () {
12611261
// DM narrow
1262-
var payload = NotificationOpenPayload(
1262+
var payload = NotificationNavigationData(
12631263
realmUrl: Uri.parse('http://chat.example'),
12641264
userId: 1001,
12651265
narrow: DmNarrow(allRecipientIds: [1001, 1002], selfUserId: 1001),
12661266
);
1267-
var url = payload.buildUrl();
1268-
check(NotificationOpenPayload.parseUrl(url))
1267+
var url = payload.buildAndroidNotificationUrl();
1268+
check(NotificationNavigationData.parseAndroidNotificationUrl(url))
12691269
..realmUrl.equals(payload.realmUrl)
12701270
..userId.equals(payload.userId)
12711271
..narrow.equals(payload.narrow);
12721272

12731273
// Topic narrow
1274-
payload = NotificationOpenPayload(
1274+
payload = NotificationNavigationData(
12751275
realmUrl: Uri.parse('http://chat.example'),
12761276
userId: 1001,
12771277
narrow: eg.topicNarrow(1, 'topic A'),
12781278
);
1279-
url = payload.buildUrl();
1280-
check(NotificationOpenPayload.parseUrl(url))
1279+
url = payload.buildAndroidNotificationUrl();
1280+
check(NotificationNavigationData.parseAndroidNotificationUrl(url))
12811281
..realmUrl.equals(payload.realmUrl)
12821282
..userId.equals(payload.userId)
12831283
..narrow.equals(payload.narrow);
12841284
});
12851285

12861286
test('buildUrl: smoke DM', () {
1287-
final url = NotificationOpenPayload(
1287+
final url = NotificationNavigationData(
12881288
realmUrl: Uri.parse('http://chat.example'),
12891289
userId: 1001,
12901290
narrow: DmNarrow(allRecipientIds: [1001, 1002], selfUserId: 1001),
1291-
).buildUrl();
1291+
).buildAndroidNotificationUrl();
12921292
check(url)
12931293
..scheme.equals('zulip')
12941294
..host.equals('notification')
@@ -1301,11 +1301,11 @@ void main() {
13011301
});
13021302

13031303
test('buildUrl: smoke topic', () {
1304-
final url = NotificationOpenPayload(
1304+
final url = NotificationNavigationData(
13051305
realmUrl: Uri.parse('http://chat.example'),
13061306
userId: 1001,
13071307
narrow: eg.topicNarrow(1, 'topic A'),
1308-
).buildUrl();
1308+
).buildAndroidNotificationUrl();
13091309
check(url)
13101310
..scheme.equals('zulip')
13111311
..host.equals('notification')
@@ -1328,7 +1328,7 @@ void main() {
13281328
'narrow_type': 'dm',
13291329
'all_recipient_ids': '1001,1002',
13301330
});
1331-
check(NotificationOpenPayload.parseUrl(url))
1331+
check(NotificationNavigationData.parseAndroidNotificationUrl(url))
13321332
..realmUrl.equals(Uri.parse('http://chat.example'))
13331333
..userId.equals(1001)
13341334
..narrow.which((it) => it.isA<DmNarrow>()
@@ -1347,7 +1347,7 @@ void main() {
13471347
'channel_id': '1',
13481348
'topic': 'topic A',
13491349
});
1350-
check(NotificationOpenPayload.parseUrl(url))
1350+
check(NotificationNavigationData.parseAndroidNotificationUrl(url))
13511351
..realmUrl.equals(Uri.parse('http://chat.example'))
13521352
..userId.equals(1001)
13531353
..narrow.which((it) => it.isA<TopicNarrow>()
@@ -1406,7 +1406,7 @@ void main() {
14061406
},
14071407
];
14081408
for (final params in testCases) {
1409-
check(() => NotificationOpenPayload.parseUrl(Uri(
1409+
check(() => NotificationNavigationData.parseAndroidNotificationUrl(Uri(
14101410
scheme: 'zulip',
14111411
host: 'notification',
14121412
queryParameters: params,
@@ -1432,7 +1432,7 @@ void main() {
14321432
'channel_id': '1',
14331433
'topic': 'topic A',
14341434
});
1435-
check(() => NotificationOpenPayload.parseUrl(url))
1435+
check(() => NotificationNavigationData.parseAndroidNotificationUrl(url))
14361436
.throws<FormatException>();
14371437
});
14381438

@@ -1447,7 +1447,7 @@ void main() {
14471447
'channel_id': '1',
14481448
'topic': 'topic A',
14491449
});
1450-
check(() => NotificationOpenPayload.parseUrl(url))
1450+
check(() => NotificationNavigationData.parseAndroidNotificationUrl(url))
14511451
.throws<FormatException>();
14521452
});
14531453
});
@@ -1531,7 +1531,7 @@ extension on Subject<StatusBarNotification> {
15311531
Subject<String> get tag => has((x) => x.tag, 'tag');
15321532
}
15331533

1534-
extension on Subject<NotificationOpenPayload> {
1534+
extension on Subject<NotificationNavigationData> {
15351535
Subject<Uri> get realmUrl => has((x) => x.realmUrl, 'realmUrl');
15361536
Subject<int> get userId => has((x) => x.userId, 'userId');
15371537
Subject<Narrow> get narrow => has((x) => x.narrow, 'narrow');

0 commit comments

Comments
 (0)