refactor: remove Namecoin label from search results per review
Remove namecoinResolvedUser StateFlow and the chain-emoji label from search results. .bit resolution still works through the existing NIP-05 path — just no special UI decoration.
This commit is contained in:
+10
-22
@@ -57,7 +57,6 @@ import kotlinx.coroutines.flow.Flow
|
|||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
import kotlinx.coroutines.flow.SharingStarted
|
import kotlinx.coroutines.flow.SharingStarted
|
||||||
import kotlinx.coroutines.flow.SharingStarted.Companion.WhileSubscribed
|
import kotlinx.coroutines.flow.SharingStarted.Companion.WhileSubscribed
|
||||||
import kotlinx.coroutines.flow.StateFlow
|
|
||||||
import kotlinx.coroutines.flow.combine
|
import kotlinx.coroutines.flow.combine
|
||||||
import kotlinx.coroutines.flow.debounce
|
import kotlinx.coroutines.flow.debounce
|
||||||
import kotlinx.coroutines.flow.distinctUntilChanged
|
import kotlinx.coroutines.flow.distinctUntilChanged
|
||||||
@@ -91,10 +90,6 @@ class SearchBarViewModel(
|
|||||||
|
|
||||||
val listState: LazyListState = LazyListState(0, 0)
|
val listState: LazyListState = LazyListState(0, 0)
|
||||||
|
|
||||||
/** The user resolved via Namecoin (.bit), if any, for the current search. */
|
|
||||||
private val _namecoinResolvedUser = MutableStateFlow<User?>(null)
|
|
||||||
val namecoinResolvedUser: StateFlow<User?> = _namecoinResolvedUser
|
|
||||||
|
|
||||||
@OptIn(kotlinx.coroutines.ExperimentalCoroutinesApi::class)
|
@OptIn(kotlinx.coroutines.ExperimentalCoroutinesApi::class)
|
||||||
val directNip05Resolver: Flow<User?> =
|
val directNip05Resolver: Flow<User?> =
|
||||||
searchTerm
|
searchTerm
|
||||||
@@ -110,26 +105,21 @@ class SearchBarViewModel(
|
|||||||
} else {
|
} else {
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
val isNamecoin = nip05 != null && nip05.domain.endsWith(".bit", ignoreCase = true)
|
|
||||||
if (nip05 != null) {
|
if (nip05 != null) {
|
||||||
val user =
|
runCatching {
|
||||||
runCatching {
|
nip05Client.get(nip05)?.let { info ->
|
||||||
nip05Client.get(nip05)?.let { info ->
|
val user = account.cache.checkGetOrCreateUser(info.pubkey)
|
||||||
val u = account.cache.checkGetOrCreateUser(info.pubkey)
|
if (user != null) {
|
||||||
if (u != null) {
|
info.relays.forEach {
|
||||||
info.relays.forEach {
|
it.normalizeRelayUrlOrNull()?.let { relay ->
|
||||||
it.normalizeRelayUrlOrNull()?.let { relay ->
|
account.cache.relayHints.addKey(user.pubkey(), relay)
|
||||||
account.cache.relayHints.addKey(u.pubkey(), relay)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
u
|
|
||||||
}
|
}
|
||||||
}.getOrNull()
|
user
|
||||||
_namecoinResolvedUser.value = if (isNamecoin) user else null
|
}
|
||||||
user
|
}.getOrNull()
|
||||||
} else if (term.startsWithAny(userUriPrefixes)) {
|
} else if (term.startsWithAny(userUriPrefixes)) {
|
||||||
_namecoinResolvedUser.value = null
|
|
||||||
runCatching {
|
runCatching {
|
||||||
Nip19Parser.uriToRoute(term)?.entity?.let { parsed ->
|
Nip19Parser.uriToRoute(term)?.entity?.let { parsed ->
|
||||||
when (parsed) {
|
when (parsed) {
|
||||||
@@ -156,10 +146,8 @@ class SearchBarViewModel(
|
|||||||
}
|
}
|
||||||
}.getOrNull()
|
}.getOrNull()
|
||||||
} else if (term.length == 64 && Hex.isHex64(term)) {
|
} else if (term.length == 64 && Hex.isHex64(term)) {
|
||||||
_namecoinResolvedUser.value = null
|
|
||||||
account.cache.getOrCreateUser(term)
|
account.cache.getOrCreateUser(term)
|
||||||
} else {
|
} else {
|
||||||
_namecoinResolvedUser.value = null
|
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
}.flowOn(Dispatchers.IO)
|
}.flowOn(Dispatchers.IO)
|
||||||
|
|||||||
-11
@@ -229,7 +229,6 @@ private fun DisplaySearchResults(
|
|||||||
val hashTags by searchBarViewModel.hashtagResults.collectAsStateWithLifecycle()
|
val hashTags by searchBarViewModel.hashtagResults.collectAsStateWithLifecycle()
|
||||||
val relays by searchBarViewModel.relayResults.collectAsStateWithLifecycle()
|
val relays by searchBarViewModel.relayResults.collectAsStateWithLifecycle()
|
||||||
val users by searchBarViewModel.searchResultsUsers.collectAsStateWithLifecycle()
|
val users by searchBarViewModel.searchResultsUsers.collectAsStateWithLifecycle()
|
||||||
val namecoinUser by searchBarViewModel.namecoinResolvedUser.collectAsStateWithLifecycle()
|
|
||||||
val publicChatChannels by searchBarViewModel.searchResultsPublicChatChannels.collectAsStateWithLifecycle()
|
val publicChatChannels by searchBarViewModel.searchResultsPublicChatChannels.collectAsStateWithLifecycle()
|
||||||
val ephemeralChannels by searchBarViewModel.searchResultsEphemeralChannels.collectAsStateWithLifecycle()
|
val ephemeralChannels by searchBarViewModel.searchResultsEphemeralChannels.collectAsStateWithLifecycle()
|
||||||
val liveActivityChannels by searchBarViewModel.searchResultsLiveActivityChannels.collectAsStateWithLifecycle()
|
val liveActivityChannels by searchBarViewModel.searchResultsLiveActivityChannels.collectAsStateWithLifecycle()
|
||||||
@@ -256,16 +255,6 @@ private fun DisplaySearchResults(
|
|||||||
users,
|
users,
|
||||||
key = { _, item -> "u" + item.pubkeyHex },
|
key = { _, item -> "u" + item.pubkeyHex },
|
||||||
) { _, item ->
|
) { _, item ->
|
||||||
if (namecoinUser == item) {
|
|
||||||
Text(
|
|
||||||
"\u26D3\uFE0F Namecoin",
|
|
||||||
style = MaterialTheme.typography.labelSmall,
|
|
||||||
color = MaterialTheme.colorScheme.primary,
|
|
||||||
fontWeight = FontWeight.Medium,
|
|
||||||
modifier = Modifier.padding(horizontal = 12.dp, vertical = 2.dp),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
UserCompose(item, accountViewModel = accountViewModel, nav = nav)
|
UserCompose(item, accountViewModel = accountViewModel, nav = nav)
|
||||||
|
|
||||||
HorizontalDivider(
|
HorizontalDivider(
|
||||||
|
|||||||
Reference in New Issue
Block a user