fix createZapRequestFor userhex
This commit is contained in:
@@ -594,16 +594,62 @@ class Account(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun createZapRequestFor(userPubKeyHex: String, message: String = "", zapType: LnZapEvent.ZapType): LnZapRequestEvent? {
|
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(
|
return LnZapRequestEvent.create(
|
||||||
|
unsignedEvent,
|
||||||
|
content
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
LnZapEvent.ZapType.PRIVATE -> {
|
||||||
|
val unsignedEvent = LnZapRequestEvent.createPrivateZap(
|
||||||
userPubKeyHex,
|
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!!,
|
keyPair.privKey!!,
|
||||||
message,
|
message,
|
||||||
zapType
|
zapType
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun report(note: Note, type: ReportEvent.ReportType, content: String = "") {
|
fun report(note: Note, type: ReportEvent.ReportType, content: String = "") {
|
||||||
if (!isWriteable() && !loginWithAmber) return
|
if (!isWriteable() && !loginWithAmber) return
|
||||||
|
|||||||
@@ -107,6 +107,22 @@ class LnZapRequestEvent(
|
|||||||
return LnZapRequestEvent(unsignedEvent.id, unsignedEvent.pubKey, unsignedEvent.createdAt, unsignedEvent.tags, unsignedEvent.content, signature)
|
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(
|
fun createPublic(
|
||||||
originalNote: EventInterface,
|
originalNote: EventInterface,
|
||||||
relays: Set<String>,
|
relays: Set<String>,
|
||||||
@@ -159,6 +175,23 @@ class LnZapRequestEvent(
|
|||||||
return LnZapRequestEvent("zap", pubKey, createdAt, tags, content, "")
|
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(
|
fun createAnonymous(
|
||||||
originalNote: EventInterface,
|
originalNote: EventInterface,
|
||||||
relays: Set<String>,
|
relays: Set<String>,
|
||||||
@@ -188,6 +221,26 @@ class LnZapRequestEvent(
|
|||||||
return LnZapRequestEvent(id.toHexKey(), pubKey, createdAt, tags, message, sig.toHexKey())
|
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(
|
fun create(
|
||||||
userHex: String,
|
userHex: String,
|
||||||
relays: Set<String>,
|
relays: Set<String>,
|
||||||
|
|||||||
Reference in New Issue
Block a user