Providing a delete fix for empty drafts.
This commit is contained in:
@@ -675,13 +675,28 @@ class Account(
|
|||||||
myRelayList.addAll(it.relays)
|
myRelayList.addAll(it.relays)
|
||||||
}
|
}
|
||||||
|
|
||||||
client.send(deletionEvent, outboxRelays.flow.value + myRelayList)
|
client.send(deletionEvent, myRelayList)
|
||||||
cache.justConsumeMyOwnEvent(deletionEvent)
|
cache.justConsumeMyOwnEvent(deletionEvent)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun delete(
|
||||||
|
event: Event,
|
||||||
|
additionalRelays: Set<NormalizedRelayUrl>,
|
||||||
|
) {
|
||||||
|
if (!isWriteable()) return
|
||||||
|
if (event.pubKey != signer.pubKey) return
|
||||||
|
|
||||||
|
signer.sign(
|
||||||
|
DeletionEvent.build(listOf(event)),
|
||||||
|
) { deletionEvent ->
|
||||||
|
client.send(deletionEvent, outboxRelays.flow.value + additionalRelays)
|
||||||
|
cache.justConsumeMyOwnEvent(deletionEvent)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
suspend fun createHTTPAuthorization(
|
suspend fun createHTTPAuthorization(
|
||||||
url: String,
|
url: String,
|
||||||
method: String,
|
method: String,
|
||||||
@@ -1438,9 +1453,10 @@ class Account(
|
|||||||
noteEvent.createDeletedEvent(signer) {
|
noteEvent.createDeletedEvent(signer) {
|
||||||
client.send(it, outboxRelays.flow.value + note.relays)
|
client.send(it, outboxRelays.flow.value + note.relays)
|
||||||
cache.justConsumeMyOwnEvent(it)
|
cache.justConsumeMyOwnEvent(it)
|
||||||
|
|
||||||
|
delete(it, note.relays.toSet())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
delete(note)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2784,6 +2784,12 @@ object LocalCache : ILocalCache {
|
|||||||
if (consumeBaseReplaceable(event, relay, wasVerified)) {
|
if (consumeBaseReplaceable(event, relay, wasVerified)) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
// passes to the AccountViewModel for further delete.
|
||||||
|
val note = Note(event.id)
|
||||||
|
note.loadEvent(event, getOrCreateUser(event.pubKey), emptyList())
|
||||||
|
relay?.let { note.addRelay(it) }
|
||||||
|
refreshObservers(note)
|
||||||
}
|
}
|
||||||
|
|
||||||
return false
|
return false
|
||||||
|
|||||||
+2
-2
@@ -28,7 +28,7 @@ import com.vitorpamplona.quartz.nip37Drafts.DraftEvent
|
|||||||
import com.vitorpamplona.quartz.nip51Lists.BookmarkListEvent
|
import com.vitorpamplona.quartz.nip51Lists.BookmarkListEvent
|
||||||
import com.vitorpamplona.quartz.nip56Reports.ReportEvent
|
import com.vitorpamplona.quartz.nip56Reports.ReportEvent
|
||||||
|
|
||||||
val DraftsAndReportsFromKeyKinds =
|
val ReportsAndBookmarksFromKeyKinds =
|
||||||
listOf(
|
listOf(
|
||||||
DraftEvent.KIND,
|
DraftEvent.KIND,
|
||||||
ReportEvent.KIND,
|
ReportEvent.KIND,
|
||||||
@@ -47,7 +47,7 @@ fun filterDraftsAndReportsFromKey(
|
|||||||
relay = relay,
|
relay = relay,
|
||||||
filter =
|
filter =
|
||||||
Filter(
|
Filter(
|
||||||
kinds = DraftsAndReportsFromKeyKinds,
|
kinds = ReportsAndBookmarksFromKeyKinds,
|
||||||
authors = listOf(pubkey),
|
authors = listOf(pubkey),
|
||||||
since = since,
|
since = since,
|
||||||
),
|
),
|
||||||
|
|||||||
+22
-3
@@ -68,9 +68,13 @@ 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.pubKey == account.signer.pubKey) {
|
||||||
event.cachedDraft(account.signer) {
|
if (!event.isDeleted()) {
|
||||||
cache.indexDraftAsRealEvent(event, it)
|
if (event.preCachedDraft(account.signer) == null) {
|
||||||
|
event.cachedDraft(account.signer) {
|
||||||
|
cache.indexDraftAsRealEvent(event, it)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -135,6 +139,21 @@ class PrecacheNewNotesProcessor(
|
|||||||
newNotes.forEach {
|
newNotes.forEach {
|
||||||
consume(it)
|
consume(it)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val toDelete =
|
||||||
|
newNotes.mapNotNull {
|
||||||
|
val noteEvent = it.event
|
||||||
|
if (noteEvent is DraftEvent && noteEvent.isDeleted()) {
|
||||||
|
it
|
||||||
|
} else {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (toDelete.isNotEmpty()) {
|
||||||
|
Log.w("PrecacheNewNotesProcessor", "Deleting ${toDelete.size} draft notes that should have been deleted already")
|
||||||
|
account.delete(toDelete)
|
||||||
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
if (e is CancellationException) throw e
|
if (e is CancellationException) throw e
|
||||||
Log.e("PrecacheNewNotesProcessor", "This shouldn't happen", e)
|
Log.e("PrecacheNewNotesProcessor", "This shouldn't happen", e)
|
||||||
|
|||||||
Reference in New Issue
Block a user