@@ -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.
0 commit comments