Skip to content

Commit

Permalink
feat(tool,nextcloud): Generate rich object parameters
Browse files Browse the repository at this point in the history
Signed-off-by: provokateurin <kate@provokateurin.de>
  • Loading branch information
provokateurin committed Apr 16, 2024
1 parent aa881db commit 66e488e
Show file tree
Hide file tree
Showing 13 changed files with 742 additions and 662 deletions.
1 change: 1 addition & 0 deletions .cspell/nextcloud.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
addressbook
apirequest
apppassword
bigfilechunking
Expand Down
58 changes: 26 additions & 32 deletions packages/neon/neon_talk/lib/src/widgets/message.dart
Original file line number Diff line number Diff line change
Expand Up @@ -116,40 +116,34 @@ InlineSpan buildRichObjectParameter({
required TextStyle? textStyle,
required bool isPreview,
}) {
Widget child;

const mentionTypes = ['user', 'call', 'guest', 'user-group', 'group'];
if (mentionTypes.contains(parameter.type)) {
child = TalkRichObjectMention(
parameter: parameter,
textStyle: textStyle,
);
} else {
if (isPreview) {
child = Text(parameter.name);
} else {
switch (parameter.type) {
case 'file':
child = TalkRichObjectFile(
parameter: parameter,
textStyle: textStyle,
);
case 'deck-card':
child = TalkRichObjectDeckCard(
parameter: parameter,
);
default:
child = TalkRichObjectFallback(
parameter: parameter,
textStyle: textStyle,
);
}
}
}

return WidgetSpan(
alignment: PlaceholderAlignment.middle,
child: child,
child: switch (parameter.type) {
spreed.RichObjectParameter_Type.user ||
spreed.RichObjectParameter_Type.call ||
spreed.RichObjectParameter_Type.guest ||
spreed.RichObjectParameter_Type.userGroup ||
spreed.RichObjectParameter_Type.group =>
TalkRichObjectMention(
parameter: parameter,
textStyle: textStyle,
),
_ => isPreview
? Text(parameter.name)
: switch (parameter.type) {
spreed.RichObjectParameter_Type.file => TalkRichObjectFile(
parameter: parameter,
textStyle: textStyle,
),
spreed.RichObjectParameter_Type.deckCard => TalkRichObjectDeckCard(
parameter: parameter,
),
_ => TalkRichObjectFallback(
parameter: parameter,
textStyle: textStyle,
),
},
},
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class TalkRichObjectFile extends StatelessWidget {
Widget build(BuildContext context) {
Widget child;

if (parameter.previewAvailable == spreed.RichObjectParameter_PreviewAvailable.yes) {
if (parameter.previewAvailable == 'yes') {
final maxHeight = MediaQuery.sizeOf(context).height / 2;

var width = parameter.width;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class TalkRichObjectMention extends StatelessWidget {
final bool highlight;

switch (parameter.type) {
case 'user':
case spreed.RichObjectParameter_Type.user:
final accountsBloc = NeonProvider.of<AccountsBloc>(context);
final account = accountsBloc.activeAccount.value!;

Expand All @@ -36,7 +36,7 @@ class TalkRichObjectMention extends StatelessWidget {
username: parameter.id,
showStatus: false,
);
case 'call':
case spreed.RichObjectParameter_Type.call:
highlight = true;
child = CircleAvatar(
child: ClipOval(
Expand All @@ -45,13 +45,13 @@ class TalkRichObjectMention extends StatelessWidget {
),
),
);
case 'guest':
case spreed.RichObjectParameter_Type.guest:
// TODO: Add highlighting when the mention is about the current guest user.
highlight = false;
child = CircleAvatar(
child: Icon(AdaptiveIcons.person),
);
case 'user-group' || 'group':
case spreed.RichObjectParameter_Type.userGroup || spreed.RichObjectParameter_Type.group:
final accountsBloc = NeonProvider.of<AccountsBloc>(context);
final userDetailsBloc = accountsBloc.activeUserDetailsBloc;
final groups = userDetailsBloc.userDetails.valueOrNull?.data?.groups ?? BuiltList();
Expand Down
24 changes: 15 additions & 9 deletions packages/neon/neon_talk/test/message_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -634,8 +634,14 @@ void main() {
for (final isPreview in [true, false]) {
group(isPreview ? 'As preview' : 'Complete', () {
group('Mention', () {
for (final type in ['user', 'call', 'guest', 'user-group', 'group']) {
testWidgets(type, (tester) async {
for (final type in [
spreed.RichObjectParameter_Type.user,
spreed.RichObjectParameter_Type.call,
spreed.RichObjectParameter_Type.guest,
spreed.RichObjectParameter_Type.userGroup,
spreed.RichObjectParameter_Type.group,
]) {
testWidgets(type.value, (tester) async {
final userDetails = MockUserDetails();
when(() => userDetails.groups).thenReturn(BuiltList());

Expand Down Expand Up @@ -687,7 +693,7 @@ void main() {
text: buildRichObjectParameter(
parameter: spreed.RichObjectParameter(
(b) => b
..type = 'file'
..type = spreed.RichObjectParameter_Type.file
..id = ''
..name = 'name',
),
Expand All @@ -709,7 +715,7 @@ void main() {
text: buildRichObjectParameter(
parameter: spreed.RichObjectParameter(
(b) => b
..type = 'deck-card'
..type = spreed.RichObjectParameter_Type.deckCard
..id = ''
..name = 'name'
..boardname = 'boardname'
Expand All @@ -733,7 +739,7 @@ void main() {
text: buildRichObjectParameter(
parameter: spreed.RichObjectParameter(
(b) => b
..type = 'unknown'
..type = spreed.RichObjectParameter_Type.addressbook
..id = ''
..name = 'name',
),
Expand Down Expand Up @@ -774,7 +780,7 @@ void main() {
BuiltMap({
type: spreed.RichObjectParameter(
(b) => b
..type = ''
..type = spreed.RichObjectParameter_Type.user
..id = ''
..name = '',
),
Expand All @@ -794,7 +800,7 @@ void main() {
BuiltMap({
'file': spreed.RichObjectParameter(
(b) => b
..type = 'file'
..type = spreed.RichObjectParameter_Type.file
..id = ''
..name = '',
),
Expand All @@ -816,13 +822,13 @@ void main() {
BuiltMap({
'actor1': spreed.RichObjectParameter(
(b) => b
..type = 'user'
..type = spreed.RichObjectParameter_Type.user
..id = ''
..name = '',
),
'actor2': spreed.RichObjectParameter(
(b) => b
..type = 'user'
..type = spreed.RichObjectParameter_Type.user
..id = ''
..name = '',
),
Expand Down
33 changes: 18 additions & 15 deletions packages/neon/neon_talk/test/rich_object_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ void main() {
child: TalkRichObjectDeckCard(
parameter: spreed.RichObjectParameter(
(b) => b
..type = ''
..type = spreed.RichObjectParameter_Type.deckCard
..id = ''
..name = 'name'
..boardname = 'boardname'
Expand All @@ -75,7 +75,7 @@ void main() {
child: TalkRichObjectMention(
parameter: spreed.RichObjectParameter(
(b) => b
..type = 'user'
..type = spreed.RichObjectParameter_Type.user
..id = 'username'
..name = 'name',
),
Expand All @@ -98,7 +98,7 @@ void main() {
child: TalkRichObjectMention(
parameter: spreed.RichObjectParameter(
(b) => b
..type = 'user'
..type = spreed.RichObjectParameter_Type.user
..id = 'other'
..name = 'name',
),
Expand All @@ -123,7 +123,7 @@ void main() {
child: TalkRichObjectMention(
parameter: spreed.RichObjectParameter(
(b) => b
..type = 'call'
..type = spreed.RichObjectParameter_Type.call
..id = ''
..name = 'name'
..iconUrl = '',
Expand All @@ -147,7 +147,7 @@ void main() {
child: TalkRichObjectMention(
parameter: spreed.RichObjectParameter(
(b) => b
..type = 'guest'
..type = spreed.RichObjectParameter_Type.guest
..id = ''
..name = 'name',
),
Expand All @@ -163,8 +163,11 @@ void main() {
);
});

for (final type in ['user-group', 'group']) {
testWidgets(type, (tester) async {
for (final type in [
spreed.RichObjectParameter_Type.userGroup,
spreed.RichObjectParameter_Type.group,
]) {
testWidgets(type.value, (tester) async {
final userDetails = MockUserDetails();
when(() => userDetails.groups).thenReturn(BuiltList(['group']));

Expand Down Expand Up @@ -193,7 +196,7 @@ void main() {
expect(find.text('name'), findsOne);
await expectLater(
find.byType(TalkRichObjectMention),
matchesGoldenFile('goldens/rich_object_mention_${type}_highlight.png'),
matchesGoldenFile('goldens/rich_object_mention_${type.value}_highlight.png'),
);

await tester.pumpWidget(
Expand All @@ -216,7 +219,7 @@ void main() {
expect(find.text('name'), findsOne);
await expectLater(
find.byType(TalkRichObjectMention),
matchesGoldenFile('goldens/rich_object_mention_${type}_other.png'),
matchesGoldenFile('goldens/rich_object_mention_${type.value}_other.png'),
);
});
}
Expand All @@ -231,10 +234,10 @@ void main() {
child: TalkRichObjectFile(
parameter: spreed.RichObjectParameter(
(b) => b
..type = ''
..type = spreed.RichObjectParameter_Type.file
..id = '0'
..name = 'name'
..previewAvailable = spreed.RichObjectParameter_PreviewAvailable.yes
..previewAvailable = 'yes'
..path = '',
),
textStyle: null,
Expand All @@ -256,10 +259,10 @@ void main() {
child: TalkRichObjectFile(
parameter: spreed.RichObjectParameter(
(b) => b
..type = ''
..type = spreed.RichObjectParameter_Type.file
..id = '0'
..name = 'name'
..previewAvailable = spreed.RichObjectParameter_PreviewAvailable.no
..previewAvailable = 'no'
..path = '',
),
textStyle: null,
Expand All @@ -282,7 +285,7 @@ void main() {
child: TalkRichObjectFallback(
parameter: spreed.RichObjectParameter(
(b) => b
..type = ''
..type = spreed.RichObjectParameter_Type.addressbook
..id = ''
..name = 'name',
),
Expand All @@ -306,7 +309,7 @@ void main() {
child: TalkRichObjectFallback(
parameter: spreed.RichObjectParameter(
(b) => b
..type = ''
..type = spreed.RichObjectParameter_Type.addressbook
..id = ''
..name = 'name'
..iconUrl = '',
Expand Down
Loading

0 comments on commit 66e488e

Please sign in to comment.