[Room] Fix restore session
This commit is contained in:
parent
949146cbf9
commit
066dcbf395
|
@ -952,6 +952,10 @@ class Client {
|
|||
|
||||
/// Use this method only for testing utilities!
|
||||
void handleSync(dynamic sync) {
|
||||
if (sync['to_device'] is Map<String, dynamic> &&
|
||||
sync['to_device']['events'] is List<dynamic>) {
|
||||
_handleToDeviceEvents(sync['to_device']['events']);
|
||||
}
|
||||
if (sync['rooms'] is Map<String, dynamic>) {
|
||||
if (sync['rooms']['join'] is Map<String, dynamic>) {
|
||||
_handleRooms(sync['rooms']['join'], Membership.join);
|
||||
|
@ -971,16 +975,18 @@ class Client {
|
|||
sync['account_data']['events'] is List<dynamic>) {
|
||||
_handleGlobalEvents(sync['account_data']['events'], 'account_data');
|
||||
}
|
||||
if (sync['to_device'] is Map<String, dynamic> &&
|
||||
sync['to_device']['events'] is List<dynamic>) {
|
||||
_handleToDeviceEvents(sync['to_device']['events']);
|
||||
}
|
||||
if (sync['device_lists'] is Map<String, dynamic>) {
|
||||
_handleDeviceListsEvents(sync['device_lists']);
|
||||
}
|
||||
if (sync['device_one_time_keys_count'] is Map<String, dynamic>) {
|
||||
_handleDeviceOneTimeKeysCount(sync['device_one_time_keys_count']);
|
||||
}
|
||||
while (_pendingToDeviceEvents.isNotEmpty) {
|
||||
_updateRoomsByToDeviceEvent(
|
||||
_pendingToDeviceEvents.removeLast(),
|
||||
addToPendingIfNotFound: false,
|
||||
);
|
||||
}
|
||||
onSync.add(sync);
|
||||
}
|
||||
|
||||
|
@ -1319,23 +1325,28 @@ class Client {
|
|||
if (eventUpdate.type == 'timeline') _sortRooms();
|
||||
}
|
||||
|
||||
void _updateRoomsByToDeviceEvent(ToDeviceEvent toDeviceEvent) {
|
||||
final List<ToDeviceEvent> _pendingToDeviceEvents = [];
|
||||
|
||||
void _updateRoomsByToDeviceEvent(ToDeviceEvent toDeviceEvent,
|
||||
{addToPendingIfNotFound = true}) async {
|
||||
try {
|
||||
switch (toDeviceEvent.type) {
|
||||
case 'm.room_key':
|
||||
case 'm.forwarded_room_key':
|
||||
var room = getRoomById(toDeviceEvent.content['room_id']);
|
||||
if (room != null) {
|
||||
final roomId = toDeviceEvent.content['room_id'];
|
||||
var room = getRoomById(roomId);
|
||||
if (room == null && addToPendingIfNotFound) {
|
||||
_pendingToDeviceEvents.add(toDeviceEvent);
|
||||
}
|
||||
final String sessionId = toDeviceEvent.content['session_id'];
|
||||
if (room != null) {
|
||||
if (toDeviceEvent.type == 'm.room_key' &&
|
||||
userDeviceKeys.containsKey(toDeviceEvent.sender) &&
|
||||
userDeviceKeys[toDeviceEvent.sender].deviceKeys.containsKey(
|
||||
toDeviceEvent.content['requesting_device_id'])) {
|
||||
userDeviceKeys[toDeviceEvent.sender]
|
||||
.deviceKeys
|
||||
.containsKey(toDeviceEvent.content['requesting_device_id'])) {
|
||||
toDeviceEvent.content['sender_claimed_ed25519_key'] =
|
||||
userDeviceKeys[toDeviceEvent.sender]
|
||||
.deviceKeys[
|
||||
toDeviceEvent.content['requesting_device_id']]
|
||||
.deviceKeys[toDeviceEvent.content['requesting_device_id']]
|
||||
.ed25519Key;
|
||||
}
|
||||
room.setSessionKey(
|
||||
|
@ -1344,7 +1355,7 @@ class Client {
|
|||
forwarded: toDeviceEvent.type == 'm.forwarded_room_key',
|
||||
);
|
||||
if (toDeviceEvent.type == 'm.forwarded_room_key') {
|
||||
sendToDevice(
|
||||
await sendToDevice(
|
||||
[],
|
||||
'm.room_key_request',
|
||||
{
|
||||
|
@ -1356,8 +1367,6 @@ class Client {
|
|||
encrypted: false,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'm.room_key_request':
|
||||
if (!toDeviceEvent.content.containsKey('body')) break;
|
||||
|
@ -1376,7 +1385,7 @@ class Client {
|
|||
if (deviceKeys.userId == userID &&
|
||||
deviceKeys.verified &&
|
||||
!deviceKeys.blocked) {
|
||||
roomKeyRequest.forwardKey();
|
||||
await roomKeyRequest.forwardKey();
|
||||
} else {
|
||||
onRoomKeyRequest.add(roomKeyRequest);
|
||||
}
|
||||
|
|
|
@ -926,7 +926,7 @@ class Room {
|
|||
return;
|
||||
}
|
||||
|
||||
void restoreGroupSessionKeys() async {
|
||||
Future<void> restoreGroupSessionKeys() async {
|
||||
// Restore the inbound and outbound session keys
|
||||
if (client.encryptionEnabled && client.storeAPI != null) {
|
||||
final String outboundGroupSessionPickle = await client.storeAPI.getItem(
|
||||
|
@ -970,6 +970,7 @@ class Room {
|
|||
json.encode(sessionKeys));
|
||||
_tryAgainDecryptLastMessage();
|
||||
_fullyRestored = true;
|
||||
return;
|
||||
}
|
||||
|
||||
bool _fullyRestored = false;
|
||||
|
|
Loading…
Reference in a new issue