Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(neon_framework): Display blurhash for rich text file previews #2614

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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
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