mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-10-11 03:34:45 +02:00
- Adds the NIP-65 relay to zap
split tag instead of kind3 relays.
- Rounds percentages to the 2 decimals.
This commit is contained in:
@@ -79,6 +79,7 @@ import kotlinx.coroutines.flow.mapLatest
|
|||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
import java.util.UUID
|
import java.util.UUID
|
||||||
|
import kotlin.math.round
|
||||||
|
|
||||||
enum class UserSuggestionAnchor {
|
enum class UserSuggestionAnchor {
|
||||||
MAIN_MESSAGE,
|
MAIN_MESSAGE,
|
||||||
@@ -474,11 +475,15 @@ open class NewPostViewModel() : ViewModel() {
|
|||||||
|
|
||||||
val zapReceiver =
|
val zapReceiver =
|
||||||
if (wantsForwardZapTo) {
|
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(
|
ZapSplitSetup(
|
||||||
lnAddressOrPubKeyHex = it.key.pubkeyHex,
|
lnAddressOrPubKeyHex = split.key.pubkeyHex,
|
||||||
relay = it.key.relaysBeingUsed.keys.firstOrNull(),
|
relay = homeRelay,
|
||||||
weight = it.percentage.toDouble(),
|
weight = round(split.percentage.toDouble() * 10000),
|
||||||
isLnAddress = false,
|
isLnAddress = false,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@@ -26,6 +26,7 @@ import androidx.compose.runtime.setValue
|
|||||||
import kotlin.math.abs
|
import kotlin.math.abs
|
||||||
|
|
||||||
class SplitItem<T>(val key: T) {
|
class SplitItem<T>(val key: T) {
|
||||||
|
// 0 to 1
|
||||||
var percentage by mutableStateOf(0f)
|
var percentage by mutableStateOf(0f)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -74,6 +74,7 @@ import com.vitorpamplona.quartz.encoders.Nip11RelayInformation
|
|||||||
import com.vitorpamplona.quartz.encoders.Nip19Bech32
|
import com.vitorpamplona.quartz.encoders.Nip19Bech32
|
||||||
import com.vitorpamplona.quartz.encoders.toHexKey
|
import com.vitorpamplona.quartz.encoders.toHexKey
|
||||||
import com.vitorpamplona.quartz.events.AddressableEvent
|
import com.vitorpamplona.quartz.events.AddressableEvent
|
||||||
|
import com.vitorpamplona.quartz.events.AdvertisedRelayListEvent
|
||||||
import com.vitorpamplona.quartz.events.ChatMessageRelayListEvent
|
import com.vitorpamplona.quartz.events.ChatMessageRelayListEvent
|
||||||
import com.vitorpamplona.quartz.events.ChatroomKey
|
import com.vitorpamplona.quartz.events.ChatroomKey
|
||||||
import com.vitorpamplona.quartz.events.ChatroomKeyable
|
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)
|
val draftNoteCache = CachedDraftNotes(this)
|
||||||
|
|
||||||
class CachedDraftNotes(val accountViewModel: AccountViewModel) : GenericBaseCacheAsync<DraftEvent, Note>(20) {
|
class CachedDraftNotes(val accountViewModel: AccountViewModel) : GenericBaseCacheAsync<DraftEvent, Note>(20) {
|
||||||
|
Reference in New Issue
Block a user