remove hacky fun for getting poll_option from ZapEvent
This commit is contained in:
@@ -3,22 +3,7 @@ package com.vitorpamplona.amethyst.model
|
|||||||
import android.content.res.Resources
|
import android.content.res.Resources
|
||||||
import androidx.core.os.ConfigurationCompat
|
import androidx.core.os.ConfigurationCompat
|
||||||
import androidx.lifecycle.LiveData
|
import androidx.lifecycle.LiveData
|
||||||
import com.vitorpamplona.amethyst.service.model.BookmarkListEvent
|
import com.vitorpamplona.amethyst.service.model.*
|
||||||
import com.vitorpamplona.amethyst.service.model.ChannelCreateEvent
|
|
||||||
import com.vitorpamplona.amethyst.service.model.ChannelMessageEvent
|
|
||||||
import com.vitorpamplona.amethyst.service.model.ChannelMetadataEvent
|
|
||||||
import com.vitorpamplona.amethyst.service.model.Contact
|
|
||||||
import com.vitorpamplona.amethyst.service.model.ContactListEvent
|
|
||||||
import com.vitorpamplona.amethyst.service.model.DeletionEvent
|
|
||||||
import com.vitorpamplona.amethyst.service.model.IdentityClaim
|
|
||||||
import com.vitorpamplona.amethyst.service.model.LnZapPaymentRequestEvent
|
|
||||||
import com.vitorpamplona.amethyst.service.model.LnZapRequestEvent
|
|
||||||
import com.vitorpamplona.amethyst.service.model.MetadataEvent
|
|
||||||
import com.vitorpamplona.amethyst.service.model.PrivateDmEvent
|
|
||||||
import com.vitorpamplona.amethyst.service.model.ReactionEvent
|
|
||||||
import com.vitorpamplona.amethyst.service.model.ReportEvent
|
|
||||||
import com.vitorpamplona.amethyst.service.model.RepostEvent
|
|
||||||
import com.vitorpamplona.amethyst.service.model.TextNoteEvent
|
|
||||||
import com.vitorpamplona.amethyst.service.relays.Client
|
import com.vitorpamplona.amethyst.service.relays.Client
|
||||||
import com.vitorpamplona.amethyst.service.relays.Constants
|
import com.vitorpamplona.amethyst.service.relays.Constants
|
||||||
import com.vitorpamplona.amethyst.service.relays.FeedType
|
import com.vitorpamplona.amethyst.service.relays.FeedType
|
||||||
@@ -30,11 +15,7 @@ import kotlinx.coroutines.DelicateCoroutinesApi
|
|||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.GlobalScope
|
import kotlinx.coroutines.GlobalScope
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import com.vitorpamplona.amethyst.service.model.*
|
|
||||||
import com.vitorpamplona.amethyst.service.relays.*
|
|
||||||
import kotlinx.coroutines.*
|
|
||||||
import nostr.postr.Persona
|
import nostr.postr.Persona
|
||||||
import java.util.*
|
|
||||||
import java.util.Locale
|
import java.util.Locale
|
||||||
|
|
||||||
val DefaultChannels = setOf(
|
val DefaultChannels = setOf(
|
||||||
@@ -165,12 +146,10 @@ class Account(
|
|||||||
userProfile().latestContactList?.relays()?.keys?.ifEmpty { null }
|
userProfile().latestContactList?.relays()?.keys?.ifEmpty { null }
|
||||||
?: localRelays.map { it.url }.toSet(),
|
?: localRelays.map { it.url }.toSet(),
|
||||||
loggedIn.privKey!!,
|
loggedIn.privKey!!,
|
||||||
pollOption
|
pollOption,
|
||||||
|
message
|
||||||
)
|
)
|
||||||
/*note.event?.let {
|
}
|
||||||
return LnZapRequestEvent.create(it, userProfile().latestContactList?.relays()?.keys?.ifEmpty { null } ?: localRelays.map { it.url }.toSet(), loggedIn.privKey!!, message)
|
|
||||||
}*/
|
|
||||||
|
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -189,13 +168,18 @@ class Account(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun createZapRequestFor(user: User): LnZapRequestEvent? {
|
fun createZapRequestFor(user: User): LnZapRequestEvent? {
|
||||||
return createZapRequestFor(user.pubkeyHex)
|
return createZapRequestFor(user)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun createZapRequestFor(userPubKeyHex: String, message: String = ""): LnZapRequestEvent? {
|
fun createZapRequestFor(userPubKeyHex: String, message: String = ""): LnZapRequestEvent? {
|
||||||
if (!isWriteable()) return null
|
if (!isWriteable()) return null
|
||||||
|
|
||||||
return LnZapRequestEvent.create(userPubKeyHex, userProfile().latestContactList?.relays()?.keys?.ifEmpty { null } ?: localRelays.map { it.url }.toSet(), loggedIn.privKey!!, message)
|
return LnZapRequestEvent.create(
|
||||||
|
userPubKeyHex,
|
||||||
|
userProfile().latestContactList?.relays()?.keys?.ifEmpty { null } ?: localRelays.map { it.url }.toSet(),
|
||||||
|
loggedIn.privKey!!,
|
||||||
|
message
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun report(note: Note, type: ReportEvent.ReportType, content: String = "") {
|
fun report(note: Note, type: ReportEvent.ReportType, content: String = "") {
|
||||||
|
|||||||
@@ -19,16 +19,9 @@ class LnZapEvent(
|
|||||||
.filter { it.firstOrNull() == "e" }
|
.filter { it.firstOrNull() == "e" }
|
||||||
.mapNotNull { it.getOrNull(1) }
|
.mapNotNull { it.getOrNull(1) }
|
||||||
|
|
||||||
/* // TODO add poll_option tag to LnZapEvent
|
override fun zappedPollOption(): Int? = containedPost()?.tags
|
||||||
override fun zappedPollOption(): Int? = tags
|
?.filter { it.firstOrNull() == POLL_OPTION }
|
||||||
.filter { it.firstOrNull() == "poll_option" }
|
?.getOrNull(0)?.getOrNull(1)?.toInt()
|
||||||
.getOrNull(1)?.getOrNull(1)?.toInt()
|
|
||||||
*/
|
|
||||||
// TODO replace this hacky way to get poll option with above function
|
|
||||||
override fun zappedPollOption(): Int? = description()
|
|
||||||
?.substringAfter("poll_option\",\"")
|
|
||||||
?.substringBefore("\"")
|
|
||||||
?.toInt()
|
|
||||||
|
|
||||||
override fun zappedAuthor() = tags
|
override fun zappedAuthor() = tags
|
||||||
.filter { it.firstOrNull() == "p" }
|
.filter { it.firstOrNull() == "p" }
|
||||||
|
|||||||
@@ -50,19 +50,16 @@ class LnZapRequestEvent(
|
|||||||
userHex: String,
|
userHex: String,
|
||||||
relays: Set<String>,
|
relays: Set<String>,
|
||||||
privateKey: ByteArray,
|
privateKey: ByteArray,
|
||||||
pollOption: Int?,
|
|
||||||
message: String,
|
message: String,
|
||||||
createdAt: Long = Date().time / 1000
|
createdAt: Long = Date().time / 1000
|
||||||
): LnZapRequestEvent {
|
): LnZapRequestEvent {
|
||||||
val content = message
|
val content = message
|
||||||
val pubKey = Utils.pubkeyCreate(privateKey).toHexKey()
|
val pubKey = Utils.pubkeyCreate(privateKey).toHexKey()
|
||||||
var tags = listOf(
|
val tags = listOf(
|
||||||
listOf("p", userHex),
|
listOf("p", userHex),
|
||||||
listOf("relays") + relays
|
listOf("relays") + relays
|
||||||
)
|
)
|
||||||
if (pollOption != null && pollOption >= 0) {
|
|
||||||
tags = tags + listOf(listOf(POLL_OPTION, pollOption.toString()))
|
|
||||||
}
|
|
||||||
val id = generateId(pubKey, createdAt, kind, tags, content)
|
val id = generateId(pubKey, createdAt, kind, tags, content)
|
||||||
val sig = Utils.sign(id, privateKey)
|
val sig = Utils.sign(id, privateKey)
|
||||||
return LnZapRequestEvent(id.toHexKey(), pubKey, createdAt, tags, content, sig.toHexKey())
|
return LnZapRequestEvent(id.toHexKey(), pubKey, createdAt, tags, content, sig.toHexKey())
|
||||||
|
|||||||
@@ -94,6 +94,7 @@ fun ZapCustomDialog(onClose: () -> Unit, account: Account, accountViewModel: Acc
|
|||||||
accountViewModel.zap(
|
accountViewModel.zap(
|
||||||
baseNote,
|
baseNote,
|
||||||
postViewModel.value()!! * 1000L,
|
postViewModel.value()!! * 1000L,
|
||||||
|
null,
|
||||||
postViewModel.customMessage.text,
|
postViewModel.customMessage.text,
|
||||||
context,
|
context,
|
||||||
onError = {
|
onError = {
|
||||||
|
|||||||
Reference in New Issue
Block a user