Convert RelationService to suspend (#2449)
This commit is contained in:
parent
fc468564dc
commit
d2b39e5cb8
|
@ -93,7 +93,7 @@ interface RelationService {
|
||||||
/**
|
/**
|
||||||
* Get the edit history of the given event
|
* Get the edit history of the given event
|
||||||
*/
|
*/
|
||||||
fun fetchEditHistory(eventId: String, callback: MatrixCallback<List<Event>>)
|
suspend fun fetchEditHistory(eventId: String): List<Event>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reply to an event in the timeline (must be in same room)
|
* Reply to an event in the timeline (must be in same room)
|
||||||
|
|
|
@ -140,13 +140,8 @@ internal class DefaultRelationService @AssistedInject constructor(
|
||||||
return eventSenderProcessor.postEvent(event, cryptoSessionInfoProvider.isRoomEncrypted(roomId))
|
return eventSenderProcessor.postEvent(event, cryptoSessionInfoProvider.isRoomEncrypted(roomId))
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun fetchEditHistory(eventId: String, callback: MatrixCallback<List<Event>>) {
|
override suspend fun fetchEditHistory(eventId: String): List<Event> {
|
||||||
val params = FetchEditHistoryTask.Params(roomId, eventId)
|
return fetchEditHistoryTask.execute(FetchEditHistoryTask.Params(roomId, eventId))
|
||||||
fetchEditHistoryTask
|
|
||||||
.configureWith(params) {
|
|
||||||
this.callback = callback
|
|
||||||
}
|
|
||||||
.executeBy(taskExecutor)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun replyToMessage(eventReplied: TimelineEvent, replyText: CharSequence, autoMarkdown: Boolean): Cancelable? {
|
override fun replyToMessage(eventReplied: TimelineEvent, replyText: CharSequence, autoMarkdown: Boolean): Cancelable? {
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
*/
|
*/
|
||||||
package im.vector.app.features.home.room.detail.timeline.edithistory
|
package im.vector.app.features.home.room.detail.timeline.edithistory
|
||||||
|
|
||||||
|
import androidx.lifecycle.viewModelScope
|
||||||
import com.airbnb.mvrx.Fail
|
import com.airbnb.mvrx.Fail
|
||||||
import com.airbnb.mvrx.FragmentViewModelContext
|
import com.airbnb.mvrx.FragmentViewModelContext
|
||||||
import com.airbnb.mvrx.Loading
|
import com.airbnb.mvrx.Loading
|
||||||
|
@ -28,10 +29,9 @@ import im.vector.app.core.date.VectorDateFormatter
|
||||||
import im.vector.app.core.platform.EmptyAction
|
import im.vector.app.core.platform.EmptyAction
|
||||||
import im.vector.app.core.platform.EmptyViewEvents
|
import im.vector.app.core.platform.EmptyViewEvents
|
||||||
import im.vector.app.core.platform.VectorViewModel
|
import im.vector.app.core.platform.VectorViewModel
|
||||||
import org.matrix.android.sdk.api.MatrixCallback
|
import kotlinx.coroutines.launch
|
||||||
import org.matrix.android.sdk.api.session.Session
|
import org.matrix.android.sdk.api.session.Session
|
||||||
import org.matrix.android.sdk.api.session.crypto.MXCryptoError
|
import org.matrix.android.sdk.api.session.crypto.MXCryptoError
|
||||||
import org.matrix.android.sdk.api.session.events.model.Event
|
|
||||||
import org.matrix.android.sdk.api.session.events.model.isReply
|
import org.matrix.android.sdk.api.session.events.model.isReply
|
||||||
import org.matrix.android.sdk.internal.crypto.algorithms.olm.OlmDecryptionResult
|
import org.matrix.android.sdk.internal.crypto.algorithms.olm.OlmDecryptionResult
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
|
@ -68,14 +68,17 @@ class ViewEditHistoryViewModel @AssistedInject constructor(@Assisted
|
||||||
|
|
||||||
private fun loadHistory() {
|
private fun loadHistory() {
|
||||||
setState { copy(editList = Loading()) }
|
setState { copy(editList = Loading()) }
|
||||||
room.fetchEditHistory(eventId, object : MatrixCallback<List<Event>> {
|
|
||||||
override fun onFailure(failure: Throwable) {
|
viewModelScope.launch {
|
||||||
|
val data = try {
|
||||||
|
room.fetchEditHistory(eventId)
|
||||||
|
} catch (failure: Throwable) {
|
||||||
setState {
|
setState {
|
||||||
copy(editList = Fail(failure))
|
copy(editList = Fail(failure))
|
||||||
}
|
}
|
||||||
|
return@launch
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onSuccess(data: List<Event>) {
|
|
||||||
var originalIsReply = false
|
var originalIsReply = false
|
||||||
|
|
||||||
val events = data.map { event ->
|
val events = data.map { event ->
|
||||||
|
@ -109,7 +112,6 @@ class ViewEditHistoryViewModel @AssistedInject constructor(@Assisted
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun handle(action: EmptyAction) {
|
override fun handle(action: EmptyAction) {
|
||||||
|
|
Loading…
Reference in New Issue