reorganize and rename widgets
This commit is contained in:
parent
05d25869ef
commit
d5f29dc344
1 changed files with 568 additions and 547 deletions
209
lib/widgets/rooms/room_summary_sheet.dart
Normal file
209
lib/widgets/rooms/room_summary_sheet.dart
Normal file
|
|
@ -0,0 +1,209 @@
|
|||
import "package:fast_immutable_collections/fast_immutable_collections.dart";
|
||||
import "package:flutter_riverpod/flutter_riverpod.dart";
|
||||
import "package:material_ui/material_ui.dart";
|
||||
import "package:material_adaptive_sheets/material_adaptive_sheets.dart";
|
||||
import "package:nexus/controllers/client.dart";
|
||||
import "package:nexus/controllers/invites.dart";
|
||||
import "package:nexus/controllers/rooms.dart";
|
||||
import "package:nexus/helpers/extensions/get_localpart.dart";
|
||||
import "package:nexus/helpers/extensions/join_room.dart";
|
||||
import "package:nexus/helpers/extensions/room_summary_display.dart";
|
||||
import "package:nexus/main.dart";
|
||||
import "package:nexus/widgets/avatars/avatar_or_hash.dart";
|
||||
import "package:nexus/widgets/common/expandable_image.dart";
|
||||
import "package:nexus/widgets/rooms/knock_sheet.dart";
|
||||
import "package:nexus/widgets/common/linkified_text.dart";
|
||||
import "package:nexus/models/room_summary.dart";
|
||||
|
||||
class const RoomSummarySheet(
|
||||
final RoomSummary summary, {
|
||||
final IList<String>? via,
|
||||
super.key,
|
||||
}) extends ConsumerWidget {
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final name = summary.name ?? summary.canonicalAlias ?? summary.roomId;
|
||||
final isInvite = summary.membership == .invite;
|
||||
final isKnocking = summary.membership == .knock;
|
||||
final mustKnock = summary.mustKnock(
|
||||
ref.watch(
|
||||
RoomsController.provider.select((rooms) => rooms.keys.toISet()),
|
||||
),
|
||||
);
|
||||
final colorScheme = Theme.of(context).colorScheme;
|
||||
|
||||
return SheetLayout(
|
||||
title: Row(
|
||||
spacing: 12,
|
||||
mainAxisSize: .min,
|
||||
children: [
|
||||
if (summary.avatarUrl != null)
|
||||
ExpandableImage(
|
||||
summary.avatarUrl == null ? null : .new(mxc: summary.avatarUrl!),
|
||||
downloadFilename: name,
|
||||
child: AvatarOrHash(
|
||||
summary.avatarUrl,
|
||||
"",
|
||||
dimension: 64,
|
||||
fallback: Icon(summary.icon),
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: Text(summary.displayName, overflow: .ellipsis, maxLines: 3),
|
||||
),
|
||||
],
|
||||
),
|
||||
actions: [
|
||||
TextButton(onPressed: Navigator.of(context).pop, child: Text("Cancel")),
|
||||
if (isInvite) ...[
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
final container = ProviderScope.containerOf(context);
|
||||
Navigator.of(context).pop();
|
||||
|
||||
InvitesController.respondMutation(summary.roomId)
|
||||
.run(
|
||||
container,
|
||||
(_) => container
|
||||
.read(InvitesController.provider.notifier)
|
||||
.decline(summary.roomId),
|
||||
)
|
||||
.onError(showError);
|
||||
},
|
||||
style: TextButton.styleFrom(foregroundColor: colorScheme.error),
|
||||
child: Text("Decline"),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
final container = ProviderScope.containerOf(context);
|
||||
|
||||
InvitesController.respondMutation(summary.roomId)
|
||||
.run(container, (_) async {
|
||||
final roomId = await context.joinRoom(
|
||||
.new(roomIdOrAlias: summary.roomId, fromInvite: true),
|
||||
name: name,
|
||||
);
|
||||
if (roomId != null) {
|
||||
container
|
||||
.read(InvitesController.provider.notifier)
|
||||
.remove(summary.roomId);
|
||||
}
|
||||
})
|
||||
.onError(showError);
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
child: Text("Accept"),
|
||||
),
|
||||
] else if (isKnocking)
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
final container = ProviderScope.containerOf(context);
|
||||
Navigator.of(context).pop();
|
||||
|
||||
container
|
||||
.read(ClientController.provider.notifier)
|
||||
.leaveRoom(summary.roomId)
|
||||
.onError(showError);
|
||||
},
|
||||
style: TextButton.styleFrom(foregroundColor: colorScheme.error),
|
||||
child: Text("Retract knock"),
|
||||
)
|
||||
else if (via != null && mustKnock)
|
||||
TextButton(
|
||||
onPressed: () async {
|
||||
if (await context.showAdaptiveSheet<bool>(
|
||||
(_) =>
|
||||
KnockSheet(summary.roomId, name: name, via: via!),
|
||||
) ==
|
||||
true &&
|
||||
context.mounted) {
|
||||
Navigator.of(context).pop();
|
||||
}
|
||||
},
|
||||
child: Text("Knock"),
|
||||
)
|
||||
else if (via != null)
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
context.joinRoom(
|
||||
.new(roomIdOrAlias: summary.roomId, via: via!),
|
||||
name: name,
|
||||
);
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
child: Text("Join"),
|
||||
),
|
||||
],
|
||||
children: [
|
||||
Column(
|
||||
children: [
|
||||
if (summary.invitedBy case final invitedBy?)
|
||||
ListTile(
|
||||
leading: AvatarOrHash(
|
||||
summary.inviterProfile?.avatarUrl,
|
||||
summary.inviterProfile?.displayName ?? invitedBy.localpart,
|
||||
),
|
||||
title: Text(
|
||||
"${summary.isDirect ? "Direct message from" : "Invited by"} ${summary.inviterProfile?.displayName ?? invitedBy.localpart}",
|
||||
),
|
||||
subtitle: SelectableText(invitedBy),
|
||||
),
|
||||
if (summary.inviteReason case final reason?)
|
||||
ListTile(
|
||||
titleAlignment: ListTileTitleAlignment.titleHeight,
|
||||
leading: const Icon(Icons.format_quote),
|
||||
title: const Text("Invite reason"),
|
||||
subtitle: SelectableText(reason),
|
||||
),
|
||||
|
||||
if (summary.joinedMembers != null)
|
||||
ListTile(
|
||||
title: Text(
|
||||
"${summary.joinedMembers ?? "Unknown number of"} members",
|
||||
),
|
||||
leading: Icon(Icons.people),
|
||||
),
|
||||
|
||||
if (summary.canonicalAlias case final canonicalAlias?)
|
||||
ListTile(
|
||||
title: Text("Canonical Alias"),
|
||||
subtitle: SelectableText(canonicalAlias),
|
||||
leading: Icon(Icons.numbers),
|
||||
),
|
||||
|
||||
ListTile(
|
||||
title: Text("Room ID"),
|
||||
subtitle: SelectableText(summary.roomId),
|
||||
leading: Icon(Icons.badge),
|
||||
),
|
||||
|
||||
if (summary.topic case final topic?)
|
||||
ListTile(
|
||||
title: Text("Topic"),
|
||||
subtitle: LinkifiedText(topic, roomId: summary.roomId),
|
||||
leading: Icon(Icons.info),
|
||||
),
|
||||
if (isKnocking)
|
||||
ListTile(
|
||||
title: Text("You've knocked"),
|
||||
subtitle: Text("Waiting for a moderator to let you in"),
|
||||
leading: Icon(Icons.hourglass_top),
|
||||
)
|
||||
else if (mustKnock)
|
||||
ListTile(
|
||||
title: Text("Knock to join"),
|
||||
leading: Icon(Icons.door_front_door),
|
||||
),
|
||||
if (summary.encryption != null)
|
||||
ListTile(title: Text("Encrypted"), leading: Icon(Icons.lock)),
|
||||
if (summary.worldReadable == true)
|
||||
ListTile(
|
||||
title: Text("Anyone can read room history"),
|
||||
leading: Icon(Icons.public),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue