1
1
import 'dart:async' ;
2
- import 'dart:convert' ;
3
2
import 'dart:io' ;
4
3
5
4
import 'package:http/http.dart' as http;
6
5
import 'package:collection/collection.dart' ;
7
- import 'package:crypto/crypto.dart' ;
8
6
import 'package:flutter_gen/gen_l10n/zulip_localizations.dart' ;
9
7
import 'package:flutter/foundation.dart' ;
10
8
import 'package:flutter/widgets.dart' hide Notification;
@@ -170,9 +168,7 @@ class NotificationDisplayManager {
170
168
}).buildUrl ();
171
169
172
170
await _androidHost.notify (
173
- // TODO the notification ID can be constant, instead of matching requestCode
174
- // (This is a legacy of `flutter_local_notifications`.)
175
- id: notificationIdAsHashOf (conversationKey),
171
+ id: kNotificationId,
176
172
tag: conversationKey,
177
173
channelId: NotificationChannelManager .kChannelId,
178
174
groupKey: groupKey,
@@ -215,7 +211,7 @@ class NotificationDisplayManager {
215
211
);
216
212
217
213
await _androidHost.notify (
218
- id: notificationIdAsHashOf (groupKey) ,
214
+ id: kNotificationId ,
219
215
tag: groupKey,
220
216
channelId: NotificationChannelManager .kChannelId,
221
217
groupKey: groupKey,
@@ -300,11 +296,18 @@ class NotificationDisplayManager {
300
296
// Even though we enable the `autoCancel` flag for summary notification
301
297
// during creation, the summary notification doesn't get auto canceled if
302
298
// child notifications are canceled programatically as done above.
303
- await _androidHost.cancel (
304
- tag: groupKey, id: notificationIdAsHashOf (groupKey));
299
+ await _androidHost.cancel (tag: groupKey, id: kNotificationId);
305
300
}
306
301
}
307
302
303
+ /// The constant numeric "ID" we use for all non-test notifications,
304
+ /// along with unique tags.
305
+ ///
306
+ /// Because we construct a unique string "tag" for each distinct
307
+ /// notification, and Android notifications are identified by the
308
+ /// pair (tag, ID), it's simplest to leave these numeric IDs all the same.
309
+ static const kNotificationId = 0x00C0FFEE ;
310
+
308
311
/// A key we use in [Notification.extras] for the [Message.id] of the
309
312
/// latest Zulip message in the notification's conversation.
310
313
///
@@ -313,21 +316,6 @@ class NotificationDisplayManager {
313
316
@visibleForTesting
314
317
static const kExtraLastZulipMessageId = 'lastZulipMessageId' ;
315
318
316
- /// A notification ID, derived as a hash of the given string key.
317
- ///
318
- /// The result fits in 31 bits, the size of a nonnegative Java `int` ,
319
- /// so that it can be used as an Android notification ID. (It's possible
320
- /// negative values would work too, which would add one bit.)
321
- ///
322
- /// This is a cryptographic hash, meaning that collisions are about as
323
- /// unlikely as one could hope for given the size of the hash.
324
- @visibleForTesting
325
- static int notificationIdAsHashOf (String key) {
326
- final bytes = sha256.convert (utf8.encode (key)).bytes;
327
- return bytes[0 ] | (bytes[1 ] << 8 ) | (bytes[2 ] << 16 )
328
- | ((bytes[3 ] & 0x7f ) << 24 );
329
- }
330
-
331
319
static String _conversationKey (MessageFcmMessage data, String groupKey) {
332
320
final conversation = switch (data.recipient) {
333
321
FcmMessageChannelRecipient (: var streamId, : var topic) => 'stream:$streamId :$topic ' ,
0 commit comments