mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2025-01-23 07:40:20 +01:00
Fix issue with callback.onSuccess() called multiple times
This commit is contained in:
parent
cedeea13e6
commit
13ddc28d05
@ -35,6 +35,7 @@ import org.matrix.android.sdk.internal.task.TaskExecutor
|
|||||||
import org.matrix.android.sdk.internal.task.configureWith
|
import org.matrix.android.sdk.internal.task.configureWith
|
||||||
import org.matrix.android.sdk.internal.task.launchToCallback
|
import org.matrix.android.sdk.internal.task.launchToCallback
|
||||||
import org.matrix.android.sdk.internal.util.MatrixCoroutineDispatchers
|
import org.matrix.android.sdk.internal.util.MatrixCoroutineDispatchers
|
||||||
|
import org.matrix.android.sdk.internal.util.awaitCallback
|
||||||
|
|
||||||
internal class DefaultStateService @AssistedInject constructor(@Assisted private val roomId: String,
|
internal class DefaultStateService @AssistedInject constructor(@Assisted private val roomId: String,
|
||||||
private val stateEventDataSource: StateEventDataSource,
|
private val stateEventDataSource: StateEventDataSource,
|
||||||
@ -132,18 +133,19 @@ internal class DefaultStateService @AssistedInject constructor(@Assisted private
|
|||||||
override fun updateAvatar(avatarUri: Uri, fileName: String, callback: MatrixCallback<Unit>): Cancelable {
|
override fun updateAvatar(avatarUri: Uri, fileName: String, callback: MatrixCallback<Unit>): Cancelable {
|
||||||
return taskExecutor.executorScope.launchToCallback(coroutineDispatchers.main, callback) {
|
return taskExecutor.executorScope.launchToCallback(coroutineDispatchers.main, callback) {
|
||||||
val response = fileUploader.uploadFromUri(avatarUri, fileName, "image/jpeg")
|
val response = fileUploader.uploadFromUri(avatarUri, fileName, "image/jpeg")
|
||||||
|
awaitCallback<Unit> {
|
||||||
sendStateEvent(
|
sendStateEvent(
|
||||||
eventType = EventType.STATE_ROOM_AVATAR,
|
eventType = EventType.STATE_ROOM_AVATAR,
|
||||||
body = mapOf("url" to response.contentUri),
|
body = mapOf("url" to response.contentUri),
|
||||||
callback = callback,
|
callback = it,
|
||||||
stateKey = null
|
stateKey = null
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun deleteAvatar(callback: MatrixCallback<Unit>): Cancelable {
|
override fun deleteAvatar(callback: MatrixCallback<Unit>): Cancelable {
|
||||||
return taskExecutor.executorScope.launchToCallback(coroutineDispatchers.main, callback) {
|
return sendStateEvent(
|
||||||
sendStateEvent(
|
|
||||||
eventType = EventType.STATE_ROOM_AVATAR,
|
eventType = EventType.STATE_ROOM_AVATAR,
|
||||||
body = emptyMap(),
|
body = emptyMap(),
|
||||||
callback = callback,
|
callback = callback,
|
||||||
@ -151,4 +153,3 @@ internal class DefaultStateService @AssistedInject constructor(@Assisted private
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user