chore: Improve UserBottomSheet UX

pull/1517/head
Krille 8 months ago
parent b186021f38
commit e2ad11970f
No known key found for this signature in database
GPG Key ID: E067ECD60F1A0652

@ -226,45 +226,10 @@ class UserBottomSheetController extends State<UserBottomSheet> {
} }
} }
bool isSending = false;
Object? sendError; Object? sendError;
final TextEditingController sendController = TextEditingController(); 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 { void knockAccept() async {
final user = widget.user!; final user = widget.user!;
final result = await showFutureLoadingDialog( final result = await showFutureLoadingDialog(

@ -7,7 +7,6 @@ import 'package:matrix/matrix.dart';
import 'package:fluffychat/config/app_config.dart'; import 'package:fluffychat/config/app_config.dart';
import 'package:fluffychat/utils/date_time_extension.dart'; import 'package:fluffychat/utils/date_time_extension.dart';
import 'package:fluffychat/utils/fluffy_share.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/utils/url_launcher.dart';
import 'package:fluffychat/widgets/avatar.dart'; import 'package:fluffychat/widgets/avatar.dart';
import 'package:fluffychat/widgets/presence_builder.dart'; import 'package:fluffychat/widgets/presence_builder.dart';
@ -34,24 +33,25 @@ class UserBottomSheetView extends StatelessWidget {
return SafeArea( return SafeArea(
child: Scaffold( child: Scaffold(
appBar: AppBar( appBar: AppBar(
leading: CloseButton( leading: Center(
onPressed: Navigator.of(context, rootNavigator: false).pop, child: CloseButton(
onPressed: Navigator.of(context, rootNavigator: false).pop,
),
), ),
centerTitle: false, centerTitle: false,
title: Text(displayname), title: Text(displayname),
actions: dmRoomId == null actions: [
? null Padding(
: [ padding: const EdgeInsets.symmetric(horizontal: 8),
Padding( child: IconButton(
padding: const EdgeInsets.symmetric(horizontal: 8), onPressed: () => FluffyShare.share(
child: FloatingActionButton.small( 'https://matrix.to/#/$userId',
elevation: 0, context,
onPressed: () => controller ),
.participantAction(UserBottomSheetAction.message), icon: Icon(Icons.adaptive.share_outlined),
child: const Icon(Icons.chat_outlined), ),
), ),
), ],
],
), ),
body: StreamBuilder<Object>( body: StreamBuilder<Object>(
stream: user?.room.client.onSync.stream.where( stream: user?.room.client.onSync.stream.where(
@ -230,42 +230,17 @@ class UserBottomSheetView extends StatelessWidget {
horizontal: 16.0, horizontal: 16.0,
vertical: 8.0, vertical: 8.0,
), ),
child: dmRoomId == null child: ElevatedButton.icon(
? ElevatedButton.icon( onPressed: () => controller.participantAction(
onPressed: () => controller.participantAction( UserBottomSheetAction.message,
UserBottomSheetAction.message, ),
), icon: const Icon(Icons.forum_outlined),
icon: const Icon(Icons.chat_outlined), label: Text(
label: Text(L10n.of(context).startConversation), dmRoomId == null
) ? L10n.of(context).startConversation
: TextField( : L10n.of(context).sendAMessage,
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,
),
),
),
), ),
if (controller.widget.onMention != null) if (controller.widget.onMention != null)
ListTile( ListTile(
@ -300,22 +275,29 @@ class UserBottomSheetView extends StatelessWidget {
items: [ items: [
DropdownMenuItem( DropdownMenuItem(
value: 0, value: 0,
child: Text(L10n.of(context).userLevel( child: Text(
user.powerLevel < 50 ? user.powerLevel : 0)), L10n.of(context).userLevel(
user.powerLevel < 50 ? user.powerLevel : 0,
),
),
), ),
DropdownMenuItem( DropdownMenuItem(
value: 50, value: 50,
child: Text(L10n.of(context).moderatorLevel( child: Text(
L10n.of(context).moderatorLevel(
user.powerLevel >= 50 && user.powerLevel < 100 user.powerLevel >= 50 && user.powerLevel < 100
? user.powerLevel ? user.powerLevel
: 50)), : 50,
),
),
), ),
DropdownMenuItem( DropdownMenuItem(
value: 100, value: 100,
child: Text(L10n.of(context).adminLevel( child: Text(
user.powerLevel >= 100 L10n.of(context).adminLevel(
? user.powerLevel user.powerLevel >= 100 ? user.powerLevel : 100,
: 100)), ),
),
), ),
DropdownMenuItem( DropdownMenuItem(
value: null, value: null,

Loading…
Cancel
Save