Skip to content

api/notif: Rename FcmMessageStreamRecipient to FcmMessageChannelRecipient #840

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions lib/api/notifications.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -159,15 +159,15 @@ 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);
}
}

/// 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.
Expand All @@ -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<String, dynamic> json) =>
_$FcmMessageStreamRecipientFromJson(json);
factory FcmMessageChannelRecipient.fromJson(Map<String, dynamic> json) =>
_$FcmMessageChannelRecipientFromJson(json);
}

/// An [FcmMessageRecipient] for a Zulip message that was a DM.
Expand Down
4 changes: 2 additions & 2 deletions lib/api/notifications.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions lib/notifications/display.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
Expand All @@ -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(
Expand Down Expand Up @@ -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';
Expand Down Expand Up @@ -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),
Expand Down
6 changes: 3 additions & 3 deletions test/api/notifications_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<FcmMessageStreamRecipient>().which((it) => it
..recipient.isA<FcmMessageChannelRecipient>().which((it) => it
..streamId.equals(42)
..streamName.equals(streamJson['stream']!)
..topic.equals(streamJson['topic']!))
Expand All @@ -94,7 +94,7 @@ void main() {

test('optional fields missing cause no error', () {
check(parse({ ...streamJson }..remove('stream')))
.recipient.isA<FcmMessageStreamRecipient>().which((it) => it
.recipient.isA<FcmMessageChannelRecipient>().which((it) => it
..streamId.equals(42)
..streamName.isNull());
});
Expand Down Expand Up @@ -251,7 +251,7 @@ extension MessageFcmMessageChecks on Subject<MessageFcmMessage> {
Subject<String> get content => has((x) => x.content, 'content');
}

extension FcmMessageStreamRecipientChecks on Subject<FcmMessageStreamRecipient> {
extension FcmMessageChannelRecipientChecks on Subject<FcmMessageChannelRecipient> {
Subject<int> get streamId => has((x) => x.streamId, 'streamId');
Subject<String?> get streamName => has((x) => x.streamName, 'streamName');
Subject<String> get topic => has((x) => x.topic, 'topic');
Expand Down