Speeds up cold startup.
This commit is contained in:
@@ -33,6 +33,10 @@ import com.vitorpamplona.amethyst.service.NostrVideoDataSource
|
|||||||
import com.vitorpamplona.amethyst.service.relays.Client
|
import com.vitorpamplona.amethyst.service.relays.Client
|
||||||
import com.vitorpamplona.amethyst.ui.actions.ImageUploader
|
import com.vitorpamplona.amethyst.ui.actions.ImageUploader
|
||||||
import com.vitorpamplona.quartz.encoders.decodePublicKeyAsHexOrNull
|
import com.vitorpamplona.quartz.encoders.decodePublicKeyAsHexOrNull
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.GlobalScope
|
||||||
|
import kotlinx.coroutines.delay
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
object ServiceManager {
|
object ServiceManager {
|
||||||
@@ -87,9 +91,12 @@ object ServiceManager {
|
|||||||
// Notification Elements
|
// Notification Elements
|
||||||
NostrHomeDataSource.start()
|
NostrHomeDataSource.start()
|
||||||
NostrAccountDataSource.start()
|
NostrAccountDataSource.start()
|
||||||
NostrChatroomListDataSource.start()
|
GlobalScope.launch(Dispatchers.IO) {
|
||||||
NostrDiscoveryDataSource.start()
|
delay(2000)
|
||||||
NostrVideoDataSource.start()
|
NostrChatroomListDataSource.start()
|
||||||
|
NostrDiscoveryDataSource.start()
|
||||||
|
NostrVideoDataSource.start()
|
||||||
|
}
|
||||||
|
|
||||||
// More Info Data Sources
|
// More Info Data Sources
|
||||||
NostrSingleEventDataSource.start()
|
NostrSingleEventDataSource.start()
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package com.vitorpamplona.amethyst.service
|
|||||||
|
|
||||||
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.User
|
||||||
import com.vitorpamplona.amethyst.service.relays.COMMON_FEED_TYPES
|
import com.vitorpamplona.amethyst.service.relays.COMMON_FEED_TYPES
|
||||||
import com.vitorpamplona.amethyst.service.relays.Client
|
import com.vitorpamplona.amethyst.service.relays.Client
|
||||||
import com.vitorpamplona.amethyst.service.relays.EOSEAccount
|
import com.vitorpamplona.amethyst.service.relays.EOSEAccount
|
||||||
@@ -34,6 +35,7 @@ object NostrAccountDataSource : NostrDataSource("AccountData") {
|
|||||||
lateinit var account: Account
|
lateinit var account: Account
|
||||||
|
|
||||||
val latestEOSEs = EOSEAccount()
|
val latestEOSEs = EOSEAccount()
|
||||||
|
val hasLoadedTheBasics = mutableMapOf<User, Boolean>()
|
||||||
|
|
||||||
fun createAccountContactListFilter(): TypedFilter {
|
fun createAccountContactListFilter(): TypedFilter {
|
||||||
return TypedFilter(
|
return TypedFilter(
|
||||||
@@ -141,7 +143,11 @@ object NostrAccountDataSource : NostrDataSource("AccountData") {
|
|||||||
)
|
)
|
||||||
|
|
||||||
val accountChannel = requestNewChannel { time, relayUrl ->
|
val accountChannel = requestNewChannel { time, relayUrl ->
|
||||||
latestEOSEs.addOrUpdate(account.userProfile(), account.defaultNotificationFollowList, relayUrl, time)
|
if (hasLoadedTheBasics[account.userProfile()] != null) {
|
||||||
|
latestEOSEs.addOrUpdate(account.userProfile(), account.defaultNotificationFollowList, relayUrl, time)
|
||||||
|
} else {
|
||||||
|
hasLoadedTheBasics[account.userProfile()] = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun consume(event: Event, relay: Relay) {
|
override fun consume(event: Event, relay: Relay) {
|
||||||
@@ -201,18 +207,28 @@ object NostrAccountDataSource : NostrDataSource("AccountData") {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun updateChannelFilters() {
|
override fun updateChannelFilters() {
|
||||||
// gets everthing about the user logged in
|
return if (hasLoadedTheBasics[account.userProfile()] != null) {
|
||||||
accountChannel.typedFilters = listOf(
|
// gets everthing about the user logged in
|
||||||
createAccountMetadataFilter(),
|
accountChannel.typedFilters = listOf(
|
||||||
createAccountContactListFilter(),
|
createAccountMetadataFilter(),
|
||||||
createAccountRelayListFilter(),
|
createAccountContactListFilter(),
|
||||||
createNotificationFilter(),
|
createAccountRelayListFilter(),
|
||||||
createGiftWrapsToMeFilter(),
|
createNotificationFilter(),
|
||||||
createAccountReportsFilter(),
|
createGiftWrapsToMeFilter(),
|
||||||
createAccountAcceptedAwardsFilter(),
|
createAccountReportsFilter(),
|
||||||
createAccountBookmarkListFilter(),
|
createAccountAcceptedAwardsFilter(),
|
||||||
createAccountLastPostsListFilter()
|
createAccountBookmarkListFilter(),
|
||||||
).ifEmpty { null }
|
createAccountLastPostsListFilter()
|
||||||
|
).ifEmpty { null }
|
||||||
|
} else {
|
||||||
|
// just the basics.
|
||||||
|
accountChannel.typedFilters = listOf(
|
||||||
|
createAccountMetadataFilter(),
|
||||||
|
createAccountContactListFilter(),
|
||||||
|
createAccountRelayListFilter(),
|
||||||
|
createAccountBookmarkListFilter()
|
||||||
|
).ifEmpty { null }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun auth(relay: Relay, challenge: String) {
|
override fun auth(relay: Relay, challenge: String) {
|
||||||
|
|||||||
Reference in New Issue
Block a user