Skip to content

Commit c624c39

Browse files
committed
feat(tool,nextcloud)!: Generate rich object parameters
Signed-off-by: provokateurin <kate@provokateurin.de>
1 parent 875411d commit c624c39

File tree

13 files changed

+761
-522
lines changed

13 files changed

+761
-522
lines changed

.cspell/nextcloud.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
addressbook
12
apirequest
23
apppassword
34
bigfilechunking

packages/neon/neon_talk/lib/src/widgets/message.dart

Lines changed: 27 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -163,40 +163,35 @@ InlineSpan buildRichObjectParameter({
163163
required TextStyle? textStyle,
164164
required bool isPreview,
165165
}) {
166-
Widget child;
167-
168-
if (isPreview) {
169-
child = Text(
170-
parameter.name,
171-
style: textStyle,
172-
);
173-
} else {
174-
switch (parameter.type) {
175-
case 'user' || 'call' || 'guest' || 'user-group' || 'group':
176-
child = TalkRichObjectMention(
177-
parameter: parameter,
178-
textStyle: textStyle,
179-
);
180-
case 'file':
181-
child = TalkRichObjectFile(
182-
parameter: parameter,
183-
textStyle: textStyle,
184-
);
185-
case 'deck-card':
186-
child = TalkRichObjectDeckCard(
187-
parameter: parameter,
188-
);
189-
default:
190-
child = TalkRichObjectFallback(
191-
parameter: parameter,
192-
textStyle: textStyle,
193-
);
194-
}
195-
}
196-
197166
return WidgetSpan(
198167
alignment: PlaceholderAlignment.middle,
199-
child: child,
168+
child: isPreview
169+
? Text(
170+
parameter.name,
171+
style: textStyle,
172+
)
173+
: switch (parameter.type) {
174+
spreed.RichObjectParameter_Type.user ||
175+
spreed.RichObjectParameter_Type.call ||
176+
spreed.RichObjectParameter_Type.guest ||
177+
spreed.RichObjectParameter_Type.userGroup ||
178+
spreed.RichObjectParameter_Type.group =>
179+
TalkRichObjectMention(
180+
parameter: parameter,
181+
textStyle: textStyle,
182+
),
183+
spreed.RichObjectParameter_Type.file => TalkRichObjectFile(
184+
parameter: parameter,
185+
textStyle: textStyle,
186+
),
187+
spreed.RichObjectParameter_Type.deckCard => TalkRichObjectDeckCard(
188+
parameter: parameter,
189+
),
190+
_ => TalkRichObjectFallback(
191+
parameter: parameter,
192+
textStyle: textStyle,
193+
),
194+
},
200195
);
201196
}
202197

