Skip to content

Commit 475f35b

Browse files
committed
unreads: Use case i9e lookups, preserving case.
This commit makes the topics having different casings for the same topic be stored under the same QueueList by making the lookups lowercase while preserving one of the variants of the used topic case. Fixes zulip#980.
1 parent 24215f6 commit 475f35b

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

lib/model/unreads.dart

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,15 @@ class Unreads extends ChangeNotifier {
4141
required ChannelStore channelStore,
4242
}) {
4343
final streams = <int, Map<String, QueueList<int>>>{};
44+
final topicMapper = <String, String>{};
4445
final dms = <DmNarrow, QueueList<int>>{};
4546
final mentions = Set.of(initial.mentions);
4647

4748
for (final unreadChannelSnapshot in initial.channels) {
4849
final streamId = unreadChannelSnapshot.streamId;
4950
final topic = unreadChannelSnapshot.topic;
50-
(streams[streamId] ??= {})[topic] = QueueList.from(unreadChannelSnapshot.unreadMessageIds);
51+
topicMapper[topic.toLowerCase()] = topic;
52+
(streams[streamId] ??= {})[topic.toLowerCase()] = QueueList.from(unreadChannelSnapshot.unreadMessageIds);
5153
}
5254

5355
for (final unreadDmSnapshot in initial.dms) {
@@ -64,6 +66,7 @@ class Unreads extends ChangeNotifier {
6466
return Unreads._(
6567
channelStore: channelStore,
6668
streams: streams,
69+
topicMapper: topicMapper,
6770
dms: dms,
6871
mentions: mentions,
6972
oldUnreadsMissing: initial.oldUnreadsMissing,
@@ -74,6 +77,7 @@ class Unreads extends ChangeNotifier {
7477
Unreads._({
7578
required this.channelStore,
7679
required this.streams,
80+
required this.topicMapper,
7781
required this.dms,
7882
required this.mentions,
7983
required this.oldUnreadsMissing,
@@ -88,6 +92,9 @@ class Unreads extends ChangeNotifier {
8892
/// Unread stream messages, as: stream ID → topic → message IDs (sorted).
8993
final Map<int, Map<String, QueueList<int>>> streams;
9094

95+
// Maps lowercase topic names for lookup to one of the variants of the topic (case preserving).
96+
final Map<String, String> topicMapper;
97+
9198
/// Unread DM messages, as: DM narrow → message IDs (sorted).
9299
final Map<DmNarrow, QueueList<int>> dms;
93100

@@ -368,7 +375,7 @@ class Unreads extends ChangeNotifier {
368375
switch (detail.type) {
369376
case MessageType.stream:
370377
final topics = (newlyUnreadInStreams[detail.streamId!] ??= {});
371-
final messageIds = (topics[detail.topic!] ??= QueueList());
378+
final messageIds = (topics[detail.topic!.toLowerCase()] ??= QueueList());
372379
messageIds.add(messageId);
373380
case MessageType.direct:
374381
final narrow = DmNarrow.ofUpdateMessageFlagsMessageDetail(selfUserId: selfUserId,
@@ -437,7 +444,8 @@ class Unreads extends ChangeNotifier {
437444
}
438445

439446
void _addLastInStreamTopic(int messageId, int streamId, String topic) {
440-
((streams[streamId] ??= {})[topic] ??= QueueList()).addLast(messageId);
447+
topicMapper[topic.toLowerCase()] = topic;
448+
((streams[streamId] ??= {})[topic.toLowerCase()] ??= QueueList()).addLast(messageId);
441449
}
442450

443451
// [messageIds] must be sorted ascending and without duplicates.

lib/widgets/inbox.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,11 @@ class _InboxPageState extends State<InboxPageBody> with PerAccountStoreAwareStat
136136
int countInStream = 0;
137137
bool streamHasMention = false;
138138
for (final MapEntry(key: topic, value: messageIds) in topics.entries) {
139-
if (!store.isTopicVisible(streamId, topic)) continue;
139+
if (!store.isTopicVisible(streamId, unreadsModel != null? unreadsModel!.topicMapper[topic]! : topic)) continue;
140140
final countInTopic = messageIds.length;
141141
final hasMention = messageIds.any((messageId) => unreadsModel!.mentions.contains(messageId));
142142
if (hasMention) streamHasMention = true;
143-
topicItems.add((topic, countInTopic, hasMention, messageIds.last));
143+
topicItems.add((unreadsModel!.topicMapper[topic]!, countInTopic, hasMention, messageIds.last));
144144
countInStream += countInTopic;
145145
}
146146
if (countInStream == 0) {

test/model/unreads_test.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ void main() {
6868
switch (message) {
6969
case StreamMessage():
7070
final perTopic = expectedStreams[message.streamId] ??= {};
71-
final messageIds = perTopic[message.topic] ??= QueueList();
71+
final messageIds = perTopic[message.topic.toLowerCase()] ??= QueueList();
7272
messageIds.add(message.id);
7373
case DmMessage():
7474
final narrow = DmNarrow.ofMessage(message, selfUserId: eg.selfUser.userId);
@@ -289,6 +289,7 @@ void main() {
289289
final stream2 = eg.stream(streamId: 2);
290290
for (final (oldStream, newStream, oldTopic, newTopic) in [
291291
(stream1, stream1, 'a', 'a'),
292+
(stream1, stream1, 'a', 'A'),
292293
(stream1, stream1, 'a', 'b'),
293294
(stream1, stream2, 'a', 'a'),
294295
(stream1, stream2, 'a', 'b'),

0 commit comments

Comments
 (0)