Skip to content

Commit

Permalink
Merge pull request #767 from krille-chan/krille/better-sharing-text
Browse files Browse the repository at this point in the history
refactor: Put forwarded text into inputfield instead of sending directly
  • Loading branch information
krille-chan authored Jan 4, 2024
2 parents af18da5 + fec39eb commit 9b5e95d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
5 changes: 4 additions & 1 deletion lib/config/routes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down
7 changes: 6 additions & 1 deletion lib/pages/chat/chat.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -69,6 +71,7 @@ class ChatPage extends StatelessWidget {
child: ChatPageWithRoom(
key: Key('chat_page_$roomId'),
room: room,
shareText: shareText,
),
),
if (FluffyThemes.isThreeColumnMode(context) &&
Expand All @@ -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
Expand Down Expand Up @@ -253,7 +258,7 @@ class ChatController extends State<ChatPageWithRoom>

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;
}
Expand Down
9 changes: 7 additions & 2 deletions lib/pages/chat_list/chat_list_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,15 @@ class ChatListItem extends StatelessWidget {
room: room,
),
);
Matrix.of(context).shareContent = null;
} else {
room.sendEvent(shareContent);
final text = shareContent.tryGet<String>('body');
Matrix.of(context).shareContent = null;
context.go(
'/rooms/${room.id}?body=$text',
);
return;
}
Matrix.of(context).shareContent = null;
}

context.go('/rooms/${room.id}');
Expand Down

0 comments on commit 9b5e95d

Please sign in to comment.