From 63d4b3ffd1c194dc087e3b6be82da8dd8fdaa78b Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Wed, 28 Jan 2026 00:11:32 +0000 Subject: [PATCH] feat(dm): implement incremental delivery for direct messages - Added `onMessage` callback to `NostrClient.listDirectMessages` to stream decrypted messages. - Updated `NostrService.loadDirectMessages` to use the callback and trigger `applyDirectMessage` incrementally. - Updated `ProfileModalController` to allow rendering updates during the initial load if the reason is `load-incremental`. - Verified changes with existing tests and code review. Co-authored-by: PR0M3TH3AN <53631862+PR0M3TH3AN@users.noreply.github.com> --- js/nostr/client.js | 7 +++++++ js/services/nostrService.js | 3 +++ js/ui/profileModalController.js | 5 ++++- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/js/nostr/client.js b/js/nostr/client.js index 19c31fb7..05511947 100644 --- a/js/nostr/client.js +++ b/js/nostr/client.js @@ -4480,6 +4480,13 @@ export class NostrClient { }); if (decrypted?.ok) { messages.push(decrypted); + if (typeof options.onMessage === "function") { + try { + options.onMessage(decrypted); + } catch (error) { + devLogger.warn("[nostr] onMessage callback threw:", error); + } + } } } catch (error) { devLogger.warn("[nostr] Failed to decrypt DM event during list.", { diff --git a/js/services/nostrService.js b/js/services/nostrService.js index 9f8ce604..5d7dfe7e 100644 --- a/js/services/nostrService.js +++ b/js/services/nostrService.js @@ -958,6 +958,9 @@ export class NostrService { ...options, limit: resolvedLimit, decryptLimit: resolvedDecryptLimit, + onMessage: (message) => { + this.applyDirectMessage(message, { reason: "load-incremental" }); + }, }); } catch (error) { userLogger.warn("[nostrService] Failed to load direct messages", error); diff --git a/js/ui/profileModalController.js b/js/ui/profileModalController.js index a03fec90..46d0edc5 100644 --- a/js/ui/profileModalController.js +++ b/js/ui/profileModalController.js @@ -4970,7 +4970,10 @@ export class ProfileModalController { } handleDirectMessagesUpdated(detail = {}) { - if (this.activeMessagesRequest) { + if ( + this.activeMessagesRequest && + detail?.reason !== "load-incremental" + ) { return; }