diff --git a/lib/pages/user_bottom_sheet/user_bottom_sheet.dart b/lib/pages/user_bottom_sheet/user_bottom_sheet.dart index 737bb96df..c2f47d433 100644 --- a/lib/pages/user_bottom_sheet/user_bottom_sheet.dart +++ b/lib/pages/user_bottom_sheet/user_bottom_sheet.dart @@ -226,45 +226,10 @@ class UserBottomSheetController extends State { } } - bool isSending = false; - Object? sendError; final TextEditingController sendController = TextEditingController(); - void sendAction([_]) async { - final userId = widget.user?.id ?? widget.profile?.userId; - final client = Matrix.of(widget.outerContext).client; - if (userId == null) throw ('user or profile must not be null!'); - - final input = sendController.text.trim(); - if (input.isEmpty) return; - - setState(() { - isSending = true; - sendError = null; - }); - try { - final roomId = await client.startDirectChat(userId); - if (!mounted) return; - final room = client.getRoomById(roomId); - if (room == null) { - throw ('DM Room found or created but room not found in client'); - } - await room.sendTextEvent(input); - setState(() { - isSending = false; - sendController.clear(); - }); - } catch (e, s) { - Logs().d('Unable to send message', e, s); - setState(() { - isSending = false; - sendError = e; - }); - } - } - void knockAccept() async { final user = widget.user!; final result = await showFutureLoadingDialog( diff --git a/lib/pages/user_bottom_sheet/user_bottom_sheet_view.dart b/lib/pages/user_bottom_sheet/user_bottom_sheet_view.dart index e82a74c1c..6a5c09bae 100644 --- a/lib/pages/user_bottom_sheet/user_bottom_sheet_view.dart +++ b/lib/pages/user_bottom_sheet/user_bottom_sheet_view.dart @@ -7,7 +7,6 @@ import 'package:matrix/matrix.dart'; import 'package:fluffychat/config/app_config.dart'; import 'package:fluffychat/utils/date_time_extension.dart'; import 'package:fluffychat/utils/fluffy_share.dart'; -import 'package:fluffychat/utils/localized_exception_extension.dart'; import 'package:fluffychat/utils/url_launcher.dart'; import 'package:fluffychat/widgets/avatar.dart'; import 'package:fluffychat/widgets/presence_builder.dart'; @@ -34,24 +33,25 @@ class UserBottomSheetView extends StatelessWidget { return SafeArea( child: Scaffold( appBar: AppBar( - leading: CloseButton( - onPressed: Navigator.of(context, rootNavigator: false).pop, + leading: Center( + child: CloseButton( + onPressed: Navigator.of(context, rootNavigator: false).pop, + ), ), centerTitle: false, title: Text(displayname), - actions: dmRoomId == null - ? null - : [ - Padding( - padding: const EdgeInsets.symmetric(horizontal: 8), - child: FloatingActionButton.small( - elevation: 0, - onPressed: () => controller - .participantAction(UserBottomSheetAction.message), - child: const Icon(Icons.chat_outlined), - ), - ), - ], + actions: [ + Padding( + padding: const EdgeInsets.symmetric(horizontal: 8), + child: IconButton( + onPressed: () => FluffyShare.share( + 'https://matrix.to/#/$userId', + context, + ), + icon: Icon(Icons.adaptive.share_outlined), + ), + ), + ], ), body: StreamBuilder( stream: user?.room.client.onSync.stream.where( @@ -230,42 +230,17 @@ class UserBottomSheetView extends StatelessWidget { horizontal: 16.0, vertical: 8.0, ), - child: dmRoomId == null - ? ElevatedButton.icon( - onPressed: () => controller.participantAction( - UserBottomSheetAction.message, - ), - icon: const Icon(Icons.chat_outlined), - label: Text(L10n.of(context).startConversation), - ) - : TextField( - controller: controller.sendController, - readOnly: controller.isSending, - onSubmitted: controller.sendAction, - minLines: 1, - maxLines: 1, - textInputAction: TextInputAction.send, - decoration: InputDecoration( - errorText: controller.sendError - ?.toLocalizedString(context), - hintText: L10n.of(context).sendMessages, - suffix: controller.isSending - ? const SizedBox( - width: 16, - height: 16, - child: CircularProgressIndicator.adaptive( - strokeWidth: 2, - ), - ) - : null, - suffixIcon: controller.isSending - ? null - : IconButton( - icon: const Icon(Icons.send_outlined), - onPressed: controller.sendAction, - ), - ), - ), + child: ElevatedButton.icon( + onPressed: () => controller.participantAction( + UserBottomSheetAction.message, + ), + icon: const Icon(Icons.forum_outlined), + label: Text( + dmRoomId == null + ? L10n.of(context).startConversation + : L10n.of(context).sendAMessage, + ), + ), ), if (controller.widget.onMention != null) ListTile( @@ -300,22 +275,29 @@ class UserBottomSheetView extends StatelessWidget { items: [ DropdownMenuItem( value: 0, - child: Text(L10n.of(context).userLevel( - user.powerLevel < 50 ? user.powerLevel : 0)), + child: Text( + L10n.of(context).userLevel( + user.powerLevel < 50 ? user.powerLevel : 0, + ), + ), ), DropdownMenuItem( value: 50, - child: Text(L10n.of(context).moderatorLevel( + child: Text( + L10n.of(context).moderatorLevel( user.powerLevel >= 50 && user.powerLevel < 100 ? user.powerLevel - : 50)), + : 50, + ), + ), ), DropdownMenuItem( value: 100, - child: Text(L10n.of(context).adminLevel( - user.powerLevel >= 100 - ? user.powerLevel - : 100)), + child: Text( + L10n.of(context).adminLevel( + user.powerLevel >= 100 ? user.powerLevel : 100, + ), + ), ), DropdownMenuItem( value: null,