Updates emoji and user autocomplete state to use Account and avoid linking AccountViewModel
This commit is contained in:
@@ -104,7 +104,7 @@ open class EditPostViewModel : ViewModel() {
|
||||
this.editedFromNote = edit
|
||||
|
||||
this.userSuggestions?.reset()
|
||||
this.userSuggestions = UserSuggestionState(accountViewModel)
|
||||
this.userSuggestions = UserSuggestionState(accountViewModel.account)
|
||||
}
|
||||
|
||||
open fun load(
|
||||
|
||||
+3
-3
@@ -20,8 +20,8 @@
|
||||
*/
|
||||
package com.vitorpamplona.amethyst.ui.note.creators.emojiSuggestions
|
||||
|
||||
import com.vitorpamplona.amethyst.model.Account
|
||||
import com.vitorpamplona.amethyst.model.nip30CustomEmojis.EmojiPackState
|
||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
@@ -29,11 +29,11 @@ import kotlinx.coroutines.flow.combine
|
||||
import kotlinx.coroutines.flow.flowOn
|
||||
|
||||
class EmojiSuggestionState(
|
||||
val accountViewModel: AccountViewModel,
|
||||
val account: Account,
|
||||
) {
|
||||
val search: MutableStateFlow<String> = MutableStateFlow("")
|
||||
val results: Flow<List<EmojiPackState.EmojiMedia>> =
|
||||
accountViewModel.account
|
||||
account
|
||||
.emoji.myEmojis
|
||||
.combine(search) { list, search ->
|
||||
if (search.length == 1) {
|
||||
|
||||
+16
-7
@@ -23,9 +23,9 @@ package com.vitorpamplona.amethyst.ui.note.creators.userSuggestions
|
||||
import androidx.compose.ui.text.TextRange
|
||||
import androidx.compose.ui.text.input.TextFieldValue
|
||||
import com.vitorpamplona.amethyst.logTime
|
||||
import com.vitorpamplona.amethyst.model.Account
|
||||
import com.vitorpamplona.amethyst.model.User
|
||||
import com.vitorpamplona.amethyst.service.relayClient.searchCommand.SearchQueryState
|
||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.FlowPreview
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
@@ -38,11 +38,12 @@ import kotlinx.coroutines.flow.onEach
|
||||
import kotlinx.coroutines.flow.update
|
||||
|
||||
class UserSuggestionState(
|
||||
val accountViewModel: AccountViewModel,
|
||||
val account: Account,
|
||||
val requireAtSymbol: Boolean = true,
|
||||
) {
|
||||
val invalidations = MutableStateFlow<Int>(0)
|
||||
val currentWord = MutableStateFlow("")
|
||||
val searchDataSourceState = SearchQueryState(MutableStateFlow(""), accountViewModel.account)
|
||||
val searchDataSourceState = SearchQueryState(MutableStateFlow(""), account)
|
||||
|
||||
@OptIn(FlowPreview::class)
|
||||
val searchTerm =
|
||||
@@ -57,7 +58,7 @@ class UserSuggestionState(
|
||||
combine(searchTerm, invalidations.debounce(100)) { prefix, version ->
|
||||
if (prefix != null) {
|
||||
logTime("UserSuggestionState Search $prefix version $version") {
|
||||
accountViewModel.findUsersStartingWithSync(prefix)
|
||||
account.cache.findUsersStartingWith(prefix, account)
|
||||
}
|
||||
} else {
|
||||
emptyList()
|
||||
@@ -78,10 +79,18 @@ class UserSuggestionState(
|
||||
}
|
||||
|
||||
fun userSearchTermOrNull(currentWord: String): String? =
|
||||
if (currentWord.startsWith("@") && currentWord.length > 2) {
|
||||
currentWord.removePrefix("@")
|
||||
if (requireAtSymbol) {
|
||||
if (currentWord.startsWith("@") && currentWord.length > 2) {
|
||||
currentWord.removePrefix("@")
|
||||
} else {
|
||||
null
|
||||
}
|
||||
} else {
|
||||
null
|
||||
if (currentWord.length > 1) {
|
||||
currentWord
|
||||
} else {
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
fun updateDataSource(searchTerm: String?) {
|
||||
|
||||
+2
-2
@@ -189,10 +189,10 @@ open class CommentPostViewModel :
|
||||
this.canAddZapRaiser = hasLnAddress()
|
||||
|
||||
this.userSuggestions?.reset()
|
||||
this.userSuggestions = UserSuggestionState(accountVM)
|
||||
this.userSuggestions = UserSuggestionState(accountVM.account)
|
||||
|
||||
this.emojiSuggestions?.reset()
|
||||
this.emojiSuggestions = EmojiSuggestionState(accountVM)
|
||||
this.emojiSuggestions = EmojiSuggestionState(accountVM.account)
|
||||
}
|
||||
|
||||
fun newPostFor(externalIdentity: ExternalId) {
|
||||
|
||||
+2
-2
@@ -188,10 +188,10 @@ class ChatNewMessageViewModel :
|
||||
this.canAddZapRaiser = hasLnAddress()
|
||||
|
||||
this.userSuggestions?.reset()
|
||||
this.userSuggestions = UserSuggestionState(accountVM)
|
||||
this.userSuggestions = UserSuggestionState(accountVM.account)
|
||||
|
||||
this.emojiSuggestions?.reset()
|
||||
this.emojiSuggestions = EmojiSuggestionState(accountVM)
|
||||
this.emojiSuggestions = EmojiSuggestionState(accountVM.account)
|
||||
|
||||
this.uploadState =
|
||||
ChatFileUploadState(
|
||||
|
||||
+2
-2
@@ -168,10 +168,10 @@ open class ChannelNewMessageViewModel :
|
||||
this.canAddZapRaiser = hasLnAddress()
|
||||
|
||||
this.userSuggestions?.reset()
|
||||
this.userSuggestions = UserSuggestionState(accountVM)
|
||||
this.userSuggestions = UserSuggestionState(accountVM.account)
|
||||
|
||||
this.emojiSuggestions?.reset()
|
||||
this.emojiSuggestions = EmojiSuggestionState(accountVM)
|
||||
this.emojiSuggestions = EmojiSuggestionState(accountVM.account)
|
||||
|
||||
this.uploadState = ChatFileUploadState(account.settings.defaultFileServer)
|
||||
}
|
||||
|
||||
+2
-2
@@ -182,10 +182,10 @@ open class NewProductViewModel :
|
||||
this.canAddZapRaiser = hasLnAddress()
|
||||
|
||||
this.userSuggestions?.reset()
|
||||
this.userSuggestions = UserSuggestionState(accountVM)
|
||||
this.userSuggestions = UserSuggestionState(accountVM.account)
|
||||
|
||||
this.emojiSuggestions?.reset()
|
||||
this.emojiSuggestions = EmojiSuggestionState(accountVM)
|
||||
this.emojiSuggestions = EmojiSuggestionState(accountVM.account)
|
||||
}
|
||||
|
||||
fun editFromDraft(draft: Note) {
|
||||
|
||||
+2
-2
@@ -229,10 +229,10 @@ open class ShortNotePostViewModel :
|
||||
this.canAddZapRaiser = hasLnAddress()
|
||||
|
||||
this.userSuggestions?.reset()
|
||||
this.userSuggestions = UserSuggestionState(accountVM)
|
||||
this.userSuggestions = UserSuggestionState(accountVM.account)
|
||||
|
||||
this.emojiSuggestions?.reset()
|
||||
this.emojiSuggestions = EmojiSuggestionState(accountVM)
|
||||
this.emojiSuggestions = EmojiSuggestionState(accountVM.account)
|
||||
}
|
||||
|
||||
open fun load(
|
||||
|
||||
+2
-2
@@ -191,10 +191,10 @@ class NewPublicMessageViewModel :
|
||||
this.canAddZapRaiser = hasLnAddress()
|
||||
|
||||
this.userSuggestions?.reset()
|
||||
this.userSuggestions = UserSuggestionState(accountVM)
|
||||
this.userSuggestions = UserSuggestionState(accountVM.account)
|
||||
|
||||
this.emojiSuggestions?.reset()
|
||||
this.emojiSuggestions = EmojiSuggestionState(accountVM)
|
||||
this.emojiSuggestions = EmojiSuggestionState(accountVM.account)
|
||||
}
|
||||
|
||||
fun load(users: Set<HexKey>) {
|
||||
|
||||
Reference in New Issue
Block a user