-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(talk_app): Add reactions overview dialog
Signed-off-by: provokateurin <[email protected]>
- Loading branch information
1 parent
3ae067c
commit ececdc4
Showing
18 changed files
with
366 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
121 changes: 121 additions & 0 deletions
121
packages/neon_framework/packages/talk_app/lib/src/widgets/reactions_overview_dialog.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
import 'package:collection/collection.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:intl/intl.dart'; | ||
import 'package:neon_framework/utils.dart'; | ||
import 'package:neon_framework/widgets.dart'; | ||
import 'package:nextcloud/spreed.dart' as spreed; | ||
import 'package:talk_app/l10n/localizations.dart'; | ||
import 'package:talk_app/src/blocs/room.dart'; | ||
import 'package:talk_app/src/utils/helpers.dart'; | ||
import 'package:talk_app/src/widgets/actor_avatar.dart'; | ||
|
||
/// Dialog that displays all reactions of all users for a particular chat message. | ||
class TalkReactionsOverviewDialog extends StatefulWidget { | ||
/// Creates a new [TalkReactionsOverviewDialog]. | ||
const TalkReactionsOverviewDialog({ | ||
required this.chatMessage, | ||
super.key, | ||
}); | ||
|
||
/// The chat message to show reactions for. | ||
final spreed.$ChatMessageInterface chatMessage; | ||
|
||
@override | ||
State<TalkReactionsOverviewDialog> createState() => _TalkReactionsOverviewDialogState(); | ||
} | ||
|
||
class _TalkReactionsOverviewDialogState extends State<TalkReactionsOverviewDialog> { | ||
late final TalkRoomBloc bloc; | ||
|
||
@override | ||
void initState() { | ||
super.initState(); | ||
|
||
bloc = NeonProvider.of<TalkRoomBloc>(context); | ||
bloc.loadReactions(widget.chatMessage); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
final localizations = TalkLocalizations.of(context); | ||
|
||
return NeonDialog( | ||
title: Text(localizations.reactions), | ||
content: DefaultTabController( | ||
length: widget.chatMessage.reactions.length + 1, | ||
child: Scaffold( | ||
appBar: TabBar( | ||
tabs: [ | ||
Tab( | ||
child: Text('${localizations.reactionsAll} ${widget.chatMessage.reactions.values.sum}'), | ||
), | ||
for (final entry in widget.chatMessage.reactions.entries) | ||
Tab( | ||
child: Text('${entry.key} ${entry.value}'), | ||
), | ||
], | ||
), | ||
body: StreamBuilder( | ||
stream: bloc.reactions, | ||
builder: (context, reactionsSnapshot) { | ||
final children = <Widget>[]; | ||
|
||
final allReactions = reactionsSnapshot.data?[widget.chatMessage.id]; | ||
if (allReactions != null) { | ||
children.add( | ||
ListView( | ||
children: [ | ||
for (final entry in allReactions.entries) | ||
for (final reaction in entry.value) buildReaction(entry.key, reaction), | ||
], | ||
), | ||
); | ||
} else { | ||
children.add(const CircularProgressIndicator()); | ||
} | ||
|
||
for (final emoji in widget.chatMessage.reactions.keys) { | ||
final reactions = allReactions?[emoji]; | ||
if (reactions != null) { | ||
children.add( | ||
ListView( | ||
children: [ | ||
for (final reaction in reactions) buildReaction(emoji, reaction), | ||
], | ||
), | ||
); | ||
} else { | ||
children.add(const CircularProgressIndicator()); | ||
} | ||
} | ||
|
||
return TabBarView( | ||
children: children, | ||
); | ||
}, | ||
), | ||
), | ||
), | ||
); | ||
} | ||
|
||
Widget buildReaction(String emoji, spreed.$ReactionInterface reaction) { | ||
return ListTile( | ||
leading: TalkActorAvatar( | ||
actorId: reaction.actorId, | ||
actorType: reaction.actorType, | ||
), | ||
title: Text( | ||
reaction.actorDisplayName, | ||
overflow: TextOverflow.ellipsis, | ||
), | ||
subtitle: Text(DateFormat.yMd().add_jm().format(reaction.parsedTimestamp)), | ||
trailing: Text( | ||
emoji, | ||
style: const TextStyle( | ||
fontSize: 20, | ||
), | ||
), | ||
); | ||
} | ||
} |
Binary file modified
BIN
+134 Bytes
(100%)
...neon_framework/packages/talk_app/test/goldens/message_comment_message_other.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+134 Bytes
(100%)
.../neon_framework/packages/talk_app/test/goldens/message_comment_message_self.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+139 Bytes
(100%)
...ework/packages/talk_app/test/goldens/message_comment_message_separate_actor.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+140 Bytes
(100%)
...work/packages/talk_app/test/goldens/message_comment_message_separate_edited.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+139 Bytes
(100%)
...kages/talk_app/test/goldens/message_comment_message_separate_system_message.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+139 Bytes
(100%)
...mework/packages/talk_app/test/goldens/message_comment_message_separate_time.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+138 Bytes
(100%)
packages/neon_framework/packages/talk_app/test/goldens/reactions.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+6.95 KB
...neon_framework/packages/talk_app/test/goldens/reactions_overview_dialog_all.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+5.88 KB
...framework/packages/talk_app/test/goldens/reactions_overview_dialog_multiple.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+4.8 KB
...n_framework/packages/talk_app/test/goldens/reactions_overview_dialog_single.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
138 changes: 138 additions & 0 deletions
138
packages/neon_framework/packages/talk_app/test/reactions_overview_dialog_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
import 'package:built_collection/built_collection.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:mocktail/mocktail.dart'; | ||
import 'package:neon_framework/models.dart'; | ||
import 'package:neon_framework/testing.dart'; | ||
import 'package:neon_framework/utils.dart'; | ||
import 'package:nextcloud/spreed.dart' as spreed; | ||
import 'package:provider/provider.dart'; | ||
import 'package:rxdart/rxdart.dart'; | ||
import 'package:talk_app/l10n/localizations.dart'; | ||
import 'package:talk_app/src/blocs/room.dart'; | ||
import 'package:talk_app/src/widgets/actor_avatar.dart'; | ||
import 'package:talk_app/src/widgets/reactions_overview_dialog.dart'; | ||
import 'package:timezone/data/latest.dart' as tzdata; | ||
import 'package:timezone/timezone.dart' as tz; | ||
|
||
import 'testing.dart'; | ||
|
||
void main() { | ||
late spreed.ChatMessage chatMessage; | ||
late TalkRoomBloc bloc; | ||
|
||
setUpAll(() { | ||
tzdata.initializeTimeZones(); | ||
tz.setLocalLocation(tz.getLocation('Europe/Berlin')); | ||
|
||
FakeNeonStorage.setup(); | ||
}); | ||
|
||
setUp(() { | ||
chatMessage = MockChatMessage(); | ||
when(() => chatMessage.id).thenReturn(0); | ||
when(() => chatMessage.reactions).thenReturn(BuiltMap({'😀': 1, '😊': 2})); | ||
when(() => chatMessage.systemMessage).thenReturn(''); | ||
|
||
final reaction1 = MockReaction(); | ||
when(() => reaction1.actorType).thenReturn(spreed.ActorType.users); | ||
when(() => reaction1.actorId).thenReturn('user1'); | ||
when(() => reaction1.actorDisplayName).thenReturn('User One'); | ||
when(() => reaction1.timestamp).thenReturn(60); | ||
|
||
final reaction2 = MockReaction(); | ||
when(() => reaction2.actorType).thenReturn(spreed.ActorType.users); | ||
when(() => reaction2.actorId).thenReturn('user2'); | ||
when(() => reaction2.actorDisplayName).thenReturn('User Two'); | ||
when(() => reaction2.timestamp).thenReturn(120); | ||
|
||
final reaction3 = MockReaction(); | ||
when(() => reaction3.actorType).thenReturn(spreed.ActorType.users); | ||
when(() => reaction3.actorId).thenReturn('user3'); | ||
when(() => reaction3.actorDisplayName).thenReturn('User Three'); | ||
when(() => reaction3.timestamp).thenReturn(180); | ||
|
||
bloc = MockRoomBloc(); | ||
when(() => bloc.reactions).thenAnswer( | ||
(_) => BehaviorSubject.seeded( | ||
BuiltMap({ | ||
0: BuiltMap<String, BuiltList<spreed.Reaction>>({ | ||
'😀': BuiltList<spreed.Reaction>([reaction1]), | ||
'😊': BuiltList<spreed.Reaction>([reaction2, reaction3]), | ||
}), | ||
}), | ||
), | ||
); | ||
}); | ||
|
||
testWidgets('Displays reactions', (tester) async { | ||
final account = MockAccount(); | ||
|
||
await tester.pumpWidgetWithAccessibility( | ||
TestApp( | ||
localizationsDelegates: TalkLocalizations.localizationsDelegates, | ||
supportedLocales: TalkLocalizations.supportedLocales, | ||
providers: [ | ||
NeonProvider<TalkRoomBloc>.value(value: bloc), | ||
Provider<Account>.value(value: account), | ||
], | ||
child: TalkReactionsOverviewDialog( | ||
chatMessage: chatMessage, | ||
), | ||
), | ||
); | ||
await tester.pumpAndSettle(); | ||
expect(find.text('All 3'), findsOne); | ||
|
||
expect(find.byType(ListTile), findsExactly(3)); | ||
expect(find.byType(TalkActorAvatar), findsExactly(3)); | ||
expect(find.text('User One'), findsOne); | ||
expect(find.text('1/1/1970 1:01 AM'), findsOne); | ||
expect(find.text('User Two'), findsOne); | ||
expect(find.text('1/1/1970 1:02 AM'), findsOne); | ||
expect(find.text('User Three'), findsOne); | ||
expect(find.text('1/1/1970 1:03 AM'), findsOne); | ||
expect(find.text('😀'), findsOne); | ||
expect(find.text('😊'), findsExactly(2)); | ||
await expectLater( | ||
find.byType(TalkReactionsOverviewDialog), | ||
matchesGoldenFile('goldens/reactions_overview_dialog_all.png'), | ||
); | ||
|
||
await tester.tap(find.text('😀 1')); | ||
await tester.pumpAndSettle(); | ||
|
||
expect(find.byType(ListTile), findsOne); | ||
expect(find.byType(TalkActorAvatar), findsOne); | ||
expect(find.text('User One'), findsOne); | ||
expect(find.text('1/1/1970 1:01 AM'), findsOne); | ||
expect(find.text('User Two'), findsNothing); | ||
expect(find.text('1/1/1970 1:02 AM'), findsNothing); | ||
expect(find.text('User Three'), findsNothing); | ||
expect(find.text('1/1/1970 1:03 AM'), findsNothing); | ||
expect(find.text('😀'), findsOne); | ||
expect(find.text('😊'), findsNothing); | ||
await expectLater( | ||
find.byType(TalkReactionsOverviewDialog), | ||
matchesGoldenFile('goldens/reactions_overview_dialog_single.png'), | ||
); | ||
|
||
await tester.tap(find.text('😊 2')); | ||
await tester.pumpAndSettle(); | ||
|
||
expect(find.byType(ListTile), findsExactly(2)); | ||
expect(find.byType(TalkActorAvatar), findsExactly(2)); | ||
expect(find.text('User One'), findsNothing); | ||
expect(find.text('1/1/1970 1:01 AM'), findsNothing); | ||
expect(find.text('User Two'), findsOne); | ||
expect(find.text('1/1/1970 1:02 AM'), findsOne); | ||
expect(find.text('User Three'), findsOne); | ||
expect(find.text('1/1/1970 1:03 AM'), findsOne); | ||
expect(find.text('😀'), findsNothing); | ||
expect(find.text('😊'), findsExactly(2)); | ||
await expectLater( | ||
find.byType(TalkReactionsOverviewDialog), | ||
matchesGoldenFile('goldens/reactions_overview_dialog_multiple.png'), | ||
); | ||
}); | ||
} |
Oops, something went wrong.