forked from GitHub-Mirror/riotX-android
Remove some work from UI thread
This commit is contained in:
parent
2800d86a57
commit
25b0cd0e4b
@ -17,7 +17,6 @@
|
|||||||
|
|
||||||
package im.vector.matrix.android.internal.crypto
|
package im.vector.matrix.android.internal.crypto
|
||||||
|
|
||||||
import android.os.Handler
|
|
||||||
import im.vector.matrix.android.api.MatrixCallback
|
import im.vector.matrix.android.api.MatrixCallback
|
||||||
import im.vector.matrix.android.api.session.events.model.EventType
|
import im.vector.matrix.android.api.session.events.model.EventType
|
||||||
import im.vector.matrix.android.internal.crypto.model.MXUsersDevicesMap
|
import im.vector.matrix.android.internal.crypto.model.MXUsersDevicesMap
|
||||||
@ -28,9 +27,12 @@ import im.vector.matrix.android.internal.crypto.store.IMXCryptoStore
|
|||||||
import im.vector.matrix.android.internal.crypto.tasks.SendToDeviceTask
|
import im.vector.matrix.android.internal.crypto.tasks.SendToDeviceTask
|
||||||
import im.vector.matrix.android.internal.session.SessionScope
|
import im.vector.matrix.android.internal.session.SessionScope
|
||||||
import im.vector.matrix.android.internal.task.TaskExecutor
|
import im.vector.matrix.android.internal.task.TaskExecutor
|
||||||
|
import im.vector.matrix.android.internal.task.TaskThread
|
||||||
import im.vector.matrix.android.internal.task.configureWith
|
import im.vector.matrix.android.internal.task.configureWith
|
||||||
|
import im.vector.matrix.android.internal.util.createBackgroundHandler
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
import java.util.concurrent.atomic.AtomicBoolean
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
@SessionScope
|
@SessionScope
|
||||||
@ -47,7 +49,7 @@ internal class OutgoingRoomKeyRequestManager @Inject constructor(
|
|||||||
|
|
||||||
// sanity check to ensure that we don't end up with two concurrent runs
|
// sanity check to ensure that we don't end up with two concurrent runs
|
||||||
// of sendOutgoingRoomKeyRequestsTimer
|
// of sendOutgoingRoomKeyRequestsTimer
|
||||||
private var sendOutgoingRoomKeyRequestsRunning: Boolean = false
|
private val sendOutgoingRoomKeyRequestsRunning = AtomicBoolean(false)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when the client is started. Sets background processes running.
|
* Called when the client is started. Sets background processes running.
|
||||||
@ -101,7 +103,9 @@ internal class OutgoingRoomKeyRequestManager @Inject constructor(
|
|||||||
* @param requestBody requestBody
|
* @param requestBody requestBody
|
||||||
*/
|
*/
|
||||||
fun cancelRoomKeyRequest(requestBody: RoomKeyRequestBody) {
|
fun cancelRoomKeyRequest(requestBody: RoomKeyRequestBody) {
|
||||||
cancelRoomKeyRequest(requestBody, false)
|
BACKGROUND_HANDLER.post {
|
||||||
|
cancelRoomKeyRequest(requestBody, false)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -110,7 +114,9 @@ internal class OutgoingRoomKeyRequestManager @Inject constructor(
|
|||||||
* @param requestBody requestBody
|
* @param requestBody requestBody
|
||||||
*/
|
*/
|
||||||
fun resendRoomKeyRequest(requestBody: RoomKeyRequestBody) {
|
fun resendRoomKeyRequest(requestBody: RoomKeyRequestBody) {
|
||||||
cancelRoomKeyRequest(requestBody, true)
|
BACKGROUND_HANDLER.post {
|
||||||
|
cancelRoomKeyRequest(requestBody, true)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -148,16 +154,16 @@ internal class OutgoingRoomKeyRequestManager @Inject constructor(
|
|||||||
* Start the background timer to send queued requests, if the timer isn't already running.
|
* Start the background timer to send queued requests, if the timer isn't already running.
|
||||||
*/
|
*/
|
||||||
private fun startTimer() {
|
private fun startTimer() {
|
||||||
if (sendOutgoingRoomKeyRequestsRunning) {
|
if (sendOutgoingRoomKeyRequestsRunning.get()) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
Handler().postDelayed(Runnable {
|
BACKGROUND_HANDLER.postDelayed(Runnable {
|
||||||
if (sendOutgoingRoomKeyRequestsRunning) {
|
if (sendOutgoingRoomKeyRequestsRunning.get()) {
|
||||||
Timber.v("## startTimer() : RoomKeyRequestSend already in progress!")
|
Timber.v("## startTimer() : RoomKeyRequestSend already in progress!")
|
||||||
return@Runnable
|
return@Runnable
|
||||||
}
|
}
|
||||||
|
|
||||||
sendOutgoingRoomKeyRequestsRunning = true
|
sendOutgoingRoomKeyRequestsRunning.set(true)
|
||||||
sendOutgoingRoomKeyRequests()
|
sendOutgoingRoomKeyRequests()
|
||||||
}, SEND_KEY_REQUESTS_DELAY_MS.toLong())
|
}, SEND_KEY_REQUESTS_DELAY_MS.toLong())
|
||||||
}
|
}
|
||||||
@ -167,7 +173,7 @@ internal class OutgoingRoomKeyRequestManager @Inject constructor(
|
|||||||
// timer will be restarted before the promise resolves).
|
// timer will be restarted before the promise resolves).
|
||||||
private fun sendOutgoingRoomKeyRequests() {
|
private fun sendOutgoingRoomKeyRequests() {
|
||||||
if (!isClientRunning) {
|
if (!isClientRunning) {
|
||||||
sendOutgoingRoomKeyRequestsRunning = false
|
sendOutgoingRoomKeyRequestsRunning.set(false)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -179,7 +185,7 @@ internal class OutgoingRoomKeyRequestManager @Inject constructor(
|
|||||||
|
|
||||||
if (null == outgoingRoomKeyRequest) {
|
if (null == outgoingRoomKeyRequest) {
|
||||||
Timber.e("## sendOutgoingRoomKeyRequests() : No more outgoing room key requests")
|
Timber.e("## sendOutgoingRoomKeyRequests() : No more outgoing room key requests")
|
||||||
sendOutgoingRoomKeyRequestsRunning = false
|
sendOutgoingRoomKeyRequestsRunning.set(false)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -213,7 +219,7 @@ internal class OutgoingRoomKeyRequestManager @Inject constructor(
|
|||||||
cryptoStore.updateOutgoingRoomKeyRequest(request)
|
cryptoStore.updateOutgoingRoomKeyRequest(request)
|
||||||
}
|
}
|
||||||
|
|
||||||
sendOutgoingRoomKeyRequestsRunning = false
|
sendOutgoingRoomKeyRequestsRunning.set(false)
|
||||||
startTimer()
|
startTimer()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -246,7 +252,7 @@ internal class OutgoingRoomKeyRequestManager @Inject constructor(
|
|||||||
sendMessageToDevices(roomKeyShareCancellation, request.recipients, request.cancellationTxnId, object : MatrixCallback<Unit> {
|
sendMessageToDevices(roomKeyShareCancellation, request.recipients, request.cancellationTxnId, object : MatrixCallback<Unit> {
|
||||||
private fun onDone() {
|
private fun onDone() {
|
||||||
cryptoStore.deleteOutgoingRoomKeyRequest(request.requestId)
|
cryptoStore.deleteOutgoingRoomKeyRequest(request.requestId)
|
||||||
sendOutgoingRoomKeyRequestsRunning = false
|
sendOutgoingRoomKeyRequestsRunning.set(false)
|
||||||
startTimer()
|
startTimer()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -288,13 +294,17 @@ internal class OutgoingRoomKeyRequestManager @Inject constructor(
|
|||||||
// TODO Change this two hard coded key to something better
|
// TODO Change this two hard coded key to something better
|
||||||
contentMap.setObject(recipient["userId"], recipient["deviceId"], message)
|
contentMap.setObject(recipient["userId"], recipient["deviceId"], message)
|
||||||
}
|
}
|
||||||
|
|
||||||
sendToDeviceTask.configureWith(SendToDeviceTask.Params(EventType.ROOM_KEY_REQUEST, contentMap, transactionId))
|
sendToDeviceTask.configureWith(SendToDeviceTask.Params(EventType.ROOM_KEY_REQUEST, contentMap, transactionId))
|
||||||
.dispatchTo(callback)
|
.dispatchTo(callback)
|
||||||
|
.executeOn(TaskThread.CALLER)
|
||||||
|
.callbackOn(TaskThread.CALLER)
|
||||||
.executeBy(taskExecutor)
|
.executeBy(taskExecutor)
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private const val SEND_KEY_REQUESTS_DELAY_MS = 500
|
private const val SEND_KEY_REQUESTS_DELAY_MS = 500
|
||||||
|
|
||||||
|
private val BACKGROUND_HANDLER = createBackgroundHandler("OutgoingRoomKeyRequest")
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -63,20 +63,12 @@ class GroupListFragment : VectorBaseFragment(), GroupSummaryController.Callback
|
|||||||
|
|
||||||
private fun renderState(state: GroupListViewState) {
|
private fun renderState(state: GroupListViewState) {
|
||||||
when (state.asyncGroups) {
|
when (state.asyncGroups) {
|
||||||
is Incomplete -> renderLoading()
|
is Incomplete -> stateView.state = StateView.State.Loading
|
||||||
is Success -> renderSuccess(state)
|
is Success -> stateView.state = StateView.State.Content
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private fun renderSuccess(state: GroupListViewState) {
|
|
||||||
stateView.state = StateView.State.Content
|
|
||||||
groupController.setData(state)
|
groupController.setData(state)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun renderLoading() {
|
|
||||||
stateView.state = StateView.State.Loading
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onGroupSelected(groupSummary: GroupSummary) {
|
override fun onGroupSelected(groupSummary: GroupSummary) {
|
||||||
viewModel.accept(GroupListActions.SelectGroup(groupSummary))
|
viewModel.accept(GroupListActions.SelectGroup(groupSummary))
|
||||||
}
|
}
|
||||||
|
@ -168,6 +168,7 @@ class RoomListFragment : VectorBaseFragment(), RoomSummaryController.Listener, O
|
|||||||
is Success -> renderSuccess(state)
|
is Success -> renderSuccess(state)
|
||||||
is Fail -> renderFailure(state.asyncFilteredRooms.error)
|
is Fail -> renderFailure(state.asyncFilteredRooms.error)
|
||||||
}
|
}
|
||||||
|
roomController.setData(state)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun renderSuccess(state: RoomListViewState) {
|
private fun renderSuccess(state: RoomListViewState) {
|
||||||
@ -178,7 +179,6 @@ class RoomListFragment : VectorBaseFragment(), RoomSummaryController.Listener, O
|
|||||||
} else {
|
} else {
|
||||||
stateView.state = StateView.State.Content
|
stateView.state = StateView.State.Content
|
||||||
}
|
}
|
||||||
roomController.setData(state)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun renderEmptyState(allRooms: List<RoomSummary>?) {
|
private fun renderEmptyState(allRooms: List<RoomSummary>?) {
|
||||||
|
Loading…
Reference in New Issue
Block a user