diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/actions/EditPostViewModel.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/actions/EditPostViewModel.kt index da02defbc..5d16b6183 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/actions/EditPostViewModel.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/actions/EditPostViewModel.kt @@ -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( 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 c29768b53..c3af93f09 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 @@ -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 = MutableStateFlow("") val results: Flow> = - accountViewModel.account + account .emoji.myEmojis .combine(search) { list, search -> if (search.length == 1) { 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 35d3531b2..5b9baefcd 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 @@ -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(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?) { 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 c24a8012b..1a99000a7 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 @@ -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) { 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 6899d7b14..ac1422be7 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 @@ -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( 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 8272af2ae..3ebd7f116 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 @@ -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) } 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 ae52a7d7f..43315ef45 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 @@ -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) { 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 e4d7d7200..09da6c2f2 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 @@ -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( 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 8b975446e..df9a033cc 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 @@ -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) {