Merge pull request #5912 from vector-im/fix/mna/issue-5855-response-state-event

[SDK] Add missing return type in RoomApi.sendStateEvent()
This commit is contained in:
Maxime NATUREL 2022-05-04 09:25:49 +02:00 committed by GitHub
commit 63119ca2a3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 23 additions and 11 deletions

1
changelog.d/5855.sdk Normal file
View file

@ -0,0 +1 @@
- Add return type to RoomApi.sendStateEvent() to retrieve the created event id

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
* @return the id of the created state 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}")
}
}
}