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

TW-2157: Fix can't mark a chat as unread #2158

Merged
merged 2 commits into from
Nov 27, 2024
Merged
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
46 changes: 40 additions & 6 deletions lib/presentation/mixins/chat_list_item_mixin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -213,16 +213,50 @@ mixin ChatListItemMixin {
required BuildContext context,
required Room room,
}) {
if (room.notificationCount > 0 &&
room.pushRuleState != PushRuleState.notify) {
return LinagoraRefColors.material().tertiary[30];
/// highlightCount or Invitation
if (room.highlightCount > 0 || room.membership == Membership.invite) {
return Theme.of(context).colorScheme.primary;
}
if (room.notificationCount > 0) {

if (hasNewMessage(room)) {
return _handleNotificationColorHasNewMessage(
room,
context,
);
}

if (room.markedUnread) {
return _handleNotificationColorMarkedUnread(
context: context,
room: room,
);
}
return Colors.transparent;
}

bool hasNewMessage(Room room) {
return room.notificationCount > 0 || room.hasNewMessages;
}

Color? _handleNotificationColorHasNewMessage(
Room room,
BuildContext context,
) {
if (room.pushRuleState == PushRuleState.mentionsOnly) {
return LinagoraRefColors.material().tertiary[30];
} else {
return Theme.of(context).colorScheme.primary;
}
if (room.membership == Membership.invite) {
}

Color? _handleNotificationColorMarkedUnread({
required BuildContext context,
required Room room,
}) {
if (room.pushRuleState == PushRuleState.mentionsOnly) {
return LinagoraRefColors.material().tertiary[30];
} else {
return Theme.of(context).colorScheme.primary;
}
return Colors.transparent;
}
}
194 changes: 134 additions & 60 deletions test/mixin/chat/chat_list_item_mixin_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,70 +26,144 @@ void main() {
chatListItemMixinTest = ChatListItemMixinTest();
});

testWidgets(
'WHEN notification count is zero\n'
'AND room is unmuted\n'
'THEN color should have transparent\n', (
WidgetTester tester,
) async {
when(room.notificationCount).thenReturn(0);
when(room.pushRuleState).thenReturn(PushRuleState.notify);

final color = chatListItemMixinTest.notificationColor(
context: context,
room: room,
);

expect(color, Colors.transparent);
group('Test highlight message and invitation', () {
testWidgets(
'WHEN group is invite\n'
'THEN color should have color primary\n', (
WidgetTester tester,
) async {
when(room.membership).thenReturn(Membership.invite);

final color = chatListItemMixinTest.notificationColor(
context: context,
room: room,
);

expect(color, Theme.of(context).colorScheme.primary);
});

testWidgets(
'WHEN has new message with mention\n'
'AND highlight count is greater than zero\n'
'AND pushRuleState is notify\n'
'THEN color should be primary\n', (
WidgetTester tester,
) async {
when(room.pushRuleState).thenReturn(PushRuleState.mentionsOnly);
when(room.highlightCount).thenReturn(1);

final color = chatListItemMixinTest.notificationColor(
context: context,
room: room,
);

expect(color, Theme.of(context).colorScheme.primary);
});
});

testWidgets(
'WHEN group is invite\n'
'THEN color should have color primary\n', (
WidgetTester tester,
) async {
when(room.membership).thenReturn(Membership.invite);

final color = chatListItemMixinTest.notificationColor(
context: context,
room: room,
);

expect(color, Theme.of(context).colorScheme.primary);
});

testWidgets(
'WHEN notification count is greater than zero\n'
'AND room is unmuted\n'
'THEN color should be primary\n', (
WidgetTester tester,
) async {
when(room.notificationCount).thenReturn(5);
when(room.pushRuleState).thenReturn(PushRuleState.notify);

final color = chatListItemMixinTest.notificationColor(
context: context,
room: room,
);

expect(color, Theme.of(context).colorScheme.primary);
group('Test room has new message', () {
testWidgets(
'WHEN notification count is zero\n'
'AND pushRuleState is notify\n'
'THEN color should have transparent\n', (
WidgetTester tester,
) async {
when(room.notificationCount).thenReturn(0);
when(room.pushRuleState).thenReturn(PushRuleState.notify);

final color = chatListItemMixinTest.notificationColor(
context: context,
room: room,
);

expect(color, Colors.transparent);
});

testWidgets(
'WHEN notification count is greater than zero\n'
'AND pushRuleState is notify\n'
'THEN color should be primary\n', (
WidgetTester tester,
) async {
when(room.notificationCount).thenReturn(5);
when(room.pushRuleState).thenReturn(PushRuleState.notify);

final color = chatListItemMixinTest.notificationColor(
context: context,
room: room,
);

expect(color, Theme.of(context).colorScheme.primary);
});

testWidgets(
'WHEN notification count is greater than zero\n'
'AND pushRuleState is mentionsOnly\n'
'THEN color should be tertiary[30]\n', (
WidgetTester tester,
) async {
when(room.notificationCount).thenReturn(5);
when(room.pushRuleState).thenReturn(PushRuleState.mentionsOnly);

final color = chatListItemMixinTest.notificationColor(
context: context,
room: room,
);

expect(color, LinagoraRefColors.material().tertiary[30]);
});

testWidgets(
'WHEN has new message \n'
'AND pushRuleState is mentionsOnly\n'
'THEN color should be tertiary[30]\n', (
WidgetTester tester,
) async {
when(room.pushRuleState).thenReturn(PushRuleState.mentionsOnly);
when(room.hasNewMessages).thenReturn(true);

final color = chatListItemMixinTest.notificationColor(
context: context,
room: room,
);

expect(color, LinagoraRefColors.material().tertiary[30]);
});
});

testWidgets(
'WHEN notification count is greater than zero\n'
'AND room is muted\n'
'THEN color should be tertiary[30]\n', (
WidgetTester tester,
) async {
when(room.notificationCount).thenReturn(5);
when(room.pushRuleState).thenReturn(PushRuleState.dontNotify);

final color = chatListItemMixinTest.notificationColor(
context: context,
room: room,
);

expect(color, LinagoraRefColors.material().tertiary[30]);
group('Test room is mark as unread', () {
testWidgets(
'WHEN marked unread for room\n'
'AND pushRuleState is notify\n'
'THEN color should be primary]\n', (
WidgetTester tester,
) async {
when(room.markedUnread).thenReturn(true);

final color = chatListItemMixinTest.notificationColor(
context: context,
room: room,
);

expect(color, Theme.of(context).colorScheme.primary);
});

testWidgets(
'WHEN marked unread for room\n'
'AND pushRuleState is mentionsOnly\n'
'THEN color should be primary]\n', (
WidgetTester tester,
) async {
when(room.markedUnread).thenReturn(true);
when(room.pushRuleState).thenReturn(PushRuleState.mentionsOnly);

final color = chatListItemMixinTest.notificationColor(
context: context,
room: room,
);

expect(color, LinagoraRefColors.material().tertiary[30]);
});
});
});
}