feat: Better encryption / verification
This commit is contained in:
parent
81d86174c4
commit
274ca76db8
8 changed files with 140 additions and 48 deletions
|
|
@ -1,4 +1,5 @@
|
|||
import 'package:famedlysdk/famedlysdk.dart';
|
||||
import 'package:famedlysdk/encryption.dart';
|
||||
import 'package:fluffychat/components/dialogs/simple_dialogs.dart';
|
||||
import 'package:fluffychat/components/message_content.dart';
|
||||
import 'package:fluffychat/components/reply_content.dart';
|
||||
|
|
@ -13,6 +14,8 @@ import '../avatar.dart';
|
|||
import '../matrix.dart';
|
||||
import '../message_reactions.dart';
|
||||
import 'state_message.dart';
|
||||
import '../../views/key_verification.dart';
|
||||
import '../../utils/app_route.dart';
|
||||
|
||||
class Message extends StatelessWidget {
|
||||
final Event event;
|
||||
|
|
@ -37,6 +40,36 @@ class Message extends StatelessWidget {
|
|||
/// of touchscreen.
|
||||
static bool useMouse = false;
|
||||
|
||||
void _verifyOrRequestKey(BuildContext context) async {
|
||||
final client = Matrix.of(context).client;
|
||||
if (client.isUnknownSession && client.encryption.crossSigning.enabled) {
|
||||
final req =
|
||||
await client.userDeviceKeys[client.userID].startVerification();
|
||||
req.onUpdate = () async {
|
||||
if (req.state == KeyVerificationState.done) {
|
||||
for (var i = 0; i < 12; i++) {
|
||||
if (await client.encryption.keyManager.isCached()) {
|
||||
break;
|
||||
}
|
||||
await Future.delayed(Duration(seconds: 1));
|
||||
}
|
||||
final timeline = await event.room.getTimeline();
|
||||
timeline.requestKeys();
|
||||
timeline.cancelSubscriptions();
|
||||
}
|
||||
};
|
||||
await Navigator.of(context).push(
|
||||
AppRoute.defaultRoute(
|
||||
context,
|
||||
KeyVerificationView(request: req),
|
||||
),
|
||||
);
|
||||
} else {
|
||||
await SimpleDialogs(context).tryRequestWithLoadingDialog(
|
||||
event.getDisplayEvent(timeline).requestKey());
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (event.type == EventTypes.Unknown) {
|
||||
|
|
@ -137,12 +170,13 @@ class Message extends StatelessWidget {
|
|||
RaisedButton(
|
||||
color: color.withAlpha(100),
|
||||
child: Text(
|
||||
L10n.of(context).requestPermission,
|
||||
client.isUnknownSession &&
|
||||
client.encryption.crossSigning.enabled
|
||||
? L10n.of(context).verify
|
||||
: L10n.of(context).requestPermission,
|
||||
style: TextStyle(color: textColor),
|
||||
),
|
||||
onPressed: () => SimpleDialogs(context)
|
||||
.tryRequestWithLoadingDialog(
|
||||
displayEvent.requestKey()),
|
||||
onPressed: () => _verifyOrRequestKey(context),
|
||||
),
|
||||
SizedBox(height: 4),
|
||||
Opacity(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue