Skip to content

Commit

Permalink
api [nfc]: Factor out TopicName.canonicalize
Browse files Browse the repository at this point in the history
  • Loading branch information
gnprice authored and chrisbobbe committed Jan 16, 2025
1 parent 61f513e commit 057ef9c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 3 additions & 0 deletions lib/api/model/model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,9 @@ extension type const TopicName(String _value) implements String {
/// The string this topic is identified by in the Zulip API.
String get apiName => _value;

/// The key to use for "same topic as" comparisons.
String canonicalize() => apiName.toLowerCase();

TopicName.fromJson(this._value);

String toJson() => apiName;
Expand Down
2 changes: 1 addition & 1 deletion lib/model/message_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ mixin _MessageSequence {
bool haveSameRecipient(Message prevMessage, Message message) {
if (prevMessage is StreamMessage && message is StreamMessage) {
if (prevMessage.streamId != message.streamId) return false;
if (prevMessage.topic.toLowerCase() != message.topic.toLowerCase()) return false;
if (prevMessage.topic.canonicalize() != message.topic.canonicalize()) return false;
} else if (prevMessage is DmMessage && message is DmMessage) {
if (!_equalIdSequences(prevMessage.allRecipientIds, message.allRecipientIds)) {
return false;
Expand Down

0 comments on commit 057ef9c

Please sign in to comment.