Krille/use stream builder
This commit is contained in:
parent
1a6b184e98
commit
ab62170bb9
3 changed files with 595 additions and 592 deletions
|
|
@ -1,5 +1,3 @@
|
|||
import 'dart:async';
|
||||
|
||||
import 'package:famedlysdk/famedlysdk.dart';
|
||||
import 'package:fluffychat/components/adaptive_page_layout.dart';
|
||||
import 'package:fluffychat/components/avatar.dart';
|
||||
|
|
@ -35,120 +33,105 @@ class ChatEncryptionSettings extends StatefulWidget {
|
|||
}
|
||||
|
||||
class _ChatEncryptionSettingsState extends State<ChatEncryptionSettings> {
|
||||
Room room;
|
||||
|
||||
StreamSubscription roomUpdate;
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
roomUpdate?.cancel();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
room ??= Matrix.of(context).client.getRoomById(widget.id);
|
||||
roomUpdate ??= room.onUpdate.stream.listen((s) => setState(() => null));
|
||||
final room = Matrix.of(context).client.getRoomById(widget.id);
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text(L10n.of(context).participatingUserDevices),
|
||||
),
|
||||
body: Column(
|
||||
children: <Widget>[
|
||||
FutureBuilder<List<DeviceKeys>>(
|
||||
future: room.getUserDeviceKeys(),
|
||||
builder: (BuildContext context, snapshot) {
|
||||
if (snapshot.hasError) {
|
||||
return Center(
|
||||
child: Text(L10n.of(context).oopsSomethingWentWrong +
|
||||
": " +
|
||||
snapshot.error.toString()),
|
||||
);
|
||||
}
|
||||
if (!snapshot.hasData) {
|
||||
return Center(child: CircularProgressIndicator());
|
||||
}
|
||||
final List<DeviceKeys> deviceKeys = snapshot.data;
|
||||
return Expanded(
|
||||
child: ListView.separated(
|
||||
separatorBuilder: (BuildContext context, int i) =>
|
||||
Divider(height: 1),
|
||||
itemCount: deviceKeys.length,
|
||||
itemBuilder: (BuildContext context, int i) => Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: <Widget>[
|
||||
if (i == 0 ||
|
||||
deviceKeys[i].userId != deviceKeys[i - 1].userId)
|
||||
Material(
|
||||
child: ListTile(
|
||||
leading: Avatar(
|
||||
room
|
||||
body: StreamBuilder(
|
||||
stream: room.onUpdate.stream,
|
||||
builder: (context, snapshot) {
|
||||
return FutureBuilder<List<DeviceKeys>>(
|
||||
future: room.getUserDeviceKeys(),
|
||||
builder: (BuildContext context, snapshot) {
|
||||
if (snapshot.hasError) {
|
||||
return Center(
|
||||
child: Text(L10n.of(context).oopsSomethingWentWrong +
|
||||
": " +
|
||||
snapshot.error.toString()),
|
||||
);
|
||||
}
|
||||
if (!snapshot.hasData) {
|
||||
return Center(child: CircularProgressIndicator());
|
||||
}
|
||||
final List<DeviceKeys> deviceKeys = snapshot.data;
|
||||
return Expanded(
|
||||
child: ListView.separated(
|
||||
separatorBuilder: (BuildContext context, int i) =>
|
||||
Divider(height: 1),
|
||||
itemCount: deviceKeys.length,
|
||||
itemBuilder: (BuildContext context, int i) => Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: <Widget>[
|
||||
if (i == 0 ||
|
||||
deviceKeys[i].userId != deviceKeys[i - 1].userId)
|
||||
Material(
|
||||
child: ListTile(
|
||||
leading: Avatar(
|
||||
room
|
||||
.getUserByMXIDSync(deviceKeys[i].userId)
|
||||
.avatarUrl,
|
||||
room
|
||||
.getUserByMXIDSync(deviceKeys[i].userId)
|
||||
.calcDisplayname(),
|
||||
),
|
||||
title: Text(room
|
||||
.getUserByMXIDSync(deviceKeys[i].userId)
|
||||
.avatarUrl,
|
||||
room
|
||||
.getUserByMXIDSync(deviceKeys[i].userId)
|
||||
.calcDisplayname(),
|
||||
.calcDisplayname()),
|
||||
subtitle: Text(deviceKeys[i].userId),
|
||||
),
|
||||
title: Text(room
|
||||
.getUserByMXIDSync(deviceKeys[i].userId)
|
||||
.calcDisplayname()),
|
||||
subtitle: Text(deviceKeys[i].userId),
|
||||
elevation: 2,
|
||||
),
|
||||
elevation: 2,
|
||||
),
|
||||
CheckboxListTile(
|
||||
title: Text(
|
||||
"${deviceKeys[i].unsigned["device_display_name"] ?? L10n.of(context).unknownDevice} - ${deviceKeys[i].deviceId}",
|
||||
style: TextStyle(
|
||||
color: deviceKeys[i].blocked
|
||||
? Colors.red
|
||||
: deviceKeys[i].verified
|
||||
? Colors.green
|
||||
: Colors.orange),
|
||||
),
|
||||
subtitle: Text(
|
||||
deviceKeys[i]
|
||||
.keys["ed25519:${deviceKeys[i].deviceId}"]
|
||||
.beautified,
|
||||
style: TextStyle(
|
||||
color:
|
||||
Theme.of(context).textTheme.bodyText2.color),
|
||||
),
|
||||
value: deviceKeys[i].verified,
|
||||
onChanged: (bool newVal) {
|
||||
if (newVal == true) {
|
||||
if (deviceKeys[i].blocked) {
|
||||
CheckboxListTile(
|
||||
title: Text(
|
||||
"${deviceKeys[i].unsigned["device_display_name"] ?? L10n.of(context).unknownDevice} - ${deviceKeys[i].deviceId}",
|
||||
style: TextStyle(
|
||||
color: deviceKeys[i].blocked
|
||||
? Colors.red
|
||||
: deviceKeys[i].verified
|
||||
? Colors.green
|
||||
: Colors.orange),
|
||||
),
|
||||
subtitle: Text(
|
||||
deviceKeys[i]
|
||||
.keys["ed25519:${deviceKeys[i].deviceId}"]
|
||||
.beautified,
|
||||
style: TextStyle(
|
||||
color: Theme.of(context)
|
||||
.textTheme
|
||||
.bodyText2
|
||||
.color),
|
||||
),
|
||||
value: deviceKeys[i].verified,
|
||||
onChanged: (bool newVal) {
|
||||
if (newVal == true) {
|
||||
if (deviceKeys[i].blocked) {
|
||||
deviceKeys[i].setBlocked(
|
||||
false, Matrix.of(context).client);
|
||||
}
|
||||
deviceKeys[i]
|
||||
.setBlocked(false, Matrix.of(context).client);
|
||||
.setVerified(true, Matrix.of(context).client);
|
||||
} else {
|
||||
if (deviceKeys[i].verified) {
|
||||
deviceKeys[i].setVerified(
|
||||
false, Matrix.of(context).client);
|
||||
}
|
||||
deviceKeys[i]
|
||||
.setBlocked(true, Matrix.of(context).client);
|
||||
}
|
||||
deviceKeys[i]
|
||||
.setVerified(true, Matrix.of(context).client);
|
||||
} else {
|
||||
if (deviceKeys[i].verified) {
|
||||
deviceKeys[i].setVerified(
|
||||
false, Matrix.of(context).client);
|
||||
}
|
||||
deviceKeys[i]
|
||||
.setBlocked(true, Matrix.of(context).client);
|
||||
}
|
||||
setState(() => null);
|
||||
},
|
||||
),
|
||||
],
|
||||
setState(() => null);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
Divider(thickness: 1, height: 1),
|
||||
ListTile(
|
||||
title: Text("Outbound MegOlm session ID:"),
|
||||
subtitle: Text(
|
||||
room.outboundGroupSession?.session_id()?.beautified ?? "None"),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue