also load session keys when requesting history
This commit is contained in:
		
							parent
							
								
									9971e7377e
								
							
						
					
					
						commit
						03beffbb46
					
				|  | @ -1024,12 +1024,7 @@ class Room { | ||||||
|     if (onHistoryReceived != null) onHistoryReceived(); |     if (onHistoryReceived != null) onHistoryReceived(); | ||||||
|     prev_batch = resp['end']; |     prev_batch = resp['end']; | ||||||
| 
 | 
 | ||||||
|     final dbActions = <Future<dynamic> Function()>[]; |     final loadFn = () async { | ||||||
|     if (client.database != null) { |  | ||||||
|       dbActions.add( |  | ||||||
|           () => client.database.setRoomPrevBatch(prev_batch, client.id, id)); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|       if (!(resp['chunk'] is List<dynamic> && |       if (!(resp['chunk'] is List<dynamic> && | ||||||
|           resp['chunk'].length > 0 && |           resp['chunk'].length > 0 && | ||||||
|           resp['end'] is String)) return; |           resp['end'] is String)) return; | ||||||
|  | @ -1043,11 +1038,14 @@ class Room { | ||||||
|             content: state, |             content: state, | ||||||
|             sortOrder: oldSortOrder, |             sortOrder: oldSortOrder, | ||||||
|           ).decrypt(this); |           ).decrypt(this); | ||||||
|         client.onEvent.add(eventUpdate); |           if (eventUpdate.eventType == 'm.room.encrypted' && | ||||||
|         if (client.database != null) { |               client.database != null) { | ||||||
|           dbActions.add( |             await loadInboundGroupSessionKey( | ||||||
|               () => client.database.storeEventUpdate(client.id, eventUpdate)); |                 state['content']['session_id'], state['content']['sender_key']); | ||||||
|  |             eventUpdate = eventUpdate.decrypt(this); | ||||||
|           } |           } | ||||||
|  |           client.onEvent.add(eventUpdate); | ||||||
|  |           await client.database?.storeEventUpdate(client.id, eventUpdate); | ||||||
|         } |         } | ||||||
|       } |       } | ||||||
| 
 | 
 | ||||||
|  | @ -1060,22 +1058,27 @@ class Room { | ||||||
|           content: hist, |           content: hist, | ||||||
|           sortOrder: oldSortOrder, |           sortOrder: oldSortOrder, | ||||||
|         ).decrypt(this); |         ).decrypt(this); | ||||||
|  |         if (eventUpdate.eventType == 'm.room.encrypted' && | ||||||
|  |             client.database != null) { | ||||||
|  |           await loadInboundGroupSessionKey( | ||||||
|  |               hist['content']['session_id'], hist['content']['sender_key']); | ||||||
|  |           eventUpdate = eventUpdate.decrypt(this); | ||||||
|  |         } | ||||||
|         client.onEvent.add(eventUpdate); |         client.onEvent.add(eventUpdate); | ||||||
|  |         await client.database?.storeEventUpdate(client.id, eventUpdate); | ||||||
|  |       } | ||||||
|  |     }; | ||||||
|  | 
 | ||||||
|     if (client.database != null) { |     if (client.database != null) { | ||||||
|         dbActions.add( |  | ||||||
|             () => client.database.storeEventUpdate(client.id, eventUpdate)); |  | ||||||
|       } |  | ||||||
|     } |  | ||||||
|     if (client.database != null) { |  | ||||||
|       dbActions.add( |  | ||||||
|           () => client.database.setRoomPrevBatch(resp['end'], client.id, id)); |  | ||||||
|     } |  | ||||||
|       await client.database?.transaction(() async { |       await client.database?.transaction(() async { | ||||||
|       for (final f in dbActions) { |         await client.database.setRoomPrevBatch(prev_batch, client.id, id); | ||||||
|         await f(); |         await loadFn(); | ||||||
|       } |         await client.database.setRoomPrevBatch(resp['end'], client.id, id); | ||||||
|         await updateSortOrder(); |         await updateSortOrder(); | ||||||
|       }); |       }); | ||||||
|  |     } else { | ||||||
|  |       await loadFn(); | ||||||
|  |     } | ||||||
|     client.onRoomUpdate.add( |     client.onRoomUpdate.add( | ||||||
|       RoomUpdate( |       RoomUpdate( | ||||||
|         id: id, |         id: id, | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue