Skip to content

Commit

Permalink
inbox: Show at-mention marker on streams
Browse files Browse the repository at this point in the history
The `hasMention` flag was added to the abstract
`_HeaderItem` class so `_AllDmsHeaderItem` is
affected by this change. It will be hard-coded
as False for DMs for now.
  • Loading branch information
sirpengi committed Feb 9, 2024
1 parent 2c182c9 commit 28d93bd
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
15 changes: 12 additions & 3 deletions lib/widgets/inbox.dart
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,12 @@ class _InboxPageState extends State<InboxPage> with PerAccountStoreAwareStateMix
for (final MapEntry(key: streamId, value: topics) in sortedUnreadStreams) {
final topicItems = <(String, int, bool, int)>[];
int countInStream = 0;
bool streamHasMention = false;
for (final MapEntry(key: topic, value: messageIds) in topics.entries) {
if (!store.isTopicVisible(streamId, 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));
countInStream += countInTopic;
}
Expand All @@ -149,7 +151,7 @@ class _InboxPageState extends State<InboxPage> with PerAccountStoreAwareStateMix
final (_, _, _, bLastUnreadId) = b;
return bLastUnreadId.compareTo(aLastUnreadId);
});
sections.add(_StreamSectionData(streamId, countInStream, topicItems));
sections.add(_StreamSectionData(streamId, countInStream, streamHasMention, topicItems));
}

return Scaffold(
Expand Down Expand Up @@ -190,20 +192,23 @@ class _AllDmsSectionData extends _InboxSectionData {
class _StreamSectionData extends _InboxSectionData {
final int streamId;
final int count;
final bool hasMention;
final List<(String, int, bool, int)> items;

const _StreamSectionData(this.streamId, this.count, this.items);
const _StreamSectionData(this.streamId, this.count, this.hasMention, this.items);
}

abstract class _HeaderItem extends StatelessWidget {
final bool collapsed;
final _InboxPageState pageState;
final int count;
final bool hasMention;

const _HeaderItem({
required this.collapsed,
required this.pageState,
required this.count,
required this.hasMention,
});

String get title;
Expand Down Expand Up @@ -247,7 +252,7 @@ abstract class _HeaderItem extends StatelessWidget {
overflow: TextOverflow.ellipsis,
title))),
const SizedBox(width: 12),
// TODO(#384) for streams, show @-mention indicator when it applies
if (hasMention) const _AtMentionMarker(),
Padding(padding: const EdgeInsetsDirectional.only(end: 16),
child: UnreadCountBadge(backgroundColor: unreadCountBadgeBackgroundColor, bold: true,
count: count)),
Expand All @@ -260,6 +265,7 @@ class _AllDmsHeaderItem extends _HeaderItem {
required super.collapsed,
required super.pageState,
required super.count,
required super.hasMention,
});

@override get title => 'Direct messages'; // TODO(i18n)
Expand Down Expand Up @@ -290,6 +296,7 @@ class _AllDmsSection extends StatelessWidget {
Widget build(BuildContext context) {
final header = _AllDmsHeaderItem(
count: data.count,
hasMention: false,
collapsed: collapsed,
pageState: pageState,
);
Expand Down Expand Up @@ -369,6 +376,7 @@ class _StreamHeaderItem extends _HeaderItem {
required super.collapsed,
required super.pageState,
required super.count,
required super.hasMention,
});

@override get title => subscription.name;
Expand Down Expand Up @@ -407,6 +415,7 @@ class _StreamSection extends StatelessWidget {
final header = _StreamHeaderItem(
subscription: subscription,
count: data.count,
hasMention: data.hasMention,
collapsed: collapsed,
pageState: pageState,
);
Expand Down
4 changes: 4 additions & 0 deletions test/widgets/inbox_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,8 @@ void main() {
unreadMessages: [eg.streamMessage(stream: stream, topic: topic,
flags: [MessageFlag.mentioned])]);

check(hasAtSign(tester, findStreamHeaderRow(tester, stream.streamId)))
.isTrue();
check(hasAtSign(tester, findRowByLabel(tester, topic))).isTrue();
});

Expand All @@ -213,6 +215,8 @@ void main() {
unreadMessages: [eg.streamMessage(stream: stream, topic: topic,
flags: [])]);

check(hasAtSign(tester, findStreamHeaderRow(tester, stream.streamId)))
.isFalse();
check(hasAtSign(tester, findRowByLabel(tester, topic))).isFalse();
});
});
Expand Down

0 comments on commit 28d93bd

Please sign in to comment.