From fec39eb602645b7acc8afb7f41612818c9a01312 Mon Sep 17 00:00:00 2001 From: Krille Date: Wed, 3 Jan 2024 13:37:36 +0100 Subject: [PATCH] refactor: Put forwarded text into inputfield instead of sending directly --- lib/config/routes.dart | 5 ++++- lib/pages/chat/chat.dart | 7 ++++++- lib/pages/chat_list/chat_list_item.dart | 9 +++++++-- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/lib/config/routes.dart b/lib/config/routes.dart index 3c5818ea..d525b94e 100644 --- a/lib/config/routes.dart +++ b/lib/config/routes.dart @@ -283,7 +283,10 @@ abstract class AppRoutes { path: ':roomid', pageBuilder: (context, state) => defaultPageBuilder( context, - ChatPage(roomId: state.pathParameters['roomid']!), + ChatPage( + roomId: state.pathParameters['roomid']!, + shareText: state.uri.queryParameters['body'], + ), ), redirect: loggedOutRedirect, routes: [ diff --git a/lib/pages/chat/chat.dart b/lib/pages/chat/chat.dart index a4561fbb..5e9295cf 100644 --- a/lib/pages/chat/chat.dart +++ b/lib/pages/chat/chat.dart @@ -41,10 +41,12 @@ import 'sticker_picker_dialog.dart'; class ChatPage extends StatelessWidget { final String roomId; + final String? shareText; const ChatPage({ super.key, required this.roomId, + this.shareText, }); @override @@ -69,6 +71,7 @@ class ChatPage extends StatelessWidget { child: ChatPageWithRoom( key: Key('chat_page_$roomId'), room: room, + shareText: shareText, ), ), if (FluffyThemes.isThreeColumnMode(context) && @@ -93,10 +96,12 @@ class ChatPage extends StatelessWidget { class ChatPageWithRoom extends StatefulWidget { final Room room; + final String? shareText; const ChatPageWithRoom({ super.key, required this.room, + this.shareText, }); @override @@ -253,7 +258,7 @@ class ChatController extends State void _loadDraft() async { final prefs = await SharedPreferences.getInstance(); - final draft = prefs.getString('draft_$roomId'); + final draft = widget.shareText ?? prefs.getString('draft_$roomId'); if (draft != null && draft.isNotEmpty) { sendController.text = draft; } diff --git a/lib/pages/chat_list/chat_list_item.dart b/lib/pages/chat_list/chat_list_item.dart index bd039021..c04d6878 100644 --- a/lib/pages/chat_list/chat_list_item.dart +++ b/lib/pages/chat_list/chat_list_item.dart @@ -124,10 +124,15 @@ class ChatListItem extends StatelessWidget { room: room, ), ); + Matrix.of(context).shareContent = null; } else { - room.sendEvent(shareContent); + final text = shareContent.tryGet('body'); + Matrix.of(context).shareContent = null; + context.go( + '/rooms/${room.id}?body=$text', + ); + return; } - Matrix.of(context).shareContent = null; } context.go('/rooms/${room.id}');