- Adds the NIP-65 relay to zap split tag instead of kind3 relays.

- Rounds percentages to the 2 decimals.
This commit is contained in:
Vitor Pamplona
2024-06-11 11:23:20 -04:00
parent b322efc286
commit 9ca6151313
3 changed files with 21 additions and 4 deletions

View File

@@ -79,6 +79,7 @@ import kotlinx.coroutines.flow.mapLatest
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import java.util.UUID
import kotlin.math.round
enum class UserSuggestionAnchor {
MAIN_MESSAGE,
@@ -474,11 +475,15 @@ open class NewPostViewModel() : ViewModel() {
val zapReceiver =
if (wantsForwardZapTo) {
forwardZapTo.items.map {
forwardZapTo.items.map { split ->
val homeRelay =
accountViewModel?.getRelayListFor(split.key)?.writeRelays()?.firstOrNull()
?: split.key.relaysBeingUsed.keys.firstOrNull { !it.contains("localhost") }
ZapSplitSetup(
lnAddressOrPubKeyHex = it.key.pubkeyHex,
relay = it.key.relaysBeingUsed.keys.firstOrNull(),
weight = it.percentage.toDouble(),
lnAddressOrPubKeyHex = split.key.pubkeyHex,
relay = homeRelay,
weight = round(split.percentage.toDouble() * 10000),
isLnAddress = false,
)
}

View File

@@ -26,6 +26,7 @@ import androidx.compose.runtime.setValue
import kotlin.math.abs
class SplitItem<T>(val key: T) {
// 0 to 1
var percentage by mutableStateOf(0f)
}

View File

@@ -74,6 +74,7 @@ import com.vitorpamplona.quartz.encoders.Nip11RelayInformation
import com.vitorpamplona.quartz.encoders.Nip19Bech32
import com.vitorpamplona.quartz.encoders.toHexKey
import com.vitorpamplona.quartz.events.AddressableEvent
import com.vitorpamplona.quartz.events.AdvertisedRelayListEvent
import com.vitorpamplona.quartz.events.ChatMessageRelayListEvent
import com.vitorpamplona.quartz.events.ChatroomKey
import com.vitorpamplona.quartz.events.ChatroomKeyable
@@ -1403,6 +1404,16 @@ class AccountViewModel(val account: Account, val settings: SettingsState) : View
}
}
fun getRelayListFor(user: User): AdvertisedRelayListEvent? {
return (getRelayListNoteFor(user)?.event as? AdvertisedRelayListEvent?)
}
fun getRelayListNoteFor(user: User): AddressableNote? {
return LocalCache.getAddressableNoteIfExists(
AdvertisedRelayListEvent.createAddressTag(user.pubkeyHex),
)
}
val draftNoteCache = CachedDraftNotes(this)
class CachedDraftNotes(val accountViewModel: AccountViewModel) : GenericBaseCacheAsync<DraftEvent, Note>(20) {