2023-03-23 14:04:48 +01:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_svg/flutter_svg.dart';
|
2023-03-28 14:54:39 +02:00
|
|
|
import 'package:go_router/go_router.dart';
|
2023-03-23 14:04:48 +01:00
|
|
|
import 'package:outbag_app/backend/permissions.dart';
|
|
|
|
import 'package:outbag_app/backend/request.dart';
|
|
|
|
import 'package:outbag_app/backend/room.dart';
|
2023-03-25 17:18:46 +01:00
|
|
|
import 'package:outbag_app/backend/user.dart';
|
2023-03-23 14:04:48 +01:00
|
|
|
import 'dart:math';
|
2023-03-23 14:48:53 +01:00
|
|
|
import 'package:outbag_app/tools/fetch_wrapper.dart';
|
2023-03-25 17:18:46 +01:00
|
|
|
import 'package:provider/provider.dart';
|
2023-03-23 14:04:48 +01:00
|
|
|
|
|
|
|
class AboutRoomPage extends StatefulWidget {
|
|
|
|
final RoomInfo? info;
|
|
|
|
final Room? room;
|
|
|
|
|
|
|
|
const AboutRoomPage(this.room, this.info, {super.key});
|
|
|
|
|
|
|
|
@override
|
|
|
|
State<StatefulWidget> createState() => _AboutRoomPageState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _AboutRoomPageState extends State<AboutRoomPage> {
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
final textTheme = Theme.of(context)
|
2023-03-24 18:21:23 +01:00
|
|
|
.textTheme
|
|
|
|
.apply(displayColor: Theme.of(context).colorScheme.onSurface);
|
2023-03-23 14:04:48 +01:00
|
|
|
|
|
|
|
double width = MediaQuery.of(context).size.width;
|
|
|
|
double height = MediaQuery.of(context).size.height;
|
|
|
|
double smallest = min(width, height);
|
|
|
|
|
2023-03-24 18:21:23 +01:00
|
|
|
return SingleChildScrollView(
|
2023-03-25 17:18:46 +01:00
|
|
|
child: Center(
|
2023-03-23 14:04:48 +01:00
|
|
|
child: Column(children: [
|
2023-03-24 18:21:23 +01:00
|
|
|
// room meta display
|
|
|
|
...(widget.room != null)
|
|
|
|
? [
|
2023-03-23 14:04:48 +01:00
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.all(14),
|
|
|
|
child: Column(
|
|
|
|
children: [
|
|
|
|
SvgPicture.asset(
|
|
|
|
(widget.room?.icon?.img)!,
|
|
|
|
width: smallest * 0.2,
|
|
|
|
height: smallest * 0.2,
|
|
|
|
),
|
|
|
|
Text(
|
|
|
|
widget.room?.name ?? '',
|
|
|
|
style: textTheme.displayMedium,
|
|
|
|
),
|
|
|
|
Text(
|
|
|
|
'${widget.room?.id}@${widget.room?.serverTag}',
|
|
|
|
style: textTheme.bodySmall,
|
|
|
|
),
|
2023-03-25 17:18:46 +01:00
|
|
|
Text(
|
|
|
|
widget.room?.description ?? '',
|
2023-03-25 10:27:21 +01:00
|
|
|
style: textTheme.bodyMedium,
|
|
|
|
textAlign: TextAlign.center,
|
|
|
|
),
|
2023-03-23 14:04:48 +01:00
|
|
|
Padding(
|
2023-03-24 18:21:23 +01:00
|
|
|
padding: const EdgeInsets.all(8),
|
|
|
|
child: SegmentedButton<int>(
|
|
|
|
showSelectedIcon: true,
|
|
|
|
multiSelectionEnabled: false,
|
|
|
|
emptySelectionAllowed: false,
|
|
|
|
segments: RoomVisibility.list().map((vis) {
|
2023-03-23 14:04:48 +01:00
|
|
|
return ButtonSegment<int>(
|
2023-03-24 18:21:23 +01:00
|
|
|
value: vis.type,
|
|
|
|
label: Text(vis.text),
|
|
|
|
icon: Icon(vis.icon));
|
|
|
|
}).toList(),
|
|
|
|
onSelectionChanged: ((vset) {
|
2023-03-23 14:04:48 +01:00
|
|
|
// check permission
|
|
|
|
// only show confirm dialog when user
|
|
|
|
// is admin, owner or has CHANGE_ADMIN permission
|
|
|
|
if (widget.info == null ||
|
2023-03-24 18:21:23 +01:00
|
|
|
(!(widget.info?.isAdmin ?? false) &&
|
|
|
|
!(widget.info?.isOwner ?? false) &&
|
|
|
|
((widget.info?.permissions)! &
|
|
|
|
RoomPermission.ota ==
|
|
|
|
0))) {
|
2023-03-23 14:04:48 +01:00
|
|
|
// action not permitted
|
|
|
|
// NOTE: no error dialog should be shown
|
|
|
|
// because the action is supposed to be hidden
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
final vis = RoomVisibility(vset.first);
|
|
|
|
showDialog(
|
2023-03-24 18:21:23 +01:00
|
|
|
context: context,
|
|
|
|
builder: (ctx) => AlertDialog(
|
|
|
|
title:
|
|
|
|
const Text('Change room visibility'),
|
|
|
|
content: Text(
|
|
|
|
'Do you really want to change the room visibility to: ${vis.text}'),
|
|
|
|
actions: [
|
|
|
|
TextButton(
|
|
|
|
onPressed: () {
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
},
|
|
|
|
child: const Text('Cancel'),
|
|
|
|
),
|
|
|
|
FilledButton(
|
|
|
|
onPressed: () async {
|
|
|
|
final scaffMgr =
|
|
|
|
ScaffoldMessenger.of(context);
|
|
|
|
final nav = Navigator.of(context);
|
2023-03-25 17:18:46 +01:00
|
|
|
final user = context.read<User>();
|
2023-03-23 14:04:48 +01:00
|
|
|
|
2023-03-24 18:21:23 +01:00
|
|
|
doNetworkRequest(scaffMgr,
|
2023-03-25 17:18:46 +01:00
|
|
|
req: () => postWithCreadentials(
|
2023-03-24 18:21:23 +01:00
|
|
|
path: 'setVisibility',
|
2023-03-25 17:18:46 +01:00
|
|
|
target: user.server,
|
2023-03-24 18:21:23 +01:00
|
|
|
body: {
|
2023-03-25 17:18:46 +01:00
|
|
|
'room': widget.room?.id,
|
|
|
|
'server': (widget
|
|
|
|
.room?.serverTag)!,
|
|
|
|
'visibility': vset.first
|
2023-03-23 14:04:48 +01:00
|
|
|
},
|
2023-03-25 17:18:46 +01:00
|
|
|
credentials: user),
|
2023-03-24 18:21:23 +01:00
|
|
|
onOK: (_) {
|
|
|
|
Room r = widget.room!;
|
|
|
|
r.visibility = vis;
|
|
|
|
r.toDisk();
|
|
|
|
},
|
|
|
|
after: () {
|
|
|
|
nav.pop();
|
|
|
|
});
|
|
|
|
},
|
|
|
|
child: const Text('Ok'),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
));
|
|
|
|
}),
|
|
|
|
selected: {(widget.room?.visibility?.type)!},
|
|
|
|
selectedIcon: Icon((widget.room?.visibility?.icon)!),
|
|
|
|
)),
|
2023-03-23 14:04:48 +01:00
|
|
|
],
|
|
|
|
),
|
|
|
|
)
|
|
|
|
]
|
2023-03-24 18:21:23 +01:00
|
|
|
: [],
|
2023-03-23 14:04:48 +01:00
|
|
|
|
2023-03-24 18:21:23 +01:00
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.all(14),
|
|
|
|
child: Column(
|
|
|
|
children: [
|
|
|
|
// edit room meta button
|
|
|
|
...(widget.info != null &&
|
|
|
|
((widget.info?.isAdmin ?? false) ||
|
|
|
|
(widget.info?.isOwner ?? false) ||
|
|
|
|
((widget.info?.permissions)! &
|
|
|
|
RoomPermission.changeMeta !=
|
|
|
|
0)))
|
2023-03-23 14:04:48 +01:00
|
|
|
? [
|
2023-03-24 13:22:48 +01:00
|
|
|
ListTile(
|
|
|
|
trailing: const Icon(Icons.chevron_right),
|
|
|
|
title: const Text('Edit Metadata'),
|
|
|
|
subtitle: const Text(
|
|
|
|
'Change the rooms name, description and icon'),
|
|
|
|
onTap: () {
|
|
|
|
// show edit room screen
|
2023-03-28 14:54:39 +02:00
|
|
|
context.goNamed('edit-room', params: {
|
|
|
|
'server': (widget.room?.serverTag)!,
|
|
|
|
'id': (widget.room?.id)!
|
|
|
|
});
|
2023-03-24 13:22:48 +01:00
|
|
|
},
|
2023-03-24 18:21:23 +01:00
|
|
|
),
|
|
|
|
]
|
2023-03-23 14:04:48 +01:00
|
|
|
: [],
|
2023-03-24 18:21:23 +01:00
|
|
|
// open members view
|
|
|
|
ListTile(
|
|
|
|
trailing: const Icon(Icons.chevron_right),
|
|
|
|
title: const Text('Members'),
|
|
|
|
subtitle: const Text('Show Member list'),
|
|
|
|
onTap: () {
|
|
|
|
// open member view screen
|
2023-03-28 14:54:39 +02:00
|
|
|
context.goNamed('room-members', params: {
|
|
|
|
'server': (widget.room?.serverTag)!,
|
|
|
|
'id': (widget.room?.id)!
|
|
|
|
});
|
2023-03-24 18:21:23 +01:00
|
|
|
},
|
|
|
|
),
|
2023-03-25 10:27:21 +01:00
|
|
|
// edit default member permission
|
|
|
|
...(widget.info != null &&
|
|
|
|
((widget.info?.isAdmin ?? false) ||
|
|
|
|
(widget.info?.isOwner ?? false) ||
|
|
|
|
((widget.info?.permissions)! &
|
|
|
|
RoomPermission.changeAdmin !=
|
|
|
|
0)))
|
|
|
|
? [
|
|
|
|
ListTile(
|
|
|
|
trailing: const Icon(Icons.chevron_right),
|
|
|
|
title: const Text('Edit Permissions'),
|
|
|
|
subtitle: const Text(
|
|
|
|
'Change the default permission-set for all members'),
|
|
|
|
onTap: () {
|
|
|
|
// show checkbox screen
|
2023-03-28 14:54:39 +02:00
|
|
|
context.goNamed('room-permissions', params: {
|
|
|
|
'server': (widget.room?.serverTag)!,
|
|
|
|
'id': (widget.room?.id)!
|
|
|
|
});
|
2023-03-25 10:27:21 +01:00
|
|
|
},
|
|
|
|
),
|
|
|
|
]
|
|
|
|
: [],
|
2023-03-24 18:21:23 +01:00
|
|
|
...(widget.info != null &&
|
|
|
|
((widget.info?.isAdmin ?? false) ||
|
|
|
|
(widget.info?.isOwner ?? false) ||
|
|
|
|
((widget.info?.permissions)! & RoomPermission.ota !=
|
|
|
|
0)))
|
2023-03-23 14:04:48 +01:00
|
|
|
? [
|
2023-03-24 18:21:23 +01:00
|
|
|
ListTile(
|
|
|
|
trailing: const Icon(Icons.chevron_right),
|
|
|
|
title: const Text('OTA'),
|
|
|
|
subtitle: const Text('Add and delete OTAs'),
|
|
|
|
onTap: () {
|
|
|
|
// show manage ota screen
|
2023-03-28 14:54:39 +02:00
|
|
|
context.goNamed('room-ota', params: {
|
|
|
|
'server': (widget.room?.serverTag)!,
|
|
|
|
'id': (widget.room?.id)!
|
|
|
|
});
|
2023-03-24 18:21:23 +01:00
|
|
|
},
|
|
|
|
),
|
|
|
|
ListTile(
|
|
|
|
trailing: const Icon(Icons.chevron_right),
|
|
|
|
title: const Text('Invites'),
|
|
|
|
subtitle: const Text('Invite people to this room'),
|
|
|
|
onTap: () {
|
|
|
|
// show manage ota screen
|
2023-03-28 14:54:39 +02:00
|
|
|
context.goNamed('room-invite', params: {
|
|
|
|
'server': (widget.room?.serverTag)!,
|
|
|
|
'id': (widget.room?.id)!
|
|
|
|
});
|
2023-03-24 18:21:23 +01:00
|
|
|
},
|
|
|
|
),
|
|
|
|
]
|
2023-03-23 14:04:48 +01:00
|
|
|
: [],
|
2023-03-24 18:21:23 +01:00
|
|
|
],
|
|
|
|
)),
|
2023-03-23 14:04:48 +01:00
|
|
|
|
2023-03-24 18:21:23 +01:00
|
|
|
...(widget.info != null)
|
|
|
|
? [
|
2023-03-23 14:04:48 +01:00
|
|
|
Padding(
|
2023-03-24 18:21:23 +01:00
|
|
|
padding: const EdgeInsets.all(8),
|
|
|
|
child: FilledButton.tonal(
|
|
|
|
child: Text(((widget.info?.isOwner)!)
|
|
|
|
? 'Delete Room'
|
|
|
|
: 'Leave Room'),
|
|
|
|
onPressed: () {
|
|
|
|
// show confirm dialog
|
|
|
|
showDialog(
|
|
|
|
context: context,
|
|
|
|
builder: (ctx) => AlertDialog(
|
|
|
|
title: Text(((widget.info?.isOwner)!)
|
|
|
|
? 'Delete Room'
|
|
|
|
: 'Leave Room'),
|
|
|
|
content: Text(
|
|
|
|
'Do you really want to ${((widget.info?.isOwner)!) ? "delete" : "leave"} the room?'),
|
|
|
|
actions: [
|
|
|
|
TextButton(
|
|
|
|
onPressed: () {
|
|
|
|
// close popup
|
|
|
|
Navigator.of(ctx).pop();
|
|
|
|
},
|
|
|
|
child: const Text('Cancel'),
|
|
|
|
),
|
|
|
|
FilledButton(
|
|
|
|
onPressed: () async {
|
|
|
|
// send request
|
|
|
|
final scaffMgr =
|
|
|
|
ScaffoldMessenger.of(ctx);
|
|
|
|
final nav = Navigator.of(ctx);
|
2023-03-28 14:54:39 +02:00
|
|
|
final router = GoRouter.of(ctx);
|
2023-03-25 17:18:46 +01:00
|
|
|
final user = ctx.read<User>();
|
2023-03-23 14:04:48 +01:00
|
|
|
|
2023-03-25 17:18:46 +01:00
|
|
|
doNetworkRequest(scaffMgr,
|
|
|
|
req: () => postWithCreadentials(
|
2023-03-24 18:21:23 +01:00
|
|
|
path: ((widget.info?.isOwner)!)
|
|
|
|
? 'deleteRoom'
|
|
|
|
: 'leaveRoom',
|
2023-03-25 17:18:46 +01:00
|
|
|
target: user.server,
|
2023-03-24 18:21:23 +01:00
|
|
|
body: {
|
|
|
|
'room': widget.room?.id,
|
|
|
|
'server':
|
|
|
|
(widget.room?.serverTag)!,
|
|
|
|
},
|
2023-03-25 17:18:46 +01:00
|
|
|
credentials: user),
|
2023-03-24 18:21:23 +01:00
|
|
|
onOK: (_) async {
|
|
|
|
// try delete room from disk
|
|
|
|
try {
|
|
|
|
await widget.room?.removeDisk();
|
|
|
|
} catch (_) {}
|
2023-03-23 14:04:48 +01:00
|
|
|
|
2023-03-24 18:21:23 +01:00
|
|
|
// go back home
|
2023-03-28 14:54:39 +02:00
|
|
|
router.pushReplacementNamed('home');
|
2023-03-24 18:21:23 +01:00
|
|
|
},
|
|
|
|
after: () {
|
|
|
|
// close popup
|
|
|
|
nav.pop();
|
2023-03-25 17:18:46 +01:00
|
|
|
});
|
2023-03-24 18:21:23 +01:00
|
|
|
},
|
|
|
|
child: Text(((widget.info?.isOwner)!)
|
|
|
|
? 'Delete'
|
|
|
|
: 'Leave'),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
));
|
|
|
|
},
|
|
|
|
))
|
2023-03-23 14:04:48 +01:00
|
|
|
]
|
2023-03-24 18:21:23 +01:00
|
|
|
: [],
|
2023-03-25 17:18:46 +01:00
|
|
|
])));
|
2023-03-23 14:04:48 +01:00
|
|
|
}
|
|
|
|
}
|