chore: Follow up user dialog

This commit is contained in:
Christian Kußowski 2026-02-25 08:25:34 +01:00
commit ad7a2d9a01
No known key found for this signature in database
GPG key ID: E067ECD60F1A0652

View file

@ -11,6 +11,7 @@ import 'package:fluffychat/config/themes.dart';
import 'package:fluffychat/l10n/l10n.dart'; import 'package:fluffychat/l10n/l10n.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/widgets/adaptive_dialogs/show_text_input_dialog.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';
import '../../utils/url_launcher.dart'; import '../../utils/url_launcher.dart';
@ -47,186 +48,238 @@ class UserDialog extends StatelessWidget {
final theme = Theme.of(context); final theme = Theme.of(context);
final avatar = profile.avatarUrl; final avatar = profile.avatarUrl;
return AlertDialog.adaptive( return AlertDialog.adaptive(
content: ConstrainedBox( content: PresenceBuilder(
constraints: const BoxConstraints(maxWidth: 256), userId: profile.userId,
child: PresenceBuilder( client: Matrix.of(context).client,
userId: profile.userId, builder: (context, presence) {
client: Matrix.of(context).client, if (presence == null) return const SizedBox.shrink();
builder: (context, presence) { final statusMsg = presence.statusMsg;
if (presence == null) return const SizedBox.shrink(); final lastActiveTimestamp = presence.lastActiveTimestamp;
final statusMsg = presence.statusMsg; final presenceText = presence.currentlyActive == true
final lastActiveTimestamp = presence.lastActiveTimestamp; ? L10n.of(context).currentlyActive
final presenceText = presence.currentlyActive == true : lastActiveTimestamp != null
? L10n.of(context).currentlyActive ? L10n.of(
: lastActiveTimestamp != null context,
? L10n.of(context).lastActiveAgo( ).lastActiveAgo(lastActiveTimestamp.localizedTimeShort(context))
lastActiveTimestamp.localizedTimeShort(context), : null;
) return Column(
: null; spacing: 16,
return Column( mainAxisSize: .min,
spacing: 16, crossAxisAlignment: .stretch,
mainAxisSize: .min, children: [
crossAxisAlignment: .stretch, Row(
children: [ spacing: 12,
Row( children: [
spacing: 12, Avatar(
children: [ mxContent: avatar,
Avatar( name: displayname,
mxContent: avatar, size: Avatar.defaultSize * 1.5,
name: displayname, onTap: avatar != null
size: Avatar.defaultSize * 1.5, ? () => showDialog(
onTap: avatar != null context: context,
? () => showDialog( builder: (_) => MxcImageViewer(avatar),
context: context, )
builder: (_) => MxcImageViewer(avatar), : null,
) ),
: null, Expanded(
), child: Column(
Expanded( crossAxisAlignment: .start,
child: Column( children: [
crossAxisAlignment: .start, Text(
children: [ displayname,
Text( maxLines: 1,
displayname, overflow: .ellipsis,
maxLines: 1, style: TextStyle(fontSize: 16),
overflow: .ellipsis, ),
style: TextStyle(fontSize: 16), const SizedBox(height: 8),
), HoverBuilder(
const SizedBox(height: 8), builder: (context, hovered) => StatefulBuilder(
HoverBuilder( builder: (context, setState) => MouseRegion(
builder: (context, hovered) => StatefulBuilder( cursor: SystemMouseCursors.click,
builder: (context, setState) => MouseRegion( child: GestureDetector(
cursor: SystemMouseCursors.click, onTap: () {
child: GestureDetector( Clipboard.setData(
onTap: () { ClipboardData(text: profile.userId),
Clipboard.setData( );
ClipboardData(text: profile.userId), setState(() {
); copied = true;
setState(() { });
copied = true; },
}); child: RichText(
}, text: TextSpan(
child: RichText( children: [
text: TextSpan( WidgetSpan(
children: [ child: Padding(
WidgetSpan( padding: const EdgeInsets.only(
child: Padding( right: 4.0,
padding: const EdgeInsets.only( ),
right: 4.0, child: AnimatedScale(
), duration:
child: AnimatedScale( FluffyThemes.animationDuration,
duration: FluffyThemes curve: FluffyThemes.animationCurve,
.animationDuration, scale: hovered
curve: ? 1.33
FluffyThemes.animationCurve, : copied
scale: hovered ? 1.25
? 1.33 : 1.0,
: copied child: Icon(
? 1.25 copied
: 1.0, ? Icons.check_circle
child: Icon( : Icons.copy,
copied size: 12,
? Icons.check_circle color: copied
: Icons.copy, ? Colors.green
size: 12, : null,
color: copied
? Colors.green
: null,
),
), ),
), ),
), ),
TextSpan(text: profile.userId), ),
], TextSpan(text: profile.userId),
style: theme.textTheme.bodyMedium ],
?.copyWith(fontSize: 10), style: theme.textTheme.bodyMedium?.copyWith(
fontSize: 10,
), ),
maxLines: 1,
overflow: .ellipsis,
textAlign: TextAlign.center,
), ),
maxLines: 1,
overflow: .ellipsis,
textAlign: TextAlign.center,
), ),
), ),
), ),
), ),
if (presenceText != null) ),
Text( if (presenceText != null)
presenceText, Text(
style: theme.textTheme.bodyMedium?.copyWith( presenceText,
fontSize: 10, style: theme.textTheme.bodyMedium?.copyWith(
), fontSize: 10,
), ),
], ),
), ],
), ),
],
),
if (statusMsg != null)
SelectableLinkify(
text: statusMsg,
textScaleFactor: MediaQuery.textScalerOf(context).scale(1),
textAlign: TextAlign.start,
options: const LinkifyOptions(humanize: false),
linkStyle: TextStyle(
color: theme.colorScheme.primary,
decoration: TextDecoration.underline,
decorationColor: theme.colorScheme.primary,
),
onOpen: (url) => UrlLauncher(context, url.url).launchUrl(),
), ),
Row( ],
mainAxisAlignment: .spaceBetween, ),
spacing: 4,
children: [ if (statusMsg != null)
_IconTextButton( SelectableLinkify(
label: L10n.of(context).chat, text: statusMsg,
icon: Icons.chat_outlined, textScaleFactor: MediaQuery.textScalerOf(context).scale(1),
onTap: () async { textAlign: TextAlign.start,
final router = GoRouter.of(context); options: const LinkifyOptions(humanize: false),
final roomIdResult = await showFutureLoadingDialog( linkStyle: TextStyle(
context: context, color: theme.colorScheme.primary,
future: () => client.startDirectChat(profile.userId), decoration: TextDecoration.underline,
); decorationColor: theme.colorScheme.primary,
final roomId = roomIdResult.result; ),
if (roomId == null) return; onOpen: (url) => UrlLauncher(context, url.url).launchUrl(),
if (context.mounted) Navigator.of(context).pop();
router.go('/rooms/$roomId');
},
),
_IconTextButton(
label: L10n.of(context).block,
icon: Icons.block_outlined,
onTap: () {
final router = GoRouter.of(context);
Navigator.of(context).pop();
router.go(
'/rooms/settings/security/ignorelist',
extra: profile.userId,
);
},
),
_IconTextButton(
label: L10n.of(context).share,
icon: Icons.adaptive.share,
onTap: () => FluffyShare.share(profile.userId, context),
),
],
), ),
], Row(
); mainAxisAlignment: .spaceBetween,
}, spacing: 4,
children: [
_AdaptiveIconTextButton(
label: L10n.of(context).block,
icon: Icons.block_outlined,
onTap: () {
final router = GoRouter.of(context);
Navigator.of(context).pop();
router.go(
'/rooms/settings/security/ignorelist',
extra: profile.userId,
);
},
),
_AdaptiveIconTextButton(
label: L10n.of(context).report,
icon: Icons.gavel_outlined,
onTap: () async {
Navigator.of(context).pop();
final reason = await showTextInputDialog(
context: context,
title: L10n.of(context).whyDoYouWantToReportThis,
okLabel: L10n.of(context).report,
cancelLabel: L10n.of(context).cancel,
hintText: L10n.of(context).reason,
);
if (reason == null || reason.isEmpty) return;
await showFutureLoadingDialog(
context: context,
future: () => Matrix.of(
context,
).client.reportUser(profile.userId, reason),
);
},
),
_AdaptiveIconTextButton(
label: L10n.of(context).share,
icon: Icons.adaptive.share,
onTap: () => FluffyShare.share(profile.userId, context),
),
],
),
_AdaptiveDialogInkWell(
onTap: () async {
final router = GoRouter.of(context);
final roomIdResult = await showFutureLoadingDialog(
context: context,
future: () => client.startDirectChat(profile.userId),
);
final roomId = roomIdResult.result;
if (roomId == null) return;
if (context.mounted) Navigator.of(context).pop();
router.go('/rooms/$roomId');
},
child: Text(
L10n.of(context).sendAMessage,
style: TextStyle(color: theme.colorScheme.secondary),
),
),
],
);
},
),
);
}
}
class _AdaptiveDialogInkWell extends StatelessWidget {
final Widget child;
final VoidCallback onTap;
const _AdaptiveDialogInkWell({required this.onTap, required this.child});
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
if ({TargetPlatform.iOS, TargetPlatform.macOS}.contains(theme.platform)) {
return CupertinoButton(
onPressed: onTap,
borderRadius: BorderRadius.circular(AppConfig.borderRadius / 2),
color: theme.colorScheme.surfaceBright,
padding: EdgeInsets.all(8),
child: child,
);
}
return Material(
color: theme.colorScheme.surfaceBright,
borderRadius: BorderRadius.circular(AppConfig.borderRadius / 2),
child: InkWell(
borderRadius: BorderRadius.circular(AppConfig.borderRadius / 2),
onTap: onTap,
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Center(child: child),
), ),
), ),
); );
} }
} }
class _IconTextButton extends StatelessWidget { class _AdaptiveIconTextButton extends StatelessWidget {
final String label; final String label;
final IconData icon; final IconData icon;
final VoidCallback onTap; final VoidCallback onTap;
const _IconTextButton({ const _AdaptiveIconTextButton({
required this.label, required this.label,
required this.icon, required this.icon,
required this.onTap, required this.onTap,
@ -234,20 +287,17 @@ class _IconTextButton extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final theme = Theme.of(context); final color = Theme.of(context).colorScheme.secondary;
return Expanded( return Expanded(
child: CupertinoButton( child: _AdaptiveDialogInkWell(
onPressed: onTap, onTap: onTap,
borderRadius: BorderRadius.circular(AppConfig.borderRadius / 2),
color: theme.colorScheme.surfaceBright,
padding: EdgeInsets.all(8),
child: Column( child: Column(
mainAxisSize: .min, mainAxisSize: .min,
children: [ children: [
Icon(icon), Icon(icon, color: color),
Text( Text(
label, label,
style: TextStyle(fontSize: 12), style: TextStyle(fontSize: 12, color: color),
maxLines: 1, maxLines: 1,
overflow: .ellipsis, overflow: .ellipsis,
), ),