From 21c1d705a18bc30500c211596fff9638329f5861 Mon Sep 17 00:00:00 2001 From: Vitor Pamplona Date: Fri, 3 Oct 2025 09:18:53 -0400 Subject: [PATCH] Only downloads DMs if the account is writeable --- .../AccountGiftWrapsEoseManager.kt | 20 ++++++++++++------- .../datasource/ChatroomFilterSubAssembler.kt | 8 +++++++- .../DMsFromUserFilterSubAssembler.kt | 16 +++++++++------ 3 files changed, 30 insertions(+), 14 deletions(-) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/relayClient/reqCommand/account/nip59GiftWraps/AccountGiftWrapsEoseManager.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/relayClient/reqCommand/account/nip59GiftWraps/AccountGiftWrapsEoseManager.kt index 38c677f4d..79a45b409 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/relayClient/reqCommand/account/nip59GiftWraps/AccountGiftWrapsEoseManager.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/relayClient/reqCommand/account/nip59GiftWraps/AccountGiftWrapsEoseManager.kt @@ -42,14 +42,20 @@ class AccountGiftWrapsEoseManager( override fun updateFilter( key: AccountQueryState, since: SincePerRelayMap?, - ): List = - key.account.dmRelays.flow.value.flatMap { relay -> - filterGiftWrapsToPubkey( - relay = relay, - pubkey = user(key).pubkeyHex, - since = since?.get(relay)?.time, - ) + ): List { + // Only loads DMs if the account is writeable + return if (key.account.isWriteable()) { + key.account.dmRelays.flow.value.flatMap { relay -> + filterGiftWrapsToPubkey( + relay = relay, + pubkey = user(key).pubkeyHex, + since = since?.get(relay)?.time, + ) + } + } else { + emptyList() } + } val userJobMap = mutableMapOf>() diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/privateDM/datasource/ChatroomFilterSubAssembler.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/privateDM/datasource/ChatroomFilterSubAssembler.kt index f875f58b6..c62456059 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/privateDM/datasource/ChatroomFilterSubAssembler.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/privateDM/datasource/ChatroomFilterSubAssembler.kt @@ -23,6 +23,7 @@ package com.vitorpamplona.amethyst.ui.screen.loggedIn.chats.privateDM.datasource import com.vitorpamplona.amethyst.service.relayClient.eoseManagers.PerUserAndFollowListEoseManager import com.vitorpamplona.amethyst.service.relays.SincePerRelayMap import com.vitorpamplona.quartz.nip01Core.relay.client.INostrClient +import com.vitorpamplona.quartz.nip01Core.relay.client.pool.RelayBasedFilter class ChatroomFilterSubAssembler( client: INostrClient, @@ -31,7 +32,12 @@ class ChatroomFilterSubAssembler( override fun updateFilter( key: ChatroomQueryState, since: SincePerRelayMap?, - ) = filterNip04DMs(key.room.users, key.account, since) + ): List? = + if (key.account.isWriteable()) { + filterNip04DMs(key.room.users, key.account, since) + } else { + emptyList() + } override fun user(key: ChatroomQueryState) = key.account.userProfile() diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/rooms/datasource/DMsFromUserFilterSubAssembler.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/rooms/datasource/DMsFromUserFilterSubAssembler.kt index 30a34dc59..f57593127 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/rooms/datasource/DMsFromUserFilterSubAssembler.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/rooms/datasource/DMsFromUserFilterSubAssembler.kt @@ -40,12 +40,16 @@ class DMsFromUserFilterSubAssembler( key: ChatroomListState, since: SincePerRelayMap?, ): List? = - key.account.homeRelays.flow.value.map { - filterNip04DMsFromMe(key.account.userProfile(), it, since?.get(it)?.time) - } + - key.account.dmRelays.flow.value.map { - filterNip04DMsToMe(key.account.userProfile(), it, since?.get(it)?.time) - } + if (key.account.isWriteable()) { + key.account.homeRelays.flow.value.map { + filterNip04DMsFromMe(key.account.userProfile(), it, since?.get(it)?.time) + } + + key.account.dmRelays.flow.value.map { + filterNip04DMsToMe(key.account.userProfile(), it, since?.get(it)?.time) + } + } else { + emptyList() + } override fun user(key: ChatroomListState) = key.account.userProfile()