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 <[email protected]>
  • Loading branch information
provokateurin committed Apr 27, 2024
1 parent 70b76b0 commit 2406cda
Show file tree
Hide file tree
Showing 16 changed files with 707 additions and 468 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 @@ -117,40 +117,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 = _parseDimension(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 @@ -646,8 +646,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 @@ -699,7 +705,7 @@ void main() {
text: buildRichObjectParameter(
parameter: spreed.RichObjectParameter(
(b) => b
..type = 'file'
..type = spreed.RichObjectParameter_Type.file
..id = ''
..name = 'name',
),
Expand All @@ -721,7 +727,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 @@ -745,7 +751,7 @@ void main() {
text: buildRichObjectParameter(
parameter: spreed.RichObjectParameter(
(b) => b
..type = 'unknown'
..type = spreed.RichObjectParameter_Type.addressbook
..id = ''
..name = 'name',
),
Expand Down Expand Up @@ -786,7 +792,7 @@ void main() {
BuiltMap({
type: spreed.RichObjectParameter(
(b) => b
..type = ''
..type = spreed.RichObjectParameter_Type.user
..id = ''
..name = '',
),
Expand All @@ -806,7 +812,7 @@ void main() {
BuiltMap({
'file': spreed.RichObjectParameter(
(b) => b
..type = 'file'
..type = spreed.RichObjectParameter_Type.file
..id = ''
..name = '',
),
Expand All @@ -828,13 +834,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 @@ -48,7 +48,7 @@ void main() {
child: TalkRichObjectDeckCard(
parameter: spreed.RichObjectParameter(
(b) => b
..type = ''
..type = spreed.RichObjectParameter_Type.deckCard
..id = ''
..name = 'name'
..boardname = 'boardname'
Expand All @@ -74,7 +74,7 @@ void main() {
child: TalkRichObjectMention(
parameter: spreed.RichObjectParameter(
(b) => b
..type = 'user'
..type = spreed.RichObjectParameter_Type.user
..id = 'username'
..name = 'name',
),
Expand All @@ -97,7 +97,7 @@ void main() {
child: TalkRichObjectMention(
parameter: spreed.RichObjectParameter(
(b) => b
..type = 'user'
..type = spreed.RichObjectParameter_Type.user
..id = 'other'
..name = 'name',
),
Expand All @@ -122,7 +122,7 @@ void main() {
child: TalkRichObjectMention(
parameter: spreed.RichObjectParameter(
(b) => b
..type = 'call'
..type = spreed.RichObjectParameter_Type.call
..id = ''
..name = 'name'
..iconUrl = '',
Expand All @@ -146,7 +146,7 @@ void main() {
child: TalkRichObjectMention(
parameter: spreed.RichObjectParameter(
(b) => b
..type = 'guest'
..type = spreed.RichObjectParameter_Type.guest
..id = ''
..name = 'name',
),
Expand All @@ -162,8 +162,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 @@ -192,7 +195,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 @@ -215,7 +218,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 @@ -230,10 +233,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 @@ -255,10 +258,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 @@ -281,7 +284,7 @@ void main() {
child: TalkRichObjectFallback(
parameter: spreed.RichObjectParameter(
(b) => b
..type = ''
..type = spreed.RichObjectParameter_Type.addressbook
..id = ''
..name = 'name',
),
Expand All @@ -305,7 +308,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 2406cda

Please sign in to comment.