[Room] Fix create megolm session
This commit is contained in:
parent
c57c7d6719
commit
391a9af2ba
|
@ -93,38 +93,40 @@ class Room {
|
||||||
Future<void> createOutboundGroupSession() async {
|
Future<void> createOutboundGroupSession() async {
|
||||||
await clearOutboundGroupSession(wipe: true);
|
await clearOutboundGroupSession(wipe: true);
|
||||||
List<DeviceKeys> deviceKeys = await getUserDeviceKeys();
|
List<DeviceKeys> deviceKeys = await getUserDeviceKeys();
|
||||||
_outboundGroupSessionDevices = [];
|
olm.OutboundGroupSession outboundGroupSession;
|
||||||
|
List<String> outboundGroupSessionDevices = [];
|
||||||
for (DeviceKeys keys in deviceKeys) {
|
for (DeviceKeys keys in deviceKeys) {
|
||||||
if (!keys.blocked) _outboundGroupSessionDevices.add(keys.deviceId);
|
if (!keys.blocked) outboundGroupSessionDevices.add(keys.deviceId);
|
||||||
}
|
}
|
||||||
_outboundGroupSessionDevices.sort();
|
outboundGroupSessionDevices.sort();
|
||||||
try {
|
try {
|
||||||
_outboundGroupSession = olm.OutboundGroupSession();
|
outboundGroupSession = olm.OutboundGroupSession();
|
||||||
_outboundGroupSession.create();
|
outboundGroupSession.create();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
_outboundGroupSession = null;
|
outboundGroupSession = null;
|
||||||
print("[LibOlm] Unable to create new outboundGroupSession: " +
|
print("[LibOlm] Unable to create new outboundGroupSession: " +
|
||||||
e.toString());
|
e.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_outboundGroupSession == null) return;
|
if (outboundGroupSession == null) return;
|
||||||
|
|
||||||
await _storeOutboundGroupSession();
|
|
||||||
// Add as an inboundSession to the [sessionKeys].
|
// Add as an inboundSession to the [sessionKeys].
|
||||||
Map<String, dynamic> rawSession = {
|
Map<String, dynamic> rawSession = {
|
||||||
"algorithm": "m.megolm.v1.aes-sha2",
|
"algorithm": "m.megolm.v1.aes-sha2",
|
||||||
"room_id": this.id,
|
"room_id": this.id,
|
||||||
"session_id": _outboundGroupSession.session_id(),
|
"session_id": outboundGroupSession.session_id(),
|
||||||
"session_key": _outboundGroupSession.session_key(),
|
"session_key": outboundGroupSession.session_key(),
|
||||||
};
|
};
|
||||||
setSessionKey(rawSession["session_id"], rawSession);
|
setSessionKey(rawSession["session_id"], rawSession);
|
||||||
try {
|
try {
|
||||||
await client.sendToDevice(deviceKeys, "m.room_key", rawSession);
|
await client.sendToDevice(deviceKeys, "m.room_key", rawSession);
|
||||||
|
_outboundGroupSession = outboundGroupSession;
|
||||||
|
_outboundGroupSessionDevices = outboundGroupSessionDevices;
|
||||||
|
await _storeOutboundGroupSession();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print(
|
print(
|
||||||
"[LibOlm] Unable to send the session key to the participating devices: " +
|
"[LibOlm] Unable to send the session key to the participating devices: " +
|
||||||
e.toString());
|
e.toString());
|
||||||
await clearOutboundGroupSession(wipe: true);
|
await this.clearOutboundGroupSession();
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue