Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
feat(tool,nextcloud)!: Generate rich object parameters
Signed-off-by: provokateurin <[email protected]>
  • Loading branch information
provokateurin committed Jul 17, 2024
commit c624c39e75b1119b66151cccbe434b9b03a6a580
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
59 changes: 27 additions & 32 deletions packages/neon/neon_talk/lib/src/widgets/message.dart
Original file line number Diff line number Diff line change
Expand Up @@ -163,40 +163,35 @@ InlineSpan buildRichObjectParameter({
required TextStyle? textStyle,
required bool isPreview,
}) {
Widget child;

if (isPreview) {
child = Text(
parameter.name,
style: textStyle,
);
} else {
switch (parameter.type) {
case 'user' || 'call' || 'guest' || 'user-group' || 'group':
child = TalkRichObjectMention(
parameter: parameter,
textStyle: textStyle,
);
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: isPreview
? Text(
parameter.name,
style: textStyle,
)
: 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,
),
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 @@ -24,7 +24,7 @@ class TalkRichObjectFile extends StatelessWidget {
Widget build(BuildContext context) {
Widget child;

if (parameter.previewAvailable == spreed.RichObjectParameter_PreviewAvailable.yes) {
if (parameter.previewAvailable == 'yes') {
child = TalkRichObjectFilePreview(
parameter: parameter,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class TalkRichObjectMention extends StatelessWidget {
final bool highlight;

switch (parameter.type) {
case 'user':
case spreed.RichObjectParameter_Type.user:
final account = NeonProvider.of<Account>(context);

highlight = account.username == parameter.id;
Expand All @@ -37,7 +37,7 @@ class TalkRichObjectMention extends StatelessWidget {
account: NeonProvider.of<Account>(context),
userStatusBloc: null,
);
case 'call':
case spreed.RichObjectParameter_Type.call:
highlight = true;
child = CircleAvatar(
child: ClipOval(
Expand All @@ -47,13 +47,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 userDetailsBloc = NeonProvider.of<UserDetailsBloc>(context);
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 @@ -1173,8 +1173,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 @@ -1221,7 +1227,7 @@ void main() {
text: buildRichObjectParameter(
parameter: spreed.RichObjectParameter(
(b) => b
..type = 'file'
..type = spreed.RichObjectParameter_Type.file
..id = ''
..name = 'name',
),
Expand All @@ -1243,7 +1249,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 @@ -1267,7 +1273,7 @@ void main() {
text: buildRichObjectParameter(
parameter: spreed.RichObjectParameter(
(b) => b
..type = 'unknown'
..type = spreed.RichObjectParameter_Type.addressbook
..id = ''
..name = 'name',
),
Expand Down Expand Up @@ -1319,7 +1325,7 @@ void main() {
BuiltMap({
type: spreed.RichObjectParameter(
(b) => b
..type = ''
..type = spreed.RichObjectParameter_Type.user
..id = ''
..name = '',
),
Expand All @@ -1344,7 +1350,7 @@ void main() {
BuiltMap({
'file': spreed.RichObjectParameter(
(b) => b
..type = 'file'
..type = spreed.RichObjectParameter_Type.file
..id = ''
..name = '',
),
Expand All @@ -1371,13 +1377,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
55 changes: 29 additions & 26 deletions packages/neon/neon_talk/test/rich_object_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ void main() {
child: TalkRichObjectDeckCard(
parameter: spreed.RichObjectParameter(
(b) => b
..type = ''
..type = spreed.RichObjectParameter_Type.deckCard
..id = ''
..name = 'name'
..boardname = 'boardname'
Expand Down Expand Up @@ -82,7 +82,7 @@ void main() {
child: TalkRichObjectMention(
parameter: spreed.RichObjectParameter(
(b) => b
..type = 'user'
..type = spreed.RichObjectParameter_Type.user
..id = 'username'
..name = 'name',
),
Expand All @@ -107,7 +107,7 @@ void main() {
child: TalkRichObjectMention(
parameter: spreed.RichObjectParameter(
(b) => b
..type = 'user'
..type = spreed.RichObjectParameter_Type.user
..id = 'other'
..name = 'name',
),
Expand All @@ -133,7 +133,7 @@ void main() {
child: TalkRichObjectMention(
parameter: spreed.RichObjectParameter(
(b) => b
..type = 'call'
..type = spreed.RichObjectParameter_Type.call
..id = ''
..name = 'name'
..iconUrl = '',
Expand All @@ -156,7 +156,7 @@ void main() {
child: TalkRichObjectMention(
parameter: spreed.RichObjectParameter(
(b) => b
..type = 'guest'
..type = spreed.RichObjectParameter_Type.guest
..id = ''
..name = 'name',
),
Expand All @@ -172,8 +172,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 All @@ -200,7 +203,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.pumpWidgetWithAccessibility(
Expand All @@ -223,7 +226,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 @@ -239,10 +242,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 = ''
..link = '/link',
),
Expand All @@ -264,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.yes
..previewAvailable = 'yes'
..path = '',
),
textStyle: null,
Expand All @@ -283,10 +286,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 Down Expand Up @@ -316,10 +319,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 = 'path',
),
textStyle: null,
Expand Down Expand Up @@ -347,10 +350,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 = 'path'
..width = ($int: width, string: null)
..height = ($int: height, string: null),
Expand Down Expand Up @@ -380,10 +383,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 = 'path'
..width = ($int: (maxWidth * widthFactor) * pixelRatio, string: null)
..height = ($int: (maxHeight * heightFactor) * pixelRatio, string: null),
Expand Down Expand Up @@ -414,10 +417,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 = 'path'
..mimetype = 'image/gif',
),
Expand Down Expand Up @@ -447,7 +450,7 @@ void main() {
child: TalkRichObjectFallback(
parameter: spreed.RichObjectParameter(
(b) => b
..type = ''
..type = spreed.RichObjectParameter_Type.calendarEvent
..id = ''
..name = 'name'
..link = '/link',
Expand All @@ -467,7 +470,7 @@ void main() {
child: TalkRichObjectFallback(
parameter: spreed.RichObjectParameter(
(b) => b
..type = ''
..type = spreed.RichObjectParameter_Type.addressbook
..id = ''
..name = 'name',
),
Expand All @@ -492,7 +495,7 @@ void main() {
child: TalkRichObjectFallback(
parameter: spreed.RichObjectParameter(
(b) => b
..type = ''
..type = spreed.RichObjectParameter_Type.addressbook
..id = ''
..name = 'name'
..iconUrl = '',
Expand Down
Loading