Skip to content

Commit

Permalink
feat(talk_app): Implement swipe-to-reply
Browse files Browse the repository at this point in the history
Signed-off-by: provokateurin <[email protected]>
  • Loading branch information
provokateurin committed Dec 8, 2024
1 parent 2f74c5b commit 1e4928e
Show file tree
Hide file tree
Showing 2 changed files with 117 additions and 0 deletions.
13 changes: 13 additions & 0 deletions packages/neon_framework/packages/talk_app/lib/src/pages/room.dart
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,19 @@ class _TalkRoomPageState extends State<TalkRoomPage> {
previousChatMessage: previousMessage,
);

if (canReplyToMessage(room, message)) {
child = Dismissible(
key: Key(message.id.toString()),
confirmDismiss: (_) async {
bloc.setReplyChatMessage(message);

// We don't use the real dismiss feature as we don't want the widget to be removed from the list
return false;
},
child: child,
);
}

if (previousMessage == null ||
(tz.local.translate(previousMessage.timestamp * 1000) ~/ _millisecondsPerDay) !=
(tz.local.translate(message.timestamp * 1000) ~/ _millisecondsPerDay)) {
Expand Down
104 changes: 104 additions & 0 deletions packages/neon_framework/packages/talk_app/test/room_page_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -236,4 +236,108 @@ void main() {
expect(find.byType(TalkMessageInput), findsNothing);
await expectLater(find.byType(TestApp), matchesGoldenFile('goldens/room_page_no_chat_permission.png'));
});

group('Swipe-to-reply', () {
late spreed.ChatMessageWithParent chatMessage;

setUp(() {
chatMessage = MockChatMessageWithParent();
when(() => chatMessage.timestamp).thenReturn(0);
when(() => chatMessage.actorId).thenReturn('test');
when(() => chatMessage.actorType).thenReturn(spreed.ActorType.users);
when(() => chatMessage.actorDisplayName).thenReturn('test');
when(() => chatMessage.messageType).thenReturn(spreed.MessageType.comment);
when(() => chatMessage.message).thenReturn('abc');
when(() => chatMessage.reactions).thenReturn(BuiltMap());
when(() => chatMessage.messageParameters).thenReturn(BuiltMap());
when(() => chatMessage.id).thenReturn(0);
when(() => chatMessage.isReplyable).thenReturn(true);

when(() => bloc.messages).thenAnswer(
(_) => BehaviorSubject.seeded(
Result.success(
BuiltList<spreed.ChatMessageWithParent>([
chatMessage,
]),
),
),
);

when(() => bloc.reactions).thenAnswer((_) => BehaviorSubject.seeded(BuiltMap()));
});

testWidgets('Allowed', (tester) async {
final account = MockAccount();

await tester.pumpWidgetWithAccessibility(
TestApp(
localizationsDelegates: TalkLocalizations.localizationsDelegates,
supportedLocales: TalkLocalizations.supportedLocales,
appThemes: const [
TalkTheme(),
],
providers: [
Provider<Account>.value(value: account),
NeonProvider<TalkRoomBloc>.value(value: bloc),
NeonProvider<ReferencesBloc>.value(value: referencesBloc),
],
child: const TalkRoomPage(),
),
);

expect(find.byType(Dismissible), findsOne);

await tester.drag(find.byType(TalkCommentMessage), const Offset(1000, 0));
await tester.pumpAndSettle();
verify(() => bloc.setReplyChatMessage(chatMessage)).called(1);
});

testWidgets('Read-only', (tester) async {
when(() => room.readOnly).thenReturn(1);

final account = MockAccount();

await tester.pumpWidgetWithAccessibility(
TestApp(
localizationsDelegates: TalkLocalizations.localizationsDelegates,
supportedLocales: TalkLocalizations.supportedLocales,
appThemes: const [
TalkTheme(),
],
providers: [
Provider<Account>.value(value: account),
NeonProvider<TalkRoomBloc>.value(value: bloc),
NeonProvider<ReferencesBloc>.value(value: referencesBloc),
],
child: const TalkRoomPage(),
),
);

expect(find.byType(Dismissible), findsNothing);
});

testWidgets('No permission', (tester) async {
when(() => room.permissions).thenReturn(0);

final account = MockAccount();

await tester.pumpWidgetWithAccessibility(
TestApp(
localizationsDelegates: TalkLocalizations.localizationsDelegates,
supportedLocales: TalkLocalizations.supportedLocales,
appThemes: const [
TalkTheme(),
],
providers: [
Provider<Account>.value(value: account),
NeonProvider<TalkRoomBloc>.value(value: bloc),
NeonProvider<ReferencesBloc>.value(value: referencesBloc),
],
child: const TalkRoomPage(),
),
);

expect(find.byType(Dismissible), findsNothing);
});
});
}

0 comments on commit 1e4928e

Please sign in to comment.