support for public and anon zaps
This commit is contained in:
@@ -337,18 +337,54 @@ class Account(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun createZapRequestFor(note: Note, pollOption: Int?, message: String = "", zapType: LnZapEvent.ZapType): LnZapRequestEvent? {
|
fun createZapRequestFor(note: Note, pollOption: Int?, message: String = "", zapType: LnZapEvent.ZapType): LnZapRequestEvent? {
|
||||||
if (!isWriteable()) return null
|
if (!isWriteable() && !loginWithAmber) return null
|
||||||
|
|
||||||
note.event?.let { event ->
|
note.event?.let { event ->
|
||||||
return LnZapRequestEvent.create(
|
if (loginWithAmber) {
|
||||||
event,
|
when (zapType) {
|
||||||
userProfile().latestContactList?.relays()?.keys?.ifEmpty { null }
|
LnZapEvent.ZapType.ANONYMOUS -> {
|
||||||
?: localRelays.map { it.url }.toSet(),
|
return LnZapRequestEvent.createAnonymous(
|
||||||
keyPair.privKey!!,
|
event,
|
||||||
pollOption,
|
userProfile().latestContactList?.relays()?.keys?.ifEmpty { null }
|
||||||
message,
|
?: localRelays.map { it.url }.toSet(),
|
||||||
zapType
|
pollOption,
|
||||||
)
|
message
|
||||||
|
)
|
||||||
|
}
|
||||||
|
LnZapEvent.ZapType.PUBLIC -> {
|
||||||
|
val unsignedEvent = LnZapRequestEvent.createPublic(
|
||||||
|
event,
|
||||||
|
userProfile().latestContactList?.relays()?.keys?.ifEmpty { null }
|
||||||
|
?: localRelays.map { it.url }.toSet(),
|
||||||
|
keyPair.pubKey.toHexKey(),
|
||||||
|
pollOption,
|
||||||
|
message
|
||||||
|
)
|
||||||
|
AmberUtils.content = ""
|
||||||
|
AmberUtils.openAmber(unsignedEvent)
|
||||||
|
if (AmberUtils.content.isBlank()) return null
|
||||||
|
return LnZapRequestEvent(
|
||||||
|
unsignedEvent.id,
|
||||||
|
unsignedEvent.pubKey,
|
||||||
|
unsignedEvent.createdAt,
|
||||||
|
unsignedEvent.tags,
|
||||||
|
unsignedEvent.content,
|
||||||
|
AmberUtils.content
|
||||||
|
)
|
||||||
|
}
|
||||||
|
else -> null
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return LnZapRequestEvent.create(
|
||||||
|
event,
|
||||||
|
userProfile().latestContactList?.relays()?.keys?.ifEmpty { null }
|
||||||
|
?: localRelays.map { it.url }.toSet(),
|
||||||
|
keyPair.privKey!!,
|
||||||
|
pollOption,
|
||||||
|
message,
|
||||||
|
zapType
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1118,14 +1118,35 @@ private fun zapClick(
|
|||||||
.show()
|
.show()
|
||||||
}
|
}
|
||||||
} else if (!accountViewModel.isWriteable()) {
|
} else if (!accountViewModel.isWriteable()) {
|
||||||
scope.launch {
|
if (accountViewModel.loggedInWithAmber()) {
|
||||||
Toast
|
if (accountViewModel.account.zapAmountChoices.size == 1) {
|
||||||
.makeText(
|
accountViewModel.zap(
|
||||||
|
baseNote,
|
||||||
|
accountViewModel.account.zapAmountChoices.first() * 1000,
|
||||||
|
null,
|
||||||
|
"",
|
||||||
context,
|
context,
|
||||||
context.getString(R.string.login_with_a_private_key_to_be_able_to_send_zaps),
|
onError = onError,
|
||||||
Toast.LENGTH_SHORT
|
onProgress = {
|
||||||
|
scope.launch(Dispatchers.Main) {
|
||||||
|
onZappingProgress(it)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
zapType = accountViewModel.account.defaultZapType
|
||||||
)
|
)
|
||||||
.show()
|
} else if (accountViewModel.account.zapAmountChoices.size > 1) {
|
||||||
|
onMultipleChoices()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
scope.launch {
|
||||||
|
Toast
|
||||||
|
.makeText(
|
||||||
|
context,
|
||||||
|
context.getString(R.string.login_with_a_private_key_to_be_able_to_send_zaps),
|
||||||
|
Toast.LENGTH_SHORT
|
||||||
|
)
|
||||||
|
.show()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else if (accountViewModel.account.zapAmountChoices.size == 1) {
|
} else if (accountViewModel.account.zapAmountChoices.size == 1) {
|
||||||
accountViewModel.zap(
|
accountViewModel.zap(
|
||||||
|
|||||||
@@ -99,6 +99,58 @@ class LnZapRequestEvent(
|
|||||||
return LnZapRequestEvent(id.toHexKey(), pubKey, createdAt, tags, content, sig.toHexKey())
|
return LnZapRequestEvent(id.toHexKey(), pubKey, createdAt, tags, content, sig.toHexKey())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun createPublic(
|
||||||
|
originalNote: EventInterface,
|
||||||
|
relays: Set<String>,
|
||||||
|
pubKey: HexKey,
|
||||||
|
pollOption: Int?,
|
||||||
|
message: String,
|
||||||
|
createdAt: Long = TimeUtils.now()
|
||||||
|
): LnZapRequestEvent {
|
||||||
|
var tags = listOf(
|
||||||
|
listOf("e", originalNote.id()),
|
||||||
|
listOf("p", originalNote.pubKey()),
|
||||||
|
listOf("relays") + relays
|
||||||
|
)
|
||||||
|
if (originalNote is AddressableEvent) {
|
||||||
|
tags = tags + listOf(listOf("a", originalNote.address().toTag()))
|
||||||
|
}
|
||||||
|
if (pollOption != null && pollOption >= 0) {
|
||||||
|
tags = tags + listOf(listOf(POLL_OPTION, pollOption.toString()))
|
||||||
|
}
|
||||||
|
|
||||||
|
val id = generateId(pubKey, createdAt, kind, tags, message)
|
||||||
|
return LnZapRequestEvent(id.toHexKey(), pubKey, createdAt, tags, message, "")
|
||||||
|
}
|
||||||
|
|
||||||
|
fun createAnonymous(
|
||||||
|
originalNote: EventInterface,
|
||||||
|
relays: Set<String>,
|
||||||
|
pollOption: Int?,
|
||||||
|
message: String,
|
||||||
|
createdAt: Long = TimeUtils.now()
|
||||||
|
): LnZapRequestEvent {
|
||||||
|
var tags = listOf(
|
||||||
|
listOf("e", originalNote.id()),
|
||||||
|
listOf("p", originalNote.pubKey()),
|
||||||
|
listOf("relays") + relays
|
||||||
|
)
|
||||||
|
if (originalNote is AddressableEvent) {
|
||||||
|
tags = tags + listOf(listOf("a", originalNote.address().toTag()))
|
||||||
|
}
|
||||||
|
if (pollOption != null && pollOption >= 0) {
|
||||||
|
tags = tags + listOf(listOf(POLL_OPTION, pollOption.toString()))
|
||||||
|
}
|
||||||
|
|
||||||
|
tags = tags + listOf(listOf("anon", ""))
|
||||||
|
val privkey = CryptoUtils.privkeyCreate()
|
||||||
|
val pubKey = CryptoUtils.pubkeyCreate(privkey).toHexKey()
|
||||||
|
|
||||||
|
val id = generateId(pubKey, createdAt, kind, tags, message)
|
||||||
|
val sig = CryptoUtils.sign(id, privkey)
|
||||||
|
return LnZapRequestEvent(id.toHexKey(), pubKey, createdAt, tags, message, sig.toHexKey())
|
||||||
|
}
|
||||||
|
|
||||||
fun create(
|
fun create(
|
||||||
userHex: String,
|
userHex: String,
|
||||||
relays: Set<String>,
|
relays: Set<String>,
|
||||||
|
|||||||
Reference in New Issue
Block a user