Switches the metadata relay for the relay being used with the most amount of posts to be the relayhint
This commit is contained in:
@@ -506,7 +506,7 @@ object LocalCache : ILocalCache, ICacheProvider {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
user.updateUserInfo(newUserMetadata, event, fallbackRelay)
|
user.updateUserInfo(newUserMetadata, event)
|
||||||
if (relay != null) {
|
if (relay != null) {
|
||||||
user.addRelayBeingUsed(relay, event.createdAt)
|
user.addRelayBeingUsed(relay, event.createdAt)
|
||||||
}
|
}
|
||||||
|
|||||||
+12
-6
@@ -49,19 +49,25 @@ fun filterNip04DMs(
|
|||||||
|
|
||||||
val outbox =
|
val outbox =
|
||||||
authorHomeRelayEvent?.writeRelaysNorm()
|
authorHomeRelayEvent?.writeRelaysNorm()
|
||||||
|
?: LocalCache
|
||||||
|
.getUserIfExists(it)
|
||||||
|
?.relaysBeingUsed
|
||||||
|
?.keys
|
||||||
|
?.ifEmpty { null }
|
||||||
?: LocalCache.relayHints.hintsForKey(it).ifEmpty { null }
|
?: LocalCache.relayHints.hintsForKey(it).ifEmpty { null }
|
||||||
?: listOfNotNull(
|
?: emptyList()
|
||||||
LocalCache.getUserIfExists(it)?.metadataOrNull()?.relay,
|
|
||||||
)
|
|
||||||
|
|
||||||
groupOutboxRelays.addAll(outbox)
|
groupOutboxRelays.addAll(outbox)
|
||||||
|
|
||||||
val inbox =
|
val inbox =
|
||||||
authorHomeRelayEvent?.readRelaysNorm()?.ifEmpty { null }
|
authorHomeRelayEvent?.readRelaysNorm()?.ifEmpty { null }
|
||||||
|
?: LocalCache
|
||||||
|
.getUserIfExists(it)
|
||||||
|
?.relaysBeingUsed
|
||||||
|
?.keys
|
||||||
|
?.ifEmpty { null }
|
||||||
?: LocalCache.relayHints.hintsForKey(it).ifEmpty { null }
|
?: LocalCache.relayHints.hintsForKey(it).ifEmpty { null }
|
||||||
?: listOfNotNull(
|
?: emptyList()
|
||||||
LocalCache.getUserIfExists(it)?.metadataOrNull()?.relay,
|
|
||||||
)
|
|
||||||
|
|
||||||
groupInboxRelays.addAll(inbox)
|
groupInboxRelays.addAll(inbox)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -230,7 +230,7 @@ open class Note(
|
|||||||
|
|
||||||
return relays.firstOrNull()
|
return relays.firstOrNull()
|
||||||
} else {
|
} else {
|
||||||
currentOutbox?.firstOrNull() ?: author?.metadataOrNull()?.relay
|
currentOutbox?.firstOrNull() ?: author?.mostUsedRelay()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -82,13 +82,19 @@ class User(
|
|||||||
|
|
||||||
fun outboxRelays() = authorRelayList()?.writeRelaysNorm()
|
fun outboxRelays() = authorRelayList()?.writeRelaysNorm()
|
||||||
|
|
||||||
fun relayHints() = authorRelayList()?.writeRelaysNorm()?.take(3) ?: listOfNotNull(metadataOrNull()?.relay)
|
fun relayHints() =
|
||||||
|
authorRelayList()?.writeRelaysNorm()?.take(3) ?: relaysBeingUsed.entries
|
||||||
|
.sortedByDescending { it.value.counter }
|
||||||
|
.take(3)
|
||||||
|
.map { it.key }
|
||||||
|
|
||||||
fun inboxRelays() = authorRelayList()?.readRelaysNorm()
|
fun inboxRelays() = authorRelayList()?.readRelaysNorm()
|
||||||
|
|
||||||
fun dmInboxRelays() = dmInboxRelayList()?.relays()?.ifEmpty { null } ?: inboxRelays()
|
fun dmInboxRelays() = dmInboxRelayList()?.relays()?.ifEmpty { null } ?: inboxRelays()
|
||||||
|
|
||||||
fun bestRelayHint() = authorRelayList()?.writeRelaysNorm()?.firstOrNull() ?: metadataOrNull()?.relay
|
fun bestRelayHint() = authorRelayList()?.writeRelaysNorm()?.firstOrNull() ?: mostUsedRelay()
|
||||||
|
|
||||||
|
fun mostUsedRelay() = relaysBeingUsed.maxByOrNull { it.value.counter }?.key
|
||||||
|
|
||||||
fun toPTag() = PTag(pubkeyHex, bestRelayHint())
|
fun toPTag() = PTag(pubkeyHex, bestRelayHint())
|
||||||
|
|
||||||
@@ -188,7 +194,6 @@ class User(
|
|||||||
fun updateUserInfo(
|
fun updateUserInfo(
|
||||||
newUserInfo: UserMetadata,
|
newUserInfo: UserMetadata,
|
||||||
metaEvent: MetadataEvent,
|
metaEvent: MetadataEvent,
|
||||||
relay: NormalizedRelayUrl?,
|
|
||||||
) {
|
) {
|
||||||
newUserInfo.cleanBlankNames()
|
newUserInfo.cleanBlankNames()
|
||||||
|
|
||||||
@@ -205,10 +210,6 @@ class User(
|
|||||||
|
|
||||||
metadata.newMetadata(newUserInfo, metaEvent)
|
metadata.newMetadata(newUserInfo, metaEvent)
|
||||||
|
|
||||||
if (relay != null) {
|
|
||||||
metadata.relay = relay
|
|
||||||
}
|
|
||||||
|
|
||||||
// doesn't create Nip05 unless needed.
|
// doesn't create Nip05 unless needed.
|
||||||
nip05StateOrNull()?.newMetadata(newUserInfo.nip05, metaEvent.pubKey)
|
nip05StateOrNull()?.newMetadata(newUserInfo.nip05, metaEvent.pubKey)
|
||||||
}
|
}
|
||||||
|
|||||||
-2
@@ -25,7 +25,6 @@ import com.vitorpamplona.amethyst.commons.model.ImmutableListOfLists
|
|||||||
import com.vitorpamplona.amethyst.commons.model.toImmutableListOfLists
|
import com.vitorpamplona.amethyst.commons.model.toImmutableListOfLists
|
||||||
import com.vitorpamplona.quartz.nip01Core.metadata.MetadataEvent
|
import com.vitorpamplona.quartz.nip01Core.metadata.MetadataEvent
|
||||||
import com.vitorpamplona.quartz.nip01Core.metadata.UserMetadata
|
import com.vitorpamplona.quartz.nip01Core.metadata.UserMetadata
|
||||||
import com.vitorpamplona.quartz.nip01Core.relay.normalizer.NormalizedRelayUrl
|
|
||||||
import com.vitorpamplona.quartz.nip39ExtIdentities.IdentityClaimTag
|
import com.vitorpamplona.quartz.nip39ExtIdentities.IdentityClaimTag
|
||||||
import com.vitorpamplona.quartz.nip39ExtIdentities.identityClaims
|
import com.vitorpamplona.quartz.nip39ExtIdentities.identityClaims
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
@@ -42,7 +41,6 @@ class UserInfo(
|
|||||||
@Stable
|
@Stable
|
||||||
class UserMetadataCache {
|
class UserMetadataCache {
|
||||||
val flow: MutableStateFlow<UserInfo?> = MutableStateFlow(null)
|
val flow: MutableStateFlow<UserInfo?> = MutableStateFlow(null)
|
||||||
var relay: NormalizedRelayUrl? = null
|
|
||||||
|
|
||||||
fun newMetadata(
|
fun newMetadata(
|
||||||
userInfo: UserMetadata,
|
userInfo: UserMetadata,
|
||||||
|
|||||||
Vendored
+1
-1
@@ -110,7 +110,7 @@ class DesktopLocalCache : ICacheProvider {
|
|||||||
if (user.metadata().shouldUpdateWith(event)) {
|
if (user.metadata().shouldUpdateWith(event)) {
|
||||||
val newUserMetadata = event.contactMetaData()
|
val newUserMetadata = event.contactMetaData()
|
||||||
if (newUserMetadata != null) {
|
if (newUserMetadata != null) {
|
||||||
user.updateUserInfo(newUserMetadata, event, null)
|
user.updateUserInfo(newUserMetadata, event)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user