Return the created eventId in methods to send state events

This commit is contained in:
Maxime NATUREL 2022-05-03 15:04:43 +02:00
parent d79a9c5b8b
commit e5bb7ae5cd
5 changed files with 22 additions and 11 deletions

View File

@ -84,8 +84,9 @@ interface StateService {
* @param eventType The type of event to send.
* @param stateKey The state_key for the state to send. Can be an empty string.
* @param body The content object of the event; the fields in this object will vary depending on the type of event
*
*/
suspend fun sendStateEvent(eventType: String, stateKey: String, body: JsonDict)
suspend fun sendStateEvent(eventType: String, stateKey: String, body: JsonDict): String
/**
* Get a state event of the room

View File

@ -194,7 +194,8 @@ internal interface RoomAPI {
@PUT(NetworkConstants.URI_API_PREFIX_PATH_R0 + "rooms/{roomId}/state/{state_event_type}")
suspend fun sendStateEvent(@Path("roomId") roomId: String,
@Path("state_event_type") stateEventType: String,
@Body params: JsonDict)
@Body params: JsonDict
): SendResponse
/**
* Send a generic state event
@ -208,7 +209,8 @@ internal interface RoomAPI {
suspend fun sendStateEvent(@Path("roomId") roomId: String,
@Path("state_event_type") stateEventType: String,
@Path("state_key") stateKey: String,
@Body params: JsonDict)
@Body params: JsonDict
): SendResponse
/**
* Get state events of a room

View File

@ -73,14 +73,14 @@ internal class DefaultStateService @AssistedInject constructor(@Assisted private
eventType: String,
stateKey: String,
body: JsonDict
) {
): String {
val params = SendStateTask.Params(
roomId = roomId,
stateKey = stateKey,
eventType = eventType,
body = body.toSafeJson(eventType)
)
sendStateTask.executeRetry(params, 3)
return sendStateTask.executeRetry(params, 3)
}
private fun JsonDict.toSafeJson(eventType: String): JsonDict {

View File

@ -21,9 +21,10 @@ import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import org.matrix.android.sdk.internal.network.executeRequest
import org.matrix.android.sdk.internal.session.room.RoomAPI
import org.matrix.android.sdk.internal.task.Task
import timber.log.Timber
import javax.inject.Inject
internal interface SendStateTask : Task<SendStateTask.Params, Unit> {
internal interface SendStateTask : Task<SendStateTask.Params, String> {
data class Params(
val roomId: String,
val stateKey: String,
@ -37,9 +38,9 @@ internal class DefaultSendStateTask @Inject constructor(
private val globalErrorReceiver: GlobalErrorReceiver
) : SendStateTask {
override suspend fun execute(params: SendStateTask.Params) {
override suspend fun execute(params: SendStateTask.Params): String {
return executeRequest(globalErrorReceiver) {
if (params.stateKey.isEmpty()) {
val response = if (params.stateKey.isEmpty()) {
roomAPI.sendStateEvent(
roomId = params.roomId,
stateEventType = params.eventType,
@ -53,6 +54,9 @@ internal class DefaultSendStateTask @Inject constructor(
params = params.body
)
}
response.eventId.also {
Timber.d("State event: $it just sent in room ${params.roomId}")
}
}
}
}

View File

@ -29,9 +29,10 @@ import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import org.matrix.android.sdk.internal.network.executeRequest
import org.matrix.android.sdk.internal.session.room.RoomAPI
import org.matrix.android.sdk.internal.task.Task
import timber.log.Timber
import javax.inject.Inject
internal interface CreateWidgetTask : Task<CreateWidgetTask.Params, Unit> {
internal interface CreateWidgetTask : Task<CreateWidgetTask.Params, String> {
data class Params(
val roomId: String,
@ -45,8 +46,8 @@ internal class DefaultCreateWidgetTask @Inject constructor(@SessionDatabase priv
@UserId private val userId: String,
private val globalErrorReceiver: GlobalErrorReceiver) : CreateWidgetTask {
override suspend fun execute(params: CreateWidgetTask.Params) {
executeRequest(globalErrorReceiver) {
override suspend fun execute(params: CreateWidgetTask.Params): String {
val response = executeRequest(globalErrorReceiver) {
roomAPI.sendStateEvent(
roomId = params.roomId,
stateEventType = EventType.STATE_ROOM_WIDGET_LEGACY,
@ -60,5 +61,8 @@ internal class DefaultCreateWidgetTask @Inject constructor(@SessionDatabase priv
.and()
.equalTo(CurrentStateEventEntityFields.ROOT.SENDER, userId)
}
return response.eventId.also {
Timber.d("Widget state event: $it just sent in room ${params.roomId}")
}
}
}