Moves the OTS processor from Account's decrypt process to Application since it doesn't need the account information.

This commit is contained in:
Vitor Pamplona
2025-09-11 11:27:29 -04:00
parent bb9a03ec5b
commit 90a5c15ee9
3 changed files with 55 additions and 23 deletions

View File

@@ -334,11 +334,10 @@ class Account(
privacyState::shouldUseTorForMoneyOperations,
Amethyst.instance.otsBlockHeightCache,
)
val newNotesPreProcessor = EventProcessor(this, cache)
val otsState = OtsState(signer, cache, otsResolverBuilder, scope, settings)
val newNotesPreProcessor = EventProcessor(this, otsVerifCache, cache)
val feedDecryptionCaches =
FeedDecryptionCaches(
peopleListCache = peopleListDecryptionCache,

View File

@@ -0,0 +1,54 @@
/**
* Copyright (c) 2025 Vitor Pamplona
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
* Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package com.vitorpamplona.amethyst.model.nip03Timestamp
import com.vitorpamplona.amethyst.model.LocalCache
import com.vitorpamplona.amethyst.model.Note
import com.vitorpamplona.quartz.nip03Timestamp.OtsEvent
import com.vitorpamplona.quartz.nip03Timestamp.VerificationStateCache
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.flow.stateIn
class IncomingOtsEventVerifier(
private val otsVerifCache: VerificationStateCache,
private val cache: LocalCache,
private val scope: CoroutineScope,
) {
val verifying =
cache.live.newEventBundles
.onEach { newNotes ->
newNotes.forEach(::consume)
}.stateIn(
scope,
SharingStarted.Eagerly,
null,
)
fun consume(note: Note) {
note.event?.let { event ->
if (event is OtsEvent) {
otsVerifCache.cacheVerify(event)
}
}
}
}

View File

@@ -28,9 +28,6 @@ import com.vitorpamplona.amethyst.model.privateChats.ChatroomList
import com.vitorpamplona.quartz.experimental.ephemChat.chat.EphemeralChatEvent
import com.vitorpamplona.quartz.nip01Core.core.Event
import com.vitorpamplona.quartz.nip01Core.core.IEvent
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.nip28PublicChat.message.ChannelMessageEvent
import com.vitorpamplona.quartz.nip37Drafts.DraftWrapEvent
@@ -44,12 +41,9 @@ import kotlinx.coroutines.CancellationException
class EventProcessor(
private val account: Account,
private val otsVerifCache: VerificationStateCache,
private val cache: LocalCache,
) {
private val chatHandler = ChatHandler(account.chatroomList)
private val otsHandler = OtsEventHandler(account.otsResolverBuilder, otsVerifCache)
private val draftHandler = DraftEventHandler(account, cache)
private val giftWrapHandler = GiftWrapEventHandler(account, cache, this)
@@ -75,7 +69,6 @@ class EventProcessor(
) {
when (event) {
is ChatroomKeyable -> chatHandler.add(event, eventNote, publicNote)
is OtsEvent -> otsHandler.add(event, eventNote, publicNote)
is DraftWrapEvent -> draftHandler.add(event, eventNote, publicNote)
is GiftWrapEvent -> giftWrapHandler.add(event, eventNote, publicNote)
is SealedRumorEvent -> sealHandler.add(event, eventNote, publicNote)
@@ -99,7 +92,6 @@ class EventProcessor(
) {
when (event) {
is ChatroomKeyable -> chatHandler.delete(event, note)
is OtsEvent -> otsHandler.delete(event, note)
is DraftWrapEvent -> draftHandler.delete(event, note)
is GiftWrapEvent -> giftWrapHandler.delete(event, note)
is SealedRumorEvent -> sealHandler.delete(event, note)
@@ -180,19 +172,6 @@ class ChatHandler(
}
}
class OtsEventHandler(
private val otsResolverBuilder: OkHttpOtsResolverBuilder,
private val otsVerifCache: VerificationStateCache,
) : EventHandler<OtsEvent> {
override suspend fun add(
event: OtsEvent,
eventNote: Note,
publicNote: Note,
) {
otsVerifCache.cacheVerify(event, otsResolverBuilder)
}
}
class DraftEventHandler(
private val account: Account,
private val cache: LocalCache,