2021-04-24 09:29:17 +02:00
|
|
|
import 'dart:math';
|
|
|
|
|
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/config/themes.dart';
|
|
|
|
import 'package:fluffychat/utils/fluffy_share.dart';
|
2021-10-26 18:50:34 +02:00
|
|
|
import '../../utils/matrix_sdk_extensions.dart/presence_extension.dart';
|
2021-05-22 08:53:52 +02:00
|
|
|
import '../../widgets/content_banner.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];
|
2021-04-24 09:29:17 +02:00
|
|
|
return Center(
|
2021-10-14 18:09:30 +02:00
|
|
|
child: SizedBox(
|
2021-04-24 09:29:17 +02:00
|
|
|
width: min(
|
|
|
|
MediaQuery.of(context).size.width, FluffyThemes.columnWidth * 1.5),
|
|
|
|
child: Material(
|
|
|
|
elevation: 4,
|
|
|
|
child: SafeArea(
|
|
|
|
child: Scaffold(
|
|
|
|
extendBodyBehindAppBar: true,
|
|
|
|
appBar: AppBar(
|
|
|
|
elevation: 0,
|
|
|
|
backgroundColor:
|
|
|
|
Theme.of(context).scaffoldBackgroundColor.withOpacity(0.5),
|
|
|
|
leading: IconButton(
|
2021-10-14 18:09:30 +02:00
|
|
|
icon: const Icon(Icons.arrow_downward_outlined),
|
2021-04-24 09:29:17 +02:00
|
|
|
onPressed: Navigator.of(context, rootNavigator: false).pop,
|
2022-01-29 12:35:03 +01:00
|
|
|
tooltip: L10n.of(context)!.close,
|
2021-04-24 09:29:17 +02:00
|
|
|
),
|
2021-09-24 15:51:33 +02:00
|
|
|
title: Text(user.calcDisplayname()),
|
2021-04-24 09:29:17 +02:00
|
|
|
actions: [
|
2021-09-24 15:51:33 +02:00
|
|
|
if (user.id != client.userID)
|
2021-04-24 09:29:17 +02:00
|
|
|
PopupMenuButton(
|
|
|
|
itemBuilder: (_) => [
|
2021-09-24 15:51:33 +02:00
|
|
|
if (controller.widget.onMention != null)
|
2021-04-24 09:29:17 +02:00
|
|
|
PopupMenuItem(
|
|
|
|
value: 'mention',
|
|
|
|
child: _TextWithIcon(
|
2022-01-29 12:35:03 +01:00
|
|
|
L10n.of(context)!.mention,
|
2021-04-24 09:29:17 +02:00
|
|
|
Icons.alternate_email_outlined,
|
|
|
|
),
|
|
|
|
),
|
2021-09-24 15:51:33 +02:00
|
|
|
if (user.id != client.userID && !user.room.isDirectChat)
|
2021-04-24 09:29:17 +02:00
|
|
|
PopupMenuItem(
|
|
|
|
value: 'message',
|
|
|
|
child: _TextWithIcon(
|
2022-01-29 12:35:03 +01:00
|
|
|
L10n.of(context)!.sendAMessage,
|
2021-04-24 09:29:17 +02:00
|
|
|
Icons.send_outlined,
|
|
|
|
),
|
|
|
|
),
|
2021-09-24 15:51:33 +02:00
|
|
|
if (user.canChangePowerLevel)
|
2021-04-24 09:29:17 +02:00
|
|
|
PopupMenuItem(
|
|
|
|
value: 'permission',
|
|
|
|
child: _TextWithIcon(
|
2022-01-29 12:35:03 +01:00
|
|
|
L10n.of(context)!.setPermissionsLevel,
|
2021-04-24 09:29:17 +02:00
|
|
|
Icons.edit_attributes_outlined,
|
|
|
|
),
|
|
|
|
),
|
2021-09-24 15:51:33 +02:00
|
|
|
if (user.canKick)
|
2021-04-24 09:29:17 +02:00
|
|
|
PopupMenuItem(
|
|
|
|
value: 'kick',
|
|
|
|
child: _TextWithIcon(
|
2022-01-29 12:35:03 +01:00
|
|
|
L10n.of(context)!.kickFromChat,
|
2021-04-24 09:29:17 +02:00
|
|
|
Icons.exit_to_app_outlined,
|
|
|
|
),
|
|
|
|
),
|
2021-09-24 15:51:33 +02:00
|
|
|
if (user.canBan && user.membership != Membership.ban)
|
2021-04-24 09:29:17 +02:00
|
|
|
PopupMenuItem(
|
|
|
|
value: 'ban',
|
|
|
|
child: _TextWithIcon(
|
2022-01-29 12:35:03 +01:00
|
|
|
L10n.of(context)!.banFromChat,
|
2021-04-24 09:29:17 +02:00
|
|
|
Icons.warning_sharp,
|
|
|
|
),
|
|
|
|
)
|
2021-09-24 15:51:33 +02:00
|
|
|
else if (user.canBan &&
|
2021-04-24 09:29:17 +02:00
|
|
|
user.membership == Membership.ban)
|
|
|
|
PopupMenuItem(
|
|
|
|
value: 'unban',
|
|
|
|
child: _TextWithIcon(
|
2022-01-29 12:35:03 +01:00
|
|
|
L10n.of(context)!.unbanFromChat,
|
2021-04-24 09:29:17 +02:00
|
|
|
Icons.warning_outlined,
|
|
|
|
),
|
|
|
|
),
|
2021-10-16 05:28:45 +02:00
|
|
|
if (!client.ignoredUsers.contains(user.id))
|
|
|
|
PopupMenuItem(
|
|
|
|
value: 'ignore',
|
|
|
|
child: _TextWithIcon(
|
2022-01-29 12:35:03 +01:00
|
|
|
L10n.of(context)!.ignore,
|
2021-10-16 05:28:45 +02:00
|
|
|
Icons.block,
|
|
|
|
),
|
|
|
|
),
|
2022-02-03 06:53:14 +01:00
|
|
|
PopupMenuItem(
|
|
|
|
value: 'report',
|
|
|
|
child: _TextWithIcon(
|
|
|
|
L10n.of(context)!.reportUser,
|
|
|
|
Icons.shield_outlined,
|
|
|
|
),
|
|
|
|
),
|
2021-04-24 09:29:17 +02:00
|
|
|
],
|
|
|
|
onSelected: controller.participantAction,
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
body: Column(
|
|
|
|
children: [
|
|
|
|
Expanded(
|
|
|
|
child: ContentBanner(
|
2022-01-29 12:35:03 +01:00
|
|
|
mxContent: user.avatarUrl,
|
2021-04-24 09:29:17 +02:00
|
|
|
defaultIcon: Icons.person_outline,
|
2021-09-22 15:03:57 +02:00
|
|
|
client: client,
|
2021-04-24 09:29:17 +02:00
|
|
|
),
|
|
|
|
),
|
|
|
|
ListTile(
|
2022-01-29 12:35:03 +01:00
|
|
|
title: Text(L10n.of(context)!.username),
|
2021-09-24 15:51:33 +02:00
|
|
|
subtitle: Text(user.id),
|
2021-12-23 13:34:04 +01:00
|
|
|
trailing: Icon(Icons.adaptive.share_outlined),
|
2021-09-24 15:51:33 +02:00
|
|
|
onTap: () => FluffyShare.share(
|
|
|
|
user.id, controller.widget.outerContext),
|
2021-04-24 09:29:17 +02:00
|
|
|
),
|
|
|
|
if (presence != null)
|
|
|
|
ListTile(
|
|
|
|
title: Text(presence.getLocalizedStatusMessage(context)),
|
|
|
|
subtitle:
|
|
|
|
Text(presence.getLocalizedLastActiveAgo(context)),
|
|
|
|
trailing: Icon(Icons.circle,
|
|
|
|
color: presence.presence.currentlyActive ?? false
|
|
|
|
? Colors.green
|
|
|
|
: Colors.grey),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class _TextWithIcon extends StatelessWidget {
|
|
|
|
final String text;
|
|
|
|
final IconData iconData;
|
|
|
|
|
|
|
|
const _TextWithIcon(
|
|
|
|
this.text,
|
|
|
|
this.iconData, {
|
2022-01-29 12:35:03 +01:00
|
|
|
Key? key,
|
2021-04-24 09:29:17 +02:00
|
|
|
}) : super(key: key);
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Row(
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
children: [
|
|
|
|
Icon(iconData),
|
2021-10-14 18:09:30 +02:00
|
|
|
const SizedBox(width: 16),
|
2021-04-24 09:29:17 +02:00
|
|
|
Text(text),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|