@@ -42,11 +42,14 @@ class Unreads extends ChangeNotifier {
42
42
}) {
43
43
final streams = < int , Map <TopicName , QueueList <int >>> {};
44
44
final dms = < DmNarrow , QueueList <int >> {};
45
+ // Maps the lowercased version of topic to one of the actual versions
46
+ final topicMapper = < String , TopicName > {};
45
47
final mentions = Set .of (initial.mentions);
46
48
47
49
for (final unreadChannelSnapshot in initial.channels) {
48
50
final streamId = unreadChannelSnapshot.streamId;
49
51
final topic = unreadChannelSnapshot.topic;
52
+ topicMapper[topic.canonicalize ()] = topic;
50
53
(streams[streamId] ?? = {})[topic] = QueueList .from (unreadChannelSnapshot.unreadMessageIds);
51
54
}
52
55
@@ -64,6 +67,7 @@ class Unreads extends ChangeNotifier {
64
67
return Unreads ._(
65
68
channelStore: channelStore,
66
69
streams: streams,
70
+ topicMapper: topicMapper,
67
71
dms: dms,
68
72
mentions: mentions,
69
73
oldUnreadsMissing: initial.oldUnreadsMissing,
@@ -74,6 +78,7 @@ class Unreads extends ChangeNotifier {
74
78
Unreads ._({
75
79
required this .channelStore,
76
80
required this .streams,
81
+ required this .topicMapper,
77
82
required this .dms,
78
83
required this .mentions,
79
84
required this .oldUnreadsMissing,
@@ -91,6 +96,9 @@ class Unreads extends ChangeNotifier {
91
96
/// Unread DM messages, as: DM narrow → message IDs (sorted).
92
97
final Map <DmNarrow , QueueList <int >> dms;
93
98
99
+ // Maps lowercase topic names for lookup to one of the variants of the topic (case preserving).
100
+ final Map <String , TopicName > topicMapper;
101
+
94
102
/// Unread messages with the self-user @-mentioned, directly or by wildcard.
95
103
///
96
104
/// At initialization, if a message is:
@@ -380,9 +388,19 @@ class Unreads extends ChangeNotifier {
380
388
}
381
389
switch (detail.type) {
382
390
case MessageType .stream:
391
+ final topicKey = detail.topic! .canonicalize ();
392
+ TopicName actualTopicName;
393
+ if (topicMapper[topicKey] != null ) {
394
+ actualTopicName = topicMapper[topicKey] as TopicName ;
395
+ } else {
396
+ topicMapper[topicKey] = detail.topic! ;
397
+ actualTopicName = detail.topic! ;
398
+ }
399
+
383
400
final topics = (newlyUnreadInStreams[detail.streamId! ] ?? = {});
384
- final messageIds = (topics[detail.topic ! ] ?? = QueueList ());
401
+ final messageIds = (topics[actualTopicName ! ] ?? = QueueList ());
385
402
messageIds.add (messageId);
403
+
386
404
case MessageType .direct:
387
405
final narrow = DmNarrow .ofUpdateMessageFlagsMessageDetail (selfUserId: selfUserId,
388
406
detail);
@@ -450,7 +468,12 @@ class Unreads extends ChangeNotifier {
450
468
}
451
469
452
470
void _addLastInStreamTopic (int messageId, int streamId, TopicName topic) {
453
- ((streams[streamId] ?? = {})[topic] ?? = QueueList ()).addLast (messageId);
471
+ if (topicMapper[topic.canonicalize ()] != null && topic.isSameAs (topicMapper[topic.canonicalize ()]! )) {
472
+ ((streams[streamId] ?? = {})[topicMapper[topic.canonicalize ()]! ] ?? = QueueList ()).addLast (messageId);
473
+ } else {
474
+ topicMapper[topic.canonicalize ()] = topic;
475
+ ((streams[streamId] ?? = {})[topic] ?? = QueueList ()).addLast (messageId);
476
+ }
454
477
}
455
478
456
479
// [messageIds] must be sorted ascending and without duplicates.
0 commit comments