Skip to content

Commit cc2ebf5

Browse files
1 parent e86626c commit cc2ebf5

File tree

2 files changed

+46
-6
lines changed

2 files changed

+46
-6
lines changed

lib/notifications/display.dart

+23-5
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ class NotificationDisplayManager {
8989
}
9090
}
9191

92-
static void _onMessageFcmMessage(MessageFcmMessage data, Map<String, dynamic> dataJson) {
92+
static Future<void> _onMessageFcmMessage(MessageFcmMessage data, Map<String, dynamic> dataJson) async {
9393
assert(debugLog('notif message content: ${data.content}'));
9494
final zulipLocalizations = GlobalLocalizations.zulipLocalizations;
9595
final title = switch (data.recipient) {
@@ -103,13 +103,16 @@ class NotificationDisplayManager {
103103
FcmMessageDmRecipient() =>
104104
data.senderFullName,
105105
};
106-
final conversationKey = _conversationKey(data);
107-
ZulipBinding.instance.androidNotificationHost.notify(
106+
final groupKey = _groupKey(data);
107+
final conversationKey = _conversationKey(data, groupKey);
108+
109+
await ZulipBinding.instance.androidNotificationHost.notify(
108110
// TODO the notification ID can be constant, instead of matching requestCode
109111
// (This is a legacy of `flutter_local_notifications`.)
110112
id: notificationIdAsHashOf(conversationKey),
111113
tag: conversationKey,
112114
channelId: NotificationChannelManager.kChannelId,
115+
groupKey: groupKey,
113116

114117
contentTitle: title,
115118
contentText: data.content,
@@ -139,6 +142,22 @@ class NotificationDisplayManager {
139142
// TODO this doesn't set the Intent flags we set in zulip-mobile; is that OK?
140143
// (This is a legacy of `flutter_local_notifications`.)
141144
),
145+
autoCancel: true,
146+
);
147+
148+
await ZulipBinding.instance.androidNotificationHost.notify(
149+
id: notificationIdAsHashOf(groupKey),
150+
channelId: NotificationChannelManager.kChannelId,
151+
tag: groupKey,
152+
groupKey: groupKey,
153+
isGroupSummary: true,
154+
color: kZulipBrandColor.value,
155+
// TODO vary notification icon for debug
156+
smallIconResourceName: 'zulip_notification', // This name must appear in keep.xml too: https://github.com/zulip/zulip-flutter/issues/528
157+
inboxStyle: InboxStyle(
158+
// TODO(#570) Show organization name, not URL
159+
summaryText: data.realmUri.toString()),
160+
autoCancel: true,
142161
);
143162
}
144163

@@ -157,8 +176,7 @@ class NotificationDisplayManager {
157176
| ((bytes[3] & 0x7f) << 24);
158177
}
159178

160-
static String _conversationKey(MessageFcmMessage data) {
161-
final groupKey = _groupKey(data);
179+
static String _conversationKey(MessageFcmMessage data, String groupKey) {
162180
final conversation = switch (data.recipient) {
163181
FcmMessageStreamRecipient(:var streamId, :var topic) => 'stream:$streamId:$topic',
164182
FcmMessageDmRecipient(:var allRecipientIds) => 'dm:${allRecipientIds.join(',')}',

test/notifications/display_test.dart

+23-1
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,13 @@ void main() {
111111
required String expectedTagComponent,
112112
}) {
113113
final expectedTag = '${data.realmUri}|${data.userId}|$expectedTagComponent';
114+
final expectedGroupKey = '${data.realmUri}|${data.userId}';
114115
final expectedId =
115116
NotificationDisplayManager.notificationIdAsHashOf(expectedTag);
116117
const expectedIntentFlags =
117118
PendingIntentFlag.immutable | PendingIntentFlag.updateCurrent;
118-
check(testBinding.androidNotificationHost.takeNotifyCalls()).single
119+
final calls = testBinding.androidNotificationHost.takeNotifyCalls();
120+
check(calls[0])
119121
..id.equals(expectedId)
120122
..tag.equals(expectedTag)
121123
..channelId.equals(NotificationChannelManager.kChannelId)
@@ -124,11 +126,31 @@ void main() {
124126
..color.equals(kZulipBrandColor.value)
125127
..smallIconResourceName.equals('zulip_notification')
126128
..extras.isNull()
129+
..groupKey.equals(expectedGroupKey)
130+
..isGroupSummary.isNull()
131+
..inboxStyle.isNull()
132+
..autoCancel.equals(true)
127133
..contentIntent.which((it) => it.isNotNull()
128134
..requestCode.equals(expectedId)
129135
..flags.equals(expectedIntentFlags)
130136
..intentPayload.equals(jsonEncode(data.toJson()))
131137
);
138+
check(calls[1])
139+
..id.equals(NotificationDisplayManager.notificationIdAsHashOf(expectedGroupKey))
140+
..tag.equals(expectedGroupKey)
141+
..channelId.equals(NotificationChannelManager.kChannelId)
142+
..contentTitle.isNull()
143+
..contentText.isNull()
144+
..color.equals(kZulipBrandColor.value)
145+
..smallIconResourceName.equals('zulip_notification')
146+
..extras.isNull()
147+
..groupKey.equals(expectedGroupKey)
148+
..isGroupSummary.equals(true)
149+
..inboxStyle.which((it) => it.isNotNull()
150+
..summaryText.equals(data.realmUri.toString())
151+
)
152+
..autoCancel.equals(true)
153+
..contentIntent.isNull();
132154
}
133155

134156
Future<void> checkNotifications(FakeAsync async, MessageFcmMessage data, {

0 commit comments

Comments
 (0)