Skip to content

Commit

Permalink
feat(neon_framework): Display blurhash for rich text file previews
Browse files Browse the repository at this point in the history
Signed-off-by: provokateurin <[email protected]>
  • Loading branch information
provokateurin committed Oct 31, 2024
1 parent 3476e9e commit 0efa671
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
2 changes: 2 additions & 0 deletions packages/neon_framework/lib/src/widgets/rich_text/file.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,15 @@ class NeonRichObjectFile extends StatelessWidget {
// Previews for animated GIFs are not animated, so we have to request the full file.
image = NeonUriImage(
account: account,
blurHash: parameter.blurhash,
uri: Uri.parse(
'${account.credentials.serverURL}/remote.php/dav/files/${account.username}/${parameter.path!}',
),
);
} else {
image = NeonApiImage(
account: account,
blurHash: parameter.blurhash,
etag: parameter.etag,
expires: null,
getRequest: (client) => client.core.preview.$getPreviewByFileId_Request(
Expand Down
37 changes: 35 additions & 2 deletions packages/neon_framework/test/rich_text_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import 'package:provider/provider.dart';
import 'package:rxdart/rxdart.dart';
import 'package:url_launcher_platform_interface/url_launcher_platform_interface.dart';

const validBlurHash = 'LEHLk~WB2yk8pyo0adR*.7kCMdnj';

class MockOnReferenceClickedCallback extends Mock {
void call(String reference);
}
Expand Down Expand Up @@ -255,6 +257,35 @@ void main() {
verify(() => urlLauncher.launchUrl('https://cloud.example.com:8443/link', any())).called(1);
});

testWidgets('With blurhash', (tester) async {
await tester.pumpWidgetWithAccessibility(
TestApp(
providers: [
Provider<Account>.value(value: account),
],
child: NeonRichObjectFile(
parameter: core.RichObjectParameter(
(b) => b
..type = core.RichObjectParameter_Type.file
..id = '0'
..name = 'name'
..previewAvailable = 'no'
..path = ''
..blurhash = validBlurHash,
),
textStyle: null,
),
),
);

expect(
find.byWidgetPredicate(
(widget) => widget is NeonApiImage && widget.blurHash == validBlurHash,
),
findsOne,
);
});

testWidgets('Without preview', (tester) async {
await tester.pumpWidgetWithAccessibility(
TestApp(
Expand Down Expand Up @@ -396,7 +427,8 @@ void main() {
..name = 'name'
..previewAvailable = 'yes'
..path = 'path'
..mimetype = 'image/gif',
..mimetype = 'image/gif'
..blurhash = validBlurHash,
),
textStyle: null,
),
Expand All @@ -407,7 +439,8 @@ void main() {
find.byWidgetPredicate(
(widget) =>
widget is NeonUriImage &&
widget.uri.toString() == 'https://cloud.example.com:8443/nextcloud/remote.php/dav/files/username/path',
widget.uri.toString() == 'https://cloud.example.com:8443/nextcloud/remote.php/dav/files/username/path' &&
widget.blurHash == validBlurHash,
),
findsOne,
);
Expand Down

0 comments on commit 0efa671

Please sign in to comment.