Fixes local cache strategy to create an option and not verify events from Seals.

This commit is contained in:
Vitor Pamplona
2025-05-16 19:27:39 -04:00
parent 049e1d15ce
commit 8a59904bfc
16 changed files with 549 additions and 422 deletions
@@ -126,7 +126,7 @@ class ThreadDualAxisChartAssemblerTest {
var counter = 0 var counter = 0
eventArray.forEach { eventArray.forEach {
TestCase.assertTrue("${it.id} failed signature check", it.verify()) TestCase.assertTrue("${it.id} failed signature check", it.verify())
LocalCache.justConsume(it, null) LocalCache.justConsume(it, null, false)
counter++ counter++
} }
@@ -1227,7 +1227,7 @@ class Account(
signer = signer, signer = signer,
) { ) {
Amethyst.instance.client.send(it) Amethyst.instance.client.send(it)
LocalCache.justConsume(it, null) LocalCache.justConsumeMyOwnEvent(it)
} }
} }
} }
@@ -1244,7 +1244,7 @@ class Account(
signer = signer, signer = signer,
) { ) {
Amethyst.instance.client.send(it) Amethyst.instance.client.send(it)
LocalCache.justConsume(it, null) LocalCache.justConsumeMyOwnEvent(it)
} }
} else { } else {
ContactListEvent.createFromScratch( ContactListEvent.createFromScratch(
@@ -1257,7 +1257,7 @@ class Account(
) { ) {
// Keep this local to avoid erasing a good contact list. // Keep this local to avoid erasing a good contact list.
// Amethyst.instance.client.send(it) // Amethyst.instance.client.send(it)
LocalCache.justConsume(it, null) LocalCache.justConsumeMyOwnEvent(it)
} }
} }
} }
@@ -1322,7 +1322,7 @@ class Account(
signer.sign(template) { signer.sign(template) {
Amethyst.instance.client.send(it) Amethyst.instance.client.send(it)
LocalCache.justConsume(it, null) LocalCache.justConsumeMyOwnEvent(it)
} }
} }
@@ -1393,7 +1393,7 @@ class Account(
ReactionEvent.build(emojiUrl, EventHintBundle(it, note.relayHintUrl())), ReactionEvent.build(emojiUrl, EventHintBundle(it, note.relayHintUrl())),
) { ) {
Amethyst.instance.client.send(it) Amethyst.instance.client.send(it)
LocalCache.consume(it) LocalCache.justConsumeMyOwnEvent(it)
} }
} }
@@ -1406,7 +1406,7 @@ class Account(
ReactionEvent.build(reaction, it), ReactionEvent.build(reaction, it),
) { ) {
Amethyst.instance.client.send(it) Amethyst.instance.client.send(it)
LocalCache.consume(it) LocalCache.justConsumeMyOwnEvent(it)
} }
} }
} }
@@ -1510,7 +1510,7 @@ class Account(
Amethyst.instance.sources.nwc Amethyst.instance.sources.nwc
.subscribe(filter) .subscribe(filter)
LocalCache.consume(event, zappedNote) { it.response(signer) { onResponse(it) } } LocalCache.consume(event, zappedNote, true) { it.response(signer) { onResponse(it) } }
Amethyst.instance.client.sendSingle( Amethyst.instance.client.sendSingle(
signedEvent = event, signedEvent = event,
@@ -1569,7 +1569,7 @@ class Account(
note.event?.let { note.event?.let {
signer.sign(ReportEvent.build(it, type)) { signer.sign(ReportEvent.build(it, type)) {
Amethyst.instance.client.send(it) Amethyst.instance.client.send(it)
LocalCache.justConsume(it, null) LocalCache.justConsumeMyOwnEvent(it)
} }
} }
} }
@@ -1588,7 +1588,7 @@ class Account(
val template = ReportEvent.build(user.pubkeyHex, type) val template = ReportEvent.build(user.pubkeyHex, type)
signer.sign(template) { signer.sign(template) {
Amethyst.instance.client.send(it) Amethyst.instance.client.send(it)
LocalCache.justConsume(it, null) LocalCache.justConsumeMyOwnEvent(it)
} }
} }
@@ -1607,7 +1607,7 @@ class Account(
DeletionEvent.build(chunkedList), DeletionEvent.build(chunkedList),
) { deletionEvent -> ) { deletionEvent ->
Amethyst.instance.client.send(deletionEvent) Amethyst.instance.client.send(deletionEvent)
LocalCache.justConsume(deletionEvent, null) LocalCache.justConsumeMyOwnEvent(deletionEvent)
} }
} }
} }
@@ -1677,7 +1677,7 @@ class Account(
signer.sign(template) { signer.sign(template) {
Amethyst.instance.client.send(it) Amethyst.instance.client.send(it)
LocalCache.justConsume(it, null) LocalCache.justConsumeMyOwnEvent(it)
} }
} }
@@ -1726,7 +1726,7 @@ class Account(
} }
signer.sign(template) { signer.sign(template) {
LocalCache.justConsume(it, null) LocalCache.justConsumeMyOwnEvent(it)
Amethyst.instance.client.send(it) Amethyst.instance.client.send(it)
settings.pendingAttestations.update { settings.pendingAttestations.update {
@@ -1760,7 +1760,7 @@ class Account(
if (contactList != null) { if (contactList != null) {
ContactListEvent.followUser(contactList, user.pubkeyHex, signer) { ContactListEvent.followUser(contactList, user.pubkeyHex, signer) {
Amethyst.instance.client.send(it) Amethyst.instance.client.send(it)
LocalCache.justConsume(it, null) LocalCache.justConsumeMyOwnEvent(it)
} }
} else { } else {
ContactListEvent.createFromScratch( ContactListEvent.createFromScratch(
@@ -1775,7 +1775,7 @@ class Account(
signer = signer, signer = signer,
) { ) {
Amethyst.instance.client.send(it) Amethyst.instance.client.send(it)
LocalCache.justConsume(it, null) LocalCache.justConsumeMyOwnEvent(it)
} }
} }
} }
@@ -1785,7 +1785,7 @@ class Account(
publicChatList.follow(channel) { publicChatList.follow(channel) {
sendToPrivateOutboxAndLocal(it) sendToPrivateOutboxAndLocal(it)
LocalCache.justConsume(it, null) LocalCache.justConsumeMyOwnEvent(it)
} }
} }
@@ -1794,7 +1794,7 @@ class Account(
publicChatList.unfollow(channel) { publicChatList.unfollow(channel) {
sendToPrivateOutboxAndLocal(it) sendToPrivateOutboxAndLocal(it)
LocalCache.justConsume(it, null) LocalCache.justConsumeMyOwnEvent(it)
} }
} }
@@ -1803,7 +1803,7 @@ class Account(
ephemeralChatList.follow(channel) { ephemeralChatList.follow(channel) {
sendToPrivateOutboxAndLocal(it) sendToPrivateOutboxAndLocal(it)
LocalCache.justConsumeInner(it, RelayBriefInfoCache.get(channel.roomId.relayUrl)) LocalCache.justConsumeInner(it, RelayBriefInfoCache.get(channel.roomId.relayUrl), true)
} }
} }
@@ -1812,7 +1812,7 @@ class Account(
ephemeralChatList.unfollow(channel) { ephemeralChatList.unfollow(channel) {
sendToPrivateOutboxAndLocal(it) sendToPrivateOutboxAndLocal(it)
LocalCache.justConsumeInner(it, RelayBriefInfoCache.get(channel.roomId.relayUrl)) LocalCache.justConsumeInner(it, RelayBriefInfoCache.get(channel.roomId.relayUrl), true)
} }
} }
@@ -1824,7 +1824,7 @@ class Account(
if (contactList != null) { if (contactList != null) {
ContactListEvent.followAddressableEvent(contactList, community.toATag(), signer) { ContactListEvent.followAddressableEvent(contactList, community.toATag(), signer) {
Amethyst.instance.client.send(it) Amethyst.instance.client.send(it)
LocalCache.justConsume(it, null) LocalCache.justConsumeMyOwnEvent(it)
} }
} else { } else {
val relays = val relays =
@@ -1840,7 +1840,7 @@ class Account(
signer = signer, signer = signer,
) { ) {
Amethyst.instance.client.send(it) Amethyst.instance.client.send(it)
LocalCache.justConsume(it, null) LocalCache.justConsumeMyOwnEvent(it)
} }
} }
} }
@@ -1857,7 +1857,7 @@ class Account(
signer, signer,
) { ) {
Amethyst.instance.client.send(it) Amethyst.instance.client.send(it)
LocalCache.justConsume(it, null) LocalCache.justConsumeMyOwnEvent(it)
} }
} else { } else {
ContactListEvent.createFromScratch( ContactListEvent.createFromScratch(
@@ -1872,7 +1872,7 @@ class Account(
signer = signer, signer = signer,
) { ) {
Amethyst.instance.client.send(it) Amethyst.instance.client.send(it)
LocalCache.justConsume(it, null) LocalCache.justConsumeMyOwnEvent(it)
} }
} }
} }
@@ -1907,7 +1907,7 @@ class Account(
fun onNewEventCreated(event: Event) { fun onNewEventCreated(event: Event) {
Amethyst.instance.client.send(event) Amethyst.instance.client.send(event)
LocalCache.justConsume(event, null) LocalCache.justConsumeMyOwnEvent(event)
} }
fun unfollow(user: User) { fun unfollow(user: User) {
@@ -2008,10 +2008,10 @@ class Account(
if (!isWriteable()) return null if (!isWriteable()) return null
Amethyst.instance.client.send(data, relayList = relayList) Amethyst.instance.client.send(data, relayList = relayList)
LocalCache.justConsume(data, null) LocalCache.justConsumeMyOwnEvent(data)
Amethyst.instance.client.send(signedEvent, relayList = relayList) Amethyst.instance.client.send(signedEvent, relayList = relayList)
LocalCache.justConsume(signedEvent, null) LocalCache.justConsumeMyOwnEvent(signedEvent)
return LocalCache.getNoteIfExists(signedEvent.id) return LocalCache.getNoteIfExists(signedEvent.id)
} }
@@ -2020,8 +2020,8 @@ class Account(
data: FileStorageEvent, data: FileStorageEvent,
signedEvent: FileStorageHeaderEvent, signedEvent: FileStorageHeaderEvent,
): Note? { ): Note? {
LocalCache.justConsume(data, null) LocalCache.justConsumeMyOwnEvent(data)
LocalCache.justConsume(signedEvent, null) LocalCache.justConsumeMyOwnEvent(signedEvent)
return LocalCache.getNoteIfExists(signedEvent.id) return LocalCache.getNoteIfExists(signedEvent.id)
} }
@@ -2062,7 +2062,7 @@ class Account(
onReady: (Note) -> Unit, onReady: (Note) -> Unit,
) { ) {
Amethyst.instance.client.send(signedEvent, relayList = relayList) Amethyst.instance.client.send(signedEvent, relayList = relayList)
LocalCache.justConsume(signedEvent, null) LocalCache.justConsumeMyOwnEvent(signedEvent)
LocalCache.getNoteIfExists(signedEvent.id)?.let { onReady(it) } LocalCache.getNoteIfExists(signedEvent.id)?.let { onReady(it) }
} }
@@ -2233,7 +2233,7 @@ class Account(
} }
} else { } else {
signer.sign(template) { signer.sign(template) {
LocalCache.justConsume(it, null) LocalCache.justConsumeMyOwnEvent(it)
Amethyst.instance.client.send(it) Amethyst.instance.client.send(it)
} }
} }
@@ -2245,7 +2245,7 @@ class Account(
onDone: (T) -> Unit = {}, onDone: (T) -> Unit = {},
) { ) {
signer.sign(template) { signer.sign(template) {
LocalCache.justConsume(it, null) LocalCache.justConsumeMyOwnEvent(it)
Amethyst.instance.client.sendPrivately(it, relayList = convertRelayList(relayList)) Amethyst.instance.client.sendPrivately(it, relayList = convertRelayList(relayList))
onDone(it) onDone(it)
} }
@@ -2257,7 +2257,7 @@ class Account(
onDone: (T) -> Unit = {}, onDone: (T) -> Unit = {},
) { ) {
signer.sign(template) { signer.sign(template) {
LocalCache.justConsume(it, null) LocalCache.justConsumeMyOwnEvent(it)
val relays = relayList(it) val relays = relayList(it)
if (relays != null) { if (relays != null) {
Amethyst.instance.client.sendPrivately(it, relayList = convertRelayList(relays)) Amethyst.instance.client.sendPrivately(it, relayList = convertRelayList(relays))
@@ -2274,7 +2274,7 @@ class Account(
broadcastNotes: Set<Note>, broadcastNotes: Set<Note>,
) { ) {
signer.sign(template) { signer.sign(template) {
LocalCache.justConsume(it, null) LocalCache.justConsumeMyOwnEvent(it)
Amethyst.instance.client.send(it, relayList = relayList) Amethyst.instance.client.send(it, relayList = relayList)
broadcastNotes.forEach { it.event?.let { Amethyst.instance.client.send(it, relayList = relayList) } } broadcastNotes.forEach { it.event?.let { Amethyst.instance.client.send(it, relayList = relayList) } }
@@ -2302,7 +2302,7 @@ class Account(
} }
} else { } else {
signer.sign(template) { signer.sign(template) {
LocalCache.justConsume(it, null) LocalCache.justConsumeMyOwnEvent(it)
Amethyst.instance.client.send(it, relayList = relayList) Amethyst.instance.client.send(it, relayList = relayList)
broadcastNotes.forEach { it.event?.let { Amethyst.instance.client.send(it, relayList = relayList) } } broadcastNotes.forEach { it.event?.let { Amethyst.instance.client.send(it, relayList = relayList) } }
@@ -2336,7 +2336,7 @@ class Account(
) )
} }
LocalCache.justConsume(it, null) LocalCache.justConsumeMyOwnEvent(it)
Amethyst.instance.client.sendPrivately(it, relayList = connect) Amethyst.instance.client.sendPrivately(it, relayList = connect)
broadcastNotes.forEach { it.event?.let { Amethyst.instance.client.sendPrivately(it, relayList = connect) } } broadcastNotes.forEach { it.event?.let { Amethyst.instance.client.sendPrivately(it, relayList = connect) } }
} }
@@ -2382,7 +2382,7 @@ class Account(
) )
}, },
) )
LocalCache.justConsume(it, null) LocalCache.justConsumeMyOwnEvent(it)
} }
} }
delete(note) delete(note)
@@ -2557,7 +2557,7 @@ class Account(
summary = summary, summary = summary,
signer = signer, signer = signer,
) { ) {
LocalCache.justConsume(it, null) LocalCache.justConsumeMyOwnEvent(it)
Amethyst.instance.client.send(it, relayList = relayList) Amethyst.instance.client.send(it, relayList = relayList)
} }
} }
@@ -2674,7 +2674,7 @@ class Account(
} else { } else {
Amethyst.instance.client.send(event) Amethyst.instance.client.send(event)
} }
LocalCache.justConsume(event, null) LocalCache.justConsumeMyOwnEvent(event)
} }
fun convertRelayList(broadcast: List<String>): List<RelaySetupInfoToConnect> = fun convertRelayList(broadcast: List<String>): List<RelaySetupInfoToConnect> =
@@ -2696,14 +2696,14 @@ class Account(
giftWrap.unwrap(signer) { gift -> giftWrap.unwrap(signer) { gift ->
if (gift is SealedRumorEvent) { if (gift is SealedRumorEvent) {
gift.unseal(signer) { rumor -> gift.unseal(signer) { rumor ->
LocalCache.justConsume(rumor, null) LocalCache.justConsumeMyOwnEvent(rumor)
} }
} }
LocalCache.justConsume(gift, null) LocalCache.justConsumeMyOwnEvent(gift)
} }
LocalCache.justConsume(giftWrap, null) LocalCache.justConsumeMyOwnEvent(giftWrap)
} }
val id = mine.firstOrNull()?.id val id = mine.firstOrNull()?.id
@@ -2753,7 +2753,7 @@ class Account(
StatusEvent.update(oldEvent, newStatus, signer) { StatusEvent.update(oldEvent, newStatus, signer) {
Amethyst.instance.client.send(it) Amethyst.instance.client.send(it)
LocalCache.justConsume(it, null) LocalCache.justConsumeMyOwnEvent(it)
} }
} }
@@ -2762,7 +2762,7 @@ class Account(
StatusEvent.create(newStatus, "general", expiration = null, signer) { StatusEvent.create(newStatus, "general", expiration = null, signer) {
Amethyst.instance.client.send(it) Amethyst.instance.client.send(it)
LocalCache.justConsume(it, null) LocalCache.justConsumeMyOwnEvent(it)
} }
} }
@@ -2772,13 +2772,13 @@ class Account(
StatusEvent.clear(oldEvent, signer) { event -> StatusEvent.clear(oldEvent, signer) { event ->
Amethyst.instance.client.send(event) Amethyst.instance.client.send(event)
LocalCache.justConsume(event, null) LocalCache.justConsumeMyOwnEvent(event)
signer.sign( signer.sign(
DeletionEvent.buildForVersionOnly(listOf(event)), DeletionEvent.buildForVersionOnly(listOf(event)),
) { event2 -> ) { event2 ->
Amethyst.instance.client.send(event2) Amethyst.instance.client.send(event2)
LocalCache.justConsume(event2, null) LocalCache.justConsumeMyOwnEvent(event2)
} }
} }
} }
@@ -2796,7 +2796,7 @@ class Account(
signer.sign(EmojiPackSelectionEvent.remove(noteEvent, emojiPackEvent)) { signer.sign(EmojiPackSelectionEvent.remove(noteEvent, emojiPackEvent)) {
Amethyst.instance.client.send(it) Amethyst.instance.client.send(it)
LocalCache.justConsume(it, null) LocalCache.justConsumeMyOwnEvent(it)
} }
} }
@@ -2813,7 +2813,7 @@ class Account(
if (usersEmojiList.event == null) { if (usersEmojiList.event == null) {
signer.sign(EmojiPackSelectionEvent.build(listOf(eventHint))) { signer.sign(EmojiPackSelectionEvent.build(listOf(eventHint))) {
Amethyst.instance.client.send(it) Amethyst.instance.client.send(it)
LocalCache.justConsume(it, null) LocalCache.justConsumeMyOwnEvent(it)
} }
} else { } else {
val noteEvent = usersEmojiList.event val noteEvent = usersEmojiList.event
@@ -2821,7 +2821,7 @@ class Account(
signer.sign(EmojiPackSelectionEvent.add(noteEvent, eventHint)) { signer.sign(EmojiPackSelectionEvent.add(noteEvent, eventHint)) {
Amethyst.instance.client.send(it) Amethyst.instance.client.send(it)
LocalCache.justConsume(it, null) LocalCache.justConsumeMyOwnEvent(it)
} }
} }
} }
@@ -2847,7 +2847,7 @@ class Account(
}, },
) { ) {
Amethyst.instance.client.send(it) Amethyst.instance.client.send(it)
LocalCache.justConsume(it, null) LocalCache.justConsumeMyOwnEvent(it)
} }
} }
@@ -2870,7 +2870,7 @@ class Account(
signer, signer,
) { ) {
Amethyst.instance.client.send(it) Amethyst.instance.client.send(it)
LocalCache.consume(it) LocalCache.justConsumeMyOwnEvent(it)
} }
} else { } else {
BookmarkListEvent.addEvent( BookmarkListEvent.addEvent(
@@ -2880,7 +2880,7 @@ class Account(
signer, signer,
) { ) {
Amethyst.instance.client.send(it) Amethyst.instance.client.send(it)
LocalCache.consume(it) LocalCache.justConsumeMyOwnEvent(it)
} }
} }
} }
@@ -2901,7 +2901,7 @@ class Account(
signer, signer,
) { ) {
Amethyst.instance.client.send(it) Amethyst.instance.client.send(it)
LocalCache.consume(it) LocalCache.justConsumeMyOwnEvent(it)
} }
} else { } else {
BookmarkListEvent.removeEvent( BookmarkListEvent.removeEvent(
@@ -2911,7 +2911,7 @@ class Account(
signer, signer,
) { ) {
Amethyst.instance.client.send(it) Amethyst.instance.client.send(it)
LocalCache.consume(it) LocalCache.justConsumeMyOwnEvent(it)
} }
} }
} }
@@ -3004,7 +3004,7 @@ class Account(
signer = signer, signer = signer,
) { ) {
Amethyst.instance.client.send(it) Amethyst.instance.client.send(it)
LocalCache.justConsume(it, null) LocalCache.justConsumeMyOwnEvent(it)
} }
} else { } else {
MuteListEvent.createListWithWord( MuteListEvent.createListWithWord(
@@ -3013,7 +3013,7 @@ class Account(
signer = signer, signer = signer,
) { ) {
Amethyst.instance.client.send(it) Amethyst.instance.client.send(it)
LocalCache.justConsume(it, null) LocalCache.justConsumeMyOwnEvent(it)
} }
} }
} }
@@ -3028,7 +3028,7 @@ class Account(
signer = signer, signer = signer,
) { ) {
Amethyst.instance.client.send(it) Amethyst.instance.client.send(it)
LocalCache.justConsume(it, null) LocalCache.justConsumeMyOwnEvent(it)
} }
} }
@@ -3041,7 +3041,7 @@ class Account(
signer = signer, signer = signer,
) { ) {
Amethyst.instance.client.send(it) Amethyst.instance.client.send(it)
LocalCache.justConsume(it, null) LocalCache.justConsumeMyOwnEvent(it)
} }
} }
} }
@@ -3057,7 +3057,7 @@ class Account(
signer = signer, signer = signer,
) { ) {
Amethyst.instance.client.send(it) Amethyst.instance.client.send(it)
LocalCache.justConsume(it, null) LocalCache.justConsumeMyOwnEvent(it)
} }
} else { } else {
MuteListEvent.createListWithUser( MuteListEvent.createListWithUser(
@@ -3066,7 +3066,7 @@ class Account(
signer = signer, signer = signer,
) { ) {
Amethyst.instance.client.send(it) Amethyst.instance.client.send(it)
LocalCache.justConsume(it, null) LocalCache.justConsumeMyOwnEvent(it)
} }
} }
} }
@@ -3081,7 +3081,7 @@ class Account(
signer = signer, signer = signer,
) { ) {
Amethyst.instance.client.send(it) Amethyst.instance.client.send(it)
LocalCache.justConsume(it, null) LocalCache.justConsumeMyOwnEvent(it)
} }
} }
@@ -3094,7 +3094,7 @@ class Account(
signer = signer, signer = signer,
) { ) {
Amethyst.instance.client.send(it) Amethyst.instance.client.send(it)
LocalCache.justConsume(it, null) LocalCache.justConsumeMyOwnEvent(it)
} }
} }
@@ -3130,7 +3130,7 @@ class Account(
} else { } else {
Amethyst.instance.client.send(it) Amethyst.instance.client.send(it)
} }
LocalCache.justConsume(it, null) LocalCache.justConsumeMyOwnEvent(it)
onReady(it) onReady(it)
} }
} }
@@ -3347,7 +3347,7 @@ class Account(
signer = signer, signer = signer,
) { ) {
Amethyst.instance.client.send(it) Amethyst.instance.client.send(it)
LocalCache.justConsume(it, null) LocalCache.justConsumeMyOwnEvent(it)
} }
} else { } else {
ChatMessageRelayListEvent.createFromScratch( ChatMessageRelayListEvent.createFromScratch(
@@ -3355,7 +3355,7 @@ class Account(
signer = signer, signer = signer,
) { ) {
Amethyst.instance.client.send(it) Amethyst.instance.client.send(it)
LocalCache.justConsume(it, null) LocalCache.justConsumeMyOwnEvent(it)
} }
} }
} }
@@ -3381,7 +3381,7 @@ class Account(
signer = signer, signer = signer,
) { ) {
Amethyst.instance.client.send(it) Amethyst.instance.client.send(it)
LocalCache.justConsume(it, null) LocalCache.justConsumeMyOwnEvent(it)
} }
} else { } else {
PrivateOutboxRelayListEvent.createFromScratch( PrivateOutboxRelayListEvent.createFromScratch(
@@ -3389,7 +3389,7 @@ class Account(
signer = signer, signer = signer,
) { ) {
Amethyst.instance.client.send(it) Amethyst.instance.client.send(it)
LocalCache.justConsume(it, null) LocalCache.justConsumeMyOwnEvent(it)
} }
} }
} }
@@ -3415,7 +3415,7 @@ class Account(
signer = signer, signer = signer,
) { ) {
Amethyst.instance.client.send(it) Amethyst.instance.client.send(it)
LocalCache.justConsume(it, null) LocalCache.justConsumeMyOwnEvent(it)
} }
} else { } else {
SearchRelayListEvent.createFromScratch( SearchRelayListEvent.createFromScratch(
@@ -3423,7 +3423,7 @@ class Account(
signer = signer, signer = signer,
) { ) {
Amethyst.instance.client.send(it) Amethyst.instance.client.send(it)
LocalCache.justConsume(it, null) LocalCache.justConsumeMyOwnEvent(it)
} }
} }
} }
@@ -3449,7 +3449,7 @@ class Account(
signer = signer, signer = signer,
) { ) {
Amethyst.instance.client.send(it) Amethyst.instance.client.send(it)
LocalCache.justConsume(it, null) LocalCache.justConsumeMyOwnEvent(it)
} }
} else { } else {
AdvertisedRelayListEvent.createFromScratch( AdvertisedRelayListEvent.createFromScratch(
@@ -3457,7 +3457,7 @@ class Account(
signer = signer, signer = signer,
) { ) {
Amethyst.instance.client.send(it) Amethyst.instance.client.send(it)
LocalCache.justConsume(it, null) LocalCache.justConsumeMyOwnEvent(it)
} }
} }
} }
@@ -3507,7 +3507,7 @@ class Account(
signer.sign(template) { signer.sign(template) {
Amethyst.instance.client.send(it) Amethyst.instance.client.send(it)
LocalCache.justConsume(it, null) LocalCache.justConsumeMyOwnEvent(it)
} }
} }
@@ -3523,7 +3523,7 @@ class Account(
signer = signer, signer = signer,
) { ) {
Amethyst.instance.client.send(it) Amethyst.instance.client.send(it)
LocalCache.justConsume(it, null) LocalCache.justConsumeMyOwnEvent(it)
} }
} else { } else {
BlossomServersEvent.createFromScratch( BlossomServersEvent.createFromScratch(
@@ -3531,7 +3531,7 @@ class Account(
signer = signer, signer = signer,
) { ) {
Amethyst.instance.client.send(it) Amethyst.instance.client.send(it)
LocalCache.justConsume(it, null) LocalCache.justConsumeMyOwnEvent(it)
} }
} }
} }
@@ -3710,32 +3710,32 @@ class Account(
Log.d("AccountRegisterObservers", "Loading saved contacts ${it.toJson()}") Log.d("AccountRegisterObservers", "Loading saved contacts ${it.toJson()}")
@OptIn(DelicateCoroutinesApi::class) @OptIn(DelicateCoroutinesApi::class)
GlobalScope.launch(Dispatchers.IO) { LocalCache.consume(it) } GlobalScope.launch(Dispatchers.IO) { LocalCache.justConsumeMyOwnEvent(it) }
} }
settings.backupUserMetadata?.let { settings.backupUserMetadata?.let {
Log.d("AccountRegisterObservers", "Loading saved user metadata ${it.toJson()}") Log.d("AccountRegisterObservers", "Loading saved user metadata ${it.toJson()}")
@OptIn(DelicateCoroutinesApi::class) @OptIn(DelicateCoroutinesApi::class)
GlobalScope.launch(Dispatchers.IO) { LocalCache.justConsume(it, null) } GlobalScope.launch(Dispatchers.IO) { LocalCache.justConsumeMyOwnEvent(it) }
} }
settings.backupDMRelayList?.let { settings.backupDMRelayList?.let {
Log.d("AccountRegisterObservers", "Loading saved DM Relay List ${it.toJson()}") Log.d("AccountRegisterObservers", "Loading saved DM Relay List ${it.toJson()}")
@OptIn(DelicateCoroutinesApi::class) @OptIn(DelicateCoroutinesApi::class)
GlobalScope.launch(Dispatchers.IO) { LocalCache.justConsume(it, null) } GlobalScope.launch(Dispatchers.IO) { LocalCache.justConsumeMyOwnEvent(it) }
} }
settings.backupNIP65RelayList?.let { settings.backupNIP65RelayList?.let {
Log.d("AccountRegisterObservers", "Loading saved nip65 relay list ${it.toJson()}") Log.d("AccountRegisterObservers", "Loading saved nip65 relay list ${it.toJson()}")
@OptIn(DelicateCoroutinesApi::class) @OptIn(DelicateCoroutinesApi::class)
GlobalScope.launch(Dispatchers.IO) { LocalCache.justConsume(it, null) } GlobalScope.launch(Dispatchers.IO) { LocalCache.justConsumeMyOwnEvent(it) }
} }
settings.backupSearchRelayList?.let { settings.backupSearchRelayList?.let {
Log.d("AccountRegisterObservers", "Loading saved search relay list ${it.toJson()}") Log.d("AccountRegisterObservers", "Loading saved search relay list ${it.toJson()}")
@OptIn(DelicateCoroutinesApi::class) @OptIn(DelicateCoroutinesApi::class)
GlobalScope.launch(Dispatchers.IO) { LocalCache.justConsume(it, null) } GlobalScope.launch(Dispatchers.IO) { LocalCache.justConsumeMyOwnEvent(it) }
} }
settings.backupPrivateHomeRelayList?.let { event -> settings.backupPrivateHomeRelayList?.let { event ->
@@ -3743,7 +3743,7 @@ class Account(
@OptIn(DelicateCoroutinesApi::class) @OptIn(DelicateCoroutinesApi::class)
GlobalScope.launch(Dispatchers.IO) { GlobalScope.launch(Dispatchers.IO) {
event.privateTags(signer) { event.privateTags(signer) {
LocalCache.justConsume(event, null) LocalCache.justConsumeMyOwnEvent(event)
} }
} }
} }
@@ -3752,7 +3752,7 @@ class Account(
Log.d("AccountRegisterObservers", "Loading saved app specific data ${event.toJson()}") Log.d("AccountRegisterObservers", "Loading saved app specific data ${event.toJson()}")
@OptIn(DelicateCoroutinesApi::class) @OptIn(DelicateCoroutinesApi::class)
GlobalScope.launch(Dispatchers.IO) { GlobalScope.launch(Dispatchers.IO) {
LocalCache.justConsume(event, null) LocalCache.justConsumeMyOwnEvent(event)
signer.decrypt(event.content, event.pubKey) { decrypted -> signer.decrypt(event.content, event.pubKey) { decrypted ->
try { try {
val syncedSettings = EventMapper.mapper.readValue<AccountSyncedSettingsInternal>(decrypted) val syncedSettings = EventMapper.mapper.readValue<AccountSyncedSettingsInternal>(decrypted)
@@ -3772,7 +3772,7 @@ class Account(
@OptIn(DelicateCoroutinesApi::class) @OptIn(DelicateCoroutinesApi::class)
GlobalScope.launch(Dispatchers.IO) { GlobalScope.launch(Dispatchers.IO) {
event.privateTags(signer) { event.privateTags(signer) {
LocalCache.justConsume(event, null) LocalCache.justConsumeMyOwnEvent(event)
} }
} }
} }
@@ -3782,7 +3782,7 @@ class Account(
@OptIn(DelicateCoroutinesApi::class) @OptIn(DelicateCoroutinesApi::class)
GlobalScope.launch(Dispatchers.IO) { GlobalScope.launch(Dispatchers.IO) {
event.privateTags(signer) { event.privateTags(signer) {
LocalCache.justConsume(event, null) LocalCache.justConsumeMyOwnEvent(event)
} }
} }
} }
@@ -3792,7 +3792,7 @@ class Account(
@OptIn(DelicateCoroutinesApi::class) @OptIn(DelicateCoroutinesApi::class)
GlobalScope.launch(Dispatchers.IO) { GlobalScope.launch(Dispatchers.IO) {
event.privateTags(signer) { event.privateTags(signer) {
LocalCache.justConsume(event, null) LocalCache.justConsumeMyOwnEvent(event)
} }
} }
} }
@@ -3939,7 +3939,7 @@ class Account(
Log.d("DB UPGRADE", "Migrating List") Log.d("DB UPGRADE", "Migrating List")
publicChatList.follow(oldChannels) { publicChatList.follow(oldChannels) {
sendToPrivateOutboxAndLocal(it) sendToPrivateOutboxAndLocal(it)
LocalCache.justConsume(it, null) LocalCache.justConsumeMyOwnEvent(it)
} }
} }
} }
File diff suppressed because it is too large Load Diff
@@ -174,7 +174,7 @@ class EventNotificationConsumer(
when (event) { when (event) {
is GiftWrapEvent -> { is GiftWrapEvent -> {
if (LocalCache.justConsume(event, null)) { if (LocalCache.justConsume(event, null, false)) {
// new event // new event
event.unwrap(signer) { event.unwrap(signer) {
// clear the encrypted payload to save memory // clear the encrypted payload to save memory
@@ -185,22 +185,21 @@ class EventNotificationConsumer(
} }
} }
is SealedRumorEvent -> { is SealedRumorEvent -> {
if (LocalCache.justConsume(event, null)) { if (LocalCache.justConsume(event, null, false)) {
// new event // new event
event.unseal(signer) { event.unseal(signer) {
// clear the encrypted payload to save memory // clear the encrypted payload to save memory
LocalCache.getOrCreateNote(event.id).event = event.copyNoContent() LocalCache.getOrCreateNote(event.id).event = event.copyNoContent()
// this is not verifiable // this is not verifiable
if (!LocalCache.hasConsumed(it)) { if (LocalCache.justConsume(it, null, true)) {
LocalCache.justConsume(it, null)
onReady(it) onReady(it)
} }
} }
} }
} }
else -> { else -> {
LocalCache.justConsume(event, null) LocalCache.justConsume(event, null, false)
onReady(event) onReady(event)
} }
} }
@@ -33,7 +33,7 @@ class CacheClientConnector(
) { ) {
val receiver = val receiver =
EventCollector(client) { event, relay -> EventCollector(client) { event, relay ->
cache.justConsume(event, relay) cache.justConsume(event, relay, false)
} }
val confirmationWatcher = val confirmationWatcher =
@@ -70,7 +70,7 @@ class SearchWatcherSubAssembler(
is Note -> filterByEvent(parsed.hex) is Note -> filterByEvent(parsed.hex)
is NEvent -> filterByEvent(parsed.hex) is NEvent -> filterByEvent(parsed.hex)
is NEmbed -> { is NEmbed -> {
cache.justConsume(parsed.event, null) cache.justConsume(parsed.event, null, false)
emptyList() emptyList()
} }
@@ -183,7 +183,7 @@ fun uriToRoute(uri: String?): Route? =
is NEmbed -> { is NEmbed -> {
if (LocalCache.getNoteIfExists(nip19.event.id) == null) { if (LocalCache.getNoteIfExists(nip19.event.id) == null) {
LocalCache.justConsume(nip19.event, null) LocalCache.justConsume(nip19.event, null, false)
} }
Route.EventRedirect(nip19.event.id) Route.EventRedirect(nip19.event.id)
} }
@@ -379,7 +379,7 @@ fun RenderContentAsMarkdownUserPreview() {
), ),
) )
LocalCache.justConsume(qa, null) LocalCache.justConsume(qa, null, false)
} }
} }
@@ -428,7 +428,7 @@ fun RenderContentAsMarkdownNotePreview() {
sig = "4c85e0eb0c46c5e3023431ad4ed8efa0abd66447ff757d246154e2349ac01ae0f88f213d02efa0a77f307f305d4a608c785ae1ca080c01cd3a9e7b8dffea6f9c", sig = "4c85e0eb0c46c5e3023431ad4ed8efa0abd66447ff757d246154e2349ac01ae0f88f213d02efa0a77f307f305d4a608c785ae1ca080c01cd3a9e7b8dffea6f9c",
) )
LocalCache.justConsume(blogPost, null) LocalCache.justConsume(blogPost, null, false)
} }
} }
@@ -153,9 +153,9 @@ fun PollNotePreview() {
runBlocking { runBlocking {
withContext(Dispatchers.IO) { withContext(Dispatchers.IO) {
LocalCache.justConsume(event, null) LocalCache.justConsume(event, null, false)
LocalCache.consume(zapVote.zapRequest!!) LocalCache.consume(zapVote.zapRequest!!, null, false)
LocalCache.justConsume(zapVote, null) LocalCache.justConsume(zapVote, null, false)
baseNote = LocalCache.getOrCreateNote("6ff9bc13d27490f6e3953325260bd996901a143de89886a0608c39e7d0160a72") baseNote = LocalCache.getOrCreateNote("6ff9bc13d27490f6e3953325260bd996901a143de89886a0608c39e7d0160a72")
} }
} }
@@ -207,7 +207,7 @@ fun PollNotePreview2() {
runBlocking { runBlocking {
withContext(Dispatchers.IO) { withContext(Dispatchers.IO) {
LocalCache.justConsume(event, null) LocalCache.justConsume(event, null, false)
baseNote = LocalCache.getOrCreateNote("3064bf97800a4b04b612fc0fd498936eae75fffbdca5bbd09d19a6dc598530ab") baseNote = LocalCache.getOrCreateNote("3064bf97800a4b04b612fc0fd498936eae75fffbdca5bbd09d19a6dc598530ab")
} }
} }
@@ -161,7 +161,7 @@ fun ZapTheDevsCardPreview() {
} }
""".trimIndent() """.trimIndent()
LocalCache.justConsume(Event.fromJson(releaseNotes), null) LocalCache.justConsume(Event.fromJson(releaseNotes), null, false)
} }
val accountViewModel = mockAccountViewModel() val accountViewModel = mockAccountViewModel()
@@ -93,7 +93,7 @@ fun RenderLiveActivityEventPreview() {
runBlocking { runBlocking {
withContext(Dispatchers.IO) { withContext(Dispatchers.IO) {
LocalCache.justConsume(event, null) LocalCache.justConsume(event, null, false)
baseNote = LocalCache.getOrCreateNote("19406ad34ce3c653d62eb73c1816ac27dcf473c2ccdccf5af7d90d2633c62561") baseNote = LocalCache.getOrCreateNote("19406ad34ce3c653d62eb73c1816ac27dcf473c2ccdccf5af7d90d2633c62561")
} }
} }
@@ -126,7 +126,7 @@ fun TorrentPreview() {
sig = "40e1ccfdc38a32e6c164bb66e50df0cd3769e0431137a07709534a72b462dfcbc40106560d0dd66841fef4cbb7aece7db64e83a0fbe414759d4d9a799e522c57", sig = "40e1ccfdc38a32e6c164bb66e50df0cd3769e0431137a07709534a72b462dfcbc40106560d0dd66841fef4cbb7aece7db64e83a0fbe414759d4d9a799e522c57",
) )
LocalCache.justConsume(torrent, null) LocalCache.justConsume(torrent, null, false)
LocalCache.getOrCreateNote("e1ab66dd66e6ac4f32119deacf80d7c50787705d343d3bb896c099cf93821757") LocalCache.getOrCreateNote("e1ab66dd66e6ac4f32119deacf80d7c50787705d343d3bb896c099cf93821757")
} }
@@ -129,8 +129,8 @@ fun TorrentCommentPreview() {
sig = "014391c310b1eebb807da4c9b11563126f2b795c9372a9432cae4dd2c0695b88584bb1c68814554c9b1a47626e3d60983e3653c29d0fdbc3a474277c140b95c3", sig = "014391c310b1eebb807da4c9b11563126f2b795c9372a9432cae4dd2c0695b88584bb1c68814554c9b1a47626e3d60983e3653c29d0fdbc3a474277c140b95c3",
) )
LocalCache.justConsume(torrent, null) LocalCache.justConsume(torrent, null, false)
LocalCache.justConsume(comment, null) LocalCache.justConsume(comment, null, false)
LocalCache.getOrCreateNote("040aba32010b5adf7cb917054e894e86c8ea7a2bcee448b2266c493f3140e9a0") LocalCache.getOrCreateNote("040aba32010b5adf7cb917054e894e86c8ea7a2bcee448b2266c493f3140e9a0")
} }
} }
@@ -1085,7 +1085,7 @@ class AccountViewModel(
var note = checkGetOrCreateNote(event.id) var note = checkGetOrCreateNote(event.id)
if (note == null) { if (note == null) {
LocalCache.justConsume(event, null) LocalCache.justConsume(event, null, false)
note = checkGetOrCreateNote(event.id) note = checkGetOrCreateNote(event.id)
} }
@@ -1469,7 +1469,7 @@ class AccountViewModel(
// clear the encrypted payload to save memory // clear the encrypted payload to save memory
LocalCache.getOrCreateNote(event.id).event = event.copyNoContent() LocalCache.getOrCreateNote(event.id).event = event.copyNoContent()
if (LocalCache.justConsume(it, null)) { if (LocalCache.justConsume(it, null, false)) {
unwrapIfNeeded(it, onReady) unwrapIfNeeded(it, onReady)
} }
} }
@@ -1483,7 +1483,7 @@ class AccountViewModel(
if (existingNote != null) { if (existingNote != null) {
unwrapIfNeeded(existingNote.event, onReady) unwrapIfNeeded(existingNote.event, onReady)
} else { } else {
if (LocalCache.justConsume(it, null)) { if (LocalCache.justConsume(it, null, false)) {
unwrapIfNeeded(it, onReady) unwrapIfNeeded(it, onReady)
} }
} }
@@ -1501,7 +1501,7 @@ class AccountViewModel(
LocalCache.getOrCreateNote(event.id).event = event.copyNoContent() LocalCache.getOrCreateNote(event.id).event = event.copyNoContent()
// this is not verifiable // this is not verifiable
if (LocalCache.justConsume(it, null)) { if (LocalCache.justConsume(it, null, true)) {
unwrapIfNeeded(it, onReady) unwrapIfNeeded(it, onReady)
} }
} }
@@ -1516,7 +1516,7 @@ class AccountViewModel(
unwrapIfNeeded(existingNote.event, onReady) unwrapIfNeeded(existingNote.event, onReady)
} else { } else {
// this is not verifiable // this is not verifiable
if (LocalCache.justConsume(it, null)) { if (LocalCache.justConsume(it, null, true)) {
unwrapIfNeeded(it, onReady) unwrapIfNeeded(it, onReady)
} }
} }
@@ -1686,7 +1686,7 @@ class AccountViewModel(
) )
} else { } else {
account.createZapRequestFor(toUserPubKeyHex, message, defaultZapType()) { zapRequest -> account.createZapRequestFor(toUserPubKeyHex, message, defaultZapType()) { zapRequest ->
LocalCache.justConsume(zapRequest, null) LocalCache.justConsumeMyOwnEvent(zapRequest)
LightningAddressResolver() LightningAddressResolver()
.lnAddressInvoice( .lnAddressInvoice(
lnaddress, lnaddress,
@@ -1766,7 +1766,7 @@ class AccountViewModel(
val baseNote = LocalCache.getOrCreateNote(parsed.event) val baseNote = LocalCache.getOrCreateNote(parsed.event)
if (baseNote.event == null) { if (baseNote.event == null) {
launch(Dispatchers.Default) { launch(Dispatchers.Default) {
LocalCache.justConsume(parsed.event, null) LocalCache.justConsume(parsed.event, null, false)
} }
} }
@@ -24,6 +24,7 @@ import android.util.Log
import com.vitorpamplona.amethyst.Amethyst 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.LocalCache.indexDraftAsRealEvent
import com.vitorpamplona.amethyst.model.Note import com.vitorpamplona.amethyst.model.Note
import com.vitorpamplona.quartz.experimental.edits.PrivateOutboxRelayListEvent import com.vitorpamplona.quartz.experimental.edits.PrivateOutboxRelayListEvent
import com.vitorpamplona.quartz.nip01Core.core.Event import com.vitorpamplona.quartz.nip01Core.core.Event
@@ -69,7 +70,9 @@ class PrecacheNewNotesProcessor(
is DraftEvent -> { is DraftEvent -> {
// Avoid decrypting over and over again if the event already exist. // Avoid decrypting over and over again if the event already exist.
if (!event.isDeleted() && event.preCachedDraft(account.signer) == null && event.pubKey == account.signer.pubKey) { if (!event.isDeleted() && event.preCachedDraft(account.signer) == null && event.pubKey == account.signer.pubKey) {
event.cachedDraft(account.signer) {} event.cachedDraft(account.signer) {
cache.indexDraftAsRealEvent(event, it)
}
} }
} }
@@ -80,7 +83,7 @@ class PrecacheNewNotesProcessor(
event.unwrap(account.signer) { event.unwrap(account.signer) {
// clear the encrypted payload to save memory // clear the encrypted payload to save memory
cache.getOrCreateNote(event.id).event = event.copyNoContent() cache.getOrCreateNote(event.id).event = event.copyNoContent()
if (cache.justConsume(it, null)) { if (cache.justConsume(it, null, false)) {
cache.copyRelaysFromTo(publicNote, it) cache.copyRelaysFromTo(publicNote, it)
consumeAlreadyVerified(it, publicNote) consumeAlreadyVerified(it, publicNote)
} }
@@ -102,7 +105,8 @@ class PrecacheNewNotesProcessor(
// clear the encrypted payload to save memory // clear the encrypted payload to save memory
cache.getOrCreateNote(event.id).event = event.copyNoContent() cache.getOrCreateNote(event.id).event = event.copyNoContent()
cache.justConsume(it, null) // avoid verifying these events.
cache.justConsume(it, null, true)
cache.copyRelaysFromTo(publicNote, it) cache.copyRelaysFromTo(publicNote, it)
} }
} else { } else {
@@ -989,7 +989,7 @@ private fun RenderWikiHeaderForThreadPreview() {
runBlocking { runBlocking {
withContext(Dispatchers.IO) { withContext(Dispatchers.IO) {
LocalCache.justConsume(event, null) LocalCache.justConsume(event, null, false)
} }
} }