feat: Allow auto request keys via key sharing requests
This commit is contained in:
		
							parent
							
								
									2e912d1a4f
								
							
						
					
					
						commit
						81e55ade67
					
				|  | @ -226,7 +226,13 @@ class KeyManager { | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   /// Attempt auto-request for a key |   /// Attempt auto-request for a key | ||||||
|   void maybeAutoRequest(String roomId, String sessionId, String senderKey) { |   void maybeAutoRequest( | ||||||
|  |     String roomId, | ||||||
|  |     String sessionId, | ||||||
|  |     String senderKey, { | ||||||
|  |     bool tryOnlineBackup = true, | ||||||
|  |     bool onlineKeyBackupOnly = true, | ||||||
|  |   }) { | ||||||
|     final room = client.getRoomById(roomId); |     final room = client.getRoomById(roomId); | ||||||
|     final requestIdent = '$roomId|$sessionId|$senderKey'; |     final requestIdent = '$roomId|$sessionId|$senderKey'; | ||||||
|     if (room != null && |     if (room != null && | ||||||
|  | @ -234,8 +240,13 @@ class KeyManager { | ||||||
|         !client.isUnknownSession) { |         !client.isUnknownSession) { | ||||||
|       // do e2ee recovery |       // do e2ee recovery | ||||||
|       _requestedSessionIds.add(requestIdent); |       _requestedSessionIds.add(requestIdent); | ||||||
|       runInRoot( |       runInRoot(() => request( | ||||||
|           () => request(room, sessionId, senderKey, onlineKeyBackupOnly: true)); |             room, | ||||||
|  |             sessionId, | ||||||
|  |             senderKey, | ||||||
|  |             tryOnlineBackup: tryOnlineBackup, | ||||||
|  |             onlineKeyBackupOnly: onlineKeyBackupOnly, | ||||||
|  |           )); | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -333,14 +333,22 @@ class Timeline { | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   /// Request the keys for undecryptable events of this timeline |   /// Request the keys for undecryptable events of this timeline | ||||||
|   void requestKeys() { |   void requestKeys({ | ||||||
|  |     bool tryOnlineBackup = true, | ||||||
|  |     bool onlineKeyBackupOnly = true, | ||||||
|  |   }) { | ||||||
|     for (final event in events) { |     for (final event in events) { | ||||||
|       if (event.type == EventTypes.Encrypted && |       if (event.type == EventTypes.Encrypted && | ||||||
|           event.messageType == MessageTypes.BadEncrypted && |           event.messageType == MessageTypes.BadEncrypted && | ||||||
|           event.content['can_request_session'] == true) { |           event.content['can_request_session'] == true) { | ||||||
|         try { |         try { | ||||||
|           room.client.encryption?.keyManager.maybeAutoRequest(room.id, |           room.client.encryption?.keyManager.maybeAutoRequest( | ||||||
|               event.content['session_id'], event.content['sender_key']); |             room.id, | ||||||
|  |             event.content['session_id'], | ||||||
|  |             event.content['sender_key'], | ||||||
|  |             tryOnlineBackup: tryOnlineBackup, | ||||||
|  |             onlineKeyBackupOnly: onlineKeyBackupOnly, | ||||||
|  |           ); | ||||||
|         } catch (_) { |         } catch (_) { | ||||||
|           // dispose |           // dispose | ||||||
|         } |         } | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue