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 May 21, 2024
1 parent d888526 commit be34dde
Show file tree
Hide file tree
Showing 15 changed files with 721 additions and 525 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 @@ -119,40 +119,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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 @@ -696,8 +696,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 @@ -749,7 +755,7 @@ void main() {
text: buildRichObjectParameter(
parameter: spreed.RichObjectParameter(
(b) => b
..type = 'file'
..type = spreed.RichObjectParameter_Type.file
..id = ''
..name = 'name',
),
Expand All @@ -771,7 +777,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 @@ -795,7 +801,7 @@ void main() {
text: buildRichObjectParameter(
parameter: spreed.RichObjectParameter(
(b) => b
..type = 'unknown'
..type = spreed.RichObjectParameter_Type.addressbook
..id = ''
..name = 'name',
),
Expand Down Expand Up @@ -836,7 +842,7 @@ void main() {
BuiltMap({
type: spreed.RichObjectParameter(
(b) => b
..type = ''
..type = spreed.RichObjectParameter_Type.user
..id = ''
..name = '',
),
Expand All @@ -856,7 +862,7 @@ void main() {
BuiltMap({
'file': spreed.RichObjectParameter(
(b) => b
..type = 'file'
..type = spreed.RichObjectParameter_Type.file
..id = ''
..name = '',
),
Expand All @@ -878,13 +884,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
82 changes: 47 additions & 35 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 @@ -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 @@ -95,14 +95,17 @@ void main() {
providers: [
NeonProvider<AccountsBloc>.value(value: accountsBloc),
],
child: TalkRichObjectMention(
parameter: spreed.RichObjectParameter(
(b) => b
..type = 'user'
..id = 'other'
..name = 'name',
child: NeonProvider<AccountsBloc>.value(
value: accountsBloc,
child: TalkRichObjectMention(
parameter: spreed.RichObjectParameter(
(b) => b
..type = spreed.RichObjectParameter_Type.user
..id = 'other'
..name = 'name',
),
textStyle: null,
),
textStyle: null,
),
),
);
Expand All @@ -120,15 +123,18 @@ void main() {
providers: [
NeonProvider<AccountsBloc>.value(value: accountsBloc),
],
child: TalkRichObjectMention(
parameter: spreed.RichObjectParameter(
(b) => b
..type = 'call'
..id = ''
..name = 'name'
..iconUrl = '',
child: NeonProvider<AccountsBloc>.value(
value: accountsBloc,
child: TalkRichObjectMention(
parameter: spreed.RichObjectParameter(
(b) => b
..type = spreed.RichObjectParameter_Type.call
..id = ''
..name = 'name'
..iconUrl = '',
),
textStyle: null,
),
textStyle: null,
),
),
);
Expand All @@ -146,7 +152,7 @@ void main() {
child: TalkRichObjectMention(
parameter: spreed.RichObjectParameter(
(b) => b
..type = 'guest'
..type = spreed.RichObjectParameter_Type.guest
..id = ''
..name = 'name',
),
Expand All @@ -162,8 +168,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 +201,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 +224,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 @@ -228,16 +237,19 @@ void main() {
providers: [
NeonProvider<AccountsBloc>.value(value: accountsBloc),
],
child: TalkRichObjectFile(
parameter: spreed.RichObjectParameter(
(b) => b
..type = ''
..id = '0'
..name = 'name'
..previewAvailable = spreed.RichObjectParameter_PreviewAvailable.yes
..path = '',
child: NeonProvider<AccountsBloc>.value(
value: accountsBloc,
child: TalkRichObjectFile(
parameter: spreed.RichObjectParameter(
(b) => b
..type = spreed.RichObjectParameter_Type.file
..id = '0'
..name = 'name'
..previewAvailable = 'yes'
..path = '',
),
textStyle: null,
),
textStyle: null,
),
),
);
Expand All @@ -255,10 +267,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 +293,7 @@ void main() {
child: TalkRichObjectFallback(
parameter: spreed.RichObjectParameter(
(b) => b
..type = ''
..type = spreed.RichObjectParameter_Type.addressbook
..id = ''
..name = 'name',
),
Expand All @@ -306,7 +318,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 be34dde

Please sign in to comment.