mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-09-25 19:56:47 +02:00
add signer dialog in the relay screen
This commit is contained in:
@@ -155,8 +155,8 @@ class Account(
|
||||
return keyPair.privKey != null
|
||||
}
|
||||
|
||||
fun sendNewRelayList(relays: Map<String, ContactListEvent.ReadWrite>) {
|
||||
if (!isWriteable()) return
|
||||
fun sendNewRelayList(relays: Map<String, ContactListEvent.ReadWrite>, signEvent: Boolean): ContactListEvent? {
|
||||
if (!isWriteable() && signEvent) return null
|
||||
|
||||
val contactList = userProfile().latestContactList
|
||||
|
||||
@@ -164,11 +164,17 @@ class Account(
|
||||
val event = ContactListEvent.updateRelayList(
|
||||
earlierVersion = contactList,
|
||||
relayUse = relays,
|
||||
privateKey = keyPair.privKey!!
|
||||
pubKey = keyPair.pubKey.toHexKey(),
|
||||
privateKey = keyPair.privKey
|
||||
)
|
||||
|
||||
if (!signEvent) {
|
||||
return event
|
||||
}
|
||||
|
||||
Client.send(event)
|
||||
LocalCache.consume(event)
|
||||
return null
|
||||
} else {
|
||||
val event = ContactListEvent.createFromScratch(
|
||||
followUsers = listOf(),
|
||||
@@ -177,13 +183,19 @@ class Account(
|
||||
followCommunities = listOf(),
|
||||
followEvents = DefaultChannels.toList(),
|
||||
relayUse = relays,
|
||||
privateKey = keyPair.privKey!!
|
||||
privateKey = keyPair.privKey!!,
|
||||
publicKey = if (!signEvent) keyPair.pubKey else null
|
||||
)
|
||||
|
||||
if (!signEvent) {
|
||||
return event
|
||||
}
|
||||
|
||||
// Keep this local to avoid erasing a good contact list.
|
||||
// Client.send(event)
|
||||
LocalCache.consume(event)
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
fun sendNewUserMetadata(toString: String, identities: List<IdentityClaim>, signEvent: Boolean = true): MetadataEvent? {
|
||||
@@ -1821,11 +1833,13 @@ class Account(
|
||||
).toSet()
|
||||
}
|
||||
|
||||
fun saveRelayList(value: List<RelaySetupInfo>) {
|
||||
localRelays = value.toSet()
|
||||
sendNewRelayList(value.associate { it.url to ContactListEvent.ReadWrite(it.read, it.write) })
|
||||
|
||||
saveable.invalidateData()
|
||||
fun saveRelayList(value: List<RelaySetupInfo>, signEvent: Boolean): ContactListEvent? {
|
||||
try {
|
||||
localRelays = value.toSet()
|
||||
return sendNewRelayList(value.associate { it.url to ContactListEvent.ReadWrite(it.read, it.write) }, signEvent)
|
||||
} finally {
|
||||
saveable.invalidateData()
|
||||
}
|
||||
}
|
||||
|
||||
fun setHideDeleteRequestDialog() {
|
||||
|
@@ -319,13 +319,22 @@ class ContactListEvent(
|
||||
)
|
||||
}
|
||||
|
||||
fun updateRelayList(earlierVersion: ContactListEvent, relayUse: Map<String, ReadWrite>?, privateKey: ByteArray, createdAt: Long = TimeUtils.now()): ContactListEvent {
|
||||
fun updateRelayList(earlierVersion: ContactListEvent, relayUse: Map<String, ReadWrite>?, pubKey: HexKey, privateKey: ByteArray?, createdAt: Long = TimeUtils.now()): ContactListEvent {
|
||||
val content = if (relayUse != null) {
|
||||
gson.toJson(relayUse)
|
||||
} else {
|
||||
""
|
||||
}
|
||||
|
||||
if (privateKey == null) {
|
||||
return create(
|
||||
content = content,
|
||||
tags = earlierVersion.tags,
|
||||
pubKey = pubKey,
|
||||
createdAt = createdAt
|
||||
)
|
||||
}
|
||||
|
||||
return create(
|
||||
content = content,
|
||||
tags = earlierVersion.tags,
|
||||
|
@@ -57,8 +57,12 @@ import androidx.compose.ui.window.Dialog
|
||||
import androidx.compose.ui.window.DialogProperties
|
||||
import androidx.lifecycle.viewmodel.compose.viewModel
|
||||
import com.vitorpamplona.amethyst.R
|
||||
import com.vitorpamplona.amethyst.model.LocalCache
|
||||
import com.vitorpamplona.amethyst.model.RelayInformation
|
||||
import com.vitorpamplona.amethyst.model.RelaySetupInfo
|
||||
import com.vitorpamplona.amethyst.service.PackageUtils
|
||||
import com.vitorpamplona.amethyst.service.model.Event
|
||||
import com.vitorpamplona.amethyst.service.relays.Client
|
||||
import com.vitorpamplona.amethyst.service.relays.Constants.defaultRelays
|
||||
import com.vitorpamplona.amethyst.service.relays.FeedType
|
||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
|
||||
@@ -68,6 +72,7 @@ import com.vitorpamplona.amethyst.ui.theme.Size35dp
|
||||
import com.vitorpamplona.amethyst.ui.theme.StdVertSpacer
|
||||
import com.vitorpamplona.amethyst.ui.theme.placeholderText
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import java.lang.Math.round
|
||||
|
||||
@@ -88,6 +93,25 @@ fun NewRelayListView(onClose: () -> Unit, accountViewModel: AccountViewModel, re
|
||||
}
|
||||
}
|
||||
|
||||
var event by remember { mutableStateOf<Event?>(null) }
|
||||
if (event != null) {
|
||||
SignerDialog(
|
||||
onClose = {
|
||||
event = null
|
||||
},
|
||||
onPost = {
|
||||
scope.launch(Dispatchers.IO) {
|
||||
Client.send(it)
|
||||
LocalCache.verifyAndConsume(it, null)
|
||||
event = null
|
||||
postViewModel.clear()
|
||||
onClose()
|
||||
}
|
||||
},
|
||||
event = event!!
|
||||
)
|
||||
}
|
||||
|
||||
Dialog(
|
||||
onDismissRequest = { onClose() },
|
||||
properties = DialogProperties(
|
||||
@@ -128,8 +152,12 @@ fun NewRelayListView(onClose: () -> Unit, accountViewModel: AccountViewModel, re
|
||||
|
||||
PostButton(
|
||||
onPost = {
|
||||
postViewModel.create()
|
||||
onClose()
|
||||
if (PackageUtils.isAmberInstalled(context)) {
|
||||
event = postViewModel.create(false)
|
||||
} else {
|
||||
postViewModel.create(true)
|
||||
onClose()
|
||||
}
|
||||
},
|
||||
true
|
||||
)
|
||||
|
@@ -26,14 +26,20 @@ class NewRelayListViewModel : ViewModel() {
|
||||
clear()
|
||||
}
|
||||
|
||||
fun create() {
|
||||
fun create(signEvent: Boolean): ContactListEvent? {
|
||||
if (!signEvent) {
|
||||
relays.let {
|
||||
return account.saveRelayList(it.value, false)
|
||||
}
|
||||
}
|
||||
relays.let {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
account.saveRelayList(it.value)
|
||||
account.saveRelayList(it.value, true)
|
||||
}
|
||||
}
|
||||
|
||||
clear()
|
||||
return null
|
||||
}
|
||||
|
||||
fun clear() {
|
||||
|
Reference in New Issue
Block a user