diff --git a/.editorconfig b/.editorconfig index 638dbbf25e..132887e831 100644 --- a/.editorconfig +++ b/.editorconfig @@ -8,7 +8,8 @@ trim_trailing_whitespace = true max_line_length = 5000 ij_kotlin_allow_trailing_comma=true ij_kotlin_allow_trailing_comma_on_call_site=true -ktlint_function_naming_ignore_when_annotated_with=Composable, Test +ktlint_function_naming_ignore_when_annotated_with=Composable +ktlint_standard_no-unused-imports=enabled [*.gradle] indent_size = 4 \ No newline at end of file diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/AppModules.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/AppModules.kt index 331f2dc827..e62736ca82 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/AppModules.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/AppModules.kt @@ -86,7 +86,7 @@ class AppModules( } val applicationIOScope = CoroutineScope(Dispatchers.IO + SupervisorJob() + exceptionHandler) - val applicationDefaultScope = CoroutineScope(Dispatchers.Default + SupervisorJob() + exceptionHandler) + val applicationDefaultScope = CoroutineScope(Dispatchers.IO + SupervisorJob() + exceptionHandler) // Blocking load of UI Preferences to avoid theme/language blinking val uiPrefs by lazy { diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/Account.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/Account.kt index dfc9fd2a32..334949ff1f 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/Account.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/Account.kt @@ -38,8 +38,8 @@ import com.vitorpamplona.amethyst.model.nip01UserMetadata.UserMetadataState import com.vitorpamplona.amethyst.model.nip02FollowLists.DeclaredFollowsPerOutboxRelay import com.vitorpamplona.amethyst.model.nip02FollowLists.FollowListOutboxOrProxyRelays import com.vitorpamplona.amethyst.model.nip02FollowLists.FollowListReusedOutboxOrProxyRelays -import com.vitorpamplona.amethyst.model.nip02FollowLists.FollowListState import com.vitorpamplona.amethyst.model.nip02FollowLists.FollowsPerOutboxRelay +import com.vitorpamplona.amethyst.model.nip02FollowLists.Kind3FollowListState import com.vitorpamplona.amethyst.model.nip03Timestamp.OtsState import com.vitorpamplona.amethyst.model.nip17Dms.DmInboxRelayState import com.vitorpamplona.amethyst.model.nip17Dms.DmRelayListState @@ -205,6 +205,7 @@ import com.vitorpamplona.quartz.nip98HttpAuth.HTTPAuthorizationEvent import com.vitorpamplona.quartz.nipA0VoiceMessages.VoiceEvent import com.vitorpamplona.quartz.nipA0VoiceMessages.VoiceReplyEvent import com.vitorpamplona.quartz.utils.Log +import com.vitorpamplona.quartz.utils.containsAny import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.DelicateCoroutinesApi import kotlinx.coroutines.Dispatchers @@ -265,7 +266,7 @@ class Account( val blockedRelayListDecryptionCache = BlockedRelayListDecryptionCache(signer) val blockedRelayList = BlockedRelayListState(signer, cache, blockedRelayListDecryptionCache, scope, settings) - val kind3FollowList = FollowListState(signer, cache, scope, settings) + val kind3FollowList = Kind3FollowListState(signer, cache, scope, settings) val followSetsState = FollowSetState(signer, cache, scope) val ephemeralChatListDecryptionCache = EphemeralChatListDecryptionCache(signer) @@ -1677,6 +1678,16 @@ class Account( note.countReportAuthorsBy(followingKeySet()) < 5 // if it has 5 reports by reliable users } + fun isDecryptedContentHidden(noteEvent: PrivateDmEvent): Boolean = + if (hiddenUsers.flow.value.hiddenWordsCase + .isNotEmpty() + ) { + val decrypted = privateDMDecryptionCache.cachedDM(noteEvent) + decrypted?.containsAny(hiddenUsers.flow.value.hiddenWordsCase) == true + } else { + false + } + fun isFollowing(user: User): Boolean = user.pubkeyHex in followingKeySet() fun isFollowing(user: HexKey): Boolean = user in followingKeySet() @@ -1761,7 +1772,7 @@ class Account( fun observeDonatedInThisVersion() = settings .observeDonatedInVersion(BuildConfig.VERSION_NAME) - .flowOn(Dispatchers.Default) + .flowOn(Dispatchers.IO) .stateIn(scope, SharingStarted.Eagerly, hasDonatedInThisVersion()) fun markDonatedInThisVersion() = settings.markDonatedInThisVersion(BuildConfig.VERSION_NAME) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/LocalCache.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/LocalCache.kt index 13714ae39c..6a4ea2a7ac 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/LocalCache.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/LocalCache.kt @@ -1962,7 +1962,7 @@ object LocalCache : ILocalCache { requestNote?.let { request -> zappedNote?.addZapPayment(request, note) } - GlobalScope.launch(Dispatchers.Default) { + GlobalScope.launch(Dispatchers.IO) { responseCallback(event) } @@ -2913,10 +2913,10 @@ class LocalCacheFlow { val deletedEventBundles = _deletedEventBundles.asSharedFlow() // read-only public view // Refreshes observers in batches. - private val bundler = BundledInsert(1000, Dispatchers.Default) + private val bundler = BundledInsert(1000, Dispatchers.IO) // Refreshes observers in batches. - private val bundler2 = BundledInsert(1000, Dispatchers.Default) + private val bundler2 = BundledInsert(1000, Dispatchers.IO) fun newNote(newNote: Note) { bundler.invalidateList(newNote) { bundledNewNotes -> diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/accountsCache/AccountCacheState.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/accountsCache/AccountCacheState.kt index d16c67b3d0..0126df2fe4 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/accountsCache/AccountCacheState.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/accountsCache/AccountCacheState.kt @@ -97,7 +97,7 @@ class AccountCacheState( client = client, scope = CoroutineScope( - Dispatchers.Default + + Dispatchers.IO + SupervisorJob() + CoroutineExceptionHandler { _, throwable -> Log.e("AccountCacheState", "Account ${signer.pubKey} caught exception: ${throwable.message}", throwable) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/edits/PrivateStorageRelayListState.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/edits/PrivateStorageRelayListState.kt index dfad190c95..b67f31d199 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/edits/PrivateStorageRelayListState.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/edits/PrivateStorageRelayListState.kt @@ -66,7 +66,7 @@ class PrivateStorageRelayListState( .map { normalizePrivateOutboxRelayListWithBackup(it.note) } .onStart { emit(normalizePrivateOutboxRelayListWithBackup(privateOutboxListNote)) - }.flowOn(Dispatchers.Default) + }.flowOn(Dispatchers.IO) .stateIn( scope, SharingStarted.Eagerly, @@ -99,7 +99,7 @@ class PrivateStorageRelayListState( } } - scope.launch(Dispatchers.Default) { + scope.launch(Dispatchers.IO) { Log.d("AccountRegisterObservers", "Private Home Relay List Collector Start") getPrivateOutboxRelayListFlow().collect { noteState -> Log.d("AccountRegisterObservers", "Updating Private Home Relay List for ${signer.pubKey}") diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/emphChat/EphemeralChatListState.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/emphChat/EphemeralChatListState.kt index fab0e395e4..3899d0aef8 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/emphChat/EphemeralChatListState.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/emphChat/EphemeralChatListState.kt @@ -69,7 +69,7 @@ class EphemeralChatListState( emit(ephemeralChatListWithBackup(noteState.note)) }.onStart { emit(ephemeralChatListWithBackup(ephemeralChatListNote)) - }.flowOn(Dispatchers.Default) + }.flowOn(Dispatchers.IO) .stateIn( scope, SharingStarted.Eagerly, @@ -117,7 +117,7 @@ class EphemeralChatListState( } } - scope.launch(Dispatchers.Default) { + scope.launch(Dispatchers.IO) { Log.d("AccountRegisterObservers", "EphemeralChatList Collector Start") getEphemeralChatListFlow().collect { noteState -> Log.d("AccountRegisterObservers", "EphemeralChatList List for ${signer.pubKey}") diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/localRelays/LocalRelayListState.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/localRelays/LocalRelayListState.kt index dcdaa2b36a..20917ae6c0 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/localRelays/LocalRelayListState.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/localRelays/LocalRelayListState.kt @@ -43,7 +43,7 @@ class LocalRelayListState( val flow = settings.localRelayServers .map { normalizeLocalRelayListWithBackup(it) } - .flowOn(Dispatchers.Default) + .flowOn(Dispatchers.IO) .stateIn( scope, SharingStarted.Eagerly, diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip01UserMetadata/AccountHomeRelayState.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip01UserMetadata/AccountHomeRelayState.kt index 6707686835..89403654e0 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip01UserMetadata/AccountHomeRelayState.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip01UserMetadata/AccountHomeRelayState.kt @@ -43,7 +43,7 @@ class AccountHomeRelayState( local.flow, ) { nip65Outbox, privateOutBox, localRelays -> nip65Outbox + privateOutBox + localRelays - }.flowOn(Dispatchers.Default) + }.flowOn(Dispatchers.IO) .stateIn( scope, SharingStarted.Eagerly, diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip01UserMetadata/AccountOutboxRelayState.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip01UserMetadata/AccountOutboxRelayState.kt index f3ccbdacf3..65f76c500c 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip01UserMetadata/AccountOutboxRelayState.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip01UserMetadata/AccountOutboxRelayState.kt @@ -46,7 +46,7 @@ class AccountOutboxRelayState( broadcast.flow, ) { nip65Outbox, privateOutBox, localRelays, broadcastRelays -> nip65Outbox + privateOutBox + localRelays + broadcastRelays - }.flowOn(Dispatchers.Default) + }.flowOn(Dispatchers.IO) .stateIn( scope, SharingStarted.Eagerly, diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip01UserMetadata/NotificationInboxRelayState.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip01UserMetadata/NotificationInboxRelayState.kt index 1d05dee9bf..0729475dc2 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip01UserMetadata/NotificationInboxRelayState.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip01UserMetadata/NotificationInboxRelayState.kt @@ -40,7 +40,7 @@ class NotificationInboxRelayState( localRelayList.flow, ) { nip65Inbox, localRelays -> nip65Inbox + localRelays - }.flowOn(Dispatchers.Default) + }.flowOn(Dispatchers.IO) .stateIn( scope, SharingStarted.Eagerly, diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip01UserMetadata/UserMetadataState.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip01UserMetadata/UserMetadataState.kt index 186419e348..d64ec40bd8 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip01UserMetadata/UserMetadataState.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip01UserMetadata/UserMetadataState.kt @@ -22,7 +22,6 @@ package com.vitorpamplona.amethyst.model.nip01UserMetadata import com.vitorpamplona.amethyst.model.AccountSettings import com.vitorpamplona.amethyst.model.LocalCache -import com.vitorpamplona.amethyst.model.User import com.vitorpamplona.amethyst.model.UserState import com.vitorpamplona.quartz.nip01Core.metadata.MetadataEvent import com.vitorpamplona.quartz.nip01Core.signers.NostrSigner @@ -40,13 +39,14 @@ class UserMetadataState( val scope: CoroutineScope, val settings: AccountSettings, ) { + // Creates a long-term reference for this note so that the GC doesn't collect the note it self + val user = cache.getOrCreateUser(signer.pubKey) + // fun getEphemeralChatListAddress() = cache.getOrCreateUser(signer.pubKey) - fun getUserMetadataUser(): User = cache.getOrCreateUser(signer.pubKey) + fun getUserMetadataFlow(): StateFlow = user.flow().metadata.stateFlow - fun getUserMetadataFlow(): StateFlow = getUserMetadataUser().flow().metadata.stateFlow - - fun getUserMetadataEvent(): MetadataEvent? = getUserMetadataUser().latestMetadata + fun getUserMetadataEvent(): MetadataEvent? = user.latestMetadata suspend fun sendNewUserMetadata( name: String? = null, @@ -112,7 +112,7 @@ class UserMetadataState( } // saves contact list for the next time. - scope.launch(Dispatchers.Default) { + scope.launch(Dispatchers.IO) { Log.d("AccountRegisterObservers", "Kind 0 Collector Start") getUserMetadataFlow().collect { Log.d("AccountRegisterObservers", "Updating Kind 0 ${it.user.toBestDisplayName()}") diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip02FollowLists/DeclaredFollowsPerOutboxRelay.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip02FollowLists/DeclaredFollowsPerOutboxRelay.kt index b36983003e..f2934b1134 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip02FollowLists/DeclaredFollowsPerOutboxRelay.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip02FollowLists/DeclaredFollowsPerOutboxRelay.kt @@ -37,7 +37,7 @@ import kotlinx.coroutines.flow.stateIn import kotlinx.coroutines.flow.transformLatest class DeclaredFollowsPerOutboxRelay( - kind3Follows: FollowListState, + kind3Follows: Kind3FollowListState, val cache: LocalCache, scope: CoroutineScope, ) { @@ -55,7 +55,7 @@ class DeclaredFollowsPerOutboxRelay( calculator.authorsPerRelaySnapshot(kind3Follows.flow.value.authors, cache) { it }, ) }.distinctUntilChanged() - .flowOn(Dispatchers.Default) + .flowOn(Dispatchers.IO) .stateIn( scope, SharingStarted.Eagerly, diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip02FollowLists/FollowListOutboxOrProxyRelays.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip02FollowLists/FollowListOutboxOrProxyRelays.kt index 44ea6d2a9c..13d29c44f2 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip02FollowLists/FollowListOutboxOrProxyRelays.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip02FollowLists/FollowListOutboxOrProxyRelays.kt @@ -42,7 +42,7 @@ import kotlinx.coroutines.flow.stateIn import kotlinx.coroutines.flow.transformLatest class FollowListOutboxOrProxyRelays( - kind3Follows: FollowListState, + kind3Follows: Kind3FollowListState, blockedRelayList: BlockedRelayListState, proxyRelayList: ProxyRelayListState, val cache: LocalCache, @@ -60,7 +60,7 @@ class FollowListOutboxOrProxyRelays( OutboxRelayLoader(true).authorsPerRelaySnapshot(kind3Follows.flow.value.authors, cache) { it.keys }, ) }.distinctUntilChanged() - .flowOn(Dispatchers.Default) + .flowOn(Dispatchers.IO) .stateIn( scope, SharingStarted.Eagerly, @@ -72,7 +72,7 @@ class FollowListOutboxOrProxyRelays( followList.minus(blockedRelays) }.onStart { emit(outboxRelayFlow.value.minus(blockedRelayList.flow.value.toSet())) - }.flowOn(Dispatchers.Default) + }.flowOn(Dispatchers.IO) .stateIn( scope, SharingStarted.Eagerly, @@ -94,7 +94,7 @@ class FollowListOutboxOrProxyRelays( outboxRelayMinusBlockedFlow.value }, ) - }.flowOn(Dispatchers.Default) + }.flowOn(Dispatchers.IO) .stateIn( scope, SharingStarted.Eagerly, @@ -108,7 +108,7 @@ class FollowListOutboxOrProxyRelays( relayList.mapTo(mutableSetOf()) { it.url } }.onStart { emit(flow.value.mapTo(mutableSetOf()) { it.url }) - }.flowOn(Dispatchers.Default) + }.flowOn(Dispatchers.IO) .stateIn( scope, SharingStarted.Eagerly, diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip02FollowLists/FollowListReusedOutboxOrProxyRelays.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip02FollowLists/FollowListReusedOutboxOrProxyRelays.kt index 78d5beec08..2f5751936e 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip02FollowLists/FollowListReusedOutboxOrProxyRelays.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip02FollowLists/FollowListReusedOutboxOrProxyRelays.kt @@ -42,7 +42,7 @@ import kotlinx.coroutines.flow.stateIn import kotlinx.coroutines.flow.transformLatest class FollowListReusedOutboxOrProxyRelays( - kind3Follows: FollowListState, + kind3Follows: Kind3FollowListState, blockedRelayList: BlockedRelayListState, proxyRelayList: ProxyRelayListState, val cache: LocalCache, @@ -78,7 +78,7 @@ class FollowListReusedOutboxOrProxyRelays( }, ) }.distinctUntilChanged() - .flowOn(Dispatchers.Default) + .flowOn(Dispatchers.IO) .stateIn( scope, SharingStarted.Eagerly, @@ -90,7 +90,7 @@ class FollowListReusedOutboxOrProxyRelays( followList.minus(blockedRelays) }.onStart { emit(outboxRelayFlow.value.minus(blockedRelayList.flow.value.toSet())) - }.flowOn(Dispatchers.Default) + }.flowOn(Dispatchers.IO) .stateIn( scope, SharingStarted.Eagerly, @@ -112,7 +112,7 @@ class FollowListReusedOutboxOrProxyRelays( outboxRelayMinusBlockedFlow.value }, ) - }.flowOn(Dispatchers.Default) + }.flowOn(Dispatchers.IO) .stateIn( scope, SharingStarted.Eagerly, @@ -126,7 +126,7 @@ class FollowListReusedOutboxOrProxyRelays( relayList.mapTo(mutableSetOf()) { it.url } }.onStart { emit(flow.value.mapTo(mutableSetOf()) { it.url }) - }.flowOn(Dispatchers.Default) + }.flowOn(Dispatchers.IO) .stateIn( scope, SharingStarted.Eagerly, diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip02FollowLists/FollowsPerOutboxRelay.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip02FollowLists/FollowsPerOutboxRelay.kt index b81e951240..921c8d353f 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip02FollowLists/FollowsPerOutboxRelay.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip02FollowLists/FollowsPerOutboxRelay.kt @@ -42,7 +42,7 @@ import kotlinx.coroutines.flow.stateIn import kotlinx.coroutines.flow.transformLatest class FollowsPerOutboxRelay( - kind3Follows: FollowListState, + kind3Follows: Kind3FollowListState, blockedRelayList: BlockedRelayListState, proxyRelayList: ProxyRelayListState, val cache: LocalCache, @@ -60,7 +60,7 @@ class FollowsPerOutboxRelay( OutboxRelayLoader().authorsPerRelaySnapshot(kind3Follows.flow.value.authors, cache) { it }, ) }.distinctUntilChanged() - .flowOn(Dispatchers.Default) + .flowOn(Dispatchers.IO) .stateIn( scope, SharingStarted.Eagerly, @@ -72,7 +72,7 @@ class FollowsPerOutboxRelay( followList.minus(blockedRelays) }.onStart { emit(outboxPerRelayFlow.value.minus(blockedRelayList.flow.value.toSet())) - }.flowOn(Dispatchers.Default) + }.flowOn(Dispatchers.IO) .stateIn( scope, SharingStarted.Eagerly, @@ -96,7 +96,7 @@ class FollowsPerOutboxRelay( } else { emit(proxyRelayList.flow.value.associateWith { kind3Follows.flow.value.authors }) } - }.flowOn(Dispatchers.Default) + }.flowOn(Dispatchers.IO) .stateIn( scope, SharingStarted.Eagerly, diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip02FollowLists/FollowListState.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip02FollowLists/Kind3FollowListState.kt similarity index 80% rename from amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip02FollowLists/FollowListState.kt rename to amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip02FollowLists/Kind3FollowListState.kt index 7bf5816de0..46f8a0cba1 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip02FollowLists/FollowListState.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip02FollowLists/Kind3FollowListState.kt @@ -25,12 +25,10 @@ import com.vitorpamplona.amethyst.model.AccountSettings import com.vitorpamplona.amethyst.model.LocalCache import com.vitorpamplona.amethyst.model.User import com.vitorpamplona.amethyst.model.UserState +import com.vitorpamplona.quartz.nip01Core.core.HexKey import com.vitorpamplona.quartz.nip01Core.signers.NostrSigner -import com.vitorpamplona.quartz.nip01Core.tags.geohash.geohashes import com.vitorpamplona.quartz.nip02FollowList.ContactListEvent import com.vitorpamplona.quartz.nip02FollowList.tags.ContactTag -import com.vitorpamplona.quartz.nip73ExternalIds.location.GeohashId -import com.vitorpamplona.quartz.nip73ExternalIds.topics.HashtagId import com.vitorpamplona.quartz.utils.Log import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.DelicateCoroutinesApi @@ -45,7 +43,7 @@ import kotlinx.coroutines.flow.stateIn import kotlinx.coroutines.flow.transformLatest import kotlinx.coroutines.launch -class FollowListState( +class Kind3FollowListState( val signer: NostrSigner, val cache: LocalCache, val scope: CoroutineScope, @@ -66,7 +64,7 @@ class FollowListState( val flow = innerFlow - .flowOn(Dispatchers.Default) + .flowOn(Dispatchers.IO) .stateIn( scope, SharingStarted.Eagerly, @@ -77,11 +75,11 @@ class FollowListState( // Creates a long-term reference for all follows of a user val userList = flow - .map { - it.authors.mapNotNull { + .map { kind3Follows -> + kind3Follows.authors.mapNotNull { cache.checkGetOrCreateUser(it) } - }.flowOn(Dispatchers.Default) + }.flowOn(Dispatchers.IO) .stateIn( scope, SharingStarted.Eagerly, @@ -96,15 +94,9 @@ class FollowListState( */ @Immutable class Kind3Follows( - val authors: Set = emptySet(), - val authorsPlusMe: Set, - val hashtags: Set = emptySet(), - val geotags: Set = emptySet(), - val communities: Set = emptySet(), - ) { - val geotagScopes: Set = geotags.mapTo(mutableSetOf()) { GeohashId.toScope(it) } - val hashtagScopes: Set = hashtags.mapTo(mutableSetOf()) { HashtagId.toScope(it) } - } + val authors: Set = emptySet(), + val authorsPlusMe: Set, + ) fun buildKind3Follows(latestContactList: ContactListEvent?): Kind3Follows { // makes sure the output include only valid p tags @@ -113,19 +105,6 @@ class FollowListState( return Kind3Follows( authors = verifiedFollowingUsers, authorsPlusMe = verifiedFollowingUsers + signer.pubKey, - hashtags = - latestContactList - ?.unverifiedFollowTagSet() - ?.map { it.lowercase() } - ?.toSet() ?: emptySet(), - geotags = - latestContactList - ?.geohashes() - ?.toSet() ?: emptySet(), - communities = - latestContactList - ?.verifiedFollowAddressSet() - ?.toSet() ?: emptySet(), ) } @@ -166,7 +145,7 @@ class FollowListState( } // saves contact list for the next time. - scope.launch(Dispatchers.Default) { + scope.launch(Dispatchers.IO) { Log.d("AccountRegisterObservers", "Kind 3 Collector Start") getFollowListFlow().collect { Log.d("AccountRegisterObservers", "Updating Kind 3 ${signer.pubKey}") diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip03Timestamp/IncomingOtsEventVerifier.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip03Timestamp/IncomingOtsEventVerifier.kt index df51825bf0..84f0b77d3e 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip03Timestamp/IncomingOtsEventVerifier.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip03Timestamp/IncomingOtsEventVerifier.kt @@ -42,7 +42,7 @@ class IncomingOtsEventVerifier( newNotes.forEach { consume(it) } - }.flowOn(Dispatchers.Default) + }.flowOn(Dispatchers.IO) .stateIn( scope, SharingStarted.Eagerly, diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip17Dms/DmInboxRelayState.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip17Dms/DmInboxRelayState.kt index d1e9def879..6ffe95928a 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip17Dms/DmInboxRelayState.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip17Dms/DmInboxRelayState.kt @@ -47,7 +47,7 @@ class DmInboxRelayState( localRelayList.flow, ) { nip65Inbox, dmRelayList, privateOutBox, localRelays -> nip65Inbox + dmRelayList + privateOutBox + localRelays - }.flowOn(Dispatchers.Default) + }.flowOn(Dispatchers.IO) .stateIn( scope, SharingStarted.Eagerly, diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip17Dms/DmRelayListState.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip17Dms/DmRelayListState.kt index f582734cfc..ba18f9850e 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip17Dms/DmRelayListState.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip17Dms/DmRelayListState.kt @@ -64,7 +64,7 @@ class DmRelayListState( getDMRelayListFlow() .map { normalizeDMRelayListWithBackup(it.note) } .onStart { emit(normalizeDMRelayListWithBackup(dmListNote)) } - .flowOn(Dispatchers.Default) + .flowOn(Dispatchers.IO) .stateIn( scope, SharingStarted.Eagerly, @@ -96,7 +96,7 @@ class DmRelayListState( } } - scope.launch(Dispatchers.Default) { + scope.launch(Dispatchers.IO) { Log.d("AccountRegisterObservers", "NIP-17 Relay List Collector Start") getDMRelayListFlow().collect { Log.d("AccountRegisterObservers", "Updating DM Relay List for ${signer.pubKey}") diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip28PublicChats/PublicChatListState.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip28PublicChats/PublicChatListState.kt index d30bc45512..f52bd4687e 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip28PublicChats/PublicChatListState.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip28PublicChats/PublicChatListState.kt @@ -71,7 +71,7 @@ class PublicChatListState( emit(publicChatListWithBackup(noteState.note)) }.onStart { emit(publicChatListWithBackup(publicChatListNote)) - }.flowOn(Dispatchers.Default) + }.flowOn(Dispatchers.IO) .stateIn( scope, SharingStarted.Eagerly, @@ -85,7 +85,7 @@ class PublicChatListState( it.mapTo(mutableSetOf()) { it.eventId } }.onStart { emit(flow.value.mapTo(mutableSetOf()) { it.eventId }) - }.flowOn(Dispatchers.Default) + }.flowOn(Dispatchers.IO) .stateIn( scope, SharingStarted.Eagerly, @@ -132,7 +132,7 @@ class PublicChatListState( } } - scope.launch(Dispatchers.Default) { + scope.launch(Dispatchers.IO) { Log.d("AccountRegisterObservers", "Channel List Collector Start") getChannelListFlow().collect { Log.d("AccountRegisterObservers", "Channel List for ${signer.pubKey}") diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip30CustomEmojis/EmojiPackState.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip30CustomEmojis/EmojiPackState.kt index 0fdb4793ae..52d0f1aee8 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip30CustomEmojis/EmojiPackState.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip30CustomEmojis/EmojiPackState.kt @@ -75,7 +75,7 @@ class EmojiPackState( emit(convertEmojiSelectionPack(it.note.event as? EmojiPackSelectionEvent)) }.onStart { emit(convertEmojiSelectionPack(getEmojiPackSelection())) - }.flowOn(Dispatchers.Default) + }.flowOn(Dispatchers.IO) .stateIn( scope, SharingStarted.Eagerly, @@ -120,7 +120,7 @@ class EmojiPackState( )?.map { it.value }?.toTypedArray() ?: emptyArray(), ), ) - }.flowOn(Dispatchers.Default) + }.flowOn(Dispatchers.IO) .stateIn( scope, SharingStarted.Eagerly, diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip47WalletConnect/NwcSignerState.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip47WalletConnect/NwcSignerState.kt index cc59221edf..8b5990b651 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip47WalletConnect/NwcSignerState.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip47WalletConnect/NwcSignerState.kt @@ -76,7 +76,7 @@ class NwcSignerState( settings.zapPaymentRequest .map { buildSigner(it) ?: signer - }.flowOn(Dispatchers.Default) + }.flowOn(Dispatchers.IO) .stateIn( scope, SharingStarted.Eagerly, @@ -91,7 +91,7 @@ class NwcSignerState( nip47Signer .map { NostrWalletConnectRequestCache(it) - }.flowOn(Dispatchers.Default) + }.flowOn(Dispatchers.IO) .stateIn(scope, SharingStarted.Eagerly, NostrWalletConnectRequestCache(nip47Signer.value)) /** @@ -102,7 +102,7 @@ class NwcSignerState( nip47Signer .map { NostrWalletConnectResponseCache(it) - }.flowOn(Dispatchers.Default) + }.flowOn(Dispatchers.IO) .stateIn(scope, SharingStarted.Eagerly, NostrWalletConnectResponseCache(nip47Signer.value)) fun buildSigner(uri: Nip47WalletConnect.Nip47URINorm?) = diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip51Lists/BookmarkListState.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip51Lists/BookmarkListState.kt index a758522536..6606229ec3 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip51Lists/BookmarkListState.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip51Lists/BookmarkListState.kt @@ -78,7 +78,7 @@ class BookmarkListState( }.onStart { emit(publicBookmarks(bookmarkList)) }.debounce(100) - .flowOn(Dispatchers.Default) + .flowOn(Dispatchers.IO) .stateIn( scope, SharingStarted.Eagerly, @@ -93,7 +93,7 @@ class BookmarkListState( }.onStart { emit(privateBookmarks(bookmarkList)) }.debounce(100) - .flowOn(Dispatchers.Default) + .flowOn(Dispatchers.IO) .stateIn( scope, SharingStarted.Eagerly, @@ -107,7 +107,7 @@ class BookmarkListState( .mapNotNull { if (it is EventBookmark) it.eventId else null }.toSet() - }.flowOn(Dispatchers.Default) + }.flowOn(Dispatchers.IO) .stateIn( scope, SharingStarted.Eagerly, @@ -121,7 +121,7 @@ class BookmarkListState( .mapNotNull { if (it is AddressBookmark) it.address else null }.toSet() - }.flowOn(Dispatchers.Default) + }.flowOn(Dispatchers.IO) .stateIn( scope, SharingStarted.Eagerly, @@ -135,7 +135,7 @@ class BookmarkListState( .mapNotNull { if (it is EventBookmark) it.eventId else null }.toSet() - }.flowOn(Dispatchers.Default) + }.flowOn(Dispatchers.IO) .stateIn( scope, SharingStarted.Eagerly, @@ -149,7 +149,7 @@ class BookmarkListState( .mapNotNull { if (it is AddressBookmark) it.address else null }.toSet() - }.flowOn(Dispatchers.Default) + }.flowOn(Dispatchers.IO) .stateIn( scope, SharingStarted.Eagerly, @@ -185,7 +185,7 @@ class BookmarkListState( emit(bookmarkList(private, public)) }.onStart { emit(bookmarkList(privateBookmarks.value, publicBookmarks.value)) - }.flowOn(Dispatchers.Default) + }.flowOn(Dispatchers.IO) .stateIn( scope, SharingStarted.Eagerly, diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip51Lists/HiddenUsersState.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip51Lists/HiddenUsersState.kt index ce359259b7..b204823506 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip51Lists/HiddenUsersState.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip51Lists/HiddenUsersState.kt @@ -93,7 +93,7 @@ class HiddenUsersState( settings.syncedSettings.security.showSensitiveContent.value, ), ) - }.flowOn(Dispatchers.Default) + }.flowOn(Dispatchers.IO) .stateIn( scope, SharingStarted.Eagerly, diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip51Lists/blockPeopleList/BlockPeopleListState.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip51Lists/blockPeopleList/BlockPeopleListState.kt index cfc6a20cdb..22ea116b2a 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip51Lists/blockPeopleList/BlockPeopleListState.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip51Lists/blockPeopleList/BlockPeopleListState.kt @@ -61,7 +61,7 @@ class BlockPeopleListState( getBlockListFlow() .map { blockListWithBackup(it.note) } .onStart { emit(blockListWithBackup(blockListNote)) } - .flowOn(Dispatchers.Default) + .flowOn(Dispatchers.IO) .stateIn( scope, SharingStarted.Eagerly, diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip51Lists/blockedRelays/BlockedRelayListState.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip51Lists/blockedRelays/BlockedRelayListState.kt index 80c87c435d..3fc015f512 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip51Lists/blockedRelays/BlockedRelayListState.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip51Lists/blockedRelays/BlockedRelayListState.kt @@ -67,7 +67,7 @@ class BlockedRelayListState( .map { normalizeBlockedRelayListWithBackup(it.note) }.onStart { emit(normalizeBlockedRelayListWithBackup(blockedListNote)) } - .flowOn(Dispatchers.Default) + .flowOn(Dispatchers.IO) .stateIn( scope, SharingStarted.Eagerly, @@ -99,7 +99,7 @@ class BlockedRelayListState( GlobalScope.launch(Dispatchers.IO) { LocalCache.justConsumeMyOwnEvent(it) } } - scope.launch(Dispatchers.Default) { + scope.launch(Dispatchers.IO) { Log.d("AccountRegisterObservers", "Blocked Relay List Collector Start") getBlockedRelayListFlow().collect { Log.d("AccountRegisterObservers", "Updating Blocked Relay List for ${signer.pubKey}") diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip51Lists/broadcastRelays/BroadcastRelayListState.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip51Lists/broadcastRelays/BroadcastRelayListState.kt index 8e6b88e8b3..388e78d4cb 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip51Lists/broadcastRelays/BroadcastRelayListState.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip51Lists/broadcastRelays/BroadcastRelayListState.kt @@ -61,7 +61,7 @@ class BroadcastRelayListState( getBroadcastRelayListFlow() .map { normalizeBroadcastRelayListWithBackup(it.note) } .onStart { emit(normalizeBroadcastRelayListWithBackup(broadcastListNote)) } - .flowOn(Dispatchers.Default) + .flowOn(Dispatchers.IO) .stateIn( scope, SharingStarted.Eagerly, diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip51Lists/geohashLists/GeohashListDecryptionCache.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip51Lists/geohashLists/GeohashListDecryptionCache.kt index 2576cbc123..4ea18aadb0 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip51Lists/geohashLists/GeohashListDecryptionCache.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip51Lists/geohashLists/GeohashListDecryptionCache.kt @@ -72,5 +72,5 @@ class GeohashListDecryptionCache( emit(EmptyGeohashListCard) } }.distinctUntilChanged() - .flowOn(Dispatchers.Default) + .flowOn(Dispatchers.IO) } diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip51Lists/geohashLists/GeohashListState.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip51Lists/geohashLists/GeohashListState.kt index 1e747c0919..dc7eaa534c 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip51Lists/geohashLists/GeohashListState.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip51Lists/geohashLists/GeohashListState.kt @@ -58,7 +58,7 @@ class GeohashListState( suspend fun geohashListWithBackup(note: Note): Set { val event = note.event as? GeohashListEvent ?: settings.backupGeohashList - return event?.let { decryptionCache.geohashes(it) } ?: emptySet() + return event?.let { decryptionCache.geohashes(it).mapTo(mutableSetOf()) { it.lowercase() } } ?: emptySet() } @OptIn(ExperimentalCoroutinesApi::class) @@ -68,7 +68,7 @@ class GeohashListState( emit(geohashListWithBackup(noteState.note)) }.onStart { emit(geohashListWithBackup(geohashListNote)) - }.flowOn(Dispatchers.Default) + }.flowOn(Dispatchers.IO) .stateIn( scope, SharingStarted.Eagerly, @@ -114,7 +114,7 @@ class GeohashListState( } } - scope.launch(Dispatchers.Default) { + scope.launch(Dispatchers.IO) { Log.d("AccountRegisterObservers", "Geohash List Collector Start") getGeohashListFlow().collect { noteState -> Log.d("AccountRegisterObservers", "Geohash List for ${signer.pubKey}") diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip51Lists/hashtagLists/HashtagListState.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip51Lists/hashtagLists/HashtagListState.kt index 16f00e03d5..dd05892a42 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip51Lists/hashtagLists/HashtagListState.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip51Lists/hashtagLists/HashtagListState.kt @@ -58,7 +58,7 @@ class HashtagListState( suspend fun hashtagListWithBackup(note: Note): Set { val event = note.event as? HashtagListEvent ?: settings.backupHashtagList - return event?.let { decryptionCache.hashtags(it) } ?: emptySet() + return event?.let { decryptionCache.hashtags(it).mapTo(mutableSetOf()) { it.lowercase() } } ?: emptySet() } @OptIn(ExperimentalCoroutinesApi::class) @@ -68,10 +68,10 @@ class HashtagListState( emit(hashtagListWithBackup(noteState.note)) }.onStart { emit(hashtagListWithBackup(hashtagListNote)) - }.flowOn(Dispatchers.Default) + }.flowOn(Dispatchers.IO) .stateIn( scope, - SharingStarted.Companion.Eagerly, + SharingStarted.Eagerly, emptySet(), ) @@ -79,9 +79,9 @@ class HashtagListState( val hashtagList = getHashtagList() return if (hashtagList == null) { - HashtagListEvent.Companion.create(hashtags, true, signer) + HashtagListEvent.create(hashtags, true, signer) } else { - HashtagListEvent.Companion.add(hashtagList, hashtags, true, signer) + HashtagListEvent.add(hashtagList, hashtags, true, signer) } } @@ -89,9 +89,9 @@ class HashtagListState( val hashtagList = getHashtagList() return if (hashtagList == null) { - HashtagListEvent.Companion.create(hashtag, true, signer) + HashtagListEvent.create(hashtag, true, signer) } else { - HashtagListEvent.Companion.add(hashtagList, hashtag, true, signer) + HashtagListEvent.add(hashtagList, hashtag, true, signer) } } @@ -99,7 +99,7 @@ class HashtagListState( val hashtagList = getHashtagList() return if (hashtagList != null) { - HashtagListEvent.Companion.remove(hashtagList, hashtag, signer) + HashtagListEvent.remove(hashtagList, hashtag, signer) } else { null } @@ -114,7 +114,7 @@ class HashtagListState( } } - scope.launch(Dispatchers.Default) { + scope.launch(Dispatchers.IO) { Log.d("AccountRegisterObservers", "Hashtag List Collector Start") getHashtagListFlow().collect { Log.d("AccountRegisterObservers", "Hashtag List for ${signer.pubKey}") diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip51Lists/indexerRelays/IndexerRelayListState.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip51Lists/indexerRelays/IndexerRelayListState.kt index 5a67aecb39..738ec1c6d7 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip51Lists/indexerRelays/IndexerRelayListState.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip51Lists/indexerRelays/IndexerRelayListState.kt @@ -67,7 +67,7 @@ class IndexerRelayListState( getIndexerRelayListFlow() .map { normalizeIndexerRelayListWithBackup(it.note) } .onStart { emit(normalizeIndexerRelayListWithBackup(indexerListNote)) } - .flowOn(Dispatchers.Default) + .flowOn(Dispatchers.IO) .stateIn( scope, SharingStarted.Eagerly, @@ -78,7 +78,7 @@ class IndexerRelayListState( getIndexerRelayListFlow() .map { normalizeIndexerRelayListWithBackupNoDefaults(it.note) } .onStart { emit(normalizeIndexerRelayListWithBackupNoDefaults(indexerListNote)) } - .flowOn(Dispatchers.Default) + .flowOn(Dispatchers.IO) .stateIn( scope, SharingStarted.Eagerly, @@ -109,7 +109,7 @@ class IndexerRelayListState( GlobalScope.launch(Dispatchers.IO) { LocalCache.justConsumeMyOwnEvent(it) } } - scope.launch(Dispatchers.Default) { + scope.launch(Dispatchers.IO) { Log.d("AccountRegisterObservers", "Index Relay List Collector Start") getIndexerRelayListFlow().collect { Log.d("AccountRegisterObservers", "Updating Index Relay List for ${signer.pubKey}") diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip51Lists/muteList/MuteListState.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip51Lists/muteList/MuteListState.kt index 2b8f7e7bf4..6ad8b31a6b 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip51Lists/muteList/MuteListState.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip51Lists/muteList/MuteListState.kt @@ -67,7 +67,7 @@ class MuteListState( getMuteListFlow() .map { muteListWithBackup(it.note) } .onStart { emit(muteListWithBackup(muteListNote)) } - .flowOn(Dispatchers.Default) + .flowOn(Dispatchers.IO) .stateIn( scope, SharingStarted.Eagerly, @@ -149,7 +149,7 @@ class MuteListState( } } - scope.launch(Dispatchers.Default) { + scope.launch(Dispatchers.IO) { Log.d("AccountRegisterObservers", "Mute List Collector Start") getMuteListFlow().collect { Log.d("AccountRegisterObservers", "Updating Mute List for ${signer.pubKey}") diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip51Lists/proxyRelays/ProxyRelayListState.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip51Lists/proxyRelays/ProxyRelayListState.kt index 13fe7f0bf0..d50c883682 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip51Lists/proxyRelays/ProxyRelayListState.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip51Lists/proxyRelays/ProxyRelayListState.kt @@ -61,7 +61,7 @@ class ProxyRelayListState( getProxyRelayListFlow() .map { normalizeProxyRelayListWithBackup(it.note) } .onStart { emit(normalizeProxyRelayListWithBackup(proxyListNote)) } - .flowOn(Dispatchers.Default) + .flowOn(Dispatchers.IO) .stateIn( scope, SharingStarted.Eagerly, diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip51Lists/relayLists/GenericRelayListCache.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip51Lists/relayLists/GenericRelayListCache.kt index c8735fbda9..e62fd6a8a0 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip51Lists/relayLists/GenericRelayListCache.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip51Lists/relayLists/GenericRelayListCache.kt @@ -72,5 +72,5 @@ open class GenericRelayListCache( emit(EmptyRelayListCard) } }.distinctUntilChanged() - .flowOn(Dispatchers.Default) + .flowOn(Dispatchers.IO) } diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip51Lists/searchRelays/SearchRelayListState.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip51Lists/searchRelays/SearchRelayListState.kt index 2f9da24015..3d5b3919fa 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip51Lists/searchRelays/SearchRelayListState.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip51Lists/searchRelays/SearchRelayListState.kt @@ -67,7 +67,7 @@ class SearchRelayListState( getSearchRelayListFlow() .map { normalizeSearchRelayListWithBackup(it.note) } .onStart { emit(normalizeSearchRelayListWithBackup(searchListNote)) } - .flowOn(Dispatchers.Default) + .flowOn(Dispatchers.IO) .stateIn( scope, SharingStarted.Companion.Eagerly, @@ -78,7 +78,7 @@ class SearchRelayListState( getSearchRelayListFlow() .map { normalizeSearchRelayListWithBackupNoDefaults(it.note) } .onStart { emit(normalizeSearchRelayListWithBackupNoDefaults(searchListNote)) } - .flowOn(Dispatchers.Default) + .flowOn(Dispatchers.IO) .stateIn( scope, SharingStarted.Eagerly, @@ -109,7 +109,7 @@ class SearchRelayListState( GlobalScope.launch(Dispatchers.IO) { LocalCache.justConsumeMyOwnEvent(it) } } - scope.launch(Dispatchers.Default) { + scope.launch(Dispatchers.IO) { Log.d("AccountRegisterObservers", "Search Relay List Collector Start") getSearchRelayListFlow().collect { Log.d("AccountRegisterObservers", "Updating Search Relay List for ${signer.pubKey}") diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip51Lists/trustedRelays/TrustedRelayListState.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip51Lists/trustedRelays/TrustedRelayListState.kt index eabd779935..96250d6f56 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip51Lists/trustedRelays/TrustedRelayListState.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip51Lists/trustedRelays/TrustedRelayListState.kt @@ -65,7 +65,7 @@ class TrustedRelayListState( getTrustedRelayListFlow() .map { normalizeTrustedRelayListWithBackup(it.note) } .onStart { emit(normalizeTrustedRelayListWithBackup(trustedListNote)) } - .flowOn(Dispatchers.Default) + .flowOn(Dispatchers.IO) .stateIn( scope, SharingStarted.Companion.Eagerly, @@ -96,7 +96,7 @@ class TrustedRelayListState( GlobalScope.launch(Dispatchers.IO) { cache.justConsumeMyOwnEvent(it) } } - scope.launch(Dispatchers.Default) { + scope.launch(Dispatchers.IO) { Log.d("AccountRegisterObservers", "Trusted Relay List Collector Start") getTrustedRelayListFlow().collect { Log.d("AccountRegisterObservers", "Updating Trusted Relay List for ${signer.pubKey}") diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip65RelayList/Nip65RelayListState.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip65RelayList/Nip65RelayListState.kt index b1d85a4294..60a2fb1078 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip65RelayList/Nip65RelayListState.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip65RelayList/Nip65RelayListState.kt @@ -71,7 +71,7 @@ class Nip65RelayListState( getNIP65RelayListFlow() .map { normalizeNIP65WriteRelayListWithBackup(it.note) } .onStart { emit(normalizeNIP65ReadRelayListWithBackup(nip65ListNote)) } - .flowOn(Dispatchers.Default) + .flowOn(Dispatchers.IO) .stateIn( scope, SharingStarted.Eagerly, @@ -82,7 +82,7 @@ class Nip65RelayListState( getNIP65RelayListFlow() .map { normalizeNIP65ReadRelayListWithBackup(it.note) } .onStart { emit(normalizeNIP65ReadRelayListWithBackup(nip65ListNote)) } - .flowOn(Dispatchers.Default) + .flowOn(Dispatchers.IO) .stateIn( scope, SharingStarted.Eagerly, @@ -93,7 +93,7 @@ class Nip65RelayListState( getNIP65RelayListFlow() .map { normalizeNIP65AllRelayListWithBackupNoDefaults(it.note) } .onStart { emit(normalizeNIP65AllRelayListWithBackupNoDefaults(nip65ListNote)) } - .flowOn(Dispatchers.Default) + .flowOn(Dispatchers.IO) .stateIn( scope, SharingStarted.Eagerly, @@ -124,7 +124,7 @@ class Nip65RelayListState( GlobalScope.launch(Dispatchers.IO) { cache.justConsumeMyOwnEvent(it) } } - scope.launch(Dispatchers.Default) { + scope.launch(Dispatchers.IO) { Log.d("AccountRegisterObservers", "NIP-65 Relay List Collector Start") getNIP65RelayListFlow().collect { Log.d("AccountRegisterObservers", "Updating NIP-65 List for ${signer.pubKey}") diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip72Communities/CommunityListState.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip72Communities/CommunityListState.kt index 7f057593a5..0e93aa73ce 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip72Communities/CommunityListState.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip72Communities/CommunityListState.kt @@ -72,7 +72,7 @@ class CommunityListState( emit(communityListWithBackup(noteState.note)) }.onStart { emit(communityListWithBackup(communityListNote)) - }.flowOn(Dispatchers.Default) + }.flowOn(Dispatchers.IO) .stateIn( scope, SharingStarted.Eagerly, @@ -86,7 +86,7 @@ class CommunityListState( hint.mapTo(mutableSetOf()) { it.address.toValue() } }.onStart { emit(flow.value.mapTo(mutableSetOf()) { it.address.toValue() }) - }.flowOn(Dispatchers.Default) + }.flowOn(Dispatchers.IO) .stateIn( scope, SharingStarted.Eagerly, @@ -147,7 +147,7 @@ class CommunityListState( } } - scope.launch(Dispatchers.Default) { + scope.launch(Dispatchers.IO) { Log.d("AccountRegisterObservers", "Community List Collector Start") getCommunityListFlow().collect { Log.d("AccountRegisterObservers", "Community List for ${signer.pubKey}") diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip78AppSpecific/AppSpecificState.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip78AppSpecific/AppSpecificState.kt index 936191085f..6a69cc8e21 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip78AppSpecific/AppSpecificState.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip78AppSpecific/AppSpecificState.kt @@ -81,7 +81,7 @@ class AppSpecificState( } } - scope.launch(Dispatchers.Default) { + scope.launch(Dispatchers.IO) { Log.d("AccountRegisterObservers", "AppSpecificData Collector Start") getAppSpecificDataFlow().collect { try { diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip96FileStorage/FileStorageServerListState.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip96FileStorage/FileStorageServerListState.kt index 519d6cb27a..2d78464d10 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip96FileStorage/FileStorageServerListState.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip96FileStorage/FileStorageServerListState.kt @@ -59,7 +59,7 @@ class FileStorageServerListState( getFileServersListFlow() .map { normalizeServers(it.note) } .onStart { emit(normalizeServers(fileStorageListNote)) } - .flowOn(Dispatchers.Default) + .flowOn(Dispatchers.IO) .stateIn( scope, SharingStarted.Eagerly, diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nipB7Blossom/BlossomServerListState.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nipB7Blossom/BlossomServerListState.kt index 47ee78e48c..c3f8f69ef5 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nipB7Blossom/BlossomServerListState.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nipB7Blossom/BlossomServerListState.kt @@ -61,7 +61,7 @@ class BlossomServerListState( getBlossomServersListFlow() .map { normalizeServers(it.note) } .onStart { emit(normalizeServers(blossomListNote)) } - .flowOn(Dispatchers.Default) + .flowOn(Dispatchers.IO) .stateIn( scope, SharingStarted.Eagerly, diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/preferences/UpdatablePropertyFlow.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/preferences/UpdatablePropertyFlow.kt index af96b24f56..5daabe5197 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/preferences/UpdatablePropertyFlow.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/preferences/UpdatablePropertyFlow.kt @@ -34,7 +34,7 @@ class UpdatablePropertyFlow( ) { val stateFlow = flow - .flowOn(Dispatchers.Default) + .flowOn(Dispatchers.IO) .stateIn( scope = scope, started = SharingStarted.Eagerly, diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/serverList/MergedFollowListsState.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/serverList/MergedFollowListsState.kt index f155da6643..c794eb0bbd 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/serverList/MergedFollowListsState.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/serverList/MergedFollowListsState.kt @@ -20,12 +20,15 @@ */ package com.vitorpamplona.amethyst.model.serverList -import com.vitorpamplona.amethyst.model.nip02FollowLists.FollowListState +import androidx.compose.runtime.Immutable +import com.vitorpamplona.amethyst.model.nip02FollowLists.Kind3FollowListState import com.vitorpamplona.amethyst.model.nip51Lists.followSets.FollowSetState import com.vitorpamplona.amethyst.model.nip51Lists.geohashLists.GeohashListState import com.vitorpamplona.amethyst.model.nip51Lists.hashtagLists.HashtagListState import com.vitorpamplona.amethyst.model.nip72Communities.CommunityListState import com.vitorpamplona.quartz.nip72ModCommunities.follow.tags.CommunityTag +import com.vitorpamplona.quartz.nip73ExternalIds.location.GeohashId +import com.vitorpamplona.quartz.nip73ExternalIds.topics.HashtagId import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.flow.SharingStarted @@ -37,38 +40,50 @@ import kotlinx.coroutines.flow.sample import kotlinx.coroutines.flow.stateIn class MergedFollowListsState( - val kind3List: FollowListState, + val kind3List: Kind3FollowListState, val followSetList: FollowSetState, val hashtagList: HashtagListState, val geohashList: GeohashListState, val communityList: CommunityListState, val scope: CoroutineScope, ) { + /** + This contains a big OR of everything the user wants to see in the a single feed. + */ + @Immutable + class AllFollows( + val authors: Set = emptySet(), + val hashtags: Set = emptySet(), + val geotags: Set = emptySet(), + val communities: Set = emptySet(), + ) { + val geotagScopes: Set = geotags.mapTo(mutableSetOf()) { GeohashId.toScope(it) } + val hashtagScopes: Set = hashtags.mapTo(mutableSetOf()) { HashtagId.toScope(it) } + } + fun mergeLists( - kind3: FollowListState.Kind3Follows, + kind3: Kind3FollowListState.Kind3Follows, followSetProfiles: Set, hashtags: Set, geohashes: Set, community: Set, - ): FollowListState.Kind3Follows = - FollowListState.Kind3Follows( - kind3.authors + followSetProfiles, - kind3.authorsPlusMe, - kind3.hashtags + hashtags, - kind3.geotags + geohashes, - kind3.communities + community.map { it.address.toValue() }, + ): AllFollows = + AllFollows( + authors = kind3.authors + followSetProfiles, + hashtags = hashtags, + geotags = geohashes, + communities = community.mapTo(mutableSetOf()) { it.address.toValue() }, ) - val flow: StateFlow = + val flow: StateFlow = combine( kind3List.flow, followSetList.profilesFlow, hashtagList.flow, geohashList.flow, communityList.flow, - ) { kind3, followSet, hashtag, geohash, community -> - mergeLists(kind3, followSet, hashtag, geohash, community) - }.onStart { + ::mergeLists, + ).onStart { emit( mergeLists( kind3List.flow.value, @@ -79,10 +94,16 @@ class MergedFollowListsState( ), ) }.sample(200) - .flowOn(Dispatchers.Default) + .flowOn(Dispatchers.IO) .stateIn( scope, SharingStarted.Eagerly, - kind3List.flow.value, + mergeLists( + kind3List.flow.value, + followSetList.profilesFlow.value, + hashtagList.flow.value, + geohashList.flow.value, + communityList.flow.value, + ), ) } diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/serverList/MergedFollowPlusMineRelayListsState.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/serverList/MergedFollowPlusMineRelayListsState.kt index 6498e7bed1..a9e0ff6d9b 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/serverList/MergedFollowPlusMineRelayListsState.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/serverList/MergedFollowPlusMineRelayListsState.kt @@ -65,7 +65,7 @@ class MergedFollowPlusMineRelayListsState( ), ), ) - }.flowOn(Dispatchers.Default) + }.flowOn(Dispatchers.IO) .stateIn( scope, SharingStarted.Eagerly, diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/serverList/MergedFollowPlusMineWithIndexRelayListsState.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/serverList/MergedFollowPlusMineWithIndexRelayListsState.kt index ae22655e80..37cc66c47c 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/serverList/MergedFollowPlusMineWithIndexRelayListsState.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/serverList/MergedFollowPlusMineWithIndexRelayListsState.kt @@ -69,7 +69,7 @@ class MergedFollowPlusMineWithIndexRelayListsState( ), ), ) - }.flowOn(Dispatchers.Default) + }.flowOn(Dispatchers.IO) .stateIn( scope, SharingStarted.Eagerly, diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/serverList/MergedFollowPlusMineWithSearchRelayListsState.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/serverList/MergedFollowPlusMineWithSearchRelayListsState.kt index 68e5af6b9e..825a6d98fe 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/serverList/MergedFollowPlusMineWithSearchRelayListsState.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/serverList/MergedFollowPlusMineWithSearchRelayListsState.kt @@ -69,7 +69,7 @@ class MergedFollowPlusMineWithSearchRelayListsState( ), ), ) - }.flowOn(Dispatchers.Default) + }.flowOn(Dispatchers.IO) .stateIn( scope, SharingStarted.Eagerly, diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/serverList/MergedServerListState.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/serverList/MergedServerListState.kt index 8c254d6601..fb011d83e7 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/serverList/MergedServerListState.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/serverList/MergedServerListState.kt @@ -64,7 +64,7 @@ class MergedServerListState( mergeServerList(nip96s, blossoms) }.onStart { emit(mergeServerList(fileServers.flow.value, blossomServers.flow.value)) - }.flowOn(Dispatchers.Default) + }.flowOn(Dispatchers.IO) .stateIn( scope, SharingStarted.Eagerly, diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/serverList/TrustedRelayListsState.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/serverList/TrustedRelayListsState.kt index 86b492d045..be26a1f190 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/serverList/TrustedRelayListsState.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/serverList/TrustedRelayListsState.kt @@ -75,7 +75,7 @@ class TrustedRelayListsState( ), ), ) - }.flowOn(Dispatchers.Default) + }.flowOn(Dispatchers.IO) .stateIn( scope, SharingStarted.Eagerly, diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/topNavFeeds/FeedTopNavFilterState.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/topNavFeeds/FeedTopNavFilterState.kt index efc97e01cd..89db926846 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/topNavFeeds/FeedTopNavFilterState.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/topNavFeeds/FeedTopNavFilterState.kt @@ -25,7 +25,7 @@ import com.vitorpamplona.amethyst.model.ALL_USER_FOLLOWS import com.vitorpamplona.amethyst.model.AROUND_ME import com.vitorpamplona.amethyst.model.GLOBAL_FOLLOWS import com.vitorpamplona.amethyst.model.LocalCache -import com.vitorpamplona.amethyst.model.nip02FollowLists.FollowListState +import com.vitorpamplona.amethyst.model.serverList.MergedFollowListsState import com.vitorpamplona.amethyst.model.topNavFeeds.allFollows.AllFollowsFeedFlow import com.vitorpamplona.amethyst.model.topNavFeeds.allUserFollows.AllUserFollowsFeedFlow import com.vitorpamplona.amethyst.model.topNavFeeds.aroundMe.AroundMeFeedFlow @@ -49,7 +49,7 @@ import kotlinx.coroutines.flow.transformLatest class FeedTopNavFilterState( val feedFilterListName: MutableStateFlow, - val allFollows: StateFlow, + val allFollows: StateFlow, val locationFlow: StateFlow, val followsRelays: StateFlow>, val blockedRelays: StateFlow>, @@ -81,7 +81,7 @@ class FeedTopNavFilterState( emitAll(loadFlowsFor(listName).flow()) }.onStart { loadFlowsFor(feedFilterListName.value).startValue(this) - }.flowOn(Dispatchers.Default) + }.flowOn(Dispatchers.IO) .stateIn( scope, SharingStarted.Eagerly, diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/topNavFeeds/MergedTopFeedAuthorListsState.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/topNavFeeds/MergedTopFeedAuthorListsState.kt index fb860ae395..0728886f20 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/topNavFeeds/MergedTopFeedAuthorListsState.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/topNavFeeds/MergedTopFeedAuthorListsState.kt @@ -100,7 +100,7 @@ class MergedTopFeedAuthorListsState( notificationNavFilter.value, ), ) - }.flowOn(Dispatchers.Default) + }.flowOn(Dispatchers.IO) .stateIn( scope, SharingStarted.Eagerly, diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/topNavFeeds/OutboxLoaderState.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/topNavFeeds/OutboxLoaderState.kt index 257fdccf03..a2980535b1 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/topNavFeeds/OutboxLoaderState.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/topNavFeeds/OutboxLoaderState.kt @@ -45,7 +45,7 @@ class OutboxLoaderState( emitAll(filterSettings.toPerRelayFlow(cache)) }.onStart { emit(topNavFilter.value.startValue(cache)) - }.flowOn(Dispatchers.Default) + }.flowOn(Dispatchers.IO) .stateIn( scope, SharingStarted.Companion.Eagerly, diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/topNavFeeds/allFollows/AllFollowsFeedFlow.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/topNavFeeds/allFollows/AllFollowsFeedFlow.kt index f233cea57d..e451c31295 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/topNavFeeds/allFollows/AllFollowsFeedFlow.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/topNavFeeds/allFollows/AllFollowsFeedFlow.kt @@ -20,7 +20,7 @@ */ package com.vitorpamplona.amethyst.model.topNavFeeds.allFollows -import com.vitorpamplona.amethyst.model.nip02FollowLists.FollowListState +import com.vitorpamplona.amethyst.model.serverList.MergedFollowListsState import com.vitorpamplona.amethyst.model.topNavFeeds.IFeedFlowsType import com.vitorpamplona.amethyst.model.topNavFeeds.IFeedTopNavFilter import com.vitorpamplona.quartz.nip01Core.relay.normalizer.NormalizedRelayUrl @@ -29,31 +29,31 @@ import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.combine class AllFollowsFeedFlow( - val allFollows: StateFlow, + val allFollows: StateFlow, val followsRelays: StateFlow>, val blockedRelays: StateFlow>, val proxyRelays: StateFlow>, ) : IFeedFlowsType { fun convert( - kind3: FollowListState.Kind3Follows?, + allFollows: MergedFollowListsState.AllFollows?, proxyRelays: Set, ): IFeedTopNavFilter = - if (kind3 != null) { + if (allFollows != null) { if (proxyRelays.isEmpty()) { AllFollowsByOutboxTopNavFilter( - authors = kind3.authors, - hashtags = kind3.hashtags, - geotags = kind3.geotags, - communities = kind3.communities, + authors = allFollows.authors, + hashtags = allFollows.hashtags, + geotags = allFollows.geotags, + communities = allFollows.communities, defaultRelays = followsRelays, blockedRelays = blockedRelays, ) } else { AllFollowsByProxyTopNavFilter( - authors = kind3.authors, - hashtags = kind3.hashtags, - geotags = kind3.geotags, - communities = kind3.communities, + authors = allFollows.authors, + hashtags = allFollows.hashtags, + geotags = allFollows.geotags, + communities = allFollows.communities, proxyRelays = proxyRelays, ) } diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/topNavFeeds/allUserFollows/AllUserFollowsFeedFlow.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/topNavFeeds/allUserFollows/AllUserFollowsFeedFlow.kt index 9ad834025a..24a26e3f72 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/topNavFeeds/allUserFollows/AllUserFollowsFeedFlow.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/topNavFeeds/allUserFollows/AllUserFollowsFeedFlow.kt @@ -20,7 +20,7 @@ */ package com.vitorpamplona.amethyst.model.topNavFeeds.allUserFollows -import com.vitorpamplona.amethyst.model.nip02FollowLists.FollowListState +import com.vitorpamplona.amethyst.model.serverList.MergedFollowListsState import com.vitorpamplona.amethyst.model.topNavFeeds.IFeedFlowsType import com.vitorpamplona.amethyst.model.topNavFeeds.IFeedTopNavFilter import com.vitorpamplona.quartz.nip01Core.relay.normalizer.NormalizedRelayUrl @@ -29,25 +29,25 @@ import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.combine class AllUserFollowsFeedFlow( - val allFollows: StateFlow, + val allFollows: StateFlow, val followsRelays: StateFlow>, val blockedRelays: StateFlow>, val proxyRelays: StateFlow>, ) : IFeedFlowsType { fun convert( - kind3: FollowListState.Kind3Follows?, + allFollows: MergedFollowListsState.AllFollows?, proxyRelays: Set, ): IFeedTopNavFilter = - if (kind3 != null) { + if (allFollows != null) { if (proxyRelays.isEmpty()) { AllUserFollowsByOutboxTopNavFilter( - authors = kind3.authors, + authors = allFollows.authors, defaultRelays = followsRelays, blockedRelays = blockedRelays, ) } else { AllUserFollowsByProxyTopNavFilter( - authors = kind3.authors, + authors = allFollows.authors, proxyRelays = proxyRelays, ) } diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/torState/TorRelayState.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/torState/TorRelayState.kt index 9480564e3e..6ec0711f8c 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/torState/TorRelayState.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/torState/TorRelayState.kt @@ -74,7 +74,7 @@ class TorRelayState( trustedRelaysViaTor = torSettingsFlow.trustedRelaysViaTor.value, ), ) - }.flowOn(Dispatchers.Default) + }.flowOn(Dispatchers.IO) .stateIn( scope, SharingStarted.Eagerly, @@ -108,7 +108,7 @@ class TorRelayState( dmRelayList = dmRelays.value, ), ) - }.flowOn(Dispatchers.Default) + }.flowOn(Dispatchers.IO) .stateIn( scope, SharingStarted.Eagerly, diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/notifications/PokeyReceiver.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/notifications/PokeyReceiver.kt index b6f3a2cd2c..077a23a917 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/notifications/PokeyReceiver.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/notifications/PokeyReceiver.kt @@ -47,7 +47,7 @@ class PokeyReceiver : BroadcastReceiver() { Log.e("AmethystCoroutine", "Caught exception: ${throwable.message}", throwable) } - val scope = CoroutineScope(Dispatchers.Default + SupervisorJob() + exceptionHandler) + val scope = CoroutineScope(Dispatchers.IO + SupervisorJob() + exceptionHandler) fun register(app: Context) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/okhttp/OkHttpWebSocket.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/okhttp/OkHttpWebSocket.kt index 56e25c7dd0..82ecb29dbb 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/okhttp/OkHttpWebSocket.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/okhttp/OkHttpWebSocket.kt @@ -76,7 +76,7 @@ class OkHttpWebSocket( inner class OkHttpWebsocketListener( val out: WebSocketListener, ) : okhttp3.WebSocketListener() { - val scope = CoroutineScope(Dispatchers.Default + exceptionHandler) + val scope = CoroutineScope(Dispatchers.IO + exceptionHandler) val incomingMessages: Channel = Channel(Channel.UNLIMITED) val job = // Launch a coroutine to process messages from the channel. scope.launch { diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/playback/composable/controls/MuteButton.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/playback/composable/controls/MuteButton.kt index 39fbc7339f..080c50288b 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/playback/composable/controls/MuteButton.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/playback/composable/controls/MuteButton.kt @@ -65,7 +65,7 @@ fun MuteButton( } LaunchedEffect(key1 = controllerVisible) { - launch(Dispatchers.Default) { + launch(Dispatchers.IO) { delay(2000) holdOn.value = false } diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/relayClient/eoseManagers/BaseEoseManager.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/relayClient/eoseManagers/BaseEoseManager.kt index d59b82205d..a5ba24b916 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/relayClient/eoseManagers/BaseEoseManager.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/relayClient/eoseManagers/BaseEoseManager.kt @@ -55,7 +55,7 @@ abstract class BaseEoseManager( fun dismissSubscription(subId: String) = orchestrator.dismissSubscription(subId) // Refreshes observers in batches. - private val bundler = BundledUpdate(sampleTime, Dispatchers.Default) + private val bundler = BundledUpdate(sampleTime, Dispatchers.IO) override fun invalidateFilters(ignoreIfDoing: Boolean) { bundler.invalidate(ignoreIfDoing, ::forceInvalidate) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/relayClient/reqCommand/account/drafts/AccountDraftsEoseManager.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/relayClient/reqCommand/account/drafts/AccountDraftsEoseManager.kt index 6b56afd3e5..0487a503ce 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/relayClient/reqCommand/account/drafts/AccountDraftsEoseManager.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/relayClient/reqCommand/account/drafts/AccountDraftsEoseManager.kt @@ -63,7 +63,7 @@ class AccountDraftsEoseManager( userJobMap[user]?.forEach { it.cancel() } userJobMap[user] = listOf( - key.account.scope.launch(Dispatchers.Default) { + key.account.scope.launch(Dispatchers.IO) { relayFlow(key).collectLatest { invalidateFilters() } diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/relayClient/reqCommand/account/follows/AccountFollowsLoaderSubAssembler.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/relayClient/reqCommand/account/follows/AccountFollowsLoaderSubAssembler.kt index fc7bcc80bf..e15a6c799d 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/relayClient/reqCommand/account/follows/AccountFollowsLoaderSubAssembler.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/relayClient/reqCommand/account/follows/AccountFollowsLoaderSubAssembler.kt @@ -67,7 +67,7 @@ class AccountFollowsLoaderSubAssembler( private val orchestrator = SubscriptionController(client) // Refreshes observers in batches of 500ms - private val bundler = BundledUpdate(500, Dispatchers.Default) + private val bundler = BundledUpdate(500, Dispatchers.IO) /** * This assembler saves the EOSE per user key. That EOSE includes their metadata, etc @@ -203,7 +203,7 @@ class AccountFollowsLoaderSubAssembler( ) { accountUpdatesJobMap[user]?.cancel() accountUpdatesJobMap[user] = - scope.launch(Dispatchers.Default) { + scope.launch(Dispatchers.IO) { followList.sample(1000).collectLatest { invalidateFilters(true) } diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/relayClient/reqCommand/account/metadata/AccountMetadataEoseManager.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/relayClient/reqCommand/account/metadata/AccountMetadataEoseManager.kt index 7ddeedd855..4b7c90f8cb 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/relayClient/reqCommand/account/metadata/AccountMetadataEoseManager.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/relayClient/reqCommand/account/metadata/AccountMetadataEoseManager.kt @@ -65,7 +65,7 @@ class AccountMetadataEoseManager( userJobMap[user]?.forEach { it.cancel() } userJobMap[user] = listOf( - key.account.scope.launch(Dispatchers.Default) { + key.account.scope.launch(Dispatchers.IO) { relayFlow(key).collectLatest { invalidateFilters() } diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/relayClient/reqCommand/account/nip01Notifications/AccountNotificationsEoseFromInboxRelaysManager.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/relayClient/reqCommand/account/nip01Notifications/AccountNotificationsEoseFromInboxRelaysManager.kt index 61d45d8bd3..c4dd643996 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/relayClient/reqCommand/account/nip01Notifications/AccountNotificationsEoseFromInboxRelaysManager.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/relayClient/reqCommand/account/nip01Notifications/AccountNotificationsEoseFromInboxRelaysManager.kt @@ -71,12 +71,12 @@ class AccountNotificationsEoseFromInboxRelaysManager( userJobMap[user]?.forEach { it.cancel() } userJobMap[user] = listOf( - key.account.scope.launch(Dispatchers.Default) { + key.account.scope.launch(Dispatchers.IO) { key.account.notificationRelays.flow.sample(1000).collectLatest { invalidateFilters() } }, - key.account.scope.launch(Dispatchers.Default) { + key.account.scope.launch(Dispatchers.IO) { key.feedContentStates.notifications.lastNoteCreatedAtWhenFullyLoaded.sample(5000).collectLatest { invalidateFilters() } diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/relayClient/reqCommand/account/nip01Notifications/AccountNotificationsEoseFromRandomRelaysManager.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/relayClient/reqCommand/account/nip01Notifications/AccountNotificationsEoseFromRandomRelaysManager.kt index 0e6f82f3fb..34074f3809 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/relayClient/reqCommand/account/nip01Notifications/AccountNotificationsEoseFromRandomRelaysManager.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/relayClient/reqCommand/account/nip01Notifications/AccountNotificationsEoseFromRandomRelaysManager.kt @@ -67,13 +67,13 @@ class AccountNotificationsEoseFromRandomRelaysManager( userJobMap[user]?.forEach { it.cancel() } userJobMap[user] = listOf( - key.account.scope.launch(Dispatchers.Default) { + key.account.scope.launch(Dispatchers.IO) { // no need to hurry here. we can wait the app stabilize key.account.followsPerRelay.debounce(5000).collectLatest { invalidateFilters() } }, - key.account.scope.launch(Dispatchers.Default) { + key.account.scope.launch(Dispatchers.IO) { key.feedContentStates.notifications.lastNoteCreatedAtWhenFullyLoaded.sample(5000).collectLatest { invalidateFilters() } diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/relayClient/reqCommand/account/nip59GiftWraps/AccountGiftWrapsEoseManager.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/relayClient/reqCommand/account/nip59GiftWraps/AccountGiftWrapsEoseManager.kt index 79a45b4092..7771c04a45 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/relayClient/reqCommand/account/nip59GiftWraps/AccountGiftWrapsEoseManager.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/relayClient/reqCommand/account/nip59GiftWraps/AccountGiftWrapsEoseManager.kt @@ -65,7 +65,7 @@ class AccountGiftWrapsEoseManager( userJobMap[user]?.forEach { it.cancel() } userJobMap[user] = listOf( - key.account.scope.launch(Dispatchers.Default) { + key.account.scope.launch(Dispatchers.IO) { key.account.dmRelays.flow.collectLatest { invalidateFilters() } diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/relayClient/reqCommand/channel/ChannelObservers.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/relayClient/reqCommand/channel/ChannelObservers.kt index 0e60c26c79..1add909d1c 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/relayClient/reqCommand/channel/ChannelObservers.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/relayClient/reqCommand/channel/ChannelObservers.kt @@ -76,7 +76,7 @@ fun observeChannelNoteAuthors( channelToParticipatingUsers(baseChannel, accountViewModel), ) }.distinctUntilChanged() - .flowOn(Dispatchers.Default) + .flowOn(Dispatchers.IO) } return flow.collectAsStateWithLifecycle(persistentListOf()) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/relayClient/reqCommand/event/EventObservers.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/relayClient/reqCommand/event/EventObservers.kt index 665d4fe799..d232a84fc2 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/relayClient/reqCommand/event/EventObservers.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/relayClient/reqCommand/event/EventObservers.kt @@ -97,7 +97,7 @@ fun observeNoteAndMap( .metadata.stateFlow .mapLatest { map(it.note) } .distinctUntilChanged() - .flowOn(Dispatchers.Default) + .flowOn(Dispatchers.IO) } // Subscribe in the LocalCache for changes that arrive in the device @@ -123,7 +123,7 @@ fun observeNoteEventAndMap( .metadata.stateFlow .mapLatest { (it.note.event as? T)?.let { map(it) } } .distinctUntilChanged() - .flowOn(Dispatchers.Default) + .flowOn(Dispatchers.IO) } // Subscribe in the LocalCache for changes that arrive in the device @@ -223,7 +223,7 @@ fun observeNoteReactionCount( .sample(200) .mapLatest { it.note.countReactions() } .distinctUntilChanged() - .flowOn(Dispatchers.Default) + .flowOn(Dispatchers.IO) } // Subscribe in the LocalCache for changes that arrive in the device @@ -278,7 +278,7 @@ fun observeNoteRepostsBy( .boosts.stateFlow .mapLatest { it.note.isBoostedBy(user) } .distinctUntilChanged() - .flowOn(Dispatchers.Default) + .flowOn(Dispatchers.IO) } return flow.collectAsStateWithLifecycle(note.isBoostedBy(user)) @@ -401,7 +401,7 @@ fun observeCommunityApprovalNeedStatus( } } }.distinctUntilChanged() - .flowOn(Dispatchers.Default) + .flowOn(Dispatchers.IO) } // Subscribe in the LocalCache for changes that arrive in the device diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/relayClient/reqCommand/event/loaders/FilterMissingAddressables.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/relayClient/reqCommand/event/loaders/FilterMissingAddressables.kt index e4f8384ec2..ebea6dd109 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/relayClient/reqCommand/event/loaders/FilterMissingAddressables.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/relayClient/reqCommand/event/loaders/FilterMissingAddressables.kt @@ -32,6 +32,10 @@ import com.vitorpamplona.quartz.utils.mapOfSet fun potentialRelaysToFindAddress(note: AddressableNote): Set { val set = mutableSetOf() + LocalCache.getOrCreateUser(note.address.pubKeyHex).outboxRelays()?.let { + set.addAll(it) + } + set.addAll(LocalCache.relayHints.hintsForAddress(note.idHex)) LocalCache.getAnyChannel(note)?.relays()?.let { set.addAll(it) } diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/relayClient/reqCommand/user/UserObservers.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/relayClient/reqCommand/user/UserObservers.kt index 77bcab70fe..fb7a6764fb 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/relayClient/reqCommand/user/UserObservers.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/relayClient/reqCommand/user/UserObservers.kt @@ -253,7 +253,7 @@ fun observeUserFollowCount( .mapLatest { userState -> userState.user.transientFollowCount() ?: 0 }.distinctUntilChanged() - .flowOn(Dispatchers.Default) + .flowOn(Dispatchers.IO) } return flow.collectAsStateWithLifecycle(0) @@ -281,7 +281,7 @@ fun observeUserTagFollowCount( }.onStart { emit((accountViewModel.hashtagFollows(user).event as? HashtagListEvent)?.let { accountViewModel.account.hashtagListDecryptionCache.hashtags(it) }?.size ?: 0) }.distinctUntilChanged() - .flowOn(Dispatchers.Default) + .flowOn(Dispatchers.IO) } return flow.collectAsStateWithLifecycle(0) @@ -309,7 +309,7 @@ fun observeUserTagFollows( }.onStart { emit((accountViewModel.hashtagFollows(user).event as? HashtagListEvent)?.let { accountViewModel.account.hashtagListDecryptionCache.hashtags(it) }?.sorted() ?: emptyList()) }.distinctUntilChanged() - .flowOn(Dispatchers.Default) + .flowOn(Dispatchers.IO) } return flow.collectAsStateWithLifecycle(emptyList()) @@ -356,7 +356,7 @@ fun observeUserBookmarkCount( .mapLatest { noteState -> (noteState.note.event as? BookmarkListEvent)?.countBookmarks() ?: 0 }.distinctUntilChanged() - .flowOn(Dispatchers.Default) + .flowOn(Dispatchers.IO) } return flow.collectAsStateWithLifecycle(0) @@ -396,7 +396,7 @@ fun observeUserFollowerCount( .mapLatest { userState -> userState.user.transientFollowerCount() }.distinctUntilChanged() - .flowOn(Dispatchers.Default) + .flowOn(Dispatchers.IO) } return flow.collectAsStateWithLifecycle(0) @@ -426,7 +426,7 @@ fun observeUserIsFollowing( .mapLatest { userState -> userState.user.isFollowing(user2) || isUserInFollowSets }.distinctUntilChanged() - .flowOn(Dispatchers.Default) + .flowOn(Dispatchers.IO) } return flow.collectAsStateWithLifecycle( @@ -450,7 +450,7 @@ fun observeUserIsFollowingHashtag( }.onStart { emit(hashtag in accountViewModel.account.hashtagList.flow.value) }.distinctUntilChanged() - .flowOn(Dispatchers.Default) + .flowOn(Dispatchers.IO) } return flow.collectAsStateWithLifecycle(hashtag in accountViewModel.account.hashtagList.flow.value) @@ -471,7 +471,7 @@ fun observeUserIsFollowingGeohash( }.onStart { emit(geohash in accountViewModel.account.geohashList.flow.value) }.distinctUntilChanged() - .flowOn(Dispatchers.Default) + .flowOn(Dispatchers.IO) } return flow.collectAsStateWithLifecycle(geohash in accountViewModel.account.geohashList.flow.value) @@ -496,7 +496,7 @@ fun observeUserIsFollowingChannel( .mapLatest { followingChannels -> channel.idHex in followingChannels }.distinctUntilChanged() - .flowOn(Dispatchers.Default) + .flowOn(Dispatchers.IO) } @SuppressLint("StateFlowValueCalledInComposition") @@ -522,7 +522,7 @@ fun observeUserIsFollowingChannel( .mapLatest { followingChannels -> channel.roomId in followingChannels }.distinctUntilChanged() - .flowOn(Dispatchers.Default) + .flowOn(Dispatchers.IO) } @SuppressLint("StateFlowValueCalledInComposition") @@ -563,7 +563,7 @@ fun observeUserZapAmount( .mapLatest { userState -> userState.user.zappedAmount() }.distinctUntilChanged() - .flowOn(Dispatchers.Default) + .flowOn(Dispatchers.IO) } return flow.collectAsStateWithLifecycle(BigDecimal.ZERO) @@ -630,7 +630,7 @@ fun observeUserStatuses( .mapLatest { userState -> LocalCache.findStatusesForUser(userState.user) }.distinctUntilChanged() - .flowOn(Dispatchers.Default) + .flowOn(Dispatchers.IO) } return flow.collectAsStateWithLifecycle(persistentListOf()) @@ -649,7 +649,7 @@ fun observeUserRelayIntoList( .mapLatest { relays -> relayUrl in relays }.distinctUntilChanged() - .flowOn(Dispatchers.Default) + .flowOn(Dispatchers.IO) } return flow.collectAsStateWithLifecycle(false) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/relayClient/reqCommand/user/watchers/FilterUserMetadataForKey.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/relayClient/reqCommand/user/watchers/FilterUserMetadataForKey.kt index ec296eeca1..3f2deb1869 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/relayClient/reqCommand/user/watchers/FilterUserMetadataForKey.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/relayClient/reqCommand/user/watchers/FilterUserMetadataForKey.kt @@ -72,7 +72,7 @@ fun filterUserMetadataForKey( users.forEach { user -> val time = since.since(user)?.get(relay)?.time - if (time == null) { + if (time == null || user.latestMetadata == null) { firstTimers.add(user.pubkeyHex) } else { updates.add(user.pubkeyHex) @@ -82,24 +82,32 @@ fun filterUserMetadataForKey( } } - listOf( - RelayBasedFilter( - relay = relay, - filter = - Filter( - kinds = UserMetadataForKeyKinds, - authors = firstTimers.sorted(), - ), - ), - RelayBasedFilter( - relay = relay, - filter = - Filter( - kinds = UserMetadataForKeyKinds, - authors = updates.sorted(), - since = minimumTime, - ), - ), + listOfNotNull( + if (firstTimers.isNotEmpty()) { + RelayBasedFilter( + relay = relay, + filter = + Filter( + kinds = UserMetadataForKeyKinds, + authors = firstTimers.sorted(), + ), + ) + } else { + null + }, + if (updates.isNotEmpty()) { + RelayBasedFilter( + relay = relay, + filter = + Filter( + kinds = UserMetadataForKeyKinds, + authors = updates.sorted(), + since = minimumTime, + ), + ) + } else { + null + }, ) }.flatten() } diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/relayClient/reqCommand/user/watchers/UserReportsSubAssembler.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/relayClient/reqCommand/user/watchers/UserReportsSubAssembler.kt index 0ef0244ee4..651077a711 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/relayClient/reqCommand/user/watchers/UserReportsSubAssembler.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/relayClient/reqCommand/user/watchers/UserReportsSubAssembler.kt @@ -69,7 +69,7 @@ class UserReportsSubAssembler( val trustedAccounts = mapOfSet { - accounts.map { it.followsPerRelay.value }.forEach { + accounts.map { it.declaredFollowsPerRelay.value }.forEach { add(it) } } diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/MainActivity.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/MainActivity.kt index 26b4398f41..a310b7465a 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/MainActivity.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/MainActivity.kt @@ -110,7 +110,7 @@ class MainActivity : AppCompatActivity() { // Graph doesn't completely clear. // @OptIn(DelicateCoroutinesApi::class) - // GlobalScope.launch(Dispatchers.Default) { + // GlobalScope.launch(Dispatchers.IO) { // serviceManager.trimMemory() // } diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/components/CashuRedeem.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/components/CashuRedeem.kt index 55ccb38714..fecaeada8c 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/components/CashuRedeem.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/components/CashuRedeem.kt @@ -85,7 +85,7 @@ fun CashuPreview( initialValue = CachedCashuParser.cached(cashutoken), key1 = cashutoken, ) { - val newToken = withContext(Dispatchers.Default) { CachedCashuParser.parse(cashutoken) } + val newToken = withContext(Dispatchers.IO) { CachedCashuParser.parse(cashutoken) } if (value != newToken) { value = newToken } diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/components/RichTextViewer.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/components/RichTextViewer.kt index b49e9fa4a0..b9388edbaf 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/components/RichTextViewer.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/components/RichTextViewer.kt @@ -583,7 +583,7 @@ fun DisplaySecretEmoji( if (secretContent == null) { LaunchedEffect(segment) { - launch(Dispatchers.Default) { + launch(Dispatchers.IO) { secretContent = CachedRichTextParser.parseText( EmojiCoder.decode(segment.segmentText), diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/components/ZoomableContentDialog.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/components/ZoomableContentDialog.kt index 4e28c413e8..42345b014b 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/components/ZoomableContentDialog.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/components/ZoomableContentDialog.kt @@ -150,7 +150,7 @@ private fun DialogContent( pagerState.scrollToPage(page) } } - launch(Dispatchers.Default) { + launch(Dispatchers.IO) { delay(2000) withContext(Dispatchers.Main) { controllerVisible.value = false diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/feeds/ChannelFeedContentState.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/feeds/ChannelFeedContentState.kt index af7b4b4192..f615ccbe7d 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/feeds/ChannelFeedContentState.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/feeds/ChannelFeedContentState.kt @@ -68,7 +68,7 @@ class ChannelFeedContentState( } private fun refresh() { - viewModelScope.launch(Dispatchers.Default) { refreshSuspended() } + viewModelScope.launch(Dispatchers.IO) { refreshSuspended() } } fun refreshSuspended() { @@ -135,8 +135,8 @@ class ChannelFeedContentState( } } - private val bundler = BundledUpdate(250, Dispatchers.Default) - private val bundlerInsert = BundledInsert>(250, Dispatchers.Default) + private val bundler = BundledUpdate(250, Dispatchers.IO) + private val bundlerInsert = BundledInsert>(250, Dispatchers.IO) override fun invalidateData(ignoreIfDoing: Boolean) { viewModelScope.launch(Dispatchers.IO) { diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/feeds/FeedContentState.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/feeds/FeedContentState.kt index b177951685..5aad2eff9d 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/feeds/FeedContentState.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/feeds/FeedContentState.kt @@ -71,7 +71,7 @@ class FeedContentState( } private fun refresh() { - viewModelScope.launch(Dispatchers.Default) { refreshSuspended() } + viewModelScope.launch(Dispatchers.IO) { refreshSuspended() } } fun visibleNotes(): List { diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/Loaders.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/Loaders.kt index 1328401a7a..ca5886d939 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/Loaders.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/Loaders.kt @@ -134,7 +134,7 @@ fun LoadOts( LaunchedEffect(key1 = noteStatus) { val newOts = - withContext(Dispatchers.Default) { + withContext(Dispatchers.IO) { LocalCache.findEarliestOtsForNote( note = noteStatus?.note ?: note, otsVerifCache = Amethyst.instance.otsVerifCache, diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/MultiSetCompose.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/MultiSetCompose.kt index 42799727bb..1468bc9cfb 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/MultiSetCompose.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/MultiSetCompose.kt @@ -260,7 +260,7 @@ fun DisplaySecretEmojiAsReaction( if (secretContent == null) { LaunchedEffect(reaction) { - launch(Dispatchers.Default) { + launch(Dispatchers.IO) { secretContent = CachedRichTextParser.parseText( EmojiCoder.decode(reaction), diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/PollNoteViewModel.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/PollNoteViewModel.kt index 9bee68081b..a18b3f221f 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/PollNoteViewModel.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/PollNoteViewModel.kt @@ -100,7 +100,7 @@ class PollNoteViewModel : ViewModel() { } fun refreshTallies() { - viewModelScope.launch(Dispatchers.Default) { + viewModelScope.launch(Dispatchers.IO) { totalZapped = totalZapped() wasZappedByLoggedInAccount = false wasZappedByLoggedInAccount = account.calculateIfNoteWasZappedByAccount(pollNote, 0) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/creators/emojiSuggestions/EmojiSuggestionState.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/creators/emojiSuggestions/EmojiSuggestionState.kt index 82b6f5e235..c29768b535 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/creators/emojiSuggestions/EmojiSuggestionState.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/creators/emojiSuggestions/EmojiSuggestionState.kt @@ -44,7 +44,7 @@ class EmojiSuggestionState( } else { emptyList() } - }.flowOn(Dispatchers.Default) + }.flowOn(Dispatchers.IO) fun reset() { if (search.value.isNotEmpty()) { diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/creators/invoice/InvoicePreview.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/creators/invoice/InvoicePreview.kt index 7ade7a83f5..3d4ff6b7b5 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/creators/invoice/InvoicePreview.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/creators/invoice/InvoicePreview.kt @@ -72,7 +72,7 @@ fun LoadValueFromInvoice( @Suppress("ProduceStateDoesNotAssignValue") val lnInvoice by produceState(initialValue = CachedLnInvoiceParser.cached(lnbcWord), key1 = lnbcWord) { - val newLnInvoice = withContext(Dispatchers.Default) { CachedLnInvoiceParser.parse(lnbcWord) } + val newLnInvoice = withContext(Dispatchers.IO) { CachedLnInvoiceParser.parse(lnbcWord) } if (value != newLnInvoice) { value = newLnInvoice } diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/creators/previews/PreviewState.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/creators/previews/PreviewState.kt index 096d8c4be6..4d36f46036 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/creators/previews/PreviewState.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/creators/previews/PreviewState.kt @@ -39,7 +39,7 @@ class PreviewState { .debounce(500) .map { CachedUrlParser.parseValidUrls(it.text) } .distinctUntilChanged() - .flowOn(Dispatchers.Default) + .flowOn(Dispatchers.IO) fun reset() { source.tryEmit(TextFieldValue("")) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/creators/userSuggestions/ShowUserSuggestionList.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/creators/userSuggestions/ShowUserSuggestionList.kt index 9ac1370016..f125148b83 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/creators/userSuggestions/ShowUserSuggestionList.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/creators/userSuggestions/ShowUserSuggestionList.kt @@ -64,12 +64,12 @@ fun ShowUserSuggestionList( AnimateOnNewSearch(userSuggestions, listState) LaunchedEffect(Unit) { - launch(Dispatchers.Default) { + launch(Dispatchers.IO) { LocalCache.live.newEventBundles.collect { userSuggestions.invalidateData() } } - launch(Dispatchers.Default) { + launch(Dispatchers.IO) { LocalCache.live.deletedEventBundles.collect { userSuggestions.invalidateData() } diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/creators/userSuggestions/UserSuggestionState.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/creators/userSuggestions/UserSuggestionState.kt index 453ab6a778..35d3531b24 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/creators/userSuggestions/UserSuggestionState.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/creators/userSuggestions/UserSuggestionState.kt @@ -62,7 +62,7 @@ class UserSuggestionState( } else { emptyList() } - }.flowOn(Dispatchers.Default) + }.flowOn(Dispatchers.IO) fun reset() { currentWord.tryEmit("") diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/elements/DisplayCommunity.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/elements/DisplayCommunity.kt index 2ccccdf268..e60b4fc4b4 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/elements/DisplayCommunity.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/elements/DisplayCommunity.kt @@ -22,14 +22,12 @@ package com.vitorpamplona.amethyst.ui.note.elements import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row -import androidx.compose.material3.LocalTextStyle import androidx.compose.material3.MaterialTheme -import androidx.compose.material3.Text import androidx.compose.runtime.Composable -import androidx.compose.runtime.remember import androidx.compose.ui.Alignment +import androidx.compose.ui.text.style.TextOverflow import com.vitorpamplona.amethyst.model.Note -import com.vitorpamplona.amethyst.ui.components.buildLinkString +import com.vitorpamplona.amethyst.ui.components.ClickableTextColor import com.vitorpamplona.amethyst.ui.navigation.navs.INav import com.vitorpamplona.amethyst.ui.navigation.routes.Route import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel @@ -53,29 +51,20 @@ private fun DisplayCommunity( note: Note, nav: INav, ) { - val communityTag = - remember(note) { note.event?.communityAddress() } ?: return + val communityTag = note.event?.communityAddress() ?: return - val displayTag = - remember(note) { - buildLinkString( - getCommunityShortName(communityTag), - ) { - nav.nav(Route.Community(communityTag.kind, communityTag.pubKeyHex, communityTag.dTag)) + ClickableTextColor( + getCommunityShortName(communityTag), + linkColor = MaterialTheme.colorScheme.primary.copy(alpha = 0.52f), + overflow = TextOverflow.Ellipsis, + maxLines = 1, + ) { + nav.nav { + note.event?.communityAddress()?.let { communityTag -> + Route.Community(communityTag.kind, communityTag.pubKeyHex, communityTag.dTag) } } - - Text( - text = displayTag, - style = - LocalTextStyle.current.copy( - color = - MaterialTheme.colorScheme.primary.copy( - alpha = 0.52f, - ), - ), - maxLines = 1, - ) + } } fun getCommunityShortName(communityAddress: Address): String { diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/elements/DisplayHashtags.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/elements/DisplayHashtags.kt index 13a3f70c0d..9700d74d8c 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/elements/DisplayHashtags.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/elements/DisplayHashtags.kt @@ -23,9 +23,7 @@ package com.vitorpamplona.amethyst.ui.note.elements import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row -import androidx.compose.material3.LocalTextStyle import androidx.compose.material3.MaterialTheme -import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.getValue @@ -36,7 +34,7 @@ import androidx.compose.ui.Alignment import androidx.compose.ui.text.style.TextOverflow import androidx.lifecycle.compose.collectAsStateWithLifecycle import com.vitorpamplona.amethyst.model.Note -import com.vitorpamplona.amethyst.ui.components.buildLinkString +import com.vitorpamplona.amethyst.ui.components.ClickableTextColor import com.vitorpamplona.amethyst.ui.navigation.navs.INav import com.vitorpamplona.amethyst.ui.navigation.routes.Route import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel @@ -82,15 +80,12 @@ private fun DisplayTagList( accountViewModel: AccountViewModel, nav: INav, ) { - Text( - text = - remember(firstTag) { - buildLinkString(" #$firstTag") { - nav.nav(Route.Hashtag(firstTag)) - } - }, - style = LocalTextStyle.current.copy(MaterialTheme.colorScheme.primary.copy(alpha = 0.52f)), + ClickableTextColor( + "#$firstTag", + linkColor = MaterialTheme.colorScheme.primary.copy(alpha = 0.52f), overflow = TextOverflow.Ellipsis, maxLines = 1, - ) + ) { + nav.nav(Route.Hashtag(firstTag)) + } } diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/nip22Comments/CommentPostViewModel.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/nip22Comments/CommentPostViewModel.kt index 4a4772c2bd..c24a8012b7 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/nip22Comments/CommentPostViewModel.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/nip22Comments/CommentPostViewModel.kt @@ -323,7 +323,7 @@ open class CommentPostViewModel : cancel() accountViewModel.account.signAndComputeBroadcast(template, extraNotesToBroadcast) - accountViewModel.viewModelScope.launch(Dispatchers.Default) { + accountViewModel.viewModelScope.launch(Dispatchers.IO) { accountViewModel.account.deleteDraftIgnoreErrors(version) } } @@ -465,7 +465,7 @@ open class CommentPostViewModel : onError: (title: String, message: String) -> Unit, context: Context, ) { - viewModelScope.launch(Dispatchers.Default) { + viewModelScope.launch(Dispatchers.IO) { val myMultiOrchestrator = multiOrchestrator ?: return@launch isUploadingImage = true @@ -673,7 +673,7 @@ open class CommentPostViewModel : } override fun updateZapFromText() { - viewModelScope.launch(Dispatchers.Default) { + viewModelScope.launch(Dispatchers.IO) { val tagger = NewMessageTagger(message.text, emptyList(), emptyList(), accountViewModel) tagger.run() diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/types/AppDefinition.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/types/AppDefinition.kt index da226558ec..85074bd440 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/types/AppDefinition.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/types/AppDefinition.kt @@ -88,7 +88,7 @@ fun RenderAppDefinition( var metadata by remember { mutableStateOf(null) } LaunchedEffect(key1 = noteEvent) { - withContext(Dispatchers.Default) { metadata = noteEvent.appMetaData() } + withContext(Dispatchers.IO) { metadata = noteEvent.appMetaData() } } metadata?.let { theAppMetadata -> diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/types/MedicalData.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/types/MedicalData.kt index 6ee786b6ae..e8606d59ef 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/types/MedicalData.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/types/MedicalData.kt @@ -185,7 +185,7 @@ fun RenderFhirResource( fun RenderFhirResource(event: FhirResourceEvent) { @Suppress("ProduceStateDoesNotAssignValue") val state by produceState(initialValue = FhirElementDatabase(), key1 = event) { - withContext(Dispatchers.Default) { + withContext(Dispatchers.IO) { parseResourceBundleOrNull(event.content)?.let { value = it } diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/FeedViewModel.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/FeedViewModel.kt index 4484f8bc8e..0ba80943e8 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/FeedViewModel.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/FeedViewModel.kt @@ -49,14 +49,14 @@ abstract class FeedViewModel( init { Log.d("Init", "Starting new Model: ${this.javaClass.simpleName}") - viewModelScope.launch(Dispatchers.Default) { + viewModelScope.launch(Dispatchers.IO) { LocalCache.live.newEventBundles.collect { newNotes -> Log.d("Rendering Metrics", "Update feeds: ${this@FeedViewModel.javaClass.simpleName} with ${newNotes.size}") feedState.updateFeedWith(newNotes) } } - viewModelScope.launch(Dispatchers.Default) { + viewModelScope.launch(Dispatchers.IO) { LocalCache.live.deletedEventBundles.collect { newNotes -> Log.d("Rendering Metrics", "Delete from feeds: ${this@FeedViewModel.javaClass.simpleName} with ${newNotes.size}") feedState.deleteFromFeed(newNotes) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/FollowListState.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/FollowListState.kt index 13ab5552e1..d98cc62770 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/FollowListState.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/FollowListState.kt @@ -253,11 +253,11 @@ class FollowListState( val kind3GlobalPeopleRoutes = _kind3GlobalPeopleRoutes - .flowOn(Dispatchers.Default) + .flowOn(Dispatchers.IO) .stateIn(viewModelScope, SharingStarted.Eagerly, defaultLists) val kind3GlobalPeople = _kind3GlobalPeople - .flowOn(Dispatchers.Default) + .flowOn(Dispatchers.IO) .stateIn(viewModelScope, SharingStarted.Eagerly, defaultLists) suspend fun initializeSuspend() { diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/UserFeedViewModel.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/UserFeedViewModel.kt index 34203a6dd9..0ee61023e7 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/UserFeedViewModel.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/UserFeedViewModel.kt @@ -49,7 +49,7 @@ open class UserFeedViewModel( val feedContent = _feedContent.asStateFlow() private fun refresh() { - viewModelScope.launch(Dispatchers.Default) { refreshSuspended() } + viewModelScope.launch(Dispatchers.IO) { refreshSuspended() } } override val isRefreshing: MutableState = mutableStateOf(false) @@ -100,14 +100,14 @@ open class UserFeedViewModel( init { Log.d("Init", "${this.javaClass.simpleName}") - viewModelScope.launch(Dispatchers.Default) { + viewModelScope.launch(Dispatchers.IO) { LocalCache.live.newEventBundles.collect { newNotes -> Log.d("Rendering Metrics", "Update feeds: ${this@UserFeedViewModel.javaClass.simpleName} with ${newNotes.size}") invalidateData() } } - viewModelScope.launch(Dispatchers.Default) { + viewModelScope.launch(Dispatchers.IO) { LocalCache.live.deletedEventBundles.collect { newNotes -> Log.d("Rendering Metrics", "Delete from feeds: ${this@UserFeedViewModel.javaClass.simpleName} with ${newNotes.size}") invalidateData() diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/AccountViewModel.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/AccountViewModel.kt index b678b35aa3..4f86b10003 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/AccountViewModel.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/AccountViewModel.kt @@ -106,6 +106,7 @@ import com.vitorpamplona.quartz.nip01Core.signers.SignerExceptions import com.vitorpamplona.quartz.nip01Core.tags.people.PubKeyReferenceTag import com.vitorpamplona.quartz.nip01Core.tags.people.isTaggedUser import com.vitorpamplona.quartz.nip03Timestamp.EmptyOtsResolverBuilder +import com.vitorpamplona.quartz.nip04Dm.messages.PrivateDmEvent import com.vitorpamplona.quartz.nip17Dm.base.ChatroomKeyable import com.vitorpamplona.quartz.nip18Reposts.GenericRepostEvent import com.vitorpamplona.quartz.nip18Reposts.RepostEvent @@ -202,7 +203,7 @@ class AccountViewModel( val notificationHasNewItemsFlow = notificationHasNewItems - .flowOn(Dispatchers.Default) + .flowOn(Dispatchers.IO) .stateIn(viewModelScope, SharingStarted.WhileSubscribed(30000), false) @OptIn(ExperimentalCoroutinesApi::class) @@ -251,7 +252,7 @@ class AccountViewModel( val messagesHasNewItemsFlow = messagesHasNewItems - .flowOn(Dispatchers.Default) + .flowOn(Dispatchers.IO) .stateIn(viewModelScope, SharingStarted.WhileSubscribed(30000), false) @OptIn(ExperimentalCoroutinesApi::class) @@ -284,7 +285,7 @@ class AccountViewModel( val homeHasNewItemsFlow = homeHasNewItems - .flowOn(Dispatchers.Default) + .flowOn(Dispatchers.IO) .stateIn(viewModelScope, SharingStarted.WhileSubscribed(30000), false) val hasNewItems = @@ -348,7 +349,10 @@ class AccountViewModel( val isPostHidden = note.isHiddenFor(accountChoices) val isHiddenAuthor = note.author?.let { account.isHidden(it) } == true - return if (isPostHidden) { + val noteEvent = note.event + val isDecryptedPostHidden = if (noteEvent is PrivateDmEvent) account.isDecryptedContentHidden(noteEvent) else false + + return if (isPostHidden || isDecryptedPostHidden) { // Spam + Blocked Users + Hidden Words + Sensitive Content NoteComposeReportState(isPostHidden, false, false, isHiddenAuthor) } else if (isFromLoggedIn || isFromLoggedInFollow) { @@ -394,7 +398,7 @@ class AccountViewModel( account.kind3FollowList.flow.value.authors, ), ) - }.flowOn(Dispatchers.Default) + }.flowOn(Dispatchers.IO) .stateIn( viewModelScope, SharingStarted.WhileSubscribed(10000, 10000), @@ -412,7 +416,7 @@ class AccountViewModel( .relays .stateFlow .map { it.note.relays.size > 3 } - .flowOn(Dispatchers.Default) + .flowOn(Dispatchers.IO) .stateIn( viewModelScope, SharingStarted.WhileSubscribed(10000, 10000), @@ -431,7 +435,7 @@ class AccountViewModel( suspend fun calculateZapAmount(zappedNote: Note): String = if (zappedNote.zapPayments.isNotEmpty()) { - withContext(Dispatchers.Default) { + withContext(Dispatchers.IO) { val it = account.calculateZappedAmount(zappedNote) showAmount(it) } @@ -442,7 +446,7 @@ class AccountViewModel( suspend fun calculateZapraiser(zappedNote: Note): ZapraiserStatus { val zapraiserAmount = zappedNote.event?.zapraiserAmount() ?: 0 return if (zappedNote.zapPayments.isNotEmpty()) { - withContext(Dispatchers.Default) { + withContext(Dispatchers.IO) { val newZapAmount = account.calculateZappedAmount(zappedNote) var percentage = newZapAmount.div(zapraiserAmount.toBigDecimal()).toFloat() @@ -1027,7 +1031,7 @@ class AccountViewModel( fun cachedModificationEventsForNote(note: Note) = LocalCache.cachedModificationEventsForNote(note) suspend fun findModificationEventsForNote(note: Note): List = - withContext(Dispatchers.Default) { + withContext(Dispatchers.IO) { LocalCache.findLatestModificationForNote(note) } @@ -1067,7 +1071,7 @@ class AccountViewModel( hexList: List, onReady: (ImmutableList) -> Unit, ) { - viewModelScope.launch(Dispatchers.Default) { + viewModelScope.launch(Dispatchers.IO) { onReady(loadUsersSync(hexList).toImmutableList()) } } @@ -1094,7 +1098,7 @@ class AccountViewModel( val onIsNew = createdAt > lastTime if (onIsNew) { - viewModelScope.launch(Dispatchers.Default) { + viewModelScope.launch(Dispatchers.IO) { account.markAsRead(routeForLastRead, createdAt) } } @@ -1142,7 +1146,7 @@ class AccountViewModel( init { Log.d("Init", "AccountViewModel") - viewModelScope.launch(Dispatchers.Default) { + viewModelScope.launch(Dispatchers.IO) { feedStates.init() // awaits for init to finish before starting to capture new events. LocalCache.live.newEventBundles.collect { newNotes -> @@ -1152,7 +1156,7 @@ class AccountViewModel( } } - viewModelScope.launch(Dispatchers.Default) { + viewModelScope.launch(Dispatchers.IO) { LocalCache.live.deletedEventBundles.collect { newNotes -> logTime("AccountViewModel deletedEventBundle Update with ${newNotes.size} new notes") { feedStates.deleteNotes(newNotes) @@ -1602,7 +1606,7 @@ class AccountViewModel( val accountViewModel: AccountViewModel, ) : GenericBaseCache(20) { override suspend fun compute(key: String): LoadedBechLink? = - withContext(Dispatchers.Default) { + withContext(Dispatchers.IO) { Nip19Parser.uriToRoute(key)?.let { var returningNote: Note? = null @@ -1621,10 +1625,10 @@ class AccountViewModel( } } is NEmbed -> - withContext(Dispatchers.Default) { + withContext(Dispatchers.IO) { val baseNote = LocalCache.getOrCreateNote(parsed.event) if (baseNote.event == null) { - launch(Dispatchers.Default) { + launch(Dispatchers.IO) { LocalCache.justConsume(parsed.event, null, false) } } diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/privateDM/dal/ChatroomFeedViewModel.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/privateDM/dal/ChatroomFeedViewModel.kt index f2b8973ac9..dd6676f115 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/privateDM/dal/ChatroomFeedViewModel.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/privateDM/dal/ChatroomFeedViewModel.kt @@ -61,7 +61,7 @@ abstract class ListChangeFeedViewModel( init { Log.d("Init", "Starting new Model: ${this.javaClass.simpleName}") - viewModelScope.launch(Dispatchers.Default) { + viewModelScope.launch(Dispatchers.IO) { localFilter.changesFlow().collect { Log.d("Init", "Collecting changes to: ${this@ListChangeFeedViewModel.javaClass.simpleName}") when (it) { diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/privateDM/send/ChatNewMessageViewModel.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/privateDM/send/ChatNewMessageViewModel.kt index 40b51d993c..6899d7b140 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/privateDM/send/ChatNewMessageViewModel.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/privateDM/send/ChatNewMessageViewModel.kt @@ -361,7 +361,7 @@ class ChatNewMessageViewModel : val version = draftTag.current innerSendPost(null) cancel() - accountViewModel.viewModelScope.launch(Dispatchers.Default) { + accountViewModel.viewModelScope.launch(Dispatchers.IO) { accountViewModel.account.deleteDraftIgnoreErrors(version) } } @@ -594,7 +594,7 @@ class ChatNewMessageViewModel : } fun updateRoomFromUsersInput() { - viewModelScope.launch(Dispatchers.Default) { + viewModelScope.launch(Dispatchers.IO) { delay(300) val toUsersTagger = NewMessageTagger(toUsers.text, null, null, accountViewModel) toUsersTagger.run() @@ -717,7 +717,7 @@ class ChatNewMessageViewModel : } override fun updateZapFromText() { - viewModelScope.launch(Dispatchers.Default) { + viewModelScope.launch(Dispatchers.IO) { val tagger = NewMessageTagger(message.text, emptyList(), emptyList(), accountViewModel) tagger.run() tagger.pTags?.forEach { taggedUser -> diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/publicChannels/send/ChannelNewMessageViewModel.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/publicChannels/send/ChannelNewMessageViewModel.kt index 92526bc53e..8272af2ae2 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/publicChannels/send/ChannelNewMessageViewModel.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/publicChannels/send/ChannelNewMessageViewModel.kt @@ -277,7 +277,7 @@ open class ChannelNewMessageViewModel : cancel() accountViewModel.account.signAndSendPrivately(template, channelRelays) - accountViewModel.viewModelScope.launch(Dispatchers.Default) { + accountViewModel.viewModelScope.launch(Dispatchers.IO) { accountViewModel.account.deleteDraftIgnoreErrors(version) } } @@ -319,7 +319,7 @@ open class ChannelNewMessageViewModel : context: Context, onceUploaded: suspend () -> Unit, ) { - viewModelScope.launch(Dispatchers.Default) { + viewModelScope.launch(Dispatchers.IO) { val uploadState = uploadState ?: return@launch val myMultiOrchestrator = uploadState.multiOrchestrator ?: return@launch @@ -630,7 +630,7 @@ open class ChannelNewMessageViewModel : } fun updateZapFromText() { - viewModelScope.launch(Dispatchers.Default) { + viewModelScope.launch(Dispatchers.IO) { val tagger = NewMessageTagger(message.text, emptyList(), emptyList(), accountViewModel) tagger.run() tagger.pTags?.forEach { taggedUser -> diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/rooms/datasource/DMsFromUserFilterSubAssembler.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/rooms/datasource/DMsFromUserFilterSubAssembler.kt index f57593127e..5a5eae5214 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/rooms/datasource/DMsFromUserFilterSubAssembler.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/rooms/datasource/DMsFromUserFilterSubAssembler.kt @@ -61,12 +61,12 @@ class DMsFromUserFilterSubAssembler( userJobMap[user]?.forEach { it.cancel() } userJobMap[user] = listOf( - key.account.scope.launch(Dispatchers.Default) { + key.account.scope.launch(Dispatchers.IO) { key.account.homeRelays.flow.collectLatest { invalidateFilters() } }, - key.account.scope.launch(Dispatchers.Default) { + key.account.scope.launch(Dispatchers.IO) { key.account.dmRelays.flow.collectLatest { invalidateFilters() } diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/rooms/datasource/FollowingEphemeralChatSubAssembler.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/rooms/datasource/FollowingEphemeralChatSubAssembler.kt index 196940e2e6..4a733cce03 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/rooms/datasource/FollowingEphemeralChatSubAssembler.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/rooms/datasource/FollowingEphemeralChatSubAssembler.kt @@ -54,7 +54,7 @@ class FollowingEphemeralChatSubAssembler( userJobMap[key.account.userProfile()]?.forEach { it.cancel() } userJobMap[key.account.userProfile()] = listOf( - key.account.scope.launch(Dispatchers.Default) { + key.account.scope.launch(Dispatchers.IO) { key.account.ephemeralChatList.liveEphemeralChatList.sample(500).collectLatest { invalidateFilters() } diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/rooms/datasource/FollowingPublicChatSubAssembler.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/rooms/datasource/FollowingPublicChatSubAssembler.kt index e08413b264..405a22c9a3 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/rooms/datasource/FollowingPublicChatSubAssembler.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/rooms/datasource/FollowingPublicChatSubAssembler.kt @@ -55,7 +55,7 @@ class FollowingPublicChatSubAssembler( userJobMap[key.account.userProfile()]?.forEach { it.cancel() } userJobMap[key.account.userProfile()] = listOf( - key.account.scope.launch(Dispatchers.Default) { + key.account.scope.launch(Dispatchers.IO) { key.account.publicChatList.flowSet.sample(500).collectLatest { invalidateFilters() } diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/discover/datasource/DiscoveryFollowsSetsAndLiveStreamsSubAssembler2.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/discover/datasource/DiscoveryFollowsSetsAndLiveStreamsSubAssembler2.kt index a1cb0e32ce..eacc12b135 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/discover/datasource/DiscoveryFollowsSetsAndLiveStreamsSubAssembler2.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/discover/datasource/DiscoveryFollowsSetsAndLiveStreamsSubAssembler2.kt @@ -70,17 +70,17 @@ class DiscoveryFollowsSetsAndLiveStreamsSubAssembler2( userJobMap[user]?.forEach { it.cancel() } userJobMap[user] = listOf( - key.scope.launch(Dispatchers.Default) { + key.scope.launch(Dispatchers.IO) { key.listNameFlow().collectLatest { invalidateFilters() } }, - key.scope.launch(Dispatchers.Default) { + key.scope.launch(Dispatchers.IO) { key.followsPerRelayFlow().sample(1000).collectLatest { invalidateFilters() } }, - key.account.scope.launch(Dispatchers.Default) { + key.account.scope.launch(Dispatchers.IO) { combine( key.feedStates.discoverFollowSets.lastNoteCreatedAtWhenFullyLoaded, key.feedStates.discoverLive.lastNoteCreatedAtWhenFullyLoaded, diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/discover/datasource/DiscoveryLongFormClassifiedsAndDVMSubAssembler1.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/discover/datasource/DiscoveryLongFormClassifiedsAndDVMSubAssembler1.kt index 6da653201a..0ba4eb8edf 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/discover/datasource/DiscoveryLongFormClassifiedsAndDVMSubAssembler1.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/discover/datasource/DiscoveryLongFormClassifiedsAndDVMSubAssembler1.kt @@ -72,17 +72,17 @@ class DiscoveryLongFormClassifiedsAndDVMSubAssembler1( userJobMap[user]?.forEach { it.cancel() } userJobMap[user] = listOf( - key.scope.launch(Dispatchers.Default) { + key.scope.launch(Dispatchers.IO) { key.listNameFlow().collectLatest { invalidateFilters() } }, - key.scope.launch(Dispatchers.Default) { + key.scope.launch(Dispatchers.IO) { key.followsPerRelayFlow().sample(500).collectLatest { invalidateFilters() } }, - key.account.scope.launch(Dispatchers.Default) { + key.account.scope.launch(Dispatchers.IO) { combine( key.feedStates.discoverReads.lastNoteCreatedAtWhenFullyLoaded, key.feedStates.discoverDVMs.lastNoteCreatedAtWhenFullyLoaded, diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/discover/datasource/DiscoveryPublicChatsAndCommunitiesSubAssembler3.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/discover/datasource/DiscoveryPublicChatsAndCommunitiesSubAssembler3.kt index 02826f8651..c5a38b8f7a 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/discover/datasource/DiscoveryPublicChatsAndCommunitiesSubAssembler3.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/discover/datasource/DiscoveryPublicChatsAndCommunitiesSubAssembler3.kt @@ -69,17 +69,17 @@ class DiscoveryPublicChatsAndCommunitiesSubAssembler3( userJobMap[user]?.forEach { it.cancel() } userJobMap[user] = listOf( - key.scope.launch(Dispatchers.Default) { + key.scope.launch(Dispatchers.IO) { key.listNameFlow().collectLatest { invalidateFilters() } }, - key.scope.launch(Dispatchers.Default) { + key.scope.launch(Dispatchers.IO) { key.followsPerRelayFlow().sample(500).collectLatest { invalidateFilters() } }, - key.account.scope.launch(Dispatchers.Default) { + key.account.scope.launch(Dispatchers.IO) { combine( key.feedStates.discoverPublicChats.lastNoteCreatedAtWhenFullyLoaded, key.feedStates.discoverCommunities.lastNoteCreatedAtWhenFullyLoaded, diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/discover/nip99Classifieds/NewProductViewModel.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/discover/nip99Classifieds/NewProductViewModel.kt index 1c8dd17b6b..ae52a7d7f1 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/discover/nip99Classifieds/NewProductViewModel.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/discover/nip99Classifieds/NewProductViewModel.kt @@ -297,7 +297,7 @@ open class NewProductViewModel : cancel() accountViewModel.account.signAndSendPrivatelyOrBroadcast(template, relayList = { relayList }) - accountViewModel.viewModelScope.launch(Dispatchers.Default) { + accountViewModel.viewModelScope.launch(Dispatchers.IO) { accountViewModel.account.deleteDraftIgnoreErrors(version) } } @@ -379,7 +379,7 @@ open class NewProductViewModel : onError: (title: String, message: String) -> Unit, context: Context, ) { - viewModelScope.launch(Dispatchers.Default) { + viewModelScope.launch(Dispatchers.IO) { val myAccount = account ?: return@launch val myMultiOrchestrator = multiOrchestrator ?: return@launch @@ -593,7 +593,7 @@ open class NewProductViewModel : } override fun updateZapFromText() { - viewModelScope.launch(Dispatchers.Default) { + viewModelScope.launch(Dispatchers.IO) { val tagger = NewMessageTagger(message.text, emptyList(), emptyList(), accountViewModel!!) tagger.run() tagger.pTags?.forEach { taggedUser -> diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/home/ShortNotePostViewModel.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/home/ShortNotePostViewModel.kt index 847214bcaf..e4d7d72009 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/home/ShortNotePostViewModel.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/home/ShortNotePostViewModel.kt @@ -483,7 +483,7 @@ open class ShortNotePostViewModel : cancel() accountViewModel.account.signAndComputeBroadcast(template, extraNotesToBroadcast) - accountViewModel.viewModelScope.launch(Dispatchers.Default) { + accountViewModel.viewModelScope.launch(Dispatchers.IO) { accountViewModel.account.deleteDraftIgnoreErrors(version) } } @@ -643,7 +643,7 @@ open class ShortNotePostViewModel : context: Context, useH265: Boolean, ) { - viewModelScope.launch(Dispatchers.Default) { + viewModelScope.launch(Dispatchers.IO) { val myMultiOrchestrator = multiOrchestrator ?: return@launch isUploadingImage = true @@ -899,7 +899,7 @@ open class ShortNotePostViewModel : } override fun updateZapFromText() { - viewModelScope.launch(Dispatchers.Default) { + viewModelScope.launch(Dispatchers.IO) { val tagger = NewMessageTagger(message.text, emptyList(), emptyList(), accountViewModel) tagger.run() diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/home/datasource/nip65Follows/HomeOutboxEventsEoseManager.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/home/datasource/nip65Follows/HomeOutboxEventsEoseManager.kt index f6e3d4c472..6646fa1ad3 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/home/datasource/nip65Follows/HomeOutboxEventsEoseManager.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/home/datasource/nip65Follows/HomeOutboxEventsEoseManager.kt @@ -91,22 +91,22 @@ class HomeOutboxEventsEoseManager( userJobMap[user]?.forEach { it.cancel() } userJobMap[user] = listOf( - key.scope.launch(Dispatchers.Default) { + key.scope.launch(Dispatchers.IO) { key.listNameFlow().collectLatest { invalidateFilters() } }, - key.scope.launch(Dispatchers.Default) { + key.scope.launch(Dispatchers.IO) { key.followRelayFlow().sample(1000).collectLatest { invalidateFilters() } }, - key.account.scope.launch(Dispatchers.Default) { + key.account.scope.launch(Dispatchers.IO) { key.feedState.homeNewThreads.lastNoteCreatedAtWhenFullyLoaded.sample(5000).collectLatest { invalidateFilters() } }, - key.account.scope.launch(Dispatchers.Default) { + key.account.scope.launch(Dispatchers.IO) { key.feedState.homeReplies.lastNoteCreatedAtWhenFullyLoaded.sample(5000).collectLatest { invalidateFilters() } diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/notifications/CardFeedContentState.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/notifications/CardFeedContentState.kt index 3d6ef0545f..e2e59f6806 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/notifications/CardFeedContentState.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/notifications/CardFeedContentState.kt @@ -104,7 +104,7 @@ class CardFeedContentState( fun lastNoteCreatedAtIfFilled() = lastNoteCreatedAtWhenFullyLoaded.value fun refresh() { - viewModelScope.launch(Dispatchers.Default) { refreshSuspended() } + viewModelScope.launch(Dispatchers.IO) { refreshSuspended() } } @Synchronized diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/notifications/dal/NotificationFeedFilter.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/notifications/dal/NotificationFeedFilter.kt index ed5a076401..fac9b7661b 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/notifications/dal/NotificationFeedFilter.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/notifications/dal/NotificationFeedFilter.kt @@ -34,6 +34,7 @@ import com.vitorpamplona.quartz.experimental.forks.isForkFromAddressWithPubkey import com.vitorpamplona.quartz.nip01Core.core.AddressableEvent import com.vitorpamplona.quartz.nip01Core.core.HexKey import com.vitorpamplona.quartz.nip01Core.tags.people.isTaggedUser +import com.vitorpamplona.quartz.nip04Dm.messages.PrivateDmEvent import com.vitorpamplona.quartz.nip10Notes.BaseThreadedEvent import com.vitorpamplona.quartz.nip10Notes.TextNoteEvent import com.vitorpamplona.quartz.nip18Reposts.GenericRepostEvent @@ -148,22 +149,23 @@ class NotificationFeedFilter( } } - return it.event !is ChannelCreateEvent && - it.event !is ChannelMetadataEvent && - it.event !is LnZapRequestEvent && - it.event !is BadgeDefinitionEvent && - it.event !is BadgeProfilesEvent && - it.event !is NIP90ContentDiscoveryResponseEvent && - it.event !is NIP90StatusEvent && - it.event !is NIP90ContentDiscoveryRequestEvent && - it.event !is GiftWrapEvent && - it.event !is PrivateTagArrayEvent && - it.event !is LnZapPaymentRequestEvent && - it.event !is LnZapPaymentResponseEvent && - (it.event is LnZapEvent || notifAuthor != loggedInUserHex) && + return noteEvent !is ChannelCreateEvent && + noteEvent !is ChannelMetadataEvent && + noteEvent !is LnZapRequestEvent && + noteEvent !is BadgeDefinitionEvent && + noteEvent !is BadgeProfilesEvent && + noteEvent !is NIP90ContentDiscoveryResponseEvent && + noteEvent !is NIP90StatusEvent && + noteEvent !is NIP90ContentDiscoveryRequestEvent && + noteEvent !is GiftWrapEvent && + noteEvent !is PrivateTagArrayEvent && + noteEvent !is LnZapPaymentRequestEvent && + noteEvent !is LnZapPaymentResponseEvent && + (noteEvent is LnZapEvent || notifAuthor != loggedInUserHex) && (filterParams.isGlobal(it.relays) || notifAuthor == null || filterParams.isAuthorInFollows(notifAuthor)) && - it.event?.isTaggedUser(loggedInUserHex) ?: false && + noteEvent?.isTaggedUser(loggedInUserHex) ?: false && (filterParams.isHiddenList || notifAuthor == null || !account.isHidden(notifAuthor)) && + (noteEvent !is PrivateDmEvent || !account.isDecryptedContentHidden(noteEvent)) && tagsAnEventByUser(it, loggedInUserHex) } diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/notifications/publicMessages/NewPublicMessageViewModel.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/notifications/publicMessages/NewPublicMessageViewModel.kt index 3231287d24..8b975446ef 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/notifications/publicMessages/NewPublicMessageViewModel.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/notifications/publicMessages/NewPublicMessageViewModel.kt @@ -320,7 +320,7 @@ class NewPublicMessageViewModel : cancel() accountViewModel.account.signAndComputeBroadcast(template, extraNotesToBroadcast) - accountViewModel.viewModelScope.launch(Dispatchers.Default) { + accountViewModel.viewModelScope.launch(Dispatchers.IO) { accountViewModel.account.deleteDraftIgnoreErrors(version) } } @@ -413,7 +413,7 @@ class NewPublicMessageViewModel : onError: (title: String, message: String) -> Unit, context: Context, ) { - viewModelScope.launch(Dispatchers.Default) { + viewModelScope.launch(Dispatchers.IO) { val myMultiOrchestrator = multiOrchestrator ?: return@launch isUploadingImage = true @@ -628,7 +628,7 @@ class NewPublicMessageViewModel : } override fun updateZapFromText() { - viewModelScope.launch(Dispatchers.Default) { + viewModelScope.launch(Dispatchers.IO) { val tagger = NewMessageTagger(message.text, emptyList(), emptyList(), accountViewModel) tagger.run() tagger.pTags?.forEach { taggedUser -> diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/profile/header/apps/WatchApp.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/profile/header/apps/WatchApp.kt index 2ead89f33f..b24d30293c 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/profile/header/apps/WatchApp.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/profile/header/apps/WatchApp.kt @@ -55,7 +55,7 @@ fun WatchApp( var appName by remember(baseApp) { mutableStateOf(null) } LaunchedEffect(key1 = appState) { - withContext(Dispatchers.Default) { + withContext(Dispatchers.IO) { (appState?.note?.event as? AppDefinitionEvent)?.appMetaData()?.let { metaData -> metaData.picture?.ifBlank { null }?.let { newLogo -> if (newLogo != appLogo) appLogo = newLogo diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/profile/relays/RelayFeedViewModel.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/profile/relays/RelayFeedViewModel.kt index a26fd24975..81440c8ecb 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/profile/relays/RelayFeedViewModel.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/profile/relays/RelayFeedViewModel.kt @@ -89,7 +89,7 @@ class RelayFeedViewModel : } }.onStart { emit(convert((currentUser.value?.nip65RelayListNote?.event as? AdvertisedRelayListEvent)?.writeRelaysNorm()?.toSet(), currentUser.value)) - }.flowOn(Dispatchers.Default) + }.flowOn(Dispatchers.IO) .stateIn(viewModelScope, SharingStarted.WhileSubscribed(5000), emptyList()) @OptIn(ExperimentalCoroutinesApi::class) @@ -113,7 +113,7 @@ class RelayFeedViewModel : } }.onStart { emit(convert((currentUser.value?.nip65RelayListNote?.event as? AdvertisedRelayListEvent)?.readRelaysNorm()?.toSet(), currentUser.value)) - }.flowOn(Dispatchers.Default) + }.flowOn(Dispatchers.IO) .stateIn(viewModelScope, SharingStarted.WhileSubscribed(5000), emptyList()) @OptIn(ExperimentalCoroutinesApi::class) @@ -137,13 +137,13 @@ class RelayFeedViewModel : } }.onStart { emit(convert((currentUser.value?.nip65RelayListNote?.event as? ChatMessageRelayListEvent)?.relays()?.toSet(), currentUser.value)) - }.flowOn(Dispatchers.Default) + }.flowOn(Dispatchers.IO) .stateIn(viewModelScope, SharingStarted.WhileSubscribed(5000), emptyList()) override val isRefreshing: MutableState = mutableStateOf(false) fun refresh() { - viewModelScope.launch(Dispatchers.Default) { + viewModelScope.launch(Dispatchers.IO) { refreshSuspended() } } diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/profile/zaps/LnZapFeedViewModel.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/profile/zaps/LnZapFeedViewModel.kt index 3e910af2c7..1619707dbe 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/profile/zaps/LnZapFeedViewModel.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/profile/zaps/LnZapFeedViewModel.kt @@ -44,7 +44,7 @@ open class LnZapFeedViewModel( val feedContent = _feedContent.asStateFlow() private fun refresh() { - viewModelScope.launch(Dispatchers.Default) { refreshSuspended() } + viewModelScope.launch(Dispatchers.IO) { refreshSuspended() } } private fun refreshSuspended() { diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/relays/common/BasicRelaySetupInfoClickableRow.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/relays/common/BasicRelaySetupInfoClickableRow.kt index 6c726d53a4..f6b99128a7 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/relays/common/BasicRelaySetupInfoClickableRow.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/relays/common/BasicRelaySetupInfoClickableRow.kt @@ -46,7 +46,6 @@ import com.vitorpamplona.amethyst.ui.stringRes import com.vitorpamplona.amethyst.ui.theme.DividerThickness import com.vitorpamplona.amethyst.ui.theme.HalfHalfVertPadding import com.vitorpamplona.amethyst.ui.theme.HalfHorzPadding -import com.vitorpamplona.amethyst.ui.theme.HalfStartPadding import com.vitorpamplona.amethyst.ui.theme.HalfVertPadding import com.vitorpamplona.amethyst.ui.theme.Height25Modifier import com.vitorpamplona.amethyst.ui.theme.LargeRelayIconModifier diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/relays/common/RelayStatusRow.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/relays/common/RelayStatusRow.kt index 8e75d1348c..361fab2983 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/relays/common/RelayStatusRow.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/relays/common/RelayStatusRow.kt @@ -20,11 +20,8 @@ */ package com.vitorpamplona.amethyst.ui.screen.loggedIn.relays.common -import android.widget.Toast import androidx.compose.foundation.gestures.detectTapGestures -import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Row -import androidx.compose.foundation.layout.size import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.DeleteSweep import androidx.compose.material.icons.filled.Download @@ -34,12 +31,8 @@ import androidx.compose.material3.Icon import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Text import androidx.compose.runtime.Composable -import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.ui.Modifier import androidx.compose.ui.input.pointer.pointerInput -import androidx.compose.ui.platform.LocalContext -import androidx.compose.ui.unit.dp -import androidx.compose.ui.unit.sp import com.vitorpamplona.amethyst.R import com.vitorpamplona.amethyst.service.countToHumanReadable import com.vitorpamplona.amethyst.service.countToHumanReadableBytes @@ -51,7 +44,6 @@ import com.vitorpamplona.amethyst.ui.theme.Size15Modifier import com.vitorpamplona.amethyst.ui.theme.allGoodColor import com.vitorpamplona.amethyst.ui.theme.placeholderText import com.vitorpamplona.amethyst.ui.theme.warningColor -import kotlinx.coroutines.launch @Composable fun RelayStatusRow( diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/search/SearchBarViewModel.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/search/SearchBarViewModel.kt index b6241290c0..583083c8cc 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/search/SearchBarViewModel.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/search/SearchBarViewModel.kt @@ -75,7 +75,7 @@ class SearchBarViewModel( invalidations.debounce(100), ) { term, version -> LocalCache.findUsersStartingWith(term, account) - }.flowOn(Dispatchers.Default) + }.flowOn(Dispatchers.IO) .stateIn(viewModelScope, WhileSubscribed(5000), emptyList()) val searchResultsNotes = @@ -86,7 +86,7 @@ class SearchBarViewModel( LocalCache .findNotesStartingWith(term, account.hiddenUsers) .sortedWith(DefaultFeedOrder) - }.flowOn(Dispatchers.Default) + }.flowOn(Dispatchers.IO) .stateIn(viewModelScope, WhileSubscribed(5000), emptyList()) val searchResultsPublicChatChannels = @@ -95,7 +95,7 @@ class SearchBarViewModel( invalidations, ) { term, version -> LocalCache.findPublicChatChannelsStartingWith(term) - }.flowOn(Dispatchers.Default) + }.flowOn(Dispatchers.IO) .stateIn(viewModelScope, WhileSubscribed(5000), emptyList()) val searchResultsEphemeralChannels = @@ -104,7 +104,7 @@ class SearchBarViewModel( invalidations, ) { term, version -> LocalCache.findEphemeralChatChannelsStartingWith(term) - }.flowOn(Dispatchers.Default) + }.flowOn(Dispatchers.IO) .stateIn(viewModelScope, WhileSubscribed(5000), emptyList()) val searchResultsLiveActivityChannels = @@ -113,7 +113,7 @@ class SearchBarViewModel( invalidations, ) { term, version -> LocalCache.findLiveActivityChannelsStartingWith(term) - }.flowOn(Dispatchers.Default) + }.flowOn(Dispatchers.IO) .stateIn(viewModelScope, WhileSubscribed(5000), emptyList()) val hashtagResults = @@ -122,7 +122,7 @@ class SearchBarViewModel( invalidations, ) { term, version -> findHashtags(term) - }.flowOn(Dispatchers.Default) + }.flowOn(Dispatchers.IO) .stateIn(viewModelScope, WhileSubscribed(5000), emptyList()) override val isRefreshing = derivedStateOf { searchValue.isNotBlank() } diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/search/SearchScreen.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/search/SearchScreen.kt index ab47c8eb7a..df6aa10582 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/search/SearchScreen.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/search/SearchScreen.kt @@ -143,7 +143,7 @@ private fun SearchBar( TextSearchDataSourceSubscription(searchBarViewModel, accountViewModel) LaunchedEffect(Unit) { - launch(Dispatchers.Default) { + launch(Dispatchers.IO) { LocalCache.live.newEventBundles.collect { if (searchBarViewModel.isSearchingFun()) { searchBarViewModel.invalidateData() @@ -151,7 +151,7 @@ private fun SearchBar( } } - launch(Dispatchers.Default) { + launch(Dispatchers.IO) { LocalCache.live.deletedEventBundles.collect { if (searchBarViewModel.isSearchingFun()) { searchBarViewModel.invalidateData() diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/settings/StringFeedViewModel.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/settings/StringFeedViewModel.kt index cc999d7977..5d49b9a508 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/settings/StringFeedViewModel.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/settings/StringFeedViewModel.kt @@ -50,7 +50,7 @@ open class StringFeedViewModel( override val isRefreshing: MutableState = mutableStateOf(false) private fun refresh() { - viewModelScope.launch(Dispatchers.Default) { refreshSuspended() } + viewModelScope.launch(Dispatchers.IO) { refreshSuspended() } } private fun refreshSuspended() { @@ -99,13 +99,13 @@ open class StringFeedViewModel( init { Log.d("Init", this.javaClass.simpleName) - viewModelScope.launch(Dispatchers.Default) { + viewModelScope.launch(Dispatchers.IO) { LocalCache.live.newEventBundles.collect { newNotes -> Log.d("Rendering Metrics", "Update feeds: ${this@StringFeedViewModel.javaClass.simpleName} with ${newNotes.size}") invalidateData() } } - viewModelScope.launch(Dispatchers.Default) { + viewModelScope.launch(Dispatchers.IO) { LocalCache.live.deletedEventBundles.collect { newNotes -> Log.d("Rendering Metrics", "Delete feeds: ${this@StringFeedViewModel.javaClass.simpleName} with ${newNotes.size}") invalidateData() diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/threadview/dal/LevelFeedViewModel.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/threadview/dal/LevelFeedViewModel.kt index 2a0115802a..3d006fffbe 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/threadview/dal/LevelFeedViewModel.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/threadview/dal/LevelFeedViewModel.kt @@ -80,7 +80,7 @@ abstract class LevelFeedViewModel( MutableStateFlow(mapOf()) }, ) - }.flowOn(Dispatchers.Default) + }.flowOn(Dispatchers.IO) .stateIn( viewModelScope, SharingStarted.WhileSubscribed(5000), diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/video/NewImageButton.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/video/NewImageButton.kt index 5c1d10c64f..05797c81f4 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/video/NewImageButton.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/video/NewImageButton.kt @@ -88,7 +88,7 @@ fun NewImageButton( val postViewModel: NewMediaModel = viewModel() postViewModel.onceUploaded { - scope.launch(Dispatchers.Default) { + scope.launch(Dispatchers.IO) { delay(500) withContext(Dispatchers.Main) { navScrollToTop() } } diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/video/datasource/subassemblies/VideoOutboxEventsFilterSubAssembler.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/video/datasource/subassemblies/VideoOutboxEventsFilterSubAssembler.kt index 5bc1288e28..ef53e0037d 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/video/datasource/subassemblies/VideoOutboxEventsFilterSubAssembler.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/video/datasource/subassemblies/VideoOutboxEventsFilterSubAssembler.kt @@ -93,12 +93,12 @@ class VideoOutboxEventsFilterSubAssembler( userJobMap[user]?.forEach { it.cancel() } userJobMap[user] = listOf( - key.scope.launch(Dispatchers.Default) { + key.scope.launch(Dispatchers.IO) { key.followsPerRelayFlow().sample(1000).collectLatest { invalidateFilters() } }, - key.scope.launch(Dispatchers.Default) { + key.scope.launch(Dispatchers.IO) { key.feedState.videoFeed.lastNoteCreatedAtWhenFullyLoaded.sample(1000).collectLatest { invalidateFilters() } diff --git a/ammolite/src/main/java/com/vitorpamplona/ammolite/relays/BundledUpdate.kt b/ammolite/src/main/java/com/vitorpamplona/ammolite/relays/BundledUpdate.kt index 66dc0d04e1..e94e62a616 100644 --- a/ammolite/src/main/java/com/vitorpamplona/ammolite/relays/BundledUpdate.kt +++ b/ammolite/src/main/java/com/vitorpamplona/ammolite/relays/BundledUpdate.kt @@ -40,7 +40,7 @@ import java.util.concurrent.atomic.AtomicBoolean @Stable class BundledUpdate( val delay: Long, - val dispatcher: CoroutineDispatcher = Dispatchers.Default, + val dispatcher: CoroutineDispatcher = Dispatchers.IO, ) { // Exists to avoid exceptions stopping the coroutine val exceptionHandler = @@ -66,7 +66,7 @@ class BundledUpdate( @Stable class BasicBundledUpdate( val delay: Long, - val dispatcher: CoroutineDispatcher = Dispatchers.Default, + val dispatcher: CoroutineDispatcher = Dispatchers.IO, val scope: CoroutineScope, ) { private var onlyOneInBlock = AtomicBoolean() @@ -104,7 +104,7 @@ class BasicBundledUpdate( @Stable class BundledInsert( val delay: Long, - val dispatcher: CoroutineDispatcher = Dispatchers.Default, + val dispatcher: CoroutineDispatcher = Dispatchers.IO, ) { // Exists to avoid exceptions stopping the coroutine val exceptionHandler = @@ -130,7 +130,7 @@ class BundledInsert( @Stable class BasicBundledInsert( val delay: Long, - val dispatcher: CoroutineDispatcher = Dispatchers.Default, + val dispatcher: CoroutineDispatcher = Dispatchers.IO, val scope: CoroutineScope, ) { private var onlyOneInBlock = AtomicBoolean() diff --git a/git-hooks/pre-commit b/git-hooks/pre-commit index e02ca661ac..e0f7abfa23 100755 --- a/git-hooks/pre-commit +++ b/git-hooks/pre-commit @@ -12,7 +12,7 @@ echo "$JAVA_HOME" echo "$(java -version)" echo "Running test... " -./gradlew spotlessCheck +./gradlew clean spotlessCheck status=$? diff --git a/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip01Core/relay/client/NostrClient.kt b/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip01Core/relay/client/NostrClient.kt index 1c818969fe..c62e09d213 100644 --- a/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip01Core/relay/client/NostrClient.kt +++ b/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip01Core/relay/client/NostrClient.kt @@ -37,13 +37,11 @@ import com.vitorpamplona.quartz.nip01Core.relay.filters.Filter import com.vitorpamplona.quartz.nip01Core.relay.normalizer.NormalizedRelayUrl import com.vitorpamplona.quartz.nip01Core.relay.sockets.WebsocketBuilder import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.FlowPreview import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.combine import kotlinx.coroutines.flow.debounce -import kotlinx.coroutines.flow.flowOn import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.flow.sample import kotlinx.coroutines.flow.stateIn @@ -108,8 +106,7 @@ class NostrClient( }.sample(300) .onEach { relayPool.updatePool(it) - }.flowOn(Dispatchers.Default) - .stateIn( + }.stateIn( scope, SharingStarted.Eagerly, activeRequests.desiredRelays.value + activeCounts.relays.value + eventOutbox.relays.value, @@ -229,7 +226,7 @@ class NostrClient( override fun renewFilters(relay: IRelayClient) { if (isActive) { - scope.launch(Dispatchers.Default) { + scope.launch { activeRequests.syncState(relay.url, relay::sendOrConnectAndSync) activeCounts.syncState(relay.url, relay::sendOrConnectAndSync) eventOutbox.syncState(relay.url, relay::sendOrConnectAndSync) diff --git a/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip01Core/relay/client/accessories/NostrClientSendAndWaitExt.kt b/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip01Core/relay/client/accessories/NostrClientSendAndWaitExt.kt index 17219af0c5..a138070319 100644 --- a/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip01Core/relay/client/accessories/NostrClientSendAndWaitExt.kt +++ b/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip01Core/relay/client/accessories/NostrClientSendAndWaitExt.kt @@ -29,8 +29,6 @@ import com.vitorpamplona.quartz.nip01Core.relay.commands.toClient.OkMessage import com.vitorpamplona.quartz.nip01Core.relay.normalizer.NormalizedRelayUrl import com.vitorpamplona.quartz.utils.Log import kotlinx.coroutines.DelicateCoroutinesApi -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.IO import kotlinx.coroutines.async import kotlinx.coroutines.channels.Channel import kotlinx.coroutines.channels.Channel.Factory.UNLIMITED @@ -95,7 +93,7 @@ suspend fun INostrClient.sendAndWaitForResponse( val resultSubscription = coroutineScope { val result = - async(Dispatchers.IO) { + async { val receivedResults = mutableMapOf() // The withTimeout block will cancel the coroutine if the loop takes too long withTimeoutOrNull(timeoutInSeconds * 1000) { diff --git a/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip01Core/relay/client/accessories/RelayOfflineTracker.kt b/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip01Core/relay/client/accessories/RelayOfflineTracker.kt index 3af03e46f1..6a31e01ea1 100644 --- a/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip01Core/relay/client/accessories/RelayOfflineTracker.kt +++ b/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip01Core/relay/client/accessories/RelayOfflineTracker.kt @@ -23,8 +23,6 @@ package com.vitorpamplona.quartz.nip01Core.relay.client.accessories import com.vitorpamplona.quartz.nip01Core.relay.client.INostrClient import com.vitorpamplona.quartz.nip01Core.relay.client.listeners.IRelayClientListener import com.vitorpamplona.quartz.nip01Core.relay.client.single.IRelayClient -import com.vitorpamplona.quartz.nip01Core.relay.commands.toClient.Message -import com.vitorpamplona.quartz.nip01Core.relay.commands.toClient.NotifyMessage import com.vitorpamplona.quartz.nip01Core.relay.normalizer.NormalizedRelayUrl import com.vitorpamplona.quartz.utils.Log diff --git a/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip01Core/relay/client/pool/PoolRequests.kt b/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip01Core/relay/client/pool/PoolRequests.kt index 0e505b1320..dfda9bed5b 100644 --- a/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip01Core/relay/client/pool/PoolRequests.kt +++ b/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip01Core/relay/client/pool/PoolRequests.kt @@ -230,13 +230,17 @@ class PoolRequests { sync: (NormalizedRelayUrl, Command) -> Unit, ) { relaysToUpdate.forEach { relay -> - val currentState = relayState.get(subId)?.currentState(relay) + sendToRelayIfChanged(subId, relay) { cmd -> + if (cmd is ReqCmd) { + val currentState = relayState.get(subId)?.currentState(relay) - if (currentState == ReqSubStatus.SENT || currentState == ReqSubStatus.QUERYING_PAST) { - // sending multiple REQs triggers multiple EOSEs back and we then don't know which - // one is which. - } else { - sendToRelayIfChanged(subId, relay) { cmd -> + if (currentState == ReqSubStatus.SENT || currentState == ReqSubStatus.QUERYING_PAST) { + // sending multiple REQs triggers multiple EOSEs back and we then don't know which + // one is which. + } else { + sync(relay, cmd) + } + } else { sync(relay, cmd) } } diff --git a/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip02FollowList/ContactListEvent.kt b/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip02FollowList/ContactListEvent.kt index 5fd4e5d0aa..e25e3011a0 100644 --- a/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip02FollowList/ContactListEvent.kt +++ b/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip02FollowList/ContactListEvent.kt @@ -23,14 +23,11 @@ package com.vitorpamplona.quartz.nip02FollowList import androidx.compose.runtime.Stable import com.vitorpamplona.quartz.nip01Core.core.BaseAddressableEvent import com.vitorpamplona.quartz.nip01Core.core.HexKey -import com.vitorpamplona.quartz.nip01Core.hints.AddressHintProvider import com.vitorpamplona.quartz.nip01Core.hints.PubKeyHintProvider import com.vitorpamplona.quartz.nip01Core.relay.normalizer.NormalizedRelayUrl import com.vitorpamplona.quartz.nip01Core.relay.normalizer.RelayUrlNormalizer import com.vitorpamplona.quartz.nip01Core.signers.NostrSigner import com.vitorpamplona.quartz.nip01Core.signers.NostrSignerSync -import com.vitorpamplona.quartz.nip01Core.tags.aTag.ATag -import com.vitorpamplona.quartz.nip01Core.tags.hashtags.hashtags import com.vitorpamplona.quartz.nip01Core.tags.people.isTaggedUser import com.vitorpamplona.quartz.nip02FollowList.tags.ContactTag import com.vitorpamplona.quartz.nip31Alts.AltTag @@ -45,12 +42,7 @@ class ContactListEvent( content: String, sig: HexKey, ) : BaseAddressableEvent(id, pubKey, createdAt, KIND, tags, content, sig), - AddressHintProvider, PubKeyHintProvider { - override fun addressHints() = tags.mapNotNull(ATag::parseAsHint) - - override fun linkedAddressIds() = tags.mapNotNull(ATag::parseAddressId) - override fun pubKeyHints() = tags.mapNotNull(ContactTag::parseAsHint) override fun linkedPubKeys() = tags.mapNotNull(ContactTag::parseKey) @@ -60,17 +52,8 @@ class ContactListEvent( */ fun verifiedFollowKeySet(): Set = tags.mapNotNullTo(mutableSetOf(), ContactTag::parseValidKey) - /** - * Returns a list of a-tags that are verified as correct. - */ - @Deprecated("Use CommunityListEvent instead.") - fun verifiedFollowAddressSet(): Set = tags.mapNotNullTo(mutableSetOf(), ATag::parseValidAddress) - fun unverifiedFollowKeySet() = tags.mapNotNull(ContactTag::parseKey) - @Deprecated("Use HashtagListEvent instead.") - fun unverifiedFollowTagSet() = tags.hashtags() - fun follows() = tags.mapNotNull(ContactTag::parseValid) fun relays(): Map? { diff --git a/quartz/src/jvmAndroid/kotlin/com/vitorpamplona/quartz/nip01Core/relay/commands/toClient/MessageDeserializer.kt b/quartz/src/jvmAndroid/kotlin/com/vitorpamplona/quartz/nip01Core/relay/commands/toClient/MessageDeserializer.kt index 95bfb8f2bd..0cf7c0a534 100644 --- a/quartz/src/jvmAndroid/kotlin/com/vitorpamplona/quartz/nip01Core/relay/commands/toClient/MessageDeserializer.kt +++ b/quartz/src/jvmAndroid/kotlin/com/vitorpamplona/quartz/nip01Core/relay/commands/toClient/MessageDeserializer.kt @@ -81,7 +81,7 @@ class MessageDeserializer : StdDeserializer(Message::class.java) { ClosedMessage.LABEL -> ClosedMessage( subId = jp.nextTextValue(), - message = jp.nextTextValue(), + message = jp.nextTextValue() ?: "", ) CountMessage.LABEL -> { diff --git a/quartz/src/jvmAndroid/kotlin/com/vitorpamplona/quartz/nip01Core/relay/sockets/okhttp/BasicOkHttpWebSocket.kt b/quartz/src/jvmAndroid/kotlin/com/vitorpamplona/quartz/nip01Core/relay/sockets/okhttp/BasicOkHttpWebSocket.kt index 79a02caf11..0d8f20ea10 100644 --- a/quartz/src/jvmAndroid/kotlin/com/vitorpamplona/quartz/nip01Core/relay/sockets/okhttp/BasicOkHttpWebSocket.kt +++ b/quartz/src/jvmAndroid/kotlin/com/vitorpamplona/quartz/nip01Core/relay/sockets/okhttp/BasicOkHttpWebSocket.kt @@ -60,7 +60,7 @@ class BasicOkHttpWebSocket( val listener = object : OkHttpWebSocketListener() { - val scope = CoroutineScope(Dispatchers.Default + exceptionHandler) + val scope = CoroutineScope(Dispatchers.IO + exceptionHandler) val incomingMessages: Channel = Channel(Channel.UNLIMITED) val job = // Launch a coroutine to process messages from the channel. scope.launch {