packages/neon/neon_talk/lib/src/widgets/rich_object/file.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class TalkRichObjectFile extends StatelessWidget {
2424
Widget build(BuildContext context) {
2525
Widget child;
2626

27-
if (parameter.previewAvailable == spreed.RichObjectParameter_PreviewAvailable.yes) {
27+
if (parameter.previewAvailable == 'yes') {
2828
child = TalkRichObjectFilePreview(
2929
parameter: parameter,
3030
);

packages/neon/neon_talk/lib/src/widgets/rich_object/mention.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class TalkRichObjectMention extends StatelessWidget {
2828
final bool highlight;
2929

3030
switch (parameter.type) {
31-
case 'user':
31+
case spreed.RichObjectParameter_Type.user:
3232
final account = NeonProvider.of<Account>(context);
3333

3434
highlight = account.username == parameter.id;
@@ -37,7 +37,7 @@ class TalkRichObjectMention extends StatelessWidget {
3737
account: NeonProvider.of<Account>(context),
3838
userStatusBloc: null,
3939
);
40-
case 'call':
40+
case spreed.RichObjectParameter_Type.call:
4141
highlight = true;
4242
child = CircleAvatar(
4343
child: ClipOval(
@@ -47,13 +47,13 @@ class TalkRichObjectMention extends StatelessWidget {
4747
),
4848
),
4949
);
50-
case 'guest':
50+
case spreed.RichObjectParameter_Type.guest:
5151
// TODO: Add highlighting when the mention is about the current guest user.
5252
highlight = false;
5353
child = CircleAvatar(
5454
child: Icon(AdaptiveIcons.person),
5555
);
56-
case 'user-group' || 'group':
56+
case spreed.RichObjectParameter_Type.userGroup || spreed.RichObjectParameter_Type.group:
5757
final userDetailsBloc = NeonProvider.of<UserDetailsBloc>(context);
5858
final groups = userDetailsBloc.userDetails.valueOrNull?.data?.groups ?? BuiltList();
5959

packages/neon/neon_talk/test/message_test.dart

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1173,8 +1173,14 @@ void main() {
11731173
for (final isPreview in [true, false]) {
11741174
group(isPreview ? 'As preview' : 'Complete', () {
11751175
group('Mention', () {
1176-
for (final type in ['user', 'call', 'guest', 'user-group', 'group']) {
1177-
testWidgets(type, (tester) async {
1176+
for (final type in [
1177+
spreed.RichObjectParameter_Type.user,
1178+
spreed.RichObjectParameter_Type.call,
1179+
spreed.RichObjectParameter_Type.guest,
1180+
spreed.RichObjectParameter_Type.userGroup,
1181+
spreed.RichObjectParameter_Type.group,
1182+
]) {
1183+
testWidgets(type.value, (tester) async {
11781184
final userDetails = MockUserDetails();
11791185
when(() => userDetails.groups).thenReturn(BuiltList());
11801186

@@ -1221,7 +1227,7 @@ void main() {
12211227
text: buildRichObjectParameter(
12221228
parameter: spreed.RichObjectParameter(
12231229
(b) => b
1224-
..type = 'file'
1230+
..type = spreed.RichObjectParameter_Type.file
12251231
..id = ''
12261232
..name = 'name',
12271233
),
@@ -1243,7 +1249,7 @@ void main() {
12431249
text: buildRichObjectParameter(
12441250
parameter: spreed.RichObjectParameter(
12451251
(b) => b
1246-
..type = 'deck-card'
1252+
..type = spreed.RichObjectParameter_Type.deckCard
12471253
..id = ''
12481254
..name = 'name'
12491255
..boardname = 'boardname'
@@ -1267,7 +1273,7 @@ void main() {
12671273
text: buildRichObjectParameter(
12681274
parameter: spreed.RichObjectParameter(
12691275
(b) => b
1270-
..type = 'unknown'
1276+
..type = spreed.RichObjectParameter_Type.addressbook
12711277
..id = ''
12721278
..name = 'name',
12731279
),
@@ -1319,7 +1325,7 @@ void main() {
13191325
BuiltMap({
13201326
type: spreed.RichObjectParameter(
13211327
(b) => b
1322-
..type = ''
1328+
..type = spreed.RichObjectParameter_Type.user
13231329
..id = ''
13241330
..name = '',
13251331
),
@@ -1344,7 +1350,7 @@ void main() {
13441350
BuiltMap({
13451351
'file': spreed.RichObjectParameter(
13461352
(b) => b
1347-
..type = 'file'
1353+
..type = spreed.RichObjectParameter_Type.file
13481354
..id = ''
13491355
..name = '',
13501356
),
@@ -1371,13 +1377,13 @@ void main() {
13711377
BuiltMap({
13721378
'actor1': spreed.RichObjectParameter(
13731379
(b) => b
1374-
..type = 'user'
1380+
..type = spreed.RichObjectParameter_Type.user
13751381
..id = ''
13761382
..name = '',
13771383
),
13781384
'actor2': spreed.RichObjectParameter(
13791385
(b) => b
1380-
..type = 'user'
1386+
..type = spreed.RichObjectParameter_Type.user
13811387
..id = ''
13821388
..name = '',
13831389
),

packages/neon/neon_talk/test/rich_object_test.dart

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ void main() {
5050
child: TalkRichObjectDeckCard(
5151
parameter: spreed.RichObjectParameter(
5252
(b) => b
53-
..type = ''
53+
..type = spreed.RichObjectParameter_Type.deckCard
5454
..id = ''
5555
..name = 'name'
5656
..boardname = 'boardname'
@@ -82,7 +82,7 @@ void main() {
8282
child: TalkRichObjectMention(
8383
parameter: spreed.RichObjectParameter(
8484
(b) => b
85-
..type = 'user'
85+
..type = spreed.RichObjectParameter_Type.user
8686
..id = 'username'
8787
..name = 'name',
8888
),
@@ -107,7 +107,7 @@ void main() {
107107
child: TalkRichObjectMention(
108108
parameter: spreed.RichObjectParameter(
109109
(b) => b
110-
..type = 'user'
110+
..type = spreed.RichObjectParameter_Type.user
111111
..id = 'other'
112112
..name = 'name',
113113
),
@@ -133,7 +133,7 @@ void main() {
133133
child: TalkRichObjectMention(
134134
parameter: spreed.RichObjectParameter(
135135
(b) => b
136-
..type = 'call'
136+
..type = spreed.RichObjectParameter_Type.call
137137
..id = ''
138138
..name = 'name'
139139
..iconUrl = '',
@@ -156,7 +156,7 @@ void main() {
156156
child: TalkRichObjectMention(
157157
parameter: spreed.RichObjectParameter(
158158
(b) => b
159-
..type = 'guest'
159+
..type = spreed.RichObjectParameter_Type.guest
160160
..id = ''
161161
..name = 'name',
162162
),
@@ -172,8 +172,11 @@ void main() {
172172
);
173173
});
174174

175-
for (final type in ['user-group', 'group']) {
176-
testWidgets(type, (tester) async {
175+
for (final type in [
176+
spreed.RichObjectParameter_Type.userGroup,
177+
spreed.RichObjectParameter_Type.group,
178+
]) {
179+
testWidgets(type.value, (tester) async {
177180
final userDetails = MockUserDetails();
178181
when(() => userDetails.groups).thenReturn(BuiltList(['group']));
179182

@@ -200,7 +203,7 @@ void main() {
200203
expect(find.text('name'), findsOne);
201204
await expectLater(
202205
find.byType(TalkRichObjectMention),
203-
matchesGoldenFile('goldens/rich_object_mention_${type}_highlight.png'),
206+
matchesGoldenFile('goldens/rich_object_mention_${type.value}_highlight.png'),
204207
);
205208

206209
await tester.pumpWidgetWithAccessibility(
@@ -223,7 +226,7 @@ void main() {
223226
expect(find.text('name'), findsOne);
224227
await expectLater(
225228
find.byType(TalkRichObjectMention),
226-
matchesGoldenFile('goldens/rich_object_mention_${type}_other.png'),
229+
matchesGoldenFile('goldens/rich_object_mention_${type.value}_other.png'),
227230
);
228231
});
229232
}
@@ -239,10 +242,10 @@ void main() {
239242
child: TalkRichObjectFile(
240243
parameter: spreed.RichObjectParameter(
241244
(b) => b
242-
..type = ''
245+
..type = spreed.RichObjectParameter_Type.file
243246
..id = '0'
244247
..name = 'name'
245-
..previewAvailable = spreed.RichObjectParameter_PreviewAvailable.no
248+
..previewAvailable = 'no'
246249
..path = ''
247250
..link = '/link',
248251
),
@@ -264,10 +267,10 @@ void main() {
264267
child: TalkRichObjectFile(
265268
parameter: spreed.RichObjectParameter(
266269
(b) => b
267-
..type = ''
270+
..type = spreed.RichObjectParameter_Type.file
268271
..id = '0'
269272
..name = 'name'
270-
..previewAvailable = spreed.RichObjectParameter_PreviewAvailable.yes
273+
..previewAvailable = 'yes'
271274
..path = '',
272275
),
273276
textStyle: null,
@@ -283,10 +286,10 @@ void main() {
283286
child: TalkRichObjectFile(
284287
parameter: spreed.RichObjectParameter(
285288
(b) => b
286-
..type = ''
289+
..type = spreed.RichObjectParameter_Type.file
287290
..id = '0'
288291
..name = 'name'
289-
..previewAvailable = spreed.RichObjectParameter_PreviewAvailable.no
292+
..previewAvailable = 'no'
290293
..path = '',
291294
),
292295
textStyle: null,
@@ -316,10 +319,10 @@ void main() {
316319
child: TalkRichObjectFile(
317320
parameter: spreed.RichObjectParameter(
318321
(b) => b
319-
..type = ''
322+
..type = spreed.RichObjectParameter_Type.file
320323
..id = '0'
321324
..name = 'name'
322-
..previewAvailable = spreed.RichObjectParameter_PreviewAvailable.yes
325+
..previewAvailable = 'yes'
323326
..path = 'path',
324327
),
325328
textStyle: null,
@@ -347,10 +350,10 @@ void main() {
347350
child: TalkRichObjectFile(
348351
parameter: spreed.RichObjectParameter(
349352
(b) => b
350-
..type = ''
353+
..type = spreed.RichObjectParameter_Type.file
351354
..id = '0'
352355
..name = 'name'
353-
..previewAvailable = spreed.RichObjectParameter_PreviewAvailable.yes
356+
..previewAvailable = 'yes'
354357
..path = 'path'
355358
..width = ($int: width, string: null)
356359
..height = ($int: height, string: null),
@@ -380,10 +383,10 @@ void main() {
380383
child: TalkRichObjectFile(
381384
parameter: spreed.RichObjectParameter(
382385
(b) => b
383-
..type = ''
386+
..type = spreed.RichObjectParameter_Type.file
384387
..id = '0'
385388
..name = 'name'
386-
..previewAvailable = spreed.RichObjectParameter_PreviewAvailable.yes
389+
..previewAvailable = 'yes'
387390
..path = 'path'
388391
..width = ($int: (maxWidth * widthFactor) * pixelRatio, string: null)
389392
..height = ($int: (maxHeight * heightFactor) * pixelRatio, string: null),
@@ -414,10 +417,10 @@ void main() {
414417
child: TalkRichObjectFile(
415418
parameter: spreed.RichObjectParameter(
416419
(b) => b
417-
..type = ''
420+
..type = spreed.RichObjectParameter_Type.file
418421
..id = '0'
419422
..name = 'name'
420-
..previewAvailable = spreed.RichObjectParameter_PreviewAvailable.yes
423+
..previewAvailable = 'yes'
421424
..path = 'path'
422425
..mimetype = 'image/gif',
423426
),
@@ -447,7 +450,7 @@ void main() {
447450
child: TalkRichObjectFallback(
448451
parameter: spreed.RichObjectParameter(
449452
(b) => b
450-
..type = ''
453+
..type = spreed.RichObjectParameter_Type.calendarEvent
451454
..id = ''
452455
..name = 'name'
453456
..link = '/link',
@@ -467,7 +470,7 @@ void main() {
467470
child: TalkRichObjectFallback(
468471
parameter: spreed.RichObjectParameter(
469472
(b) => b
470-
..type = ''
473+
..type = spreed.RichObjectParameter_Type.addressbook
471474
..id = ''
472475
..name = 'name',
473476
),
@@ -492,7 +495,7 @@ void main() {
492495
child: TalkRichObjectFallback(
493496
parameter: spreed.RichObjectParameter(
494497
(b) => b
495-
..type = ''
498+
..type = spreed.RichObjectParameter_Type.addressbook
496499
..id = ''
497500
..name = 'name'
498501
..iconUrl = '',

0 commit comments

Comments
 (0)