mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-11-27 12:00:03 +03:00
Fix try-catch behavior of sendStateEvent actions
Signed-off-by: aqulu <dev@aqu.lu>
This commit is contained in:
parent
40b9f03132
commit
ed822becc6
1 changed files with 29 additions and 23 deletions
|
@ -22,6 +22,7 @@ import com.squareup.inject.assisted.AssistedInject
|
|||
import im.vector.app.R
|
||||
import im.vector.app.core.resources.StringProvider
|
||||
import kotlinx.coroutines.GlobalScope
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.launch
|
||||
import org.matrix.android.sdk.api.query.QueryStringValue
|
||||
import org.matrix.android.sdk.api.session.Session
|
||||
|
@ -312,18 +313,12 @@ class WidgetPostAPIHandler @AssistedInject constructor(@Assisted private val roo
|
|||
|
||||
val params = HashMap<String, Any>()
|
||||
params["status"] = status
|
||||
|
||||
GlobalScope.launch {
|
||||
try {
|
||||
room.sendStateEvent(
|
||||
eventType = EventType.PLUMBING,
|
||||
stateKey = null,
|
||||
body = params
|
||||
)
|
||||
widgetPostAPIMediator.sendSuccess(eventData)
|
||||
} catch (failure: Exception) {
|
||||
widgetPostAPIMediator.sendError(stringProvider.getString(R.string.widget_integration_failed_to_send_request), eventData)
|
||||
}
|
||||
launchWidgetAPIAction(widgetPostAPIMediator, eventData) {
|
||||
room.sendStateEvent(
|
||||
eventType = EventType.PLUMBING,
|
||||
stateKey = null,
|
||||
body = params
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -342,17 +337,13 @@ class WidgetPostAPIHandler @AssistedInject constructor(@Assisted private val roo
|
|||
Timber.d(description)
|
||||
val content = eventData["content"] as JsonDict
|
||||
val stateKey = "_$userId"
|
||||
GlobalScope.launch {
|
||||
try {
|
||||
room.sendStateEvent(
|
||||
eventType = EventType.BOT_OPTIONS,
|
||||
stateKey = stateKey,
|
||||
body = content
|
||||
)
|
||||
widgetPostAPIMediator.sendSuccess(eventData)
|
||||
} catch (failure: Exception) {
|
||||
widgetPostAPIMediator.sendError(stringProvider.getString(R.string.widget_integration_failed_to_send_request), eventData)
|
||||
}
|
||||
|
||||
launchWidgetAPIAction(widgetPostAPIMediator, eventData) {
|
||||
room.sendStateEvent(
|
||||
eventType = EventType.BOT_OPTIONS,
|
||||
stateKey = stateKey,
|
||||
body = content
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -471,4 +462,19 @@ class WidgetPostAPIHandler @AssistedInject constructor(@Assisted private val roo
|
|||
private fun createWidgetAPICallback(widgetPostAPIMediator: WidgetPostAPIMediator, eventData: JsonDict): WidgetAPICallback {
|
||||
return WidgetAPICallback(widgetPostAPIMediator, eventData, stringProvider)
|
||||
}
|
||||
|
||||
private fun launchWidgetAPIAction(widgetPostAPIMediator: WidgetPostAPIMediator, eventData: JsonDict, block: suspend () -> Unit): Job {
|
||||
return GlobalScope.launch {
|
||||
kotlin.runCatching {
|
||||
block()
|
||||
}.fold(
|
||||
onSuccess = {
|
||||
widgetPostAPIMediator.sendSuccess(eventData)
|
||||
},
|
||||
onFailure = {
|
||||
widgetPostAPIMediator.sendError(stringProvider.getString(R.string.widget_integration_failed_to_send_request), eventData)
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue