mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2024-09-29 16:30:49 +00:00
fix createZapRequestFor userhex
This commit is contained in:
parent
2fa4281b6f
commit
d726b3b5b5
@ -594,16 +594,62 @@ class Account(
|
||||
}
|
||||
|
||||
fun createZapRequestFor(userPubKeyHex: String, message: String = "", zapType: LnZapEvent.ZapType): LnZapRequestEvent? {
|
||||
if (!isWriteable()) return null
|
||||
if (!isWriteable() && !loginWithAmber) return null
|
||||
if (loginWithAmber) {
|
||||
return when (zapType) {
|
||||
LnZapEvent.ZapType.ANONYMOUS -> {
|
||||
return LnZapRequestEvent.createAnonymous(
|
||||
userPubKeyHex,
|
||||
userProfile().latestContactList?.relays()?.keys?.ifEmpty { null }
|
||||
?: localRelays.map { it.url }.toSet(),
|
||||
message
|
||||
)
|
||||
}
|
||||
LnZapEvent.ZapType.PUBLIC -> {
|
||||
val unsignedEvent = LnZapRequestEvent.createPublic(
|
||||
userPubKeyHex,
|
||||
userProfile().latestContactList?.relays()?.keys?.ifEmpty { null }
|
||||
?: localRelays.map { it.url }.toSet(),
|
||||
keyPair.pubKey.toHexKey(),
|
||||
message
|
||||
)
|
||||
AmberUtils.openAmber(unsignedEvent)
|
||||
val content = AmberUtils.content[unsignedEvent.id] ?: ""
|
||||
if (content.isBlank()) return null
|
||||
|
||||
return LnZapRequestEvent.create(
|
||||
unsignedEvent,
|
||||
content
|
||||
)
|
||||
}
|
||||
|
||||
LnZapEvent.ZapType.PRIVATE -> {
|
||||
val unsignedEvent = LnZapRequestEvent.createPrivateZap(
|
||||
userPubKeyHex,
|
||||
userProfile().latestContactList?.relays()?.keys?.ifEmpty { null } ?: localRelays.map { it.url }.toSet(),
|
||||
userProfile().latestContactList?.relays()?.keys?.ifEmpty { null }
|
||||
?: localRelays.map { it.url }.toSet(),
|
||||
keyPair.pubKey.toHexKey(),
|
||||
message
|
||||
)
|
||||
AmberUtils.openAmber(unsignedEvent, "event")
|
||||
val content = AmberUtils.content[unsignedEvent.id] ?: ""
|
||||
if (content.isBlank()) return null
|
||||
|
||||
return Event.fromJson(content) as LnZapRequestEvent
|
||||
}
|
||||
else -> null
|
||||
}
|
||||
} else {
|
||||
return LnZapRequestEvent.create(
|
||||
userPubKeyHex,
|
||||
userProfile().latestContactList?.relays()?.keys?.ifEmpty { null }
|
||||
?: localRelays.map { it.url }.toSet(),
|
||||
keyPair.privKey!!,
|
||||
message,
|
||||
zapType
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fun report(note: Note, type: ReportEvent.ReportType, content: String = "") {
|
||||
if (!isWriteable() && !loginWithAmber) return
|
||||
|
@ -107,6 +107,22 @@ class LnZapRequestEvent(
|
||||
return LnZapRequestEvent(unsignedEvent.id, unsignedEvent.pubKey, unsignedEvent.createdAt, unsignedEvent.tags, unsignedEvent.content, signature)
|
||||
}
|
||||
|
||||
fun createPublic(
|
||||
userHex: String,
|
||||
relays: Set<String>,
|
||||
pubKey: HexKey,
|
||||
message: String,
|
||||
createdAt: Long = TimeUtils.now()
|
||||
): LnZapRequestEvent {
|
||||
val tags = listOf(
|
||||
listOf("p", userHex),
|
||||
listOf("relays") + relays
|
||||
)
|
||||
|
||||
val id = generateId(pubKey, createdAt, kind, tags, message)
|
||||
return LnZapRequestEvent(id.toHexKey(), pubKey, createdAt, tags, message, "")
|
||||
}
|
||||
|
||||
fun createPublic(
|
||||
originalNote: EventInterface,
|
||||
relays: Set<String>,
|
||||
@ -159,6 +175,23 @@ class LnZapRequestEvent(
|
||||
return LnZapRequestEvent("zap", pubKey, createdAt, tags, content, "")
|
||||
}
|
||||
|
||||
fun createPrivateZap(
|
||||
userHex: String,
|
||||
relays: Set<String>,
|
||||
pubKey: HexKey,
|
||||
message: String,
|
||||
createdAt: Long = TimeUtils.now()
|
||||
): LnZapRequestEvent {
|
||||
val content = message
|
||||
var tags = listOf(
|
||||
listOf("p", userHex),
|
||||
listOf("relays") + relays
|
||||
)
|
||||
tags = tags + listOf(listOf("anon", ""))
|
||||
|
||||
return LnZapRequestEvent("zap", pubKey, createdAt, tags, content, "")
|
||||
}
|
||||
|
||||
fun createAnonymous(
|
||||
originalNote: EventInterface,
|
||||
relays: Set<String>,
|
||||
@ -188,6 +221,26 @@ class LnZapRequestEvent(
|
||||
return LnZapRequestEvent(id.toHexKey(), pubKey, createdAt, tags, message, sig.toHexKey())
|
||||
}
|
||||
|
||||
fun createAnonymous(
|
||||
userHex: String,
|
||||
relays: Set<String>,
|
||||
message: String,
|
||||
createdAt: Long = TimeUtils.now()
|
||||
): LnZapRequestEvent {
|
||||
var tags = listOf(
|
||||
listOf("p", userHex),
|
||||
listOf("relays") + relays
|
||||
)
|
||||
|
||||
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(
|
||||
userHex: String,
|
||||
relays: Set<String>,
|
||||
|
Loading…
Reference in New Issue
Block a user