Skip to content

Commit

Permalink
Add inline selected emojis to the recently used list.
Browse files Browse the repository at this point in the history
Fixes #12514
  • Loading branch information
cody-signal authored and alex-signal committed Oct 25, 2022
1 parent 341b8ef commit 0819c8d
Showing 1 changed file with 7 additions and 1 deletion.
Expand Up @@ -4,17 +4,22 @@ import androidx.lifecycle.ViewModel
import io.reactivex.rxjava3.core.Observable
import io.reactivex.rxjava3.schedulers.Schedulers
import io.reactivex.rxjava3.subjects.PublishSubject
import org.thoughtcrime.securesms.components.emoji.RecentEmojiPageModel
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies
import org.thoughtcrime.securesms.keyboard.emoji.search.EmojiSearchRepository
import org.thoughtcrime.securesms.keyvalue.SignalStore
import org.thoughtcrime.securesms.util.TextSecurePreferences
import org.thoughtcrime.securesms.util.adapter.mapping.AnyMappingModel

/**
* Activity (at least) scope view model for managing inline queries. The view model needs to be larger scope so it can
* be shared between the fragment requesting the search and the instace of [InlineQueryResultsFragment] used for displaying
* the results.
*/
class InlineQueryViewModel(private val emojiSearchRepository: EmojiSearchRepository = EmojiSearchRepository(ApplicationDependencies.getApplication())) : ViewModel() {
class InlineQueryViewModel(
private val emojiSearchRepository: EmojiSearchRepository = EmojiSearchRepository(ApplicationDependencies.getApplication()),
private val recentEmojis: RecentEmojiPageModel = RecentEmojiPageModel(ApplicationDependencies.getApplication(), TextSecurePreferences.RECENT_STORAGE_KEY)
) : ViewModel() {

private val querySubject: PublishSubject<InlineQuery> = PublishSubject.create()
private val selectionSubject: PublishSubject<InlineQueryReplacement> = PublishSubject.create()
Expand Down Expand Up @@ -46,6 +51,7 @@ class InlineQueryViewModel(private val emojiSearchRepository: EmojiSearchReposit
fun onSelection(model: AnyMappingModel) {
when (model) {
is InlineQueryEmojiResult.Model -> {
recentEmojis.onCodePointSelected(model.preferredEmoji)
selectionSubject.onNext(InlineQueryReplacement.Emoji(model.preferredEmoji, model.keywordSearch))
}
}
Expand Down

0 comments on commit 0819c8d

Please sign in to comment.