handleEventUpdate method
Implementation
Future<void> handleEventUpdate(Event update) async {
final type = update.type.startsWith('m.key.verification.')
? update.type
: update.content.tryGet<String>('msgtype');
if (type == null ||
!type.startsWith('m.key.verification.') ||
client.verificationMethods.isEmpty) {
return;
}
if (type == EventTypes.KeyVerificationRequest) {
update.content['timestamp'] =
update.originServerTs.millisecondsSinceEpoch;
}
final transactionId =
KeyVerification.getTransactionId(update.content) ?? update.eventId;
final req = _requests[transactionId];
if (req != null) {
final otherDeviceId = update.content.tryGet<String>('from_device');
if (update.senderId != client.userID) {
await req.handlePayload(type, update.content, update.eventId);
} else if (update.senderId == client.userID &&
otherDeviceId != null &&
otherDeviceId != client.deviceID) {
// okay, another of our devices answered
req.otherDeviceAccepted();
req.dispose();
_requests.remove(transactionId);
}
} else if (update.senderId != client.userID) {
if (!{EventTypes.KeyVerificationRequest, EventTypes.KeyVerificationStart}
.contains(type)) {
return; // we can only start on these
}
final room = client.getRoomById(update.roomId!) ??
Room(id: update.roomId!, client: client);
final newKeyRequest = KeyVerification(
encryption: encryption,
userId: update.senderId,
room: room,
);
await newKeyRequest.handlePayload(
type,
update.content,
update.eventId,
);
if (newKeyRequest.state != KeyVerificationState.askAccept) {
// something went wrong, let's just dispose the request
newKeyRequest.dispose();
} else {
// new request! Let's notify it and stuff
_requests[transactionId] = newKeyRequest;
client.onKeyVerificationRequest.add(newKeyRequest);
}
}
}