Fixes relay drops and difficulty in connecting.
Refactors the use of relay objects to avoid creating full state relay connections only once
This commit is contained in:
@@ -258,7 +258,7 @@ class Account(
|
|||||||
var mappedRelaySet =
|
var mappedRelaySet =
|
||||||
baseRelaySet.map {
|
baseRelaySet.map {
|
||||||
if (newDMRelaySet.contains(it.url)) {
|
if (newDMRelaySet.contains(it.url)) {
|
||||||
Relay(it.url, true, true, it.activeTypes + FeedType.PRIVATE_DMS)
|
RelaySetupInfo(it.url, true, true, it.feedTypes + FeedType.PRIVATE_DMS)
|
||||||
} else {
|
} else {
|
||||||
it
|
it
|
||||||
}
|
}
|
||||||
@@ -266,7 +266,7 @@ class Account(
|
|||||||
|
|
||||||
newDMRelaySet.forEach { newUrl ->
|
newDMRelaySet.forEach { newUrl ->
|
||||||
if (mappedRelaySet.none { it.url == newUrl }) {
|
if (mappedRelaySet.none { it.url == newUrl }) {
|
||||||
mappedRelaySet = mappedRelaySet + Relay(newUrl, true, true, setOf(FeedType.PRIVATE_DMS))
|
mappedRelaySet = mappedRelaySet + RelaySetupInfo(newUrl, true, true, setOf(FeedType.PRIVATE_DMS))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -277,7 +277,7 @@ class Account(
|
|||||||
mappedRelaySet =
|
mappedRelaySet =
|
||||||
mappedRelaySet.map {
|
mappedRelaySet.map {
|
||||||
if (searchRelaySet.contains(it.url)) {
|
if (searchRelaySet.contains(it.url)) {
|
||||||
Relay(it.url, true, it.write || false, it.activeTypes + FeedType.SEARCH)
|
RelaySetupInfo(it.url, true, it.write || false, it.feedTypes + FeedType.SEARCH)
|
||||||
} else {
|
} else {
|
||||||
it
|
it
|
||||||
}
|
}
|
||||||
@@ -285,7 +285,7 @@ class Account(
|
|||||||
|
|
||||||
searchRelaySet.forEach { newUrl ->
|
searchRelaySet.forEach { newUrl ->
|
||||||
if (mappedRelaySet.none { it.url == newUrl }) {
|
if (mappedRelaySet.none { it.url == newUrl }) {
|
||||||
mappedRelaySet = mappedRelaySet + Relay(newUrl, true, false, setOf(FeedType.SEARCH))
|
mappedRelaySet = mappedRelaySet + RelaySetupInfo(newUrl, true, false, setOf(FeedType.SEARCH))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -296,7 +296,7 @@ class Account(
|
|||||||
mappedRelaySet =
|
mappedRelaySet =
|
||||||
mappedRelaySet.map {
|
mappedRelaySet.map {
|
||||||
if (privateOutboxRelaySet.contains(it.url)) {
|
if (privateOutboxRelaySet.contains(it.url)) {
|
||||||
Relay(it.url, true, true, it.activeTypes + setOf(FeedType.FOLLOWS, FeedType.PUBLIC_CHATS, FeedType.GLOBAL, FeedType.PRIVATE_DMS))
|
RelaySetupInfo(it.url, true, true, it.feedTypes + setOf(FeedType.FOLLOWS, FeedType.PUBLIC_CHATS, FeedType.GLOBAL, FeedType.PRIVATE_DMS))
|
||||||
} else {
|
} else {
|
||||||
it
|
it
|
||||||
}
|
}
|
||||||
@@ -304,7 +304,7 @@ class Account(
|
|||||||
|
|
||||||
privateOutboxRelaySet.forEach { newUrl ->
|
privateOutboxRelaySet.forEach { newUrl ->
|
||||||
if (mappedRelaySet.none { it.url == newUrl }) {
|
if (mappedRelaySet.none { it.url == newUrl }) {
|
||||||
mappedRelaySet = mappedRelaySet + Relay(newUrl, true, true, setOf(FeedType.FOLLOWS, FeedType.PUBLIC_CHATS, FeedType.GLOBAL, FeedType.PRIVATE_DMS))
|
mappedRelaySet = mappedRelaySet + RelaySetupInfo(newUrl, true, true, setOf(FeedType.FOLLOWS, FeedType.PUBLIC_CHATS, FeedType.GLOBAL, FeedType.PRIVATE_DMS))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -315,7 +315,7 @@ class Account(
|
|||||||
mappedRelaySet =
|
mappedRelaySet =
|
||||||
mappedRelaySet.map {
|
mappedRelaySet.map {
|
||||||
if (localRelayServers.contains(it.url)) {
|
if (localRelayServers.contains(it.url)) {
|
||||||
Relay(it.url, true, true, it.activeTypes + setOf(FeedType.FOLLOWS, FeedType.PUBLIC_CHATS, FeedType.GLOBAL, FeedType.PRIVATE_DMS))
|
RelaySetupInfo(it.url, true, true, it.feedTypes + setOf(FeedType.FOLLOWS, FeedType.PUBLIC_CHATS, FeedType.GLOBAL, FeedType.PRIVATE_DMS))
|
||||||
} else {
|
} else {
|
||||||
it
|
it
|
||||||
}
|
}
|
||||||
@@ -323,7 +323,7 @@ class Account(
|
|||||||
|
|
||||||
localRelayServers.forEach { newUrl ->
|
localRelayServers.forEach { newUrl ->
|
||||||
if (mappedRelaySet.none { it.url == newUrl }) {
|
if (mappedRelaySet.none { it.url == newUrl }) {
|
||||||
mappedRelaySet = mappedRelaySet + Relay(newUrl, true, true, setOf(FeedType.FOLLOWS, FeedType.PUBLIC_CHATS, FeedType.GLOBAL, FeedType.PRIVATE_DMS))
|
mappedRelaySet = mappedRelaySet + RelaySetupInfo(newUrl, true, true, setOf(FeedType.FOLLOWS, FeedType.PUBLIC_CHATS, FeedType.GLOBAL, FeedType.PRIVATE_DMS))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -337,7 +337,7 @@ class Account(
|
|||||||
if (nip65setup != null) {
|
if (nip65setup != null) {
|
||||||
val write = nip65setup.type == AdvertisedRelayListEvent.AdvertisedRelayType.BOTH || nip65setup.type == AdvertisedRelayListEvent.AdvertisedRelayType.READ
|
val write = nip65setup.type == AdvertisedRelayListEvent.AdvertisedRelayType.BOTH || nip65setup.type == AdvertisedRelayListEvent.AdvertisedRelayType.READ
|
||||||
|
|
||||||
Relay(relay.url, true, relay.write || write, relay.activeTypes + setOf(FeedType.FOLLOWS, FeedType.GLOBAL, FeedType.PUBLIC_CHATS))
|
RelaySetupInfo(relay.url, true, relay.write || write, relay.feedTypes + setOf(FeedType.FOLLOWS, FeedType.GLOBAL, FeedType.PUBLIC_CHATS))
|
||||||
} else {
|
} else {
|
||||||
relay
|
relay
|
||||||
}
|
}
|
||||||
@@ -347,7 +347,7 @@ class Account(
|
|||||||
if (mappedRelaySet.none { it.url == newNip65Setup.relayUrl }) {
|
if (mappedRelaySet.none { it.url == newNip65Setup.relayUrl }) {
|
||||||
val write = newNip65Setup.type == AdvertisedRelayListEvent.AdvertisedRelayType.BOTH || newNip65Setup.type == AdvertisedRelayListEvent.AdvertisedRelayType.READ
|
val write = newNip65Setup.type == AdvertisedRelayListEvent.AdvertisedRelayType.BOTH || newNip65Setup.type == AdvertisedRelayListEvent.AdvertisedRelayType.READ
|
||||||
|
|
||||||
mappedRelaySet = mappedRelaySet + Relay(newNip65Setup.relayUrl, true, write, setOf(FeedType.FOLLOWS, FeedType.PUBLIC_CHATS))
|
mappedRelaySet = mappedRelaySet + RelaySetupInfo(newNip65Setup.relayUrl, true, write, setOf(FeedType.FOLLOWS, FeedType.PUBLIC_CHATS))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1316,7 +1316,7 @@ class Account(
|
|||||||
fun consumeAndSendNip95(
|
fun consumeAndSendNip95(
|
||||||
data: FileStorageEvent,
|
data: FileStorageEvent,
|
||||||
signedEvent: FileStorageHeaderEvent,
|
signedEvent: FileStorageHeaderEvent,
|
||||||
relayList: List<Relay>? = null,
|
relayList: List<RelaySetupInfo>? = null,
|
||||||
): Note? {
|
): Note? {
|
||||||
if (!isWriteable()) return null
|
if (!isWriteable()) return null
|
||||||
|
|
||||||
@@ -1342,7 +1342,7 @@ class Account(
|
|||||||
fun sendNip95(
|
fun sendNip95(
|
||||||
data: FileStorageEvent,
|
data: FileStorageEvent,
|
||||||
signedEvent: FileStorageHeaderEvent,
|
signedEvent: FileStorageHeaderEvent,
|
||||||
relayList: List<Relay>? = null,
|
relayList: List<RelaySetupInfo>? = null,
|
||||||
) {
|
) {
|
||||||
Client.send(data, relayList = relayList)
|
Client.send(data, relayList = relayList)
|
||||||
Client.send(signedEvent, relayList = relayList)
|
Client.send(signedEvent, relayList = relayList)
|
||||||
@@ -1350,7 +1350,7 @@ class Account(
|
|||||||
|
|
||||||
fun sendHeader(
|
fun sendHeader(
|
||||||
signedEvent: FileHeaderEvent,
|
signedEvent: FileHeaderEvent,
|
||||||
relayList: List<Relay>? = null,
|
relayList: List<RelaySetupInfo>? = null,
|
||||||
onReady: (Note) -> Unit,
|
onReady: (Note) -> Unit,
|
||||||
) {
|
) {
|
||||||
Client.send(signedEvent, relayList = relayList)
|
Client.send(signedEvent, relayList = relayList)
|
||||||
@@ -1394,7 +1394,7 @@ class Account(
|
|||||||
alt: String?,
|
alt: String?,
|
||||||
sensitiveContent: Boolean,
|
sensitiveContent: Boolean,
|
||||||
originalHash: String? = null,
|
originalHash: String? = null,
|
||||||
relayList: List<Relay>? = null,
|
relayList: List<RelaySetupInfo>? = null,
|
||||||
onReady: (Note) -> Unit,
|
onReady: (Note) -> Unit,
|
||||||
) {
|
) {
|
||||||
if (!isWriteable()) return
|
if (!isWriteable()) return
|
||||||
@@ -1429,7 +1429,7 @@ class Account(
|
|||||||
zapReceiver: List<ZapSplitSetup>? = null,
|
zapReceiver: List<ZapSplitSetup>? = null,
|
||||||
wantsToMarkAsSensitive: Boolean,
|
wantsToMarkAsSensitive: Boolean,
|
||||||
zapRaiserAmount: Long? = null,
|
zapRaiserAmount: Long? = null,
|
||||||
relayList: List<Relay>? = null,
|
relayList: List<RelaySetupInfo>? = null,
|
||||||
geohash: String? = null,
|
geohash: String? = null,
|
||||||
nip94attachments: List<Event>? = null,
|
nip94attachments: List<Event>? = null,
|
||||||
draftTag: String?,
|
draftTag: String?,
|
||||||
@@ -1502,7 +1502,7 @@ class Account(
|
|||||||
root: String?,
|
root: String?,
|
||||||
directMentions: Set<HexKey>,
|
directMentions: Set<HexKey>,
|
||||||
forkedFrom: Event?,
|
forkedFrom: Event?,
|
||||||
relayList: List<Relay>? = null,
|
relayList: List<RelaySetupInfo>? = null,
|
||||||
geohash: String? = null,
|
geohash: String? = null,
|
||||||
nip94attachments: List<FileHeaderEvent>? = null,
|
nip94attachments: List<FileHeaderEvent>? = null,
|
||||||
draftTag: String?,
|
draftTag: String?,
|
||||||
@@ -1591,7 +1591,7 @@ class Account(
|
|||||||
root: String?,
|
root: String?,
|
||||||
directMentions: Set<HexKey>,
|
directMentions: Set<HexKey>,
|
||||||
forkedFrom: Event?,
|
forkedFrom: Event?,
|
||||||
relayList: List<Relay>? = null,
|
relayList: List<RelaySetupInfo>? = null,
|
||||||
geohash: String? = null,
|
geohash: String? = null,
|
||||||
nip94attachments: List<FileHeaderEvent>? = null,
|
nip94attachments: List<FileHeaderEvent>? = null,
|
||||||
draftTag: String?,
|
draftTag: String?,
|
||||||
@@ -1659,7 +1659,7 @@ class Account(
|
|||||||
originalNote: Note,
|
originalNote: Note,
|
||||||
notify: HexKey?,
|
notify: HexKey?,
|
||||||
summary: String? = null,
|
summary: String? = null,
|
||||||
relayList: List<Relay>? = null,
|
relayList: List<RelaySetupInfo>? = null,
|
||||||
) {
|
) {
|
||||||
if (!isWriteable()) return
|
if (!isWriteable()) return
|
||||||
|
|
||||||
@@ -1689,7 +1689,7 @@ class Account(
|
|||||||
zapReceiver: List<ZapSplitSetup>? = null,
|
zapReceiver: List<ZapSplitSetup>? = null,
|
||||||
wantsToMarkAsSensitive: Boolean,
|
wantsToMarkAsSensitive: Boolean,
|
||||||
zapRaiserAmount: Long? = null,
|
zapRaiserAmount: Long? = null,
|
||||||
relayList: List<Relay>? = null,
|
relayList: List<RelaySetupInfo>? = null,
|
||||||
geohash: String? = null,
|
geohash: String? = null,
|
||||||
nip94attachments: List<FileHeaderEvent>? = null,
|
nip94attachments: List<FileHeaderEvent>? = null,
|
||||||
draftTag: String?,
|
draftTag: String?,
|
||||||
@@ -2605,7 +2605,7 @@ class Account(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Takes a User's relay list and adds the types of feeds they are active for.
|
// Takes a User's relay list and adds the types of feeds they are active for.
|
||||||
fun activeRelays(): Array<Relay>? {
|
fun activeRelays(): Array<RelaySetupInfo>? {
|
||||||
val usersRelayList =
|
val usersRelayList =
|
||||||
userProfile().latestContactList?.relays()?.map {
|
userProfile().latestContactList?.relays()?.map {
|
||||||
val url = RelayUrlFormatter.normalize(it.key)
|
val url = RelayUrlFormatter.normalize(it.key)
|
||||||
@@ -2618,24 +2618,24 @@ class Account(
|
|||||||
?.feedTypes
|
?.feedTypes
|
||||||
?: FeedType.values().toSet()
|
?: FeedType.values().toSet()
|
||||||
|
|
||||||
Relay(url, it.value.read, it.value.write, localFeedTypes)
|
RelaySetupInfo(url, it.value.read, it.value.write, localFeedTypes)
|
||||||
} ?: return null
|
} ?: return null
|
||||||
|
|
||||||
return usersRelayList.toTypedArray()
|
return usersRelayList.toTypedArray()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun convertLocalRelays(): Array<Relay> {
|
fun convertLocalRelays(): Array<RelaySetupInfo> {
|
||||||
return localRelays.map { Relay(RelayUrlFormatter.normalize(it.url), it.read, it.write, it.feedTypes) }.toTypedArray()
|
return localRelays.map { RelaySetupInfo(RelayUrlFormatter.normalize(it.url), it.read, it.write, it.feedTypes) }.toTypedArray()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun activeGlobalRelays(): Array<String> {
|
fun activeGlobalRelays(): Array<String> {
|
||||||
return connectToRelays.value
|
return connectToRelays.value
|
||||||
.filter { it.activeTypes.contains(FeedType.GLOBAL) }
|
.filter { it.feedTypes.contains(FeedType.GLOBAL) }
|
||||||
.map { it.url }
|
.map { it.url }
|
||||||
.toTypedArray()
|
.toTypedArray()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun activeWriteRelays(): List<Relay> {
|
fun activeWriteRelays(): List<RelaySetupInfo> {
|
||||||
return connectToRelays.value.filter { it.write }
|
return connectToRelays.value.filter { it.write }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -21,6 +21,7 @@
|
|||||||
package com.vitorpamplona.amethyst.service.relays
|
package com.vitorpamplona.amethyst.service.relays
|
||||||
|
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
|
import com.vitorpamplona.amethyst.model.RelaySetupInfo
|
||||||
import com.vitorpamplona.amethyst.service.checkNotInMainThread
|
import com.vitorpamplona.amethyst.service.checkNotInMainThread
|
||||||
import com.vitorpamplona.quartz.events.Event
|
import com.vitorpamplona.quartz.events.Event
|
||||||
import com.vitorpamplona.quartz.events.EventInterface
|
import com.vitorpamplona.quartz.events.EventInterface
|
||||||
@@ -41,10 +42,10 @@ object Client : RelayPool.Listener {
|
|||||||
|
|
||||||
@Synchronized
|
@Synchronized
|
||||||
fun reconnect(
|
fun reconnect(
|
||||||
relays: Array<Relay>?,
|
relays: Array<RelaySetupInfo>?,
|
||||||
onlyIfChanged: Boolean = false,
|
onlyIfChanged: Boolean = false,
|
||||||
) {
|
) {
|
||||||
Log.d("Relay", "Relay Pool Reconnecting to ${relays?.size} relays: \n${relays?.joinToString("\n") { it.url + " " + it.read + " " + it.write + " " + it.activeTypes.joinToString(",") { it.name } }}")
|
Log.d("Relay", "Relay Pool Reconnecting to ${relays?.size} relays: \n${relays?.joinToString("\n") { it.url + " " + it.read + " " + it.write + " " + it.feedTypes.joinToString(",") { it.name } }}")
|
||||||
checkNotInMainThread()
|
checkNotInMainThread()
|
||||||
|
|
||||||
if (onlyIfChanged) {
|
if (onlyIfChanged) {
|
||||||
@@ -56,10 +57,11 @@ object Client : RelayPool.Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (relays != null) {
|
if (relays != null) {
|
||||||
|
val newRelays = relays.map { Relay(it.url, it.read, it.write, it.feedTypes) }
|
||||||
RelayPool.register(this)
|
RelayPool.register(this)
|
||||||
RelayPool.loadRelays(relays.toList())
|
RelayPool.loadRelays(newRelays)
|
||||||
RelayPool.requestAndWatch()
|
RelayPool.requestAndWatch()
|
||||||
this.relays = relays
|
this.relays = newRelays.toTypedArray()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -70,15 +72,16 @@ object Client : RelayPool.Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (relays != null) {
|
if (relays != null) {
|
||||||
|
val newRelays = relays.map { Relay(it.url, it.read, it.write, it.feedTypes) }
|
||||||
RelayPool.register(this)
|
RelayPool.register(this)
|
||||||
RelayPool.loadRelays(relays.toList())
|
RelayPool.loadRelays(newRelays)
|
||||||
RelayPool.requestAndWatch()
|
RelayPool.requestAndWatch()
|
||||||
this.relays = relays
|
this.relays = newRelays.toTypedArray()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun isSameRelaySetConfig(newRelayConfig: Array<Relay>?): Boolean {
|
fun isSameRelaySetConfig(newRelayConfig: Array<RelaySetupInfo>?): Boolean {
|
||||||
if (relays.size != newRelayConfig?.size) return false
|
if (relays.size != newRelayConfig?.size) return false
|
||||||
|
|
||||||
relays.forEach { oldRelayInfo ->
|
relays.forEach { oldRelayInfo ->
|
||||||
@@ -142,7 +145,7 @@ object Client : RelayPool.Listener {
|
|||||||
signedEvent: EventInterface,
|
signedEvent: EventInterface,
|
||||||
relay: String? = null,
|
relay: String? = null,
|
||||||
feedTypes: Set<FeedType>? = null,
|
feedTypes: Set<FeedType>? = null,
|
||||||
relayList: List<Relay>? = null,
|
relayList: List<RelaySetupInfo>? = null,
|
||||||
onDone: (() -> Unit)? = null,
|
onDone: (() -> Unit)? = null,
|
||||||
) {
|
) {
|
||||||
checkNotInMainThread()
|
checkNotInMainThread()
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ package com.vitorpamplona.amethyst.service.relays
|
|||||||
import android.util.Log
|
import android.util.Log
|
||||||
import com.vitorpamplona.amethyst.BuildConfig
|
import com.vitorpamplona.amethyst.BuildConfig
|
||||||
import com.vitorpamplona.amethyst.model.RelayBriefInfoCache
|
import com.vitorpamplona.amethyst.model.RelayBriefInfoCache
|
||||||
|
import com.vitorpamplona.amethyst.model.RelaySetupInfo
|
||||||
import com.vitorpamplona.amethyst.service.HttpClientManager
|
import com.vitorpamplona.amethyst.service.HttpClientManager
|
||||||
import com.vitorpamplona.amethyst.service.checkNotInMainThread
|
import com.vitorpamplona.amethyst.service.checkNotInMainThread
|
||||||
import com.vitorpamplona.quartz.encoders.HexKey
|
import com.vitorpamplona.quartz.encoders.HexKey
|
||||||
@@ -523,11 +524,11 @@ class Relay(
|
|||||||
writeToSocket("""["CLOSE","$subscriptionId"]""")
|
writeToSocket("""["CLOSE","$subscriptionId"]""")
|
||||||
}
|
}
|
||||||
|
|
||||||
fun isSameRelayConfig(other: Relay): Boolean {
|
fun isSameRelayConfig(other: RelaySetupInfo): Boolean {
|
||||||
return url == other.url &&
|
return url == other.url &&
|
||||||
write == other.write &&
|
write == other.write &&
|
||||||
read == other.read &&
|
read == other.read &&
|
||||||
activeTypes == other.activeTypes
|
activeTypes == other.feedTypes
|
||||||
}
|
}
|
||||||
|
|
||||||
enum class StateType {
|
enum class StateType {
|
||||||
|
|||||||
@@ -21,6 +21,7 @@
|
|||||||
package com.vitorpamplona.amethyst.service.relays
|
package com.vitorpamplona.amethyst.service.relays
|
||||||
|
|
||||||
import androidx.compose.runtime.Immutable
|
import androidx.compose.runtime.Immutable
|
||||||
|
import com.vitorpamplona.amethyst.model.RelaySetupInfo
|
||||||
import com.vitorpamplona.amethyst.service.checkNotInMainThread
|
import com.vitorpamplona.amethyst.service.checkNotInMainThread
|
||||||
import com.vitorpamplona.quartz.events.Event
|
import com.vitorpamplona.quartz.events.Event
|
||||||
import com.vitorpamplona.quartz.events.EventInterface
|
import com.vitorpamplona.quartz.events.EventInterface
|
||||||
@@ -148,7 +149,7 @@ object RelayPool : Relay.Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun sendToSelectedRelays(
|
fun sendToSelectedRelays(
|
||||||
list: List<Relay>,
|
list: List<RelaySetupInfo>,
|
||||||
signedEvent: EventInterface,
|
signedEvent: EventInterface,
|
||||||
) {
|
) {
|
||||||
list.forEach { relay -> relays.filter { it.url == relay.url }.forEach { it.sendOverride(signedEvent) } }
|
list.forEach { relay -> relays.filter { it.url == relay.url }.forEach { it.sendOverride(signedEvent) } }
|
||||||
|
|||||||
@@ -36,11 +36,11 @@ import com.vitorpamplona.amethyst.commons.richtext.RichTextParser
|
|||||||
import com.vitorpamplona.amethyst.model.Account
|
import com.vitorpamplona.amethyst.model.Account
|
||||||
import com.vitorpamplona.amethyst.model.LocalCache
|
import com.vitorpamplona.amethyst.model.LocalCache
|
||||||
import com.vitorpamplona.amethyst.model.Note
|
import com.vitorpamplona.amethyst.model.Note
|
||||||
|
import com.vitorpamplona.amethyst.model.RelaySetupInfo
|
||||||
import com.vitorpamplona.amethyst.model.User
|
import com.vitorpamplona.amethyst.model.User
|
||||||
import com.vitorpamplona.amethyst.service.FileHeader
|
import com.vitorpamplona.amethyst.service.FileHeader
|
||||||
import com.vitorpamplona.amethyst.service.Nip96Uploader
|
import com.vitorpamplona.amethyst.service.Nip96Uploader
|
||||||
import com.vitorpamplona.amethyst.service.NostrSearchEventOrUserDataSource
|
import com.vitorpamplona.amethyst.service.NostrSearchEventOrUserDataSource
|
||||||
import com.vitorpamplona.amethyst.service.relays.Relay
|
|
||||||
import com.vitorpamplona.amethyst.ui.components.MediaCompressor
|
import com.vitorpamplona.amethyst.ui.components.MediaCompressor
|
||||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
|
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
|
||||||
import com.vitorpamplona.quartz.events.FileHeaderEvent
|
import com.vitorpamplona.quartz.events.FileHeaderEvent
|
||||||
@@ -109,11 +109,11 @@ open class EditPostViewModel() : ViewModel() {
|
|||||||
editedFromNote = edit
|
editedFromNote = edit
|
||||||
}
|
}
|
||||||
|
|
||||||
fun sendPost(relayList: List<Relay>? = null) {
|
fun sendPost(relayList: List<RelaySetupInfo>? = null) {
|
||||||
viewModelScope.launch(Dispatchers.IO) { innerSendPost(relayList) }
|
viewModelScope.launch(Dispatchers.IO) { innerSendPost(relayList) }
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun innerSendPost(relayList: List<Relay>? = null) {
|
suspend fun innerSendPost(relayList: List<RelaySetupInfo>? = null) {
|
||||||
if (accountViewModel == null) {
|
if (accountViewModel == null) {
|
||||||
cancel()
|
cancel()
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -31,10 +31,10 @@ import androidx.lifecycle.ViewModel
|
|||||||
import androidx.lifecycle.viewModelScope
|
import androidx.lifecycle.viewModelScope
|
||||||
import com.vitorpamplona.amethyst.R
|
import com.vitorpamplona.amethyst.R
|
||||||
import com.vitorpamplona.amethyst.model.Account
|
import com.vitorpamplona.amethyst.model.Account
|
||||||
|
import com.vitorpamplona.amethyst.model.RelaySetupInfo
|
||||||
import com.vitorpamplona.amethyst.service.FileHeader
|
import com.vitorpamplona.amethyst.service.FileHeader
|
||||||
import com.vitorpamplona.amethyst.service.Nip96MediaServers
|
import com.vitorpamplona.amethyst.service.Nip96MediaServers
|
||||||
import com.vitorpamplona.amethyst.service.Nip96Uploader
|
import com.vitorpamplona.amethyst.service.Nip96Uploader
|
||||||
import com.vitorpamplona.amethyst.service.relays.Relay
|
|
||||||
import com.vitorpamplona.amethyst.ui.components.MediaCompressor
|
import com.vitorpamplona.amethyst.ui.components.MediaCompressor
|
||||||
import kotlinx.coroutines.CancellationException
|
import kotlinx.coroutines.CancellationException
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
@@ -80,7 +80,7 @@ open class NewMediaModel : ViewModel() {
|
|||||||
|
|
||||||
fun upload(
|
fun upload(
|
||||||
context: Context,
|
context: Context,
|
||||||
relayList: List<Relay>? = null,
|
relayList: List<RelaySetupInfo>? = null,
|
||||||
) {
|
) {
|
||||||
isUploadingImage = true
|
isUploadingImage = true
|
||||||
|
|
||||||
@@ -188,7 +188,7 @@ open class NewMediaModel : ViewModel() {
|
|||||||
localContentType: String?,
|
localContentType: String?,
|
||||||
alt: String,
|
alt: String,
|
||||||
sensitiveContent: Boolean,
|
sensitiveContent: Boolean,
|
||||||
relayList: List<Relay>? = null,
|
relayList: List<RelaySetupInfo>? = null,
|
||||||
context: Context,
|
context: Context,
|
||||||
) {
|
) {
|
||||||
uploadingPercentage.value = 0.40f
|
uploadingPercentage.value = 0.40f
|
||||||
@@ -272,7 +272,7 @@ open class NewMediaModel : ViewModel() {
|
|||||||
mimeType: String?,
|
mimeType: String?,
|
||||||
alt: String,
|
alt: String,
|
||||||
sensitiveContent: Boolean,
|
sensitiveContent: Boolean,
|
||||||
relayList: List<Relay>? = null,
|
relayList: List<RelaySetupInfo>? = null,
|
||||||
context: Context,
|
context: Context,
|
||||||
) {
|
) {
|
||||||
if (bytes.size > 80000) {
|
if (bytes.size > 80000) {
|
||||||
|
|||||||
@@ -40,12 +40,12 @@ import com.vitorpamplona.amethyst.commons.richtext.RichTextParser
|
|||||||
import com.vitorpamplona.amethyst.model.Account
|
import com.vitorpamplona.amethyst.model.Account
|
||||||
import com.vitorpamplona.amethyst.model.LocalCache
|
import com.vitorpamplona.amethyst.model.LocalCache
|
||||||
import com.vitorpamplona.amethyst.model.Note
|
import com.vitorpamplona.amethyst.model.Note
|
||||||
|
import com.vitorpamplona.amethyst.model.RelaySetupInfo
|
||||||
import com.vitorpamplona.amethyst.model.User
|
import com.vitorpamplona.amethyst.model.User
|
||||||
import com.vitorpamplona.amethyst.service.FileHeader
|
import com.vitorpamplona.amethyst.service.FileHeader
|
||||||
import com.vitorpamplona.amethyst.service.LocationUtil
|
import com.vitorpamplona.amethyst.service.LocationUtil
|
||||||
import com.vitorpamplona.amethyst.service.Nip96Uploader
|
import com.vitorpamplona.amethyst.service.Nip96Uploader
|
||||||
import com.vitorpamplona.amethyst.service.NostrSearchEventOrUserDataSource
|
import com.vitorpamplona.amethyst.service.NostrSearchEventOrUserDataSource
|
||||||
import com.vitorpamplona.amethyst.service.relays.Relay
|
|
||||||
import com.vitorpamplona.amethyst.ui.components.MediaCompressor
|
import com.vitorpamplona.amethyst.ui.components.MediaCompressor
|
||||||
import com.vitorpamplona.amethyst.ui.components.Split
|
import com.vitorpamplona.amethyst.ui.components.Split
|
||||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
|
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
|
||||||
@@ -438,7 +438,7 @@ open class NewPostViewModel() : ViewModel() {
|
|||||||
urlPreview = findUrlInMessage()
|
urlPreview = findUrlInMessage()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun sendPost(relayList: List<Relay>? = null) {
|
fun sendPost(relayList: List<RelaySetupInfo>? = null) {
|
||||||
viewModelScope.launch(Dispatchers.IO) {
|
viewModelScope.launch(Dispatchers.IO) {
|
||||||
innerSendPost(relayList, null)
|
innerSendPost(relayList, null)
|
||||||
accountViewModel?.deleteDraft(draftTag)
|
accountViewModel?.deleteDraft(draftTag)
|
||||||
@@ -446,18 +446,18 @@ open class NewPostViewModel() : ViewModel() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun sendDraft(relayList: List<Relay>? = null) {
|
fun sendDraft(relayList: List<RelaySetupInfo>? = null) {
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
sendDraftSync(relayList)
|
sendDraftSync(relayList)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun sendDraftSync(relayList: List<Relay>? = null) {
|
suspend fun sendDraftSync(relayList: List<RelaySetupInfo>? = null) {
|
||||||
innerSendPost(relayList, draftTag)
|
innerSendPost(relayList, draftTag)
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun innerSendPost(
|
private suspend fun innerSendPost(
|
||||||
relayList: List<Relay>? = null,
|
relayList: List<RelaySetupInfo>? = null,
|
||||||
localDraft: String?,
|
localDraft: String?,
|
||||||
) = withContext(Dispatchers.IO) {
|
) = withContext(Dispatchers.IO) {
|
||||||
if (accountViewModel == null) {
|
if (accountViewModel == null) {
|
||||||
|
|||||||
@@ -47,8 +47,8 @@ import androidx.compose.ui.window.Dialog
|
|||||||
import androidx.compose.ui.window.DialogProperties
|
import androidx.compose.ui.window.DialogProperties
|
||||||
import com.vitorpamplona.amethyst.R
|
import com.vitorpamplona.amethyst.R
|
||||||
import com.vitorpamplona.amethyst.model.RelayBriefInfoCache
|
import com.vitorpamplona.amethyst.model.RelayBriefInfoCache
|
||||||
|
import com.vitorpamplona.amethyst.model.RelaySetupInfo
|
||||||
import com.vitorpamplona.amethyst.service.Nip11Retriever
|
import com.vitorpamplona.amethyst.service.Nip11Retriever
|
||||||
import com.vitorpamplona.amethyst.service.relays.Relay
|
|
||||||
import com.vitorpamplona.amethyst.ui.actions.relays.RelayInformationDialog
|
import com.vitorpamplona.amethyst.ui.actions.relays.RelayInformationDialog
|
||||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
|
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
|
||||||
import com.vitorpamplona.amethyst.ui.theme.FeedPadding
|
import com.vitorpamplona.amethyst.ui.theme.FeedPadding
|
||||||
@@ -57,7 +57,7 @@ import kotlinx.collections.immutable.ImmutableList
|
|||||||
import kotlinx.collections.immutable.toImmutableList
|
import kotlinx.collections.immutable.toImmutableList
|
||||||
|
|
||||||
data class RelayList(
|
data class RelayList(
|
||||||
val relay: Relay,
|
val relay: RelaySetupInfo,
|
||||||
val relayInfo: RelayBriefInfoCache.RelayBriefInfo,
|
val relayInfo: RelayBriefInfoCache.RelayBriefInfo,
|
||||||
val isSelected: Boolean,
|
val isSelected: Boolean,
|
||||||
)
|
)
|
||||||
@@ -69,9 +69,9 @@ data class RelayInfoDialog(
|
|||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun RelaySelectionDialog(
|
fun RelaySelectionDialog(
|
||||||
preSelectedList: ImmutableList<Relay>,
|
preSelectedList: ImmutableList<RelaySetupInfo>,
|
||||||
onClose: () -> Unit,
|
onClose: () -> Unit,
|
||||||
onPost: (list: ImmutableList<Relay>) -> Unit,
|
onPost: (list: ImmutableList<RelaySetupInfo>) -> Unit,
|
||||||
accountViewModel: AccountViewModel,
|
accountViewModel: AccountViewModel,
|
||||||
nav: (String) -> Unit,
|
nav: (String) -> Unit,
|
||||||
) {
|
) {
|
||||||
|
|||||||
Reference in New Issue
Block a user