mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-10-11 03:43:36 +02:00
Fixes error when trying to decrypt the PrivateOutboxRelayList event for an account that is not currently active.
This commit is contained in:
@@ -122,7 +122,6 @@ object NostrAccountDataSource : AmethystNostrDataSource("AccountData") {
|
|||||||
ContactListEvent.KIND,
|
ContactListEvent.KIND,
|
||||||
AdvertisedRelayListEvent.KIND,
|
AdvertisedRelayListEvent.KIND,
|
||||||
ChatMessageRelayListEvent.KIND,
|
ChatMessageRelayListEvent.KIND,
|
||||||
PrivateOutboxRelayListEvent.KIND,
|
|
||||||
SearchRelayListEvent.KIND,
|
SearchRelayListEvent.KIND,
|
||||||
FileServersEvent.KIND,
|
FileServersEvent.KIND,
|
||||||
MuteListEvent.KIND,
|
MuteListEvent.KIND,
|
||||||
|
@@ -57,7 +57,7 @@ class NIP90ContentDiscoveryResponseEvent(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (e: Throwable) {
|
} catch (e: Throwable) {
|
||||||
Log.w("GeneralList", "Error parsing the JSON ${e.message}")
|
Log.w("NIP90ContentDiscoveryResponseEvent", "Error parsing the JSON ${e.message}")
|
||||||
}
|
}
|
||||||
|
|
||||||
return events ?: listOf()
|
return events ?: listOf()
|
||||||
|
@@ -41,27 +41,25 @@ class PrivateOutboxRelayListEvent(
|
|||||||
|
|
||||||
override fun dTag() = FIXED_D_TAG
|
override fun dTag() = FIXED_D_TAG
|
||||||
|
|
||||||
fun relays(): List<String>? {
|
fun relays(): List<String>? =
|
||||||
return tags.mapNotNull {
|
tags
|
||||||
if (it.size > 1 && it[0] == "relay") {
|
.mapNotNull {
|
||||||
it[1]
|
|
||||||
} else {
|
|
||||||
null
|
|
||||||
}
|
|
||||||
}.plus(
|
|
||||||
privateTagsCache?.mapNotNull {
|
|
||||||
if (it.size > 1 && it[0] == "relay") {
|
if (it.size > 1 && it[0] == "relay") {
|
||||||
it[1]
|
it[1]
|
||||||
} else {
|
} else {
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
} ?: emptyList(),
|
}.plus(
|
||||||
).ifEmpty { null }
|
privateTagsCache?.mapNotNull {
|
||||||
}
|
if (it.size > 1 && it[0] == "relay") {
|
||||||
|
it[1]
|
||||||
|
} else {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
} ?: emptyList(),
|
||||||
|
).ifEmpty { null }
|
||||||
|
|
||||||
fun cachedPrivateTags(): Array<Array<String>>? {
|
fun cachedPrivateTags(): Array<Array<String>>? = privateTagsCache
|
||||||
return privateTagsCache
|
|
||||||
}
|
|
||||||
|
|
||||||
fun privateTags(
|
fun privateTags(
|
||||||
signer: NostrSigner,
|
signer: NostrSigner,
|
||||||
@@ -79,11 +77,15 @@ class PrivateOutboxRelayListEvent(
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
signer.nip44Decrypt(content, pubKey) {
|
signer.nip44Decrypt(content, pubKey) {
|
||||||
privateTagsCache = mapper.readValue<Array<Array<String>>>(it)
|
try {
|
||||||
privateTagsCache?.let { onReady(it) }
|
privateTagsCache = mapper.readValue<Array<Array<String>>>(it)
|
||||||
|
privateTagsCache?.let { onReady(it) }
|
||||||
|
} catch (e: Throwable) {
|
||||||
|
Log.w("PrivateOutboxRelayListEvent", "Error parsing the JSON: ${e.message}. Json `$it` from event `${toNostrUri()}`")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (e: Throwable) {
|
} catch (e: Throwable) {
|
||||||
Log.w("GeneralList", "Error parsing the JSON ${e.message}")
|
Log.w("PrivateOutboxRelayListEvent", "Error decrypting content: ${e.message}. Event: `${toNostrUri()}`")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -92,13 +94,9 @@ class PrivateOutboxRelayListEvent(
|
|||||||
const val FIXED_D_TAG = ""
|
const val FIXED_D_TAG = ""
|
||||||
val TAGS = arrayOf(arrayOf("alt", "Relay list to store private content from this author"))
|
val TAGS = arrayOf(arrayOf("alt", "Relay list to store private content from this author"))
|
||||||
|
|
||||||
fun createAddressATag(pubKey: HexKey): ATag {
|
fun createAddressATag(pubKey: HexKey): ATag = ATag(KIND, pubKey, FIXED_D_TAG, null)
|
||||||
return ATag(KIND, pubKey, FIXED_D_TAG, null)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun createAddressTag(pubKey: HexKey): String {
|
fun createAddressTag(pubKey: HexKey): String = ATag.assembleATag(KIND, pubKey, FIXED_D_TAG)
|
||||||
return ATag.assembleATag(KIND, pubKey, FIXED_D_TAG)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun encryptTags(
|
fun encryptTags(
|
||||||
privateTags: Array<Array<String>>? = null,
|
privateTags: Array<Array<String>>? = null,
|
||||||
@@ -114,11 +112,11 @@ class PrivateOutboxRelayListEvent(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun createTagArray(relays: List<String>): Array<Array<String>> {
|
fun createTagArray(relays: List<String>): Array<Array<String>> =
|
||||||
return relays.map {
|
relays
|
||||||
arrayOf("relay", it)
|
.map {
|
||||||
}.toTypedArray()
|
arrayOf("relay", it)
|
||||||
}
|
}.toTypedArray()
|
||||||
|
|
||||||
fun updateRelayList(
|
fun updateRelayList(
|
||||||
earlierVersion: PrivateOutboxRelayListEvent,
|
earlierVersion: PrivateOutboxRelayListEvent,
|
||||||
@@ -128,11 +126,13 @@ class PrivateOutboxRelayListEvent(
|
|||||||
onReady: (PrivateOutboxRelayListEvent) -> Unit,
|
onReady: (PrivateOutboxRelayListEvent) -> Unit,
|
||||||
) {
|
) {
|
||||||
val tags =
|
val tags =
|
||||||
earlierVersion.privateTagsCache?.filter { it[0] != "relay" }?.plus(
|
earlierVersion.privateTagsCache
|
||||||
relays.map {
|
?.filter { it[0] != "relay" }
|
||||||
arrayOf("relay", it)
|
?.plus(
|
||||||
},
|
relays.map {
|
||||||
)?.toTypedArray() ?: emptyArray()
|
arrayOf("relay", it)
|
||||||
|
},
|
||||||
|
)?.toTypedArray() ?: emptyArray()
|
||||||
|
|
||||||
encryptTags(tags, signer) {
|
encryptTags(tags, signer) {
|
||||||
signer.sign<PrivateOutboxRelayListEvent>(createdAt, KIND, TAGS, it) {
|
signer.sign<PrivateOutboxRelayListEvent>(createdAt, KIND, TAGS, it) {
|
||||||
|
@@ -52,9 +52,7 @@ class Permission(
|
|||||||
val type: String,
|
val type: String,
|
||||||
val kind: Int? = null,
|
val kind: Int? = null,
|
||||||
) {
|
) {
|
||||||
fun toJson(): String {
|
fun toJson(): String = "{\"type\":\"${type}\",\"kind\":$kind}"
|
||||||
return "{\"type\":\"${type}\",\"kind\":$kind}"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class Result(
|
class Result(
|
||||||
@@ -89,9 +87,7 @@ class Result(
|
|||||||
/**
|
/**
|
||||||
* Parses the json with a string of events to an Array of Event objects.
|
* Parses the json with a string of events to an Array of Event objects.
|
||||||
*/
|
*/
|
||||||
fun fromJsonArray(json: String): Array<Result> {
|
fun fromJsonArray(json: String): Array<Result> = mapper.readValue(json)
|
||||||
return mapper.readValue(json)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -272,9 +268,7 @@ class ExternalSignerLauncher(
|
|||||||
signerType: SignerType,
|
signerType: SignerType,
|
||||||
data: Array<out String>,
|
data: Array<out String>,
|
||||||
columnName: String = "signature",
|
columnName: String = "signature",
|
||||||
): kotlin.Result<String?> {
|
): kotlin.Result<String?> = getDataFromResolver(signerType, data, columnName, contentResolver)
|
||||||
return getDataFromResolver(signerType, data, columnName, contentResolver)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun getDataFromResolver(
|
private fun getDataFromResolver(
|
||||||
signerType: SignerType,
|
signerType: SignerType,
|
||||||
@@ -298,8 +292,7 @@ class ExternalSignerLauncher(
|
|||||||
"1",
|
"1",
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
)
|
).use {
|
||||||
.use {
|
|
||||||
if (it == null) {
|
if (it == null) {
|
||||||
return kotlin.Result.success(null)
|
return kotlin.Result.success(null)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user