kopia lustrzana https://github.com/vitorpamplona/amethyst
only decrypt giftwrap in the dms screen
rodzic
58cf0d9f5d
commit
8c4af4ac85
|
@ -532,7 +532,6 @@ class Account(
|
|||
|
||||
if (privKey != null) return zapResponseEvent.response(privKey, pubKey)
|
||||
|
||||
Log.d("zaps", "decrypt with amber")
|
||||
AmberUtils.decrypt(zapResponseEvent.content, pubKey.toHexKey(), zapResponseEvent.id)
|
||||
if (AmberUtils.content.isBlank()) return null
|
||||
return zapResponseEvent.response(AmberUtils.content)
|
||||
|
@ -2529,9 +2528,12 @@ class Account(
|
|||
if (!isWriteable() && !loginWithAmber) return null
|
||||
|
||||
if (loginWithAmber) {
|
||||
AmberUtils.content = ""
|
||||
AmberUtils.decrypt(event.content, event.pubKey, event.id, SignerType.NIP44_DECRYPT)
|
||||
val decryptedContent = AmberUtils.cachedDecryptedContent[event.id] ?: ""
|
||||
var decryptedContent = AmberUtils.cachedDecryptedContent[event.id]
|
||||
if (decryptedContent == null) {
|
||||
AmberUtils.content = ""
|
||||
AmberUtils.decrypt(event.content, event.pubKey, event.id, SignerType.NIP44_DECRYPT)
|
||||
}
|
||||
decryptedContent = AmberUtils.cachedDecryptedContent[event.id] ?: ""
|
||||
if (decryptedContent.isEmpty()) return null
|
||||
return event.cachedGift(keyPair.pubKey, decryptedContent)
|
||||
}
|
||||
|
@ -2543,9 +2545,12 @@ class Account(
|
|||
if (!isWriteable() && !loginWithAmber) return null
|
||||
|
||||
if (loginWithAmber) {
|
||||
AmberUtils.content = ""
|
||||
AmberUtils.decrypt(event.content, event.pubKey, event.id, SignerType.NIP44_DECRYPT)
|
||||
val decryptedContent = AmberUtils.cachedDecryptedContent[event.id] ?: ""
|
||||
var decryptedContent = AmberUtils.cachedDecryptedContent[event.id]
|
||||
if (decryptedContent == null) {
|
||||
AmberUtils.content = ""
|
||||
AmberUtils.decrypt(event.content, event.pubKey, event.id, SignerType.NIP44_DECRYPT)
|
||||
}
|
||||
decryptedContent = AmberUtils.cachedDecryptedContent[event.id] ?: ""
|
||||
if (decryptedContent.isEmpty()) return null
|
||||
return event.cachedGossip(keyPair.pubKey, decryptedContent)
|
||||
}
|
||||
|
|
|
@ -30,9 +30,6 @@ import com.vitorpamplona.quartz.events.SealedGossipEvent
|
|||
import com.vitorpamplona.quartz.events.StatusEvent
|
||||
import com.vitorpamplona.quartz.events.TextNoteEvent
|
||||
import kotlinx.coroutines.DelicateCoroutinesApi
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.GlobalScope
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
object NostrAccountDataSource : NostrDataSource("AccountData") {
|
||||
lateinit var account: Account
|
||||
|
@ -157,17 +154,6 @@ object NostrAccountDataSource : NostrDataSource("AccountData") {
|
|||
event.cachedGift(privateKey)?.let {
|
||||
this.consume(it, relay)
|
||||
}
|
||||
} else if (account.loginWithAmber) {
|
||||
GlobalScope.launch(Dispatchers.IO) {
|
||||
val decryptedContent = AmberUtils.cachedDecryptedContent[event.id] ?: ""
|
||||
if (decryptedContent.isNotBlank()) {
|
||||
event.cachedGift(account.keyPair.pubKey, decryptedContent)?.let {
|
||||
consume(it, relay)
|
||||
}
|
||||
} else {
|
||||
AmberUtils.decryptGossip(event)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -177,17 +163,6 @@ object NostrAccountDataSource : NostrDataSource("AccountData") {
|
|||
event.cachedGossip(privateKey)?.let {
|
||||
LocalCache.justConsume(it, relay)
|
||||
}
|
||||
} else if (account.loginWithAmber) {
|
||||
GlobalScope.launch(Dispatchers.IO) {
|
||||
val decryptedContent = AmberUtils.cachedDecryptedContent[event.id] ?: ""
|
||||
if (decryptedContent.isNotBlank()) {
|
||||
event.cachedGossip(account.keyPair.pubKey, decryptedContent)?.let {
|
||||
LocalCache.justConsume(it, relay)
|
||||
}
|
||||
} else {
|
||||
AmberUtils.decryptGossip(event)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Don't store sealed gossips to avoid rebroadcasting by mistake.
|
||||
|
|
|
@ -100,27 +100,6 @@ class EventNotificationConsumer(private val applicationContext: Context) {
|
|||
event.cachedGift(key)?.let {
|
||||
unwrapAndConsume(it, account)
|
||||
}
|
||||
} else if (account.loginWithAmber) {
|
||||
var cached = AmberUtils.cachedDecryptedContent[event.id]
|
||||
if (cached == null) {
|
||||
AmberUtils.content = ""
|
||||
AmberUtils.decrypt(
|
||||
event.content,
|
||||
event.pubKey,
|
||||
event.id,
|
||||
SignerType.NIP44_DECRYPT
|
||||
)
|
||||
cached = AmberUtils.cachedDecryptedContent[event.id] ?: ""
|
||||
}
|
||||
|
||||
if (cached.isNotBlank()) {
|
||||
event.cachedGift(account.keyPair.pubKey, cached)?.let {
|
||||
LocalCache.justConsume(it, null)
|
||||
it
|
||||
}
|
||||
} else {
|
||||
null
|
||||
}
|
||||
} else {
|
||||
null
|
||||
}
|
||||
|
@ -133,26 +112,6 @@ class EventNotificationConsumer(private val applicationContext: Context) {
|
|||
LocalCache.justConsume(it, null)
|
||||
it
|
||||
}
|
||||
} else if (account.loginWithAmber) {
|
||||
var cached = AmberUtils.cachedDecryptedContent[event.id]
|
||||
if (cached == null) {
|
||||
AmberUtils.content = ""
|
||||
AmberUtils.decrypt(
|
||||
event.content,
|
||||
event.pubKey,
|
||||
event.id,
|
||||
SignerType.NIP44_DECRYPT
|
||||
)
|
||||
cached = AmberUtils.cachedDecryptedContent[event.id] ?: ""
|
||||
}
|
||||
if (cached.isNotBlank()) {
|
||||
event.cachedGossip(account.keyPair.pubKey, cached)?.let {
|
||||
LocalCache.justConsume(it, null)
|
||||
it
|
||||
}
|
||||
} else {
|
||||
null
|
||||
}
|
||||
} else {
|
||||
null
|
||||
}
|
||||
|
|
|
@ -39,6 +39,8 @@ import androidx.compose.ui.unit.dp
|
|||
import androidx.lifecycle.Lifecycle
|
||||
import androidx.lifecycle.LifecycleEventObserver
|
||||
import com.vitorpamplona.amethyst.R
|
||||
import com.vitorpamplona.amethyst.model.LocalCache
|
||||
import com.vitorpamplona.amethyst.service.IntentUtils
|
||||
import com.vitorpamplona.amethyst.service.NostrChatroomListDataSource
|
||||
import com.vitorpamplona.amethyst.ui.screen.ChatroomListFeedView
|
||||
import com.vitorpamplona.amethyst.ui.screen.FeedViewModel
|
||||
|
@ -46,6 +48,8 @@ import com.vitorpamplona.amethyst.ui.screen.NostrChatroomListKnownFeedViewModel
|
|||
import com.vitorpamplona.amethyst.ui.screen.NostrChatroomListNewFeedViewModel
|
||||
import com.vitorpamplona.amethyst.ui.theme.TabRowHeight
|
||||
import com.vitorpamplona.amethyst.ui.theme.placeholderText
|
||||
import com.vitorpamplona.quartz.events.Event
|
||||
import com.vitorpamplona.quartz.events.GiftWrapEvent
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
|
@ -66,6 +70,19 @@ fun ChatroomListScreen(
|
|||
|
||||
WatchAccountForListScreen(knownFeedViewModel, newFeedViewModel, accountViewModel)
|
||||
|
||||
LaunchedEffect(Unit) {
|
||||
if (accountViewModel.loggedInWithAmber()) {
|
||||
coroutineScope.launch(Dispatchers.IO) {
|
||||
val gifts = LocalCache.notes.elements().toList().filter { it.event is GiftWrapEvent }
|
||||
gifts.forEach {
|
||||
it.event?.let {
|
||||
IntentUtils.consume(it as Event)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val lifeCycleOwner = LocalLifecycleOwner.current
|
||||
DisposableEffect(accountViewModel) {
|
||||
val observer = LifecycleEventObserver { _, event ->
|
||||
|
|
Ładowanie…
Reference in New Issue