Init room in constructor.

This commit is contained in:
Onuray Sahin 2020-09-30 10:58:32 +03:00 committed by Benoit Marty
parent 4dbeaeb465
commit d4a0659483

View file

@ -29,6 +29,7 @@ import im.vector.app.core.extensions.exhaustive
import im.vector.app.core.platform.VectorViewModel
import kotlinx.coroutines.launch
import org.matrix.android.sdk.api.session.Session
import org.matrix.android.sdk.api.session.room.Room
import org.matrix.android.sdk.api.session.search.SearchResult
import org.matrix.android.sdk.internal.util.awaitCallback
@ -37,6 +38,12 @@ class SearchViewModel @AssistedInject constructor(
private val session: Session
) : VectorViewModel<SearchViewState, SearchAction, SearchViewEvents>(initialState) {
private var room: Room? = null
init {
room = initialState.roomId?.let { session.getRoom(it) }
}
@AssistedInject.Factory
interface Factory {
fun create(initialState: SearchViewState): SearchViewModel
@ -94,9 +101,7 @@ class SearchViewModel @AssistedInject constructor(
viewModelScope.launch {
try {
val result = awaitCallback<SearchResult> {
session
.getRoom(state.roomId)
?.search(
room?.search(
searchTerm = state.searchTerm,
nextBatch = state.searchResult?.nextBatch,
orderByRecent = true,