feat: Experimental support for room upgrades

This commit is contained in:
Christian Pauly 2021-03-28 19:48:42 +02:00
parent c0a8079e5d
commit a3af5a9f14
2 changed files with 68 additions and 0 deletions

View File

@ -698,6 +698,36 @@ class _ChatState extends State<Chat> {
child: Column( child: Column(
children: <Widget>[ children: <Widget>[
ConnectionStatusHeader(), ConnectionStatusHeader(),
if (room.getState(EventTypes.RoomTombstone) != null)
Container(
height: 56,
color: Theme.of(context).secondaryHeaderColor,
child: ListTile(
leading: Icon(Icons.upgrade_outlined),
title: Text(room
.getState(EventTypes.RoomTombstone)
.parsedTombstoneContent
.body),
onTap: () async {
final result = await showFutureLoadingDialog(
context: context,
future: () => room.client.joinRoom(room
.getState(EventTypes.RoomTombstone)
.parsedTombstoneContent
.replacementRoom),
);
await showFutureLoadingDialog(
context: context,
future: () => room.leave(),
);
if (result.error == null) {
await AdaptivePageLayout.of(context)
.pushNamedAndRemoveUntilIsFirst(
'/rooms/${result.result}');
}
},
),
),
Expanded( Expanded(
child: FutureBuilder<bool>( child: FutureBuilder<bool>(
future: getTimeline(context), future: getTimeline(context),

View File

@ -1,5 +1,6 @@
import 'dart:developer'; import 'dart:developer';
import 'package:adaptive_page_layout/adaptive_page_layout.dart';
import 'package:fluffychat/components/dialogs/permission_slider_dialog.dart'; import 'package:fluffychat/components/dialogs/permission_slider_dialog.dart';
import 'package:future_loading_dialog/future_loading_dialog.dart'; import 'package:future_loading_dialog/future_loading_dialog.dart';
import 'package:fluffychat/components/matrix.dart'; import 'package:fluffychat/components/matrix.dart';
@ -123,6 +124,43 @@ class ChatPermissionsSettings extends StatelessWidget {
context, entry.key, entry.value, context, entry.key, entry.value,
category: 'events'), category: 'events'),
), ),
if (room.ownPowerLevel >= 100) ...{
Divider(thickness: 1),
FutureBuilder<ServerCapabilities>(
future: room.client.requestServerCapabilities(),
builder: (context, snapshot) {
if (!snapshot.hasData) {
return Center(child: CircularProgressIndicator());
}
final String roomVersion = room
.getState(EventTypes.RoomCreate)
.content['room_version'] ??
'1';
final shouldHaveVersion =
snapshot.data.mRoomVersions.defaultVersion;
return ListTile(
title: Text('Current room version: $roomVersion'),
subtitle: roomVersion == shouldHaveVersion
? null
: Text(
'Upgrade to $shouldHaveVersion available!',
style: TextStyle(
fontWeight: FontWeight.bold,
color: Theme.of(context).accentColor),
),
onTap: roomVersion == shouldHaveVersion
? null
: () => showFutureLoadingDialog(
context: context,
future: () => room.client
.upgradeRoom(roomId, shouldHaveVersion),
).then((_) =>
AdaptivePageLayout.of(context).pop()),
);
},
),
},
], ],
), ),
], ],