mirror of
https://gitlab.com/famedly/fluffychat.git
synced 2025-02-17 14:30:40 +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)
|
.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) {
|
|
||||||
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(
|
|
||||||
tooltip: widget.room.encrypted
|
tooltip: widget.room.encrypted
|
||||||
? L10n.of(context)!.encrypted
|
? L10n.of(context)!.encrypted
|
||||||
: L10n.of(context)!.encryptionNotEnabled,
|
: L10n.of(context)!.encryptionNotEnabled,
|
||||||
@ -106,9 +81,13 @@ class _EncryptionButtonState extends State<EncryptionButton> {
|
|||||||
? Icons.lock_outlined
|
? Icons.lock_outlined
|
||||||
: Icons.lock_open_outlined,
|
: Icons.lock_open_outlined,
|
||||||
size: 20,
|
size: 20,
|
||||||
color: color),
|
color: widget.room.joinRules != JoinRules.public &&
|
||||||
|
!widget.room.encrypted
|
||||||
|
? Colors.red
|
||||||
|
: snapshot.data == EncryptionHealthState.unverifiedDevices
|
||||||
|
? Colors.orange
|
||||||
|
: null),
|
||||||
onPressed: _enableEncryptionAction,
|
onPressed: _enableEncryptionAction,
|
||||||
);
|
));
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user