diff --git a/lib/api/notifications.dart b/lib/api/notifications.dart index 8e12528a66..0717f5afe9 100644 --- a/lib/api/notifications.dart +++ b/lib/api/notifications.dart @@ -142,7 +142,7 @@ class MessageFcmMessage extends FcmMessageWithIdentity { break; case FcmMessageDmRecipient(:var allRecipientIds): result['pm_users'] = const _IntListConverter().toJson(allRecipientIds); - case FcmMessageStreamRecipient(): + case FcmMessageChannelRecipient(): result['stream_id'] = const _IntConverter().toJson(recipient.streamId); if (recipient.streamName != null) result['stream'] = recipient.streamName; result['topic'] = recipient.topic; @@ -159,7 +159,7 @@ sealed class FcmMessageRecipient { // There's also a `recipient_type` field, but we don't really need it. // The presence or absence of `stream_id` is just as informative. return json.containsKey('stream_id') - ? FcmMessageStreamRecipient.fromJson(json) + ? FcmMessageChannelRecipient.fromJson(json) : FcmMessageDmRecipient.fromJson(json); } } @@ -167,7 +167,7 @@ sealed class FcmMessageRecipient { /// An [FcmMessageRecipient] for a Zulip message to a stream. @JsonSerializable(fieldRename: FieldRename.snake, createToJson: false) @_IntConverter() -class FcmMessageStreamRecipient extends FcmMessageRecipient { +class FcmMessageChannelRecipient extends FcmMessageRecipient { // Sending the stream ID in notifications is new in Zulip Server 5. // But handling the lack of it would add complication, and we don't strictly // need to -- we intend (#268) to cut pre-server-5 support before beta release. @@ -182,10 +182,10 @@ class FcmMessageStreamRecipient extends FcmMessageRecipient { final String topic; - FcmMessageStreamRecipient({required this.streamId, required this.streamName, required this.topic}); + FcmMessageChannelRecipient({required this.streamId, required this.streamName, required this.topic}); - factory FcmMessageStreamRecipient.fromJson(Map json) => - _$FcmMessageStreamRecipientFromJson(json); + factory FcmMessageChannelRecipient.fromJson(Map json) => + _$FcmMessageChannelRecipientFromJson(json); } /// An [FcmMessageRecipient] for a Zulip message that was a DM. diff --git a/lib/api/notifications.g.dart b/lib/api/notifications.g.dart index 07282ff076..8dda549b90 100644 --- a/lib/api/notifications.g.dart +++ b/lib/api/notifications.g.dart @@ -41,9 +41,9 @@ Map _$MessageFcmMessageToJson(MessageFcmMessage instance) => 'content': instance.content, }; -FcmMessageStreamRecipient _$FcmMessageStreamRecipientFromJson( +FcmMessageChannelRecipient _$FcmMessageChannelRecipientFromJson( Map json) => - FcmMessageStreamRecipient( + FcmMessageChannelRecipient( streamId: const _IntConverter().fromJson(json['stream_id'] as String), streamName: json['stream'] as String?, topic: json['topic'] as String, diff --git a/lib/notifications/display.dart b/lib/notifications/display.dart index 841fd13aae..a427d9e444 100644 --- a/lib/notifications/display.dart +++ b/lib/notifications/display.dart @@ -111,7 +111,7 @@ class NotificationDisplayManager { name: zulipLocalizations.notifSelfUser), messages: [], isGroupConversation: switch (data.recipient) { - FcmMessageStreamRecipient() => true, + FcmMessageChannelRecipient() => true, FcmMessageDmRecipient(:var allRecipientIds) when allRecipientIds.length > 2 => true, FcmMessageDmRecipient() => false, }); @@ -123,9 +123,9 @@ class NotificationDisplayManager { // group-DM threads (pending #794) get titled with the latest sender, rather than // the first. messagingStyle.conversationTitle = switch (data.recipient) { - FcmMessageStreamRecipient(:var streamName?, :var topic) => + FcmMessageChannelRecipient(:var streamName?, :var topic) => '#$streamName > $topic', - FcmMessageStreamRecipient(:var topic) => + FcmMessageChannelRecipient(:var topic) => '#(unknown channel) > $topic', // TODO get stream name from data FcmMessageDmRecipient(:var allRecipientIds) when allRecipientIds.length > 2 => zulipLocalizations.notifGroupDmConversationLabel( @@ -220,7 +220,7 @@ class NotificationDisplayManager { static String _conversationKey(MessageFcmMessage data, String groupKey) { final conversation = switch (data.recipient) { - FcmMessageStreamRecipient(:var streamId, :var topic) => 'stream:$streamId:$topic', + FcmMessageChannelRecipient(:var streamId, :var topic) => 'stream:$streamId:$topic', FcmMessageDmRecipient(:var allRecipientIds) => 'dm:${allRecipientIds.join(',')}', }; return '$groupKey|$conversation'; @@ -263,7 +263,7 @@ class NotificationDisplayManager { if (account == null) return; // TODO(log) final narrow = switch (data.recipient) { - FcmMessageStreamRecipient(:var streamId, :var topic) => + FcmMessageChannelRecipient(:var streamId, :var topic) => TopicNarrow(streamId, topic), FcmMessageDmRecipient(:var allRecipientIds) => DmNarrow(allRecipientIds: allRecipientIds, selfUserId: account.userId), diff --git a/test/api/notifications_test.dart b/test/api/notifications_test.dart index 57d8e1d717..af041cdc46 100644 --- a/test/api/notifications_test.dart +++ b/test/api/notifications_test.dart @@ -76,7 +76,7 @@ void main() { ..senderAvatarUrl.equals(Uri.parse(streamJson['sender_avatar_url']!)) ..senderFullName.equals(streamJson['sender_full_name']!) ..zulipMessageId.equals(12345) - ..recipient.isA().which((it) => it + ..recipient.isA().which((it) => it ..streamId.equals(42) ..streamName.equals(streamJson['stream']!) ..topic.equals(streamJson['topic']!)) @@ -94,7 +94,7 @@ void main() { test('optional fields missing cause no error', () { check(parse({ ...streamJson }..remove('stream'))) - .recipient.isA().which((it) => it + .recipient.isA().which((it) => it ..streamId.equals(42) ..streamName.isNull()); }); @@ -251,7 +251,7 @@ extension MessageFcmMessageChecks on Subject { Subject get content => has((x) => x.content, 'content'); } -extension FcmMessageStreamRecipientChecks on Subject { +extension FcmMessageChannelRecipientChecks on Subject { Subject get streamId => has((x) => x.streamId, 'streamId'); Subject get streamName => has((x) => x.streamName, 'streamName'); Subject get topic => has((x) => x.topic, 'topic');