fluffychat/lib/pages/chat_details/chat_details_view.dart

394 lines
21 KiB
Dart
Raw Normal View History

2021-10-26 18:50:34 +02:00
import 'package:flutter/material.dart';
2021-10-26 18:50:34 +02:00
import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:matrix/matrix.dart';
2021-10-26 18:50:34 +02:00
import 'package:matrix_link_text/link_text.dart';
import 'package:vrouter/vrouter.dart';
2021-10-26 18:50:34 +02:00
import 'package:fluffychat/config/app_config.dart';
2021-11-09 21:32:16 +01:00
import 'package:fluffychat/pages/chat_details/chat_details.dart';
import 'package:fluffychat/pages/chat_details/participant_list_item.dart';
2021-10-26 18:50:34 +02:00
import 'package:fluffychat/utils/fluffy_share.dart';
import 'package:fluffychat/utils/matrix_sdk_extensions.dart/matrix_locals.dart';
import 'package:fluffychat/widgets/avatar.dart';
2021-05-22 08:53:52 +02:00
import 'package:fluffychat/widgets/chat_settings_popup_menu.dart';
import 'package:fluffychat/widgets/content_banner.dart';
import 'package:fluffychat/widgets/layouts/max_width_body.dart';
2021-10-26 18:50:34 +02:00
import 'package:fluffychat/widgets/matrix.dart';
import '../../utils/url_launcher.dart';
2021-05-22 09:13:47 +02:00
class ChatDetailsView extends StatelessWidget {
final ChatDetailsController controller;
2022-01-29 12:35:03 +01:00
const ChatDetailsView(this.controller, {Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
2022-01-29 12:35:03 +01:00
final room = Matrix.of(context).client.getRoomById(controller.roomId!);
if (room == null) {
return Scaffold(
appBar: AppBar(
2022-01-29 12:35:03 +01:00
title: Text(L10n.of(context)!.oopsSomethingWentWrong),
),
body: Center(
2022-01-29 12:35:03 +01:00
child: Text(L10n.of(context)!.youAreNoLongerParticipatingInThisChat),
),
);
}
2022-01-29 12:35:03 +01:00
controller.members!.removeWhere((u) => u.membership == Membership.leave);
final actualMembersCount = (room.summary.mInvitedMemberCount ?? 0) +
(room.summary.mJoinedMemberCount ?? 0);
final canRequestMoreMembers =
2022-01-29 12:35:03 +01:00
controller.members!.length < actualMembersCount;
final iconColor = Theme.of(context).textTheme.bodyText1!.color;
return StreamBuilder(
stream: room.onUpdate.stream,
builder: (context, snapshot) {
return Scaffold(
body: NestedScrollView(
headerSliverBuilder:
(BuildContext context, bool innerBoxIsScrolled) => <Widget>[
SliverAppBar(
2021-05-23 13:11:55 +02:00
leading: IconButton(
2021-10-14 18:09:30 +02:00
icon: const Icon(Icons.close_outlined),
2021-08-15 13:26:16 +02:00
onPressed: () =>
VRouter.of(context).path.startsWith('/spaces/')
? VRouter.of(context).pop()
: VRouter.of(context)
2022-01-29 12:35:03 +01:00
.toSegments(['rooms', controller.roomId!]),
2021-05-23 13:11:55 +02:00
),
elevation: Theme.of(context).appBarTheme.elevation,
expandedHeight: 300.0,
floating: true,
pinned: true,
actions: <Widget>[
2022-01-29 12:35:03 +01:00
if (room.canonicalAlias.isNotEmpty)
IconButton(
2022-01-29 12:35:03 +01:00
tooltip: L10n.of(context)!.share,
icon: Icon(Icons.adaptive.share_outlined),
onPressed: () => FluffyShare.share(
AppConfig.inviteLinkPrefix + room.canonicalAlias,
context),
),
ChatSettingsPopupMenu(room, false)
],
title: Text(
2022-05-18 08:54:50 +02:00
room.getLocalizedDisplayname(
MatrixLocals(L10n.of(context)!)),
),
2021-09-13 17:41:53 +02:00
backgroundColor:
Theme.of(context).appBarTheme.backgroundColor,
flexibleSpace: FlexibleSpaceBar(
2022-01-29 12:35:03 +01:00
background: ContentBanner(
mxContent: room.avatar,
onEdit: room.canSendEvent('m.room.avatar')
? controller.setAvatarAction
: null),
),
),
],
body: MaxWidthBody(
child: ListView.builder(
2022-01-29 12:35:03 +01:00
itemCount: controller.members!.length +
1 +
(canRequestMoreMembers ? 1 : 0),
itemBuilder: (BuildContext context, int i) => i == 0
? Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
ListTile(
leading: room.canSendEvent('m.room.topic')
? CircleAvatar(
backgroundColor: Theme.of(context)
.scaffoldBackgroundColor,
2021-11-14 13:24:01 +01:00
foregroundColor: iconColor,
radius: Avatar.defaultSize / 2,
2021-11-14 13:24:01 +01:00
child: const Icon(Icons.edit_outlined),
)
: null,
title: Text(
2022-01-29 12:35:03 +01:00
'${L10n.of(context)!.groupDescription}:',
style: TextStyle(
2021-05-24 10:59:00 +02:00
color: Theme.of(context)
.colorScheme
.secondary,
fontWeight: FontWeight.bold)),
subtitle: LinkText(
2022-01-29 12:35:03 +01:00
text: room.topic.isEmpty
? L10n.of(context)!.addGroupDescription
: room.topic,
2021-10-17 14:15:29 +02:00
linkStyle:
const TextStyle(color: Colors.blueAccent),
textStyle: TextStyle(
fontSize: 14,
color: Theme.of(context)
.textTheme
2022-01-29 12:35:03 +01:00
.bodyText2!
.color,
),
onLinkTap: (url) =>
UrlLauncher(context, url).launchUrl(),
),
onTap: room.canSendEvent('m.room.topic')
? controller.setTopicAction
: null,
),
2021-11-13 21:42:35 +01:00
const SizedBox(height: 8),
const Divider(height: 1),
ListTile(
title: Text(
2022-01-29 12:35:03 +01:00
L10n.of(context)!.settings,
style: TextStyle(
2021-05-24 10:59:00 +02:00
color:
Theme.of(context).colorScheme.secondary,
fontWeight: FontWeight.bold,
),
),
2021-11-13 21:42:35 +01:00
trailing: Icon(controller.displaySettings
2021-11-14 13:24:01 +01:00
? Icons.keyboard_arrow_down_outlined
: Icons.keyboard_arrow_right_outlined),
2021-11-13 21:42:35 +01:00
onTap: controller.toggleDisplaySettings,
),
2021-11-13 21:42:35 +01:00
if (controller.displaySettings) ...[
if (room.canSendEvent('m.room.name'))
ListTile(
leading: CircleAvatar(
backgroundColor: Theme.of(context)
.scaffoldBackgroundColor,
2021-11-14 13:24:01 +01:00
foregroundColor: iconColor,
child: const Icon(
Icons.people_outline_outlined),
),
2022-01-29 12:35:03 +01:00
title: Text(L10n.of(context)!
.changeTheNameOfTheGroup),
2021-11-13 21:42:35 +01:00
subtitle: Text(room.getLocalizedDisplayname(
2022-01-29 12:35:03 +01:00
MatrixLocals(L10n.of(context)!))),
2021-11-13 21:42:35 +01:00
onTap: controller.setDisplaynameAction,
),
if (room.joinRules == JoinRules.public)
ListTile(
leading: CircleAvatar(
backgroundColor: Theme.of(context)
.scaffoldBackgroundColor,
2021-11-14 13:24:01 +01:00
foregroundColor: iconColor,
child: const Icon(Icons.link_outlined),
),
2021-11-13 21:42:35 +01:00
onTap: controller.editAliases,
2022-01-29 12:35:03 +01:00
title:
Text(L10n.of(context)!.editRoomAliases),
2021-11-13 21:42:35 +01:00
subtitle: Text(
2022-01-29 12:35:03 +01:00
(room.canonicalAlias.isNotEmpty)
2021-11-13 21:42:35 +01:00
? room.canonicalAlias
2022-01-29 12:35:03 +01:00
: L10n.of(context)!.none),
2021-11-13 21:42:35 +01:00
),
ListTile(
leading: CircleAvatar(
backgroundColor:
Theme.of(context).scaffoldBackgroundColor,
2021-11-14 13:24:01 +01:00
foregroundColor: iconColor,
2021-11-13 21:42:35 +01:00
child: const Icon(
Icons.insert_emoticon_outlined),
),
2022-01-29 12:35:03 +01:00
title: Text(L10n.of(context)!.emoteSettings),
2021-11-13 21:42:35 +01:00
subtitle:
2022-01-29 12:35:03 +01:00
Text(L10n.of(context)!.setCustomEmotes),
2021-11-13 21:42:35 +01:00
onTap: controller.goToEmoteSettings,
),
PopupMenuButton(
onSelected: controller.setJoinRulesAction,
itemBuilder: (BuildContext context) =>
<PopupMenuEntry<JoinRules>>[
if (room.canChangeJoinRules)
PopupMenuItem<JoinRules>(
value: JoinRules.public,
child: Text(JoinRules.public
.getLocalizedString(
2022-01-29 12:35:03 +01:00
MatrixLocals(L10n.of(context)!))),
2021-11-13 21:42:35 +01:00
),
if (room.canChangeJoinRules)
PopupMenuItem<JoinRules>(
value: JoinRules.invite,
child: Text(JoinRules.invite
.getLocalizedString(
2022-01-29 12:35:03 +01:00
MatrixLocals(L10n.of(context)!))),
2021-11-13 21:42:35 +01:00
),
],
child: ListTile(
leading: CircleAvatar(
backgroundColor: Theme.of(context)
.scaffoldBackgroundColor,
2021-11-14 13:24:01 +01:00
foregroundColor: iconColor,
child: const Icon(Icons.shield_outlined)),
2022-01-29 12:35:03 +01:00
title: Text(L10n.of(context)!
2021-11-13 21:42:35 +01:00
.whoIsAllowedToJoinThisGroup),
subtitle: Text(
2022-01-29 12:35:03 +01:00
room.joinRules!.getLocalizedString(
MatrixLocals(L10n.of(context)!)),
2021-11-13 21:42:35 +01:00
),
),
),
PopupMenuButton(
2021-11-13 21:42:35 +01:00
onSelected:
controller.setHistoryVisibilityAction,
itemBuilder: (BuildContext context) =>
2021-11-13 21:42:35 +01:00
<PopupMenuEntry<HistoryVisibility>>[
if (room.canChangeHistoryVisibility)
PopupMenuItem<HistoryVisibility>(
value: HistoryVisibility.invited,
child: Text(HistoryVisibility.invited
.getLocalizedString(
2022-01-29 12:35:03 +01:00
MatrixLocals(L10n.of(context)!))),
),
2021-11-13 21:42:35 +01:00
if (room.canChangeHistoryVisibility)
PopupMenuItem<HistoryVisibility>(
value: HistoryVisibility.joined,
child: Text(HistoryVisibility.joined
.getLocalizedString(
2022-01-29 12:35:03 +01:00
MatrixLocals(L10n.of(context)!))),
2021-11-13 21:42:35 +01:00
),
if (room.canChangeHistoryVisibility)
PopupMenuItem<HistoryVisibility>(
value: HistoryVisibility.shared,
child: Text(HistoryVisibility.shared
.getLocalizedString(
2022-01-29 12:35:03 +01:00
MatrixLocals(L10n.of(context)!))),
2021-11-13 21:42:35 +01:00
),
if (room.canChangeHistoryVisibility)
PopupMenuItem<HistoryVisibility>(
value: HistoryVisibility.worldReadable,
child: Text(HistoryVisibility
.worldReadable
.getLocalizedString(
2022-01-29 12:35:03 +01:00
MatrixLocals(L10n.of(context)!))),
),
],
child: ListTile(
leading: CircleAvatar(
backgroundColor: Theme.of(context)
.scaffoldBackgroundColor,
2021-11-14 13:24:01 +01:00
foregroundColor: iconColor,
child:
const Icon(Icons.visibility_outlined),
),
2022-01-29 12:35:03 +01:00
title: Text(L10n.of(context)!
2021-11-13 21:42:35 +01:00
.visibilityOfTheChatHistory),
subtitle: Text(
2022-01-29 12:35:03 +01:00
room.historyVisibility!.getLocalizedString(
MatrixLocals(L10n.of(context)!)),
),
),
),
2021-11-13 21:42:35 +01:00
if (room.joinRules == JoinRules.public)
PopupMenuButton(
onSelected: controller.setGuestAccessAction,
itemBuilder: (BuildContext context) =>
<PopupMenuEntry<GuestAccess>>[
if (room.canChangeGuestAccess)
PopupMenuItem<GuestAccess>(
value: GuestAccess.canJoin,
child: Text(
GuestAccess.canJoin
.getLocalizedString(MatrixLocals(
2022-01-29 12:35:03 +01:00
L10n.of(context)!)),
2021-11-13 21:42:35 +01:00
),
),
if (room.canChangeGuestAccess)
PopupMenuItem<GuestAccess>(
value: GuestAccess.forbidden,
child: Text(
GuestAccess.forbidden
.getLocalizedString(MatrixLocals(
2022-01-29 12:35:03 +01:00
L10n.of(context)!)),
2021-11-13 21:42:35 +01:00
),
),
],
child: ListTile(
leading: CircleAvatar(
backgroundColor: Theme.of(context)
.scaffoldBackgroundColor,
2021-11-14 13:24:01 +01:00
foregroundColor: iconColor,
child: const Icon(
Icons.person_add_alt_1_outlined),
2021-11-13 21:42:35 +01:00
),
2022-01-29 12:35:03 +01:00
title: Text(L10n.of(context)!
2021-11-13 21:42:35 +01:00
.areGuestsAllowedToJoin),
subtitle: Text(
room.guestAccess.getLocalizedString(
2022-01-29 12:35:03 +01:00
MatrixLocals(L10n.of(context)!)),
2021-11-13 21:42:35 +01:00
),
),
),
ListTile(
title:
2022-01-29 12:35:03 +01:00
Text(L10n.of(context)!.editChatPermissions),
2021-11-13 21:42:35 +01:00
subtitle: Text(
2022-01-29 12:35:03 +01:00
L10n.of(context)!.whoCanPerformWhichAction),
2021-11-13 21:42:35 +01:00
leading: CircleAvatar(
backgroundColor:
Theme.of(context).scaffoldBackgroundColor,
2021-11-14 13:24:01 +01:00
foregroundColor: iconColor,
2021-11-13 21:42:35 +01:00
child: const Icon(
2021-11-14 13:24:01 +01:00
Icons.edit_attributes_outlined),
2021-11-13 21:42:35 +01:00
),
onTap: () =>
VRouter.of(context).to('permissions'),
),
2021-11-13 21:42:35 +01:00
],
const Divider(height: 1),
ListTile(
title: Text(
actualMembersCount > 1
2022-01-29 12:35:03 +01:00
? L10n.of(context)!.countParticipants(
actualMembersCount.toString())
2022-01-29 12:35:03 +01:00
: L10n.of(context)!.emptyChat,
style: TextStyle(
2021-05-24 10:59:00 +02:00
color:
Theme.of(context).colorScheme.secondary,
fontWeight: FontWeight.bold,
),
),
),
room.canInvite
? ListTile(
2022-01-29 12:35:03 +01:00
title:
Text(L10n.of(context)!.inviteContact),
leading: CircleAvatar(
backgroundColor:
Theme.of(context).primaryColor,
foregroundColor: Colors.white,
radius: Avatar.defaultSize / 2,
2021-10-14 18:09:30 +02:00
child: const Icon(Icons.add_outlined),
),
2021-08-04 10:15:42 +02:00
onTap: () =>
VRouter.of(context).to('invite'),
)
: Container(),
],
)
2022-01-29 12:35:03 +01:00
: i < controller.members!.length + 1
? ParticipantListItem(controller.members![i - 1])
: ListTile(
2022-01-29 12:35:03 +01:00
title: Text(L10n.of(context)!
.loadCountMoreParticipants(
(actualMembersCount -
2022-01-29 12:35:03 +01:00
controller.members!.length)
.toString())),
leading: CircleAvatar(
backgroundColor:
Theme.of(context).scaffoldBackgroundColor,
2021-10-14 18:09:30 +02:00
child: const Icon(
Icons.refresh,
color: Colors.grey,
),
),
onTap: controller.requestMoreMembersAction,
),
),
),
),
);
});
}
}