git » sdk » commit 8579964

OMEMO: Use contact device list cache instead of requesting every time we send a message

author Matthew Wild
2025-05-09 10:43:53 UTC
committer Stephen Paul Weber
2025-09-29 13:43:04 UTC
parent 0a22cea7688bef1a5e7a924f62dd8970253ef9e4

OMEMO: Use contact device list cache instead of requesting every time we send a message

doc/OMEMO.md +1 -1
snikket/OMEMO.hx +10 -2

diff --git a/doc/OMEMO.md b/doc/OMEMO.md
index 48412bd..69fcc0c 100644
--- a/doc/OMEMO.md
+++ b/doc/OMEMO.md
@@ -15,7 +15,7 @@ compile with the NO_OMEMO flag.
 - [x] Allow non-OMEMO messages to recipients with no published keys when policy allows
 - [x] Encrypt outgoing messages to the sending account's other devices
 - [x] Persistence: IndexedDB (for web)
-- [ ] Use cache for remote contact devices
+- [x] Use cache for remote contact devices
 - [ ] Persistence: SQLite backend (for native)
 - [ ] API to control encryption of outgoing messages
 - [ ] API to determine cryptographic identity of message sender
diff --git a/snikket/OMEMO.hx b/snikket/OMEMO.hx
index d31c786..f28440f 100644
--- a/snikket/OMEMO.hx
+++ b/snikket/OMEMO.hx
@@ -956,14 +956,22 @@ class OMEMO {
 	}
 
 	private function getContactDevices(jid:JID):Promise<Array<Int>> {
+		final jidBareStr = jid.asBare().asString();
 		return new Promise((resolve, reject) -> {
 			// FIXME: Use local storage
-			final deviceListGet = new PubsubGet(jid.asString(), "eu.siacs.conversations.axolotl.devicelist");
+			var chat = client.getDirectChat(jidBareStr, false);
+			if(chat.omemoContactDeviceIDs != null) {
+				resolve(chat.omemoContactDeviceIDs);
+				return;
+			}
+			final deviceListGet = new PubsubGet(jidBareStr, "eu.siacs.conversations.axolotl.devicelist");
 			deviceListGet.onFinished(() -> {
 				final devices = deviceIdsFromPubsubItems(deviceListGet.getResult());
 				if(devices != null) {
-					resolve(devices??[]);
+					chat.omemoContactDeviceIDs = devices;
+					resolve(devices);
 				} else {
+					chat.omemoContactDeviceIDs = [];
 					reject("no-devices");
 				}
 			});