mirror of
https://github.com/krille-chan/fluffychat
synced 2024-09-19 17:35:18 +00:00
refactor: Encryption button
This commit is contained in:
parent
16d894b566
commit
fae0436f4e
1 changed files with 19 additions and 40 deletions
|
@ -70,45 +70,24 @@ class _EncryptionButtonState extends State<EncryptionButton> {
|
||||||
.where((s) => s.deviceLists != null)
|
.where((s) => s.deviceLists != null)
|
||||||
.listen((s) => setState(() {}));
|
.listen((s) => setState(() {}));
|
||||||
}
|
}
|
||||||
return FutureBuilder<List<User>>(
|
return FutureBuilder<EncryptionHealthState>(
|
||||||
future:
|
future: widget.room.calcEncryptionHealthState(),
|
||||||
widget.room.encrypted ? widget.room.requestParticipants() : null,
|
builder: (BuildContext context, snapshot) => IconButton(
|
||||||
builder: (BuildContext context, snapshot) {
|
tooltip: widget.room.encrypted
|
||||||
Color? color;
|
? L10n.of(context)!.encrypted
|
||||||
if (widget.room.encrypted && snapshot.hasData) {
|
: L10n.of(context)!.encryptionNotEnabled,
|
||||||
final users = snapshot.data!;
|
icon: Icon(
|
||||||
users.removeWhere((u) =>
|
widget.room.encrypted
|
||||||
!{Membership.invite, Membership.join}.contains(u.membership) ||
|
? Icons.lock_outlined
|
||||||
!widget.room.client.userDeviceKeys.containsKey(u.id));
|
: Icons.lock_open_outlined,
|
||||||
var allUsersValid = true;
|
size: 20,
|
||||||
var oneUserInvalid = false;
|
color: widget.room.joinRules != JoinRules.public &&
|
||||||
for (final u in users) {
|
!widget.room.encrypted
|
||||||
final status = widget.room.client.userDeviceKeys[u.id]!.verified;
|
? Colors.red
|
||||||
if (status != UserVerifiedStatus.verified) {
|
: snapshot.data == EncryptionHealthState.unverifiedDevices
|
||||||
allUsersValid = false;
|
? Colors.orange
|
||||||
}
|
: null),
|
||||||
if (status == UserVerifiedStatus.unknownDevice) {
|
onPressed: _enableEncryptionAction,
|
||||||
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(
|
|
||||||
tooltip: widget.room.encrypted
|
|
||||||
? L10n.of(context)!.encrypted
|
|
||||||
: L10n.of(context)!.encryptionNotEnabled,
|
|
||||||
icon: Icon(
|
|
||||||
widget.room.encrypted
|
|
||||||
? Icons.lock_outlined
|
|
||||||
: Icons.lock_open_outlined,
|
|
||||||
size: 20,
|
|
||||||
color: color),
|
|
||||||
onPressed: _enableEncryptionAction,
|
|
||||||
);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue