Skip to content

Commit 55cab94

Browse files
committed
notif [nfc]: Change _groupKey method to take a realm URL and user ID
`_groupKey` method takes an `FcmMessageWithIdentity` object as an argument. This object is only used to get the realm URL and user ID. So, it makes sense to change the method to take `realmUrl` and `userId` directly. This change simplifies the method's signature and improves code clarity. Discussion: https://chat.zulip.org/#narrow/channel/516-mobile-dev-help/topic/Removing.20notifications.20for.20logged.20out.20account/near/2088813
1 parent a5af8d3 commit 55cab94

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

lib/notifications/display.dart

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import 'dart:async';
22
import 'dart:io';
33

4-
import 'package:http/http.dart' as http;
54
import 'package:collection/collection.dart';
65
import 'package:flutter/foundation.dart';
76
import 'package:flutter/widgets.dart' hide Notification;
7+
import 'package:http/http.dart' as http;
88

99
import '../api/model/model.dart';
1010
import '../api/notifications.dart';
@@ -231,7 +231,7 @@ class NotificationDisplayManager {
231231
static Future<void> _onMessageFcmMessage(MessageFcmMessage data, Map<String, dynamic> dataJson) async {
232232
assert(debugLog('notif message content: ${data.content}'));
233233
final zulipLocalizations = GlobalLocalizations.zulipLocalizations;
234-
final groupKey = _groupKey(data);
234+
final groupKey = _groupKey(data.realmUrl, data.userId);
235235
final conversationKey = _conversationKey(data, groupKey);
236236

237237
final oldMessagingStyle = await _androidHost
@@ -365,7 +365,7 @@ class NotificationDisplayManager {
365365
// There may be a lot of messages mentioned here, across a lot of
366366
// conversations. But they'll all be for one account, so they'll
367367
// fall under one notification group.
368-
final groupKey = _groupKey(data);
368+
final groupKey = _groupKey(data.realmUrl, data.userId);
369369

370370
// Find any conversations we can cancel the notification for.
371371
// The API doesn't lend itself to removing individual messages as
@@ -445,10 +445,10 @@ class NotificationDisplayManager {
445445
return '$groupKey|$conversation';
446446
}
447447

448-
static String _groupKey(FcmMessageWithIdentity data) {
448+
static String _groupKey(Uri realmUrl, int userId) {
449449
// The realm URL can't contain a `|`, because `|` is not a URL code point:
450450
// https://url.spec.whatwg.org/#url-code-points
451-
return "${data.realmUrl}|${data.userId}";
451+
return "$realmUrl|$userId";
452452
}
453453

454454
static String _personKey(Uri realmUrl, int userId) => "$realmUrl|$userId";

0 commit comments

Comments
 (0)