Skip to content
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

Fix unread topic case sensitivity. #1214

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
14 changes: 11 additions & 3 deletions lib/model/unreads.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,15 @@ class Unreads extends ChangeNotifier {
required ChannelStore channelStore,
}) {
final streams = <int, Map<String, QueueList<int>>>{};
final topicMapper = <String, String>{};
final dms = <DmNarrow, QueueList<int>>{};
final mentions = Set.of(initial.mentions);

for (final unreadChannelSnapshot in initial.channels) {
final streamId = unreadChannelSnapshot.streamId;
final topic = unreadChannelSnapshot.topic;
(streams[streamId] ??= {})[topic] = QueueList.from(unreadChannelSnapshot.unreadMessageIds);
topicMapper[topic.toLowerCase()] = topic;
(streams[streamId] ??= {})[topic.toLowerCase()] = QueueList.from(unreadChannelSnapshot.unreadMessageIds);
}

for (final unreadDmSnapshot in initial.dms) {
Expand All @@ -64,6 +66,7 @@ class Unreads extends ChangeNotifier {
return Unreads._(
channelStore: channelStore,
streams: streams,
topicMapper: topicMapper,
dms: dms,
mentions: mentions,
oldUnreadsMissing: initial.oldUnreadsMissing,
Expand All @@ -74,6 +77,7 @@ class Unreads extends ChangeNotifier {
Unreads._({
required this.channelStore,
required this.streams,
required this.topicMapper,
required this.dms,
required this.mentions,
required this.oldUnreadsMissing,
Expand All @@ -88,6 +92,9 @@ class Unreads extends ChangeNotifier {
/// Unread stream messages, as: stream ID → topic → message IDs (sorted).
final Map<int, Map<String, QueueList<int>>> streams;

// Maps lowercase topic names for lookup to one of the variants of the topic (case preserving).
final Map<String, String> topicMapper;

/// Unread DM messages, as: DM narrow → message IDs (sorted).
final Map<DmNarrow, QueueList<int>> dms;

Expand Down Expand Up @@ -368,7 +375,7 @@ class Unreads extends ChangeNotifier {
switch (detail.type) {
case MessageType.stream:
final topics = (newlyUnreadInStreams[detail.streamId!] ??= {});
final messageIds = (topics[detail.topic!] ??= QueueList());
final messageIds = (topics[detail.topic!.toLowerCase()] ??= QueueList());
messageIds.add(messageId);
case MessageType.direct:
final narrow = DmNarrow.ofUpdateMessageFlagsMessageDetail(selfUserId: selfUserId,
Expand Down Expand Up @@ -437,7 +444,8 @@ class Unreads extends ChangeNotifier {
}

void _addLastInStreamTopic(int messageId, int streamId, String topic) {
((streams[streamId] ??= {})[topic] ??= QueueList()).addLast(messageId);
topicMapper[topic.toLowerCase()] = topic;
((streams[streamId] ??= {})[topic.toLowerCase()] ??= QueueList()).addLast(messageId);
}

// [messageIds] must be sorted ascending and without duplicates.
Expand Down
4 changes: 2 additions & 2 deletions lib/widgets/inbox.dart
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,11 @@ class _InboxPageState extends State<InboxPageBody> with PerAccountStoreAwareStat
int countInStream = 0;
bool streamHasMention = false;
for (final MapEntry(key: topic, value: messageIds) in topics.entries) {
if (!store.isTopicVisible(streamId, topic)) continue;
if (!store.isTopicVisible(streamId, unreadsModel != null? unreadsModel!.topicMapper[topic]! : topic)) continue;
final countInTopic = messageIds.length;
final hasMention = messageIds.any((messageId) => unreadsModel!.mentions.contains(messageId));
if (hasMention) streamHasMention = true;
topicItems.add((topic, countInTopic, hasMention, messageIds.last));
topicItems.add((unreadsModel!.topicMapper[topic]!, countInTopic, hasMention, messageIds.last));
countInStream += countInTopic;
}
if (countInStream == 0) {
Expand Down
3 changes: 2 additions & 1 deletion test/model/unreads_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ void main() {
switch (message) {
case StreamMessage():
final perTopic = expectedStreams[message.streamId] ??= {};
final messageIds = perTopic[message.topic] ??= QueueList();
final messageIds = perTopic[message.topic.toLowerCase()] ??= QueueList();
messageIds.add(message.id);
case DmMessage():
final narrow = DmNarrow.ofMessage(message, selfUserId: eg.selfUser.userId);
Expand Down Expand Up @@ -289,6 +289,7 @@ void main() {
final stream2 = eg.stream(streamId: 2);
for (final (oldStream, newStream, oldTopic, newTopic) in [
(stream1, stream1, 'a', 'a'),
(stream1, stream1, 'a', 'A'),
(stream1, stream1, 'a', 'b'),
(stream1, stream2, 'a', 'a'),
(stream1, stream2, 'a', 'b'),
Expand Down