From f93f1c1ecdbd6eb02683804512ab98581bab38d7 Mon Sep 17 00:00:00 2001 From: sherlock Date: Mon, 28 Aug 2023 17:01:58 +0700 Subject: [PATCH] fixup! fixup! fixup! TW-403: add share screen --- .../chat_list/receive_sharing_intent_mixin.dart | 12 +++++++----- lib/pages/share/share.dart | 5 +++-- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/lib/pages/chat_list/receive_sharing_intent_mixin.dart b/lib/pages/chat_list/receive_sharing_intent_mixin.dart index 1dd15b1492..df42c997cf 100644 --- a/lib/pages/chat_list/receive_sharing_intent_mixin.dart +++ b/lib/pages/chat_list/receive_sharing_intent_mixin.dart @@ -22,16 +22,18 @@ mixin ReceiveSharingIntentMixin on State { void _processIncomingSharedFiles(List files) { if (files.isEmpty) return; - final file = File(files.first.path.replaceFirst('file://', '')); + final shareFile = files.first; + final path = Uri.decodeFull(shareFile.path.replaceFirst('file://', '')); + final file = File(path); Matrix.of(context).shareContent = { 'msgtype': 'chat.fluffy.shared_file', 'file': MatrixFile( - bytes: file.readAsBytesSync(), name: file.path, filePath: file.path, ).detectFileType, + 'thumbnailPath': shareFile.thumbnail, }; - context.go('/share'); + context.push('/share'); } void _processIncomingSharedText(String? text) { @@ -46,12 +48,12 @@ mixin ReceiveSharingIntentMixin on State { 'msgtype': 'm.text', 'body': text, }; - context.go('/share'); + context.push('/share'); } void _processIncomingUris(String? text) async { if (text == null) return; - context.go('/share'); + context.push('/share'); WidgetsBinding.instance.addPostFrameCallback((_) { UrlLauncher(context, text).openMatrixToUrl(); }); diff --git a/lib/pages/share/share.dart b/lib/pages/share/share.dart index b7d4a4f7d6..1135b868a1 100644 --- a/lib/pages/share/share.dart +++ b/lib/pages/share/share.dart @@ -5,6 +5,7 @@ import 'package:fluffychat/domain/usecase/send_image_interactor.dart'; import 'package:fluffychat/pages/share/share_view.dart'; import 'package:fluffychat/presentation/extensions/send_file_extension.dart'; import 'package:fluffychat/presentation/mixins/send_files_mixin.dart'; +import 'package:fluffychat/utils/matrix_sdk_extensions/matrix_file_extension.dart'; import 'package:fluffychat/widgets/matrix.dart'; import 'package:flutter/material.dart'; import 'package:go_router/go_router.dart'; @@ -52,9 +53,8 @@ class ShareController extends State with SendFilesMixin { if (shareContent.tryGet('msgtype') == 'chat.fluffy.shared_file' && shareFile != null && shareFile.filePath != null) { - context.go('/rooms/${room.id}'); final txId = Matrix.of(context).client.generateUniqueTransactionId(); - room.sendingFilePlaceholders[txId] = shareFile; + room.sendingFilePlaceholders[txId] = shareFile.detectFileType; room.sendFileEvent( FileInfo(shareFile.name, shareFile.filePath!, shareFile.size), msgType: shareFile.msgType, @@ -63,6 +63,7 @@ class ShareController extends State with SendFilesMixin { } else { room.sendEvent(shareContent); } + context.go('/rooms/${room.id}'); Matrix.of(context).shareContent = null; } }