Skip to content

Commit

Permalink
TW-2154: Fix no counter of unread messages for muted chats
Browse files Browse the repository at this point in the history
  • Loading branch information
nqhhdev authored and hoangdat committed Nov 27, 2024
1 parent dee79a7 commit a61165f
Show file tree
Hide file tree
Showing 2 changed files with 170 additions and 80 deletions.
41 changes: 36 additions & 5 deletions lib/presentation/mixins/chat_list_item_mixin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -213,19 +213,50 @@ mixin ChatListItemMixin {
required BuildContext context,
required Room room,
}) {
/// highlightCount or Invitation
if (room.highlightCount > 0 || room.membership == Membership.invite) {
return Theme.of(context).colorScheme.primary;
}
if (room.notificationCount > 0 &&
room.pushRuleState != PushRuleState.notify) {
return LinagoraRefColors.material().tertiary[30];

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.notificationCount > 0) {
}

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;
}
}
209 changes: 134 additions & 75 deletions test/mixin/chat/chat_list_item_mixin_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,85 +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]);
});

testWidgets(
'WHEN marked unread for room\n'
'THEN color should be tertiary[30]\n', (
WidgetTester tester,
) async {
when(room.markedUnread).thenReturn(true);

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]);
});
});
});
}

0 comments on commit a61165f

Please sign in to comment.