Removes dependency on the application class from DecryptAndIndexProcessor

This commit is contained in:
Vitor Pamplona
2025-09-09 12:17:28 -04:00
parent dc97e5004e
commit f9590055b0
4 changed files with 15 additions and 5 deletions

View File

@@ -136,6 +136,7 @@ import com.vitorpamplona.quartz.nip01Core.tags.hashtags.hashtags
import com.vitorpamplona.quartz.nip01Core.tags.people.hasAnyTaggedUser import com.vitorpamplona.quartz.nip01Core.tags.people.hasAnyTaggedUser
import com.vitorpamplona.quartz.nip01Core.tags.people.taggedUserIds import com.vitorpamplona.quartz.nip01Core.tags.people.taggedUserIds
import com.vitorpamplona.quartz.nip01Core.tags.references.references import com.vitorpamplona.quartz.nip01Core.tags.references.references
import com.vitorpamplona.quartz.nip03Timestamp.VerificationStateCache
import com.vitorpamplona.quartz.nip03Timestamp.ots.okhttp.OkHttpOtsResolverBuilder import com.vitorpamplona.quartz.nip03Timestamp.ots.okhttp.OkHttpOtsResolverBuilder
import com.vitorpamplona.quartz.nip04Dm.PrivateDMCache import com.vitorpamplona.quartz.nip04Dm.PrivateDMCache
import com.vitorpamplona.quartz.nip04Dm.messages.PrivateDmEvent import com.vitorpamplona.quartz.nip04Dm.messages.PrivateDmEvent
@@ -225,6 +226,7 @@ class Account(
val signer: NostrSigner, val signer: NostrSigner,
val geolocationFlow: StateFlow<LocationState.LocationResult>, val geolocationFlow: StateFlow<LocationState.LocationResult>,
val nwcFilterAssembler: NWCPaymentFilterAssembler, val nwcFilterAssembler: NWCPaymentFilterAssembler,
val otsVerifCache: VerificationStateCache,
val cache: LocalCache, val cache: LocalCache,
val client: INostrClient, val client: INostrClient,
val scope: CoroutineScope, val scope: CoroutineScope,
@@ -335,7 +337,7 @@ class Account(
val otsState = OtsState(signer, cache, otsResolverBuilder, scope, settings) val otsState = OtsState(signer, cache, otsResolverBuilder, scope, settings)
val newNotesPreProcessor = EventProcessor(this, LocalCache) val newNotesPreProcessor = EventProcessor(this, otsVerifCache, cache)
val feedDecryptionCaches = val feedDecryptionCaches =
FeedDecryptionCaches( FeedDecryptionCaches(

View File

@@ -33,6 +33,7 @@ import com.vitorpamplona.quartz.nip01Core.core.toHexKey
import com.vitorpamplona.quartz.nip01Core.relay.client.INostrClient import com.vitorpamplona.quartz.nip01Core.relay.client.INostrClient
import com.vitorpamplona.quartz.nip01Core.signers.NostrSigner import com.vitorpamplona.quartz.nip01Core.signers.NostrSigner
import com.vitorpamplona.quartz.nip01Core.signers.NostrSignerInternal import com.vitorpamplona.quartz.nip01Core.signers.NostrSignerInternal
import com.vitorpamplona.quartz.nip03Timestamp.VerificationStateCache
import com.vitorpamplona.quartz.nip55AndroidSigner.client.NostrSignerExternal import com.vitorpamplona.quartz.nip55AndroidSigner.client.NostrSignerExternal
import kotlinx.coroutines.CoroutineExceptionHandler import kotlinx.coroutines.CoroutineExceptionHandler
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
@@ -94,6 +95,7 @@ class AccountCacheState(
signer = signer, signer = signer,
geolocationFlow = geolocationFlow, geolocationFlow = geolocationFlow,
nwcFilterAssembler = nwcFilterAssembler, nwcFilterAssembler = nwcFilterAssembler,
otsVerifCache = VerificationStateCache(),
cache = cache, cache = cache,
client = client, client = client,
scope = scope =

View File

@@ -106,6 +106,7 @@ import com.vitorpamplona.quartz.nip01Core.signers.SignerExceptions
import com.vitorpamplona.quartz.nip01Core.tags.addressables.Address import com.vitorpamplona.quartz.nip01Core.tags.addressables.Address
import com.vitorpamplona.quartz.nip01Core.tags.people.PubKeyReferenceTag import com.vitorpamplona.quartz.nip01Core.tags.people.PubKeyReferenceTag
import com.vitorpamplona.quartz.nip01Core.tags.people.isTaggedUser import com.vitorpamplona.quartz.nip01Core.tags.people.isTaggedUser
import com.vitorpamplona.quartz.nip03Timestamp.VerificationStateCache
import com.vitorpamplona.quartz.nip11RelayInfo.Nip11RelayInformation import com.vitorpamplona.quartz.nip11RelayInfo.Nip11RelayInformation
import com.vitorpamplona.quartz.nip17Dm.base.ChatroomKeyable import com.vitorpamplona.quartz.nip17Dm.base.ChatroomKeyable
import com.vitorpamplona.quartz.nip18Reposts.GenericRepostEvent import com.vitorpamplona.quartz.nip18Reposts.GenericRepostEvent
@@ -1698,6 +1699,7 @@ fun mockAccountViewModel(): AccountViewModel {
signer = NostrSignerInternal(keyPair), signer = NostrSignerInternal(keyPair),
geolocationFlow = MutableStateFlow<LocationState.LocationResult>(LocationState.LocationResult.Loading), geolocationFlow = MutableStateFlow<LocationState.LocationResult>(LocationState.LocationResult.Loading),
nwcFilterAssembler = nwcFilters, nwcFilterAssembler = nwcFilters,
otsVerifCache = VerificationStateCache(),
cache = LocalCache, cache = LocalCache,
client = client, client = client,
scope = scope, scope = scope,
@@ -1739,6 +1741,7 @@ fun mockVitorAccountViewModel(): AccountViewModel {
signer = NostrSignerInternal(keyPair), signer = NostrSignerInternal(keyPair),
geolocationFlow = MutableStateFlow<LocationState.LocationResult>(LocationState.LocationResult.Loading), geolocationFlow = MutableStateFlow<LocationState.LocationResult>(LocationState.LocationResult.Loading),
nwcFilterAssembler = nwcFilters, nwcFilterAssembler = nwcFilters,
otsVerifCache = VerificationStateCache(),
cache = LocalCache, cache = LocalCache,
client = EmptyNostrClient, client = EmptyNostrClient,
scope = scope, scope = scope,

View File

@@ -21,7 +21,6 @@
package com.vitorpamplona.amethyst.ui.screen.loggedIn package com.vitorpamplona.amethyst.ui.screen.loggedIn
import android.util.Log import android.util.Log
import com.vitorpamplona.amethyst.Amethyst
import com.vitorpamplona.amethyst.model.Account import com.vitorpamplona.amethyst.model.Account
import com.vitorpamplona.amethyst.model.LocalCache import com.vitorpamplona.amethyst.model.LocalCache
import com.vitorpamplona.amethyst.model.Note import com.vitorpamplona.amethyst.model.Note
@@ -30,6 +29,8 @@ import com.vitorpamplona.quartz.experimental.ephemChat.chat.EphemeralChatEvent
import com.vitorpamplona.quartz.nip01Core.core.Event import com.vitorpamplona.quartz.nip01Core.core.Event
import com.vitorpamplona.quartz.nip01Core.core.IEvent import com.vitorpamplona.quartz.nip01Core.core.IEvent
import com.vitorpamplona.quartz.nip03Timestamp.OtsEvent import com.vitorpamplona.quartz.nip03Timestamp.OtsEvent
import com.vitorpamplona.quartz.nip03Timestamp.VerificationStateCache
import com.vitorpamplona.quartz.nip03Timestamp.ots.okhttp.OkHttpOtsResolverBuilder
import com.vitorpamplona.quartz.nip17Dm.base.ChatroomKeyable import com.vitorpamplona.quartz.nip17Dm.base.ChatroomKeyable
import com.vitorpamplona.quartz.nip28PublicChat.message.ChannelMessageEvent import com.vitorpamplona.quartz.nip28PublicChat.message.ChannelMessageEvent
import com.vitorpamplona.quartz.nip37Drafts.DraftWrapEvent import com.vitorpamplona.quartz.nip37Drafts.DraftWrapEvent
@@ -43,10 +44,11 @@ import kotlinx.coroutines.CancellationException
class EventProcessor( class EventProcessor(
private val account: Account, private val account: Account,
private val otsVerifCache: VerificationStateCache,
private val cache: LocalCache, private val cache: LocalCache,
) { ) {
private val chatHandler = ChatHandler(account.chatroomList) private val chatHandler = ChatHandler(account.chatroomList)
private val otsHandler = OtsEventHandler(account) private val otsHandler = OtsEventHandler(account.otsResolverBuilder, otsVerifCache)
private val draftHandler = DraftEventHandler(account, cache) private val draftHandler = DraftEventHandler(account, cache)
@@ -179,14 +181,15 @@ class ChatHandler(
} }
class OtsEventHandler( class OtsEventHandler(
private val account: Account, private val otsResolverBuilder: OkHttpOtsResolverBuilder,
private val otsVerifCache: VerificationStateCache,
) : EventHandler<OtsEvent> { ) : EventHandler<OtsEvent> {
override suspend fun add( override suspend fun add(
event: OtsEvent, event: OtsEvent,
eventNote: Note, eventNote: Note,
publicNote: Note, publicNote: Note,
) { ) {
Amethyst.instance.otsVerifCache.cacheVerify(event, account.otsResolverBuilder) otsVerifCache.cacheVerify(event, otsResolverBuilder)
} }
} }