mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-11-22 09:25:49 +03:00
Merge pull request #3075 from Dominaezzz/suspend_functions_6
Convert ReadService to suspend functions
This commit is contained in:
commit
8c328fe5ef
4 changed files with 41 additions and 30 deletions
|
@ -17,7 +17,6 @@
|
|||
package org.matrix.android.sdk.api.session.room.read
|
||||
|
||||
import androidx.lifecycle.LiveData
|
||||
import org.matrix.android.sdk.api.MatrixCallback
|
||||
import org.matrix.android.sdk.api.session.room.model.ReadReceipt
|
||||
import org.matrix.android.sdk.api.util.Optional
|
||||
|
||||
|
@ -35,17 +34,17 @@ interface ReadService {
|
|||
/**
|
||||
* Force the read marker to be set on the latest event.
|
||||
*/
|
||||
fun markAsRead(params: MarkAsReadParams = MarkAsReadParams.BOTH, callback: MatrixCallback<Unit>)
|
||||
suspend fun markAsRead(params: MarkAsReadParams = MarkAsReadParams.BOTH)
|
||||
|
||||
/**
|
||||
* Set the read receipt on the event with provided eventId.
|
||||
*/
|
||||
fun setReadReceipt(eventId: String, callback: MatrixCallback<Unit>)
|
||||
suspend fun setReadReceipt(eventId: String)
|
||||
|
||||
/**
|
||||
* Set the read marker on the event with provided eventId.
|
||||
*/
|
||||
fun setReadMarker(fullyReadEventId: String, callback: MatrixCallback<Unit>)
|
||||
suspend fun setReadMarker(fullyReadEventId: String)
|
||||
|
||||
/**
|
||||
* Check if an event is already read, ie. your read receipt is set on a more recent event.
|
||||
|
|
|
@ -22,7 +22,6 @@ import dagger.assisted.Assisted
|
|||
import dagger.assisted.AssistedInject
|
||||
import dagger.assisted.AssistedFactory
|
||||
import com.zhuinden.monarchy.Monarchy
|
||||
import org.matrix.android.sdk.api.MatrixCallback
|
||||
import org.matrix.android.sdk.api.session.room.model.ReadReceipt
|
||||
import org.matrix.android.sdk.api.session.room.read.ReadService
|
||||
import org.matrix.android.sdk.api.util.Optional
|
||||
|
@ -36,7 +35,6 @@ import org.matrix.android.sdk.internal.database.query.where
|
|||
import org.matrix.android.sdk.internal.di.SessionDatabase
|
||||
import org.matrix.android.sdk.internal.di.UserId
|
||||
import org.matrix.android.sdk.internal.task.TaskExecutor
|
||||
import org.matrix.android.sdk.internal.task.configureWith
|
||||
|
||||
internal class DefaultReadService @AssistedInject constructor(
|
||||
@Assisted private val roomId: String,
|
||||
|
@ -52,35 +50,23 @@ internal class DefaultReadService @AssistedInject constructor(
|
|||
fun create(roomId: String): DefaultReadService
|
||||
}
|
||||
|
||||
override fun markAsRead(params: ReadService.MarkAsReadParams, callback: MatrixCallback<Unit>) {
|
||||
override suspend fun markAsRead(params: ReadService.MarkAsReadParams) {
|
||||
val taskParams = SetReadMarkersTask.Params(
|
||||
roomId = roomId,
|
||||
forceReadMarker = params.forceReadMarker(),
|
||||
forceReadReceipt = params.forceReadReceipt()
|
||||
)
|
||||
setReadMarkersTask
|
||||
.configureWith(taskParams) {
|
||||
this.callback = callback
|
||||
}
|
||||
.executeBy(taskExecutor)
|
||||
setReadMarkersTask.execute(taskParams)
|
||||
}
|
||||
|
||||
override fun setReadReceipt(eventId: String, callback: MatrixCallback<Unit>) {
|
||||
override suspend fun setReadReceipt(eventId: String) {
|
||||
val params = SetReadMarkersTask.Params(roomId, fullyReadEventId = null, readReceiptEventId = eventId)
|
||||
setReadMarkersTask
|
||||
.configureWith(params) {
|
||||
this.callback = callback
|
||||
}
|
||||
.executeBy(taskExecutor)
|
||||
setReadMarkersTask.execute(params)
|
||||
}
|
||||
|
||||
override fun setReadMarker(fullyReadEventId: String, callback: MatrixCallback<Unit>) {
|
||||
override suspend fun setReadMarker(fullyReadEventId: String) {
|
||||
val params = SetReadMarkersTask.Params(roomId, fullyReadEventId = fullyReadEventId, readReceiptEventId = null)
|
||||
setReadMarkersTask
|
||||
.configureWith(params) {
|
||||
this.callback = callback
|
||||
}
|
||||
.executeBy(taskExecutor)
|
||||
setReadMarkersTask.execute(params)
|
||||
}
|
||||
|
||||
override fun isEventRead(eventId: String): Boolean {
|
||||
|
|
|
@ -180,7 +180,12 @@ class RoomDetailViewModel @AssistedInject constructor(
|
|||
observePowerLevel()
|
||||
updateShowDialerOptionState()
|
||||
room.getRoomSummaryLive()
|
||||
room.markAsRead(ReadService.MarkAsReadParams.READ_RECEIPT, NoOpMatrixCallback())
|
||||
viewModelScope.launch {
|
||||
try {
|
||||
room.markAsRead(ReadService.MarkAsReadParams.READ_RECEIPT)
|
||||
} catch (_: Exception) {
|
||||
}
|
||||
}
|
||||
// Inform the SDK that the room is displayed
|
||||
session.onRoomDisplayed(initialState.roomId)
|
||||
callManager.addPstnSupportListener(this)
|
||||
|
@ -545,7 +550,12 @@ class RoomDetailViewModel @AssistedInject constructor(
|
|||
private fun stopTrackingUnreadMessages() {
|
||||
if (trackUnreadMessages.getAndSet(false)) {
|
||||
mostRecentDisplayedEvent?.root?.eventId?.also {
|
||||
room.setReadMarker(it, callback = NoOpMatrixCallback())
|
||||
viewModelScope.launch {
|
||||
try {
|
||||
room.setReadMarker(it)
|
||||
} catch (_: Exception) {
|
||||
}
|
||||
}
|
||||
}
|
||||
mostRecentDisplayedEvent = null
|
||||
}
|
||||
|
@ -1239,14 +1249,21 @@ class RoomDetailViewModel @AssistedInject constructor(
|
|||
}
|
||||
}
|
||||
bufferedMostRecentDisplayedEvent.root.eventId?.let { eventId ->
|
||||
room.setReadReceipt(eventId, callback = NoOpMatrixCallback())
|
||||
viewModelScope.launch {
|
||||
room.setReadReceipt(eventId)
|
||||
}
|
||||
}
|
||||
})
|
||||
.disposeOnClear()
|
||||
}
|
||||
|
||||
private fun handleMarkAllAsRead() {
|
||||
room.markAsRead(ReadService.MarkAsReadParams.BOTH, NoOpMatrixCallback())
|
||||
viewModelScope.launch {
|
||||
try {
|
||||
room.markAsRead(ReadService.MarkAsReadParams.BOTH)
|
||||
} catch (_: Exception) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun handleReportContent(action: RoomDetailAction.ReportContent) {
|
||||
|
|
|
@ -23,6 +23,8 @@ import androidx.core.app.RemoteInput
|
|||
import im.vector.app.R
|
||||
import im.vector.app.core.di.ActiveSessionHolder
|
||||
import im.vector.app.core.extensions.vectorComponent
|
||||
import kotlinx.coroutines.GlobalScope
|
||||
import kotlinx.coroutines.launch
|
||||
import org.matrix.android.sdk.api.NoOpMatrixCallback
|
||||
import org.matrix.android.sdk.api.session.Session
|
||||
import org.matrix.android.sdk.api.session.room.Room
|
||||
|
@ -88,8 +90,15 @@ class NotificationBroadcastReceiver : BroadcastReceiver() {
|
|||
|
||||
private fun handleMarkAsRead(roomId: String) {
|
||||
activeSessionHolder.getActiveSession().let { session ->
|
||||
session.getRoom(roomId)
|
||||
?.markAsRead(ReadService.MarkAsReadParams.READ_RECEIPT, NoOpMatrixCallback())
|
||||
val room = session.getRoom(roomId)
|
||||
if (room != null) {
|
||||
GlobalScope.launch {
|
||||
try {
|
||||
room.markAsRead(ReadService.MarkAsReadParams.READ_RECEIPT)
|
||||
} catch (_: Exception) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue