fix: Set image width and height
Uses the thumbnail generation of Matrix SDK.
This commit is contained in:
parent
fa6a7435d6
commit
c600c74e3e
7 changed files with 47 additions and 124 deletions
|
|
@ -13,7 +13,6 @@ import 'package:fluffychat/pages/add_story/add_story_view.dart';
|
|||
import 'package:fluffychat/pages/add_story/invite_story_page.dart';
|
||||
import 'package:fluffychat/utils/matrix_sdk_extensions.dart/matrix_file_extension.dart';
|
||||
import 'package:fluffychat/utils/resize_image.dart';
|
||||
import 'package:fluffychat/utils/room_send_file_extension.dart';
|
||||
import 'package:fluffychat/utils/string_color.dart';
|
||||
import 'package:fluffychat/widgets/matrix.dart';
|
||||
import '../../utils/matrix_sdk_extensions.dart/client_stories_extension.dart';
|
||||
|
|
@ -29,8 +28,8 @@ class AddStoryController extends State<AddStoryPage> {
|
|||
final TextEditingController controller = TextEditingController();
|
||||
late Color backgroundColor;
|
||||
late Color backgroundColorDark;
|
||||
MatrixFile? image;
|
||||
MatrixFile? video;
|
||||
MatrixImageFile? image;
|
||||
MatrixVideoFile? video;
|
||||
|
||||
VideoPlayerController? videoPlayerController;
|
||||
|
||||
|
|
@ -49,8 +48,13 @@ class AddStoryController extends State<AddStoryPage> {
|
|||
);
|
||||
final fileName = picked.fileName;
|
||||
if (fileName == null) return;
|
||||
final shrinked = await MatrixImageFile.shrink(
|
||||
bytes: picked.toUint8List(),
|
||||
name: fileName,
|
||||
compute: Matrix.of(context).client.runInBackground,
|
||||
);
|
||||
setState(() {
|
||||
image = MatrixFile(bytes: picked.toUint8List(), name: fileName);
|
||||
image = shrinked;
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -60,8 +64,13 @@ class AddStoryController extends State<AddStoryPage> {
|
|||
);
|
||||
if (picked == null) return;
|
||||
final bytes = await picked.readAsBytes();
|
||||
final shrinked = await MatrixImageFile.shrink(
|
||||
bytes: bytes,
|
||||
name: picked.name,
|
||||
compute: Matrix.of(context).client.runInBackground,
|
||||
);
|
||||
setState(() {
|
||||
image = MatrixFile(bytes: bytes, name: picked.name);
|
||||
image = shrinked;
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -73,7 +82,7 @@ class AddStoryController extends State<AddStoryPage> {
|
|||
final bytes = await picked.readAsBytes();
|
||||
|
||||
setState(() {
|
||||
video = MatrixFile(bytes: bytes, name: picked.name);
|
||||
video = MatrixVideoFile(bytes: bytes, name: picked.name);
|
||||
videoPlayerController = VideoPlayerController.file(File(picked.path))
|
||||
..setLooping(true);
|
||||
});
|
||||
|
|
@ -109,16 +118,17 @@ class AddStoryController extends State<AddStoryPage> {
|
|||
var video = this.video?.detectFileType;
|
||||
if (video != null) {
|
||||
video = await video.resizeVideo();
|
||||
await storiesRoom.sendFileEventWithThumbnail(
|
||||
final thumbnail = await video.getVideoThumbnail();
|
||||
await storiesRoom.sendFileEvent(
|
||||
video,
|
||||
extraContent: {'body': controller.text},
|
||||
thumbnail: thumbnail,
|
||||
);
|
||||
return;
|
||||
}
|
||||
var image = this.image?.detectFileType;
|
||||
final image = this.image;
|
||||
if (image != null) {
|
||||
image = await image.resizeImage();
|
||||
await storiesRoom.sendFileEventWithThumbnail(
|
||||
await storiesRoom.sendFileEvent(
|
||||
image,
|
||||
extraContent: {'body': controller.text},
|
||||
);
|
||||
|
|
@ -142,9 +152,10 @@ class AddStoryController extends State<AddStoryPage> {
|
|||
final shareContent = Matrix.of(context).shareContent;
|
||||
// ignore: unnecessary_null_comparison
|
||||
if (shareContent != null) {
|
||||
image = shareContent.tryGet<MatrixFile>('file');
|
||||
final shareFile = shareContent.tryGet<MatrixFile>('file')?.detectFileType;
|
||||
|
||||
controller.text = shareContent.tryGet<String>('body') ?? '';
|
||||
if (shareContent.tryGet<String>('msgtype') == MessageTypes.Image) {
|
||||
if (shareFile is MatrixImageFile) {
|
||||
Event(
|
||||
content: shareContent,
|
||||
type: EventTypes.Message,
|
||||
|
|
@ -154,10 +165,10 @@ class AddStoryController extends State<AddStoryPage> {
|
|||
originServerTs: DateTime.now(),
|
||||
).downloadAndDecryptAttachment().then((file) {
|
||||
setState(() {
|
||||
image = file;
|
||||
image = shareFile;
|
||||
});
|
||||
});
|
||||
} else if (shareContent.tryGet<String>('msgtype') == MessageTypes.Video) {
|
||||
} else if (shareFile is MatrixVideoFile) {
|
||||
Event(
|
||||
content: shareContent,
|
||||
type: EventTypes.Message,
|
||||
|
|
@ -167,7 +178,7 @@ class AddStoryController extends State<AddStoryPage> {
|
|||
originServerTs: DateTime.now(),
|
||||
).downloadAndDecryptAttachment().then((file) {
|
||||
setState(() {
|
||||
video = file;
|
||||
video = shareFile;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@ import 'package:matrix/matrix.dart';
|
|||
|
||||
import '../../utils/matrix_sdk_extensions.dart/matrix_file_extension.dart';
|
||||
import '../../utils/resize_image.dart';
|
||||
import '../../utils/room_send_file_extension.dart';
|
||||
|
||||
class SendFileDialog extends StatefulWidget {
|
||||
final Room room;
|
||||
|
|
@ -31,15 +30,21 @@ class _SendFileDialogState extends State<SendFileDialog> {
|
|||
|
||||
Future<void> _send() async {
|
||||
var file = widget.file;
|
||||
MatrixImageFile? thumbnail;
|
||||
if (file is MatrixImageFile &&
|
||||
!origImage &&
|
||||
file.bytes.length > minSizeToCompress) {
|
||||
file = await file.resizeImage();
|
||||
file = await MatrixImageFile.shrink(
|
||||
bytes: file.bytes,
|
||||
name: file.name,
|
||||
compute: widget.room.client.runInBackground,
|
||||
);
|
||||
}
|
||||
if (file is MatrixVideoFile && file.bytes.length > minSizeToCompress) {
|
||||
file = await file.resizeVideo();
|
||||
thumbnail = await file.getVideoThumbnail();
|
||||
}
|
||||
await widget.room.sendFileEventWithThumbnail(file);
|
||||
await widget.room.sendFileEvent(file, thumbnail: thumbnail);
|
||||
}
|
||||
|
||||
@override
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ import 'package:future_loading_dialog/future_loading_dialog.dart';
|
|||
import 'package:matrix/matrix.dart';
|
||||
import 'package:vrouter/vrouter.dart';
|
||||
|
||||
import '../../utils/resize_image.dart';
|
||||
import '../../widgets/matrix.dart';
|
||||
import 'settings_emotes_view.dart';
|
||||
|
||||
|
|
@ -206,14 +205,19 @@ class EmotesSettingsController extends State<EmotesSettings> {
|
|||
name: result.fileName!,
|
||||
);
|
||||
try {
|
||||
file = await file.resizeImage(calcBlurhash: false);
|
||||
file = (await file.generateThumbnail(
|
||||
compute: Matrix.of(context).client.runInBackground,
|
||||
))!;
|
||||
} catch (_) {
|
||||
// do nothing
|
||||
}
|
||||
final uploadResp = await showFutureLoadingDialog(
|
||||
context: context,
|
||||
future: () => Matrix.of(context).client.uploadContent(file.bytes,
|
||||
filename: file.name, contentType: file.mimeType),
|
||||
future: () => Matrix.of(context).client.uploadContent(
|
||||
file.bytes,
|
||||
filename: file.name,
|
||||
contentType: file.mimeType,
|
||||
),
|
||||
);
|
||||
if (uploadResp.error == null) {
|
||||
setState(() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue