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