2021-10-26 18:50:34 +02:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
|
|
|
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
2021-06-18 10:29:48 +02:00
|
|
|
import 'package:matrix/matrix.dart';
|
2021-10-26 18:50:34 +02:00
|
|
|
|
2021-04-24 09:29:17 +02:00
|
|
|
import 'package:fluffychat/utils/fluffy_share.dart';
|
2023-01-07 10:29:34 +01:00
|
|
|
import 'package:fluffychat/widgets/avatar.dart';
|
2022-12-30 17:54:01 +01:00
|
|
|
import '../../utils/matrix_sdk_extensions/presence_extension.dart';
|
2021-09-22 15:03:57 +02:00
|
|
|
import '../../widgets/matrix.dart';
|
2021-11-09 21:32:16 +01:00
|
|
|
import 'user_bottom_sheet.dart';
|
2021-04-24 09:29:17 +02:00
|
|
|
|
2021-05-22 09:13:47 +02:00
|
|
|
class UserBottomSheetView extends StatelessWidget {
|
2021-04-24 09:29:17 +02:00
|
|
|
final UserBottomSheetController controller;
|
|
|
|
|
2022-01-29 12:35:03 +01:00
|
|
|
const UserBottomSheetView(this.controller, {Key? key}) : super(key: key);
|
2021-04-24 09:29:17 +02:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
final user = controller.widget.user;
|
2021-09-24 15:51:33 +02:00
|
|
|
final client = Matrix.of(context).client;
|
|
|
|
final presence = client.presences[user.id];
|
2023-01-07 10:29:34 +01:00
|
|
|
return SafeArea(
|
|
|
|
child: Scaffold(
|
|
|
|
appBar: AppBar(
|
|
|
|
leading: CloseButton(
|
|
|
|
onPressed: Navigator.of(context, rootNavigator: false).pop,
|
|
|
|
),
|
|
|
|
title: Text(user.calcDisplayname()),
|
|
|
|
actions: [
|
|
|
|
if (user.id != client.userID)
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.all(8.0),
|
|
|
|
child: OutlinedButton.icon(
|
|
|
|
onPressed: () => controller
|
|
|
|
.participantAction(UserBottomSheetAction.message),
|
2023-03-15 19:26:58 +01:00
|
|
|
icon: const Icon(Icons.forum_outlined),
|
|
|
|
label: Text(L10n.of(context)!.sendAMessage),
|
2021-04-24 09:29:17 +02:00
|
|
|
),
|
|
|
|
),
|
2023-01-07 10:29:34 +01:00
|
|
|
],
|
|
|
|
),
|
|
|
|
body: ListView(
|
|
|
|
children: [
|
|
|
|
Row(
|
|
|
|
children: [
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.all(16.0),
|
|
|
|
child: Avatar(
|
|
|
|
mxContent: user.avatarUrl,
|
|
|
|
name: user.calcDisplayname(),
|
|
|
|
size: Avatar.defaultSize * 2,
|
|
|
|
fontSize: 24,
|
2021-04-24 09:29:17 +02:00
|
|
|
),
|
2023-01-07 10:29:34 +01:00
|
|
|
),
|
|
|
|
Expanded(
|
|
|
|
child: ListTile(
|
|
|
|
contentPadding: const EdgeInsets.only(right: 16.0),
|
|
|
|
title: Text(user.id),
|
|
|
|
subtitle: presence == null
|
|
|
|
? null
|
|
|
|
: Text(presence.getLocalizedLastActiveAgo(context)),
|
|
|
|
trailing: IconButton(
|
|
|
|
icon: Icon(Icons.adaptive.share),
|
|
|
|
onPressed: () => FluffyShare.share(
|
|
|
|
user.id,
|
|
|
|
context,
|
|
|
|
),
|
2022-07-08 15:42:47 +02:00
|
|
|
),
|
2021-04-24 09:29:17 +02:00
|
|
|
),
|
2023-01-07 10:29:34 +01:00
|
|
|
),
|
|
|
|
],
|
2021-04-24 09:29:17 +02:00
|
|
|
),
|
2023-01-07 10:29:34 +01:00
|
|
|
if (controller.widget.onMention != null)
|
|
|
|
ListTile(
|
2023-03-15 19:26:58 +01:00
|
|
|
leading: const Icon(Icons.alternate_email_outlined),
|
2023-01-07 10:29:34 +01:00
|
|
|
title: Text(L10n.of(context)!.mention),
|
|
|
|
onTap: () =>
|
|
|
|
controller.participantAction(UserBottomSheetAction.mention),
|
|
|
|
),
|
|
|
|
if (user.canChangePowerLevel)
|
|
|
|
ListTile(
|
|
|
|
title: Text(L10n.of(context)!.setPermissionsLevel),
|
2023-03-15 19:26:58 +01:00
|
|
|
leading: const Icon(Icons.edit_attributes_outlined),
|
2023-01-07 10:29:34 +01:00
|
|
|
onTap: () => controller
|
|
|
|
.participantAction(UserBottomSheetAction.permission),
|
|
|
|
),
|
|
|
|
if (user.canKick)
|
|
|
|
ListTile(
|
|
|
|
title: Text(L10n.of(context)!.kickFromChat),
|
2023-03-15 19:26:58 +01:00
|
|
|
leading: const Icon(Icons.exit_to_app_outlined),
|
2023-01-07 10:29:34 +01:00
|
|
|
onTap: () =>
|
|
|
|
controller.participantAction(UserBottomSheetAction.kick),
|
|
|
|
),
|
|
|
|
if (user.canBan && user.membership != Membership.ban)
|
|
|
|
ListTile(
|
|
|
|
title: Text(L10n.of(context)!.banFromChat),
|
|
|
|
trailing: const Icon(Icons.warning_sharp),
|
|
|
|
onTap: () =>
|
|
|
|
controller.participantAction(UserBottomSheetAction.ban),
|
|
|
|
)
|
|
|
|
else if (user.canBan && user.membership == Membership.ban)
|
|
|
|
ListTile(
|
|
|
|
title: Text(L10n.of(context)!.unbanFromChat),
|
2023-03-15 19:26:58 +01:00
|
|
|
leading: const Icon(Icons.warning_outlined),
|
2023-01-07 10:29:34 +01:00
|
|
|
onTap: () =>
|
|
|
|
controller.participantAction(UserBottomSheetAction.unban),
|
|
|
|
),
|
|
|
|
if (user.id != client.userID &&
|
|
|
|
!client.ignoredUsers.contains(user.id))
|
|
|
|
ListTile(
|
|
|
|
textColor: Theme.of(context).colorScheme.onErrorContainer,
|
|
|
|
iconColor: Theme.of(context).colorScheme.onErrorContainer,
|
|
|
|
title: Text(L10n.of(context)!.ignore),
|
2023-03-15 19:26:58 +01:00
|
|
|
leading: const Icon(Icons.block),
|
2023-01-07 10:29:34 +01:00
|
|
|
onTap: () =>
|
|
|
|
controller.participantAction(UserBottomSheetAction.ignore),
|
|
|
|
),
|
|
|
|
if (user.id != client.userID)
|
|
|
|
ListTile(
|
|
|
|
textColor: Theme.of(context).colorScheme.error,
|
|
|
|
iconColor: Theme.of(context).colorScheme.error,
|
|
|
|
title: Text(L10n.of(context)!.reportUser),
|
2023-03-15 19:26:58 +01:00
|
|
|
leading: const Icon(Icons.shield_outlined),
|
2023-01-07 10:29:34 +01:00
|
|
|
onTap: () =>
|
|
|
|
controller.participantAction(UserBottomSheetAction.report),
|
|
|
|
),
|
|
|
|
],
|
2021-04-24 09:29:17 +02:00
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|