mirror of
https://gitlab.com/famedly/fluffychat.git
synced 2024-11-23 20:49:26 +01:00
refactor: Encryption button
This commit is contained in:
parent
740d40c51a
commit
fa0ea99657
@ -70,34 +70,9 @@ class _EncryptionButtonState extends State<EncryptionButton> {
|
||||
.where((s) => s.deviceLists != null)
|
||||
.listen((s) => setState(() {}));
|
||||
}
|
||||
return FutureBuilder<List<User>>(
|
||||
future:
|
||||
widget.room.encrypted ? widget.room.requestParticipants() : null,
|
||||
builder: (BuildContext context, snapshot) {
|
||||
Color? color;
|
||||
if (widget.room.encrypted && snapshot.hasData) {
|
||||
final users = snapshot.data!;
|
||||
users.removeWhere((u) =>
|
||||
!{Membership.invite, Membership.join}.contains(u.membership) ||
|
||||
!widget.room.client.userDeviceKeys.containsKey(u.id));
|
||||
var allUsersValid = true;
|
||||
var oneUserInvalid = false;
|
||||
for (final u in users) {
|
||||
final status = widget.room.client.userDeviceKeys[u.id]!.verified;
|
||||
if (status != UserVerifiedStatus.verified) {
|
||||
allUsersValid = false;
|
||||
}
|
||||
if (status == UserVerifiedStatus.unknownDevice) {
|
||||
oneUserInvalid = true;
|
||||
}
|
||||
}
|
||||
if (oneUserInvalid) color = Colors.red;
|
||||
if (!allUsersValid) color = Colors.orange;
|
||||
} else if (!widget.room.encrypted &&
|
||||
widget.room.joinRules != JoinRules.public) {
|
||||
color = Colors.red;
|
||||
}
|
||||
return IconButton(
|
||||
return FutureBuilder<EncryptionHealthState>(
|
||||
future: widget.room.calcEncryptionHealthState(),
|
||||
builder: (BuildContext context, snapshot) => IconButton(
|
||||
tooltip: widget.room.encrypted
|
||||
? L10n.of(context)!.encrypted
|
||||
: L10n.of(context)!.encryptionNotEnabled,
|
||||
@ -106,9 +81,13 @@ class _EncryptionButtonState extends State<EncryptionButton> {
|
||||
? Icons.lock_outlined
|
||||
: Icons.lock_open_outlined,
|
||||
size: 20,
|
||||
color: color),
|
||||
color: widget.room.joinRules != JoinRules.public &&
|
||||
!widget.room.encrypted
|
||||
? Colors.red
|
||||
: snapshot.data == EncryptionHealthState.unverifiedDevices
|
||||
? Colors.orange
|
||||
: null),
|
||||
onPressed: _enableEncryptionAction,
|
||||
);
|
||||
});
|
||||
));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user