@@ -7,6 +7,7 @@ import 'package:flutter/widgets.dart';
77import 'package:flutter_local_notifications/flutter_local_notifications.dart' ;
88
99import '../api/notifications.dart' ;
10+ import '../host/android_notifications.dart' ;
1011import '../log.dart' ;
1112import '../model/binding.dart' ;
1213import '../model/narrow.dart' ;
@@ -99,40 +100,42 @@ class NotificationDisplayManager {
99100 data.senderFullName,
100101 };
101102 final conversationKey = _conversationKey (data);
102- ZulipBinding .instance.notifications.show (
103- // When creating the PendingIntent for the user to open the notification,
104- // the plugin makes the underlying Intent objects look the same.
105- // They differ in their extras, but that doesn't count:
106- // https://developer.android.com/reference/android/app/PendingIntent
107- //
108- // This leaves only PendingIntent.requestCode to distinguish one
109- // PendingIntent from another; the plugin sets that to the notification ID.
110- // We need a distinct PendingIntent for each conversation, so that the
111- // notifications can lead to the right conversations when opened.
112- // So, use a hash of the conversation key.
113- notificationIdAsHashOf (conversationKey),
114- title,
115- data.content,
116- payload: jsonEncode (dataJson),
117- NotificationDetails (android: AndroidNotificationDetails (
118- NotificationChannelManager .kChannelId,
119- // This [FlutterLocalNotificationsPlugin.show] call can potentially create
120- // a new channel, if our channel doesn't already exist. That *shouldn't*
121- // happen; if it does, it won't get the right settings. Set the channel
122- // name in that case to something that has a chance of warning the user,
123- // and that can serve as a signature to diagnose the situation in support.
124- // But really we should fix flutter_local_notifications to not do that
125- // (see issue linked below), or replace that package entirely (#351).
126- '(Zulip internal error)' , // TODO never implicitly create channel: https://github.com/MaikuB/flutter_local_notifications/issues/2135
127- tag: conversationKey,
128- color: kZulipBrandColor,
129- // TODO vary notification icon for debug
130- icon: 'zulip_notification' , // This name must appear in keep.xml too: https://github.com/zulip/zulip-flutter/issues/528
131- // TODO(#128) inbox-style
132-
133- // TODO plugin sets PendingIntent.FLAG_UPDATE_CURRENT; is that OK?
134- // TODO plugin doesn't set our Intent flags; is that OK?
135- )));
103+ ZulipBinding .instance.androidNotificationHost.notify (
104+ // TODO the notification ID can be constant, instead of matching requestCode
105+ // (This is a legacy of `flutter_local_notifications`.)
106+ id: notificationIdAsHashOf (conversationKey),
107+ tag: conversationKey,
108+ channelId: NotificationChannelManager .kChannelId,
109+
110+ contentTitle: title,
111+ contentText: data.content,
112+ color: kZulipBrandColor.value,
113+ // TODO vary notification icon for debug
114+ smallIconResourceName: 'zulip_notification' , // This name must appear in keep.xml too: https://github.com/zulip/zulip-flutter/issues/528
115+ // TODO(#128) inbox-style
116+
117+ contentIntent: PendingIntent (
118+ // TODO make intent URLs distinct, instead of requestCode
119+ // (This way is a legacy of flutter_local_notifications.)
120+ // The Intent objects we make for different conversations look the same.
121+ // They differ in their extras, but that doesn't count:
122+ // https://developer.android.com/reference/android/app/PendingIntent
123+ //
124+ // This leaves only PendingIntent.requestCode to distinguish one
125+ // PendingIntent from another; the plugin sets that to the notification ID.
126+ // We need a distinct PendingIntent for each conversation, so that the
127+ // notifications can lead to the right conversations when opened.
128+ // So, use a hash of the conversation key.
129+ requestCode: notificationIdAsHashOf (conversationKey),
130+
131+ // TODO is setting PendingIntentFlag.updateCurrent OK?
132+ // (That's a legacy of `flutter_local_notifications`.)
133+ flags: PendingIntentFlag .immutable | PendingIntentFlag .updateCurrent,
134+ intentPayload: jsonEncode (dataJson),
135+ // TODO this doesn't set the Intent flags we set in zulip-mobile; is that OK?
136+ // (This is a legacy of `flutter_local_notifications`.)
137+ ),
138+ );
136139 }
137140
138141 /// A notification ID, derived as a hash of the given string key.
0 commit comments