Return the created eventId in methods to send state events
This commit is contained in:
parent
d79a9c5b8b
commit
e5bb7ae5cd
@ -84,8 +84,9 @@ interface StateService {
|
|||||||
* @param eventType The type of event to send.
|
* @param eventType The type of event to send.
|
||||||
* @param stateKey The state_key for the state to send. Can be an empty string.
|
* @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
|
* @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
|
* Get a state event of the room
|
||||||
|
@ -194,7 +194,8 @@ internal interface RoomAPI {
|
|||||||
@PUT(NetworkConstants.URI_API_PREFIX_PATH_R0 + "rooms/{roomId}/state/{state_event_type}")
|
@PUT(NetworkConstants.URI_API_PREFIX_PATH_R0 + "rooms/{roomId}/state/{state_event_type}")
|
||||||
suspend fun sendStateEvent(@Path("roomId") roomId: String,
|
suspend fun sendStateEvent(@Path("roomId") roomId: String,
|
||||||
@Path("state_event_type") stateEventType: String,
|
@Path("state_event_type") stateEventType: String,
|
||||||
@Body params: JsonDict)
|
@Body params: JsonDict
|
||||||
|
): SendResponse
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send a generic state event
|
* Send a generic state event
|
||||||
@ -208,7 +209,8 @@ internal interface RoomAPI {
|
|||||||
suspend fun sendStateEvent(@Path("roomId") roomId: String,
|
suspend fun sendStateEvent(@Path("roomId") roomId: String,
|
||||||
@Path("state_event_type") stateEventType: String,
|
@Path("state_event_type") stateEventType: String,
|
||||||
@Path("state_key") stateKey: String,
|
@Path("state_key") stateKey: String,
|
||||||
@Body params: JsonDict)
|
@Body params: JsonDict
|
||||||
|
): SendResponse
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get state events of a room
|
* Get state events of a room
|
||||||
|
@ -73,14 +73,14 @@ internal class DefaultStateService @AssistedInject constructor(@Assisted private
|
|||||||
eventType: String,
|
eventType: String,
|
||||||
stateKey: String,
|
stateKey: String,
|
||||||
body: JsonDict
|
body: JsonDict
|
||||||
) {
|
): String {
|
||||||
val params = SendStateTask.Params(
|
val params = SendStateTask.Params(
|
||||||
roomId = roomId,
|
roomId = roomId,
|
||||||
stateKey = stateKey,
|
stateKey = stateKey,
|
||||||
eventType = eventType,
|
eventType = eventType,
|
||||||
body = body.toSafeJson(eventType)
|
body = body.toSafeJson(eventType)
|
||||||
)
|
)
|
||||||
sendStateTask.executeRetry(params, 3)
|
return sendStateTask.executeRetry(params, 3)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun JsonDict.toSafeJson(eventType: String): JsonDict {
|
private fun JsonDict.toSafeJson(eventType: String): JsonDict {
|
||||||
|
@ -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.network.executeRequest
|
||||||
import org.matrix.android.sdk.internal.session.room.RoomAPI
|
import org.matrix.android.sdk.internal.session.room.RoomAPI
|
||||||
import org.matrix.android.sdk.internal.task.Task
|
import org.matrix.android.sdk.internal.task.Task
|
||||||
|
import timber.log.Timber
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
internal interface SendStateTask : Task<SendStateTask.Params, Unit> {
|
internal interface SendStateTask : Task<SendStateTask.Params, String> {
|
||||||
data class Params(
|
data class Params(
|
||||||
val roomId: String,
|
val roomId: String,
|
||||||
val stateKey: String,
|
val stateKey: String,
|
||||||
@ -37,9 +38,9 @@ internal class DefaultSendStateTask @Inject constructor(
|
|||||||
private val globalErrorReceiver: GlobalErrorReceiver
|
private val globalErrorReceiver: GlobalErrorReceiver
|
||||||
) : SendStateTask {
|
) : SendStateTask {
|
||||||
|
|
||||||
override suspend fun execute(params: SendStateTask.Params) {
|
override suspend fun execute(params: SendStateTask.Params): String {
|
||||||
return executeRequest(globalErrorReceiver) {
|
return executeRequest(globalErrorReceiver) {
|
||||||
if (params.stateKey.isEmpty()) {
|
val response = if (params.stateKey.isEmpty()) {
|
||||||
roomAPI.sendStateEvent(
|
roomAPI.sendStateEvent(
|
||||||
roomId = params.roomId,
|
roomId = params.roomId,
|
||||||
stateEventType = params.eventType,
|
stateEventType = params.eventType,
|
||||||
@ -53,6 +54,9 @@ internal class DefaultSendStateTask @Inject constructor(
|
|||||||
params = params.body
|
params = params.body
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
response.eventId.also {
|
||||||
|
Timber.d("State event: $it just sent in room ${params.roomId}")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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.network.executeRequest
|
||||||
import org.matrix.android.sdk.internal.session.room.RoomAPI
|
import org.matrix.android.sdk.internal.session.room.RoomAPI
|
||||||
import org.matrix.android.sdk.internal.task.Task
|
import org.matrix.android.sdk.internal.task.Task
|
||||||
|
import timber.log.Timber
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
internal interface CreateWidgetTask : Task<CreateWidgetTask.Params, Unit> {
|
internal interface CreateWidgetTask : Task<CreateWidgetTask.Params, String> {
|
||||||
|
|
||||||
data class Params(
|
data class Params(
|
||||||
val roomId: String,
|
val roomId: String,
|
||||||
@ -45,8 +46,8 @@ internal class DefaultCreateWidgetTask @Inject constructor(@SessionDatabase priv
|
|||||||
@UserId private val userId: String,
|
@UserId private val userId: String,
|
||||||
private val globalErrorReceiver: GlobalErrorReceiver) : CreateWidgetTask {
|
private val globalErrorReceiver: GlobalErrorReceiver) : CreateWidgetTask {
|
||||||
|
|
||||||
override suspend fun execute(params: CreateWidgetTask.Params) {
|
override suspend fun execute(params: CreateWidgetTask.Params): String {
|
||||||
executeRequest(globalErrorReceiver) {
|
val response = executeRequest(globalErrorReceiver) {
|
||||||
roomAPI.sendStateEvent(
|
roomAPI.sendStateEvent(
|
||||||
roomId = params.roomId,
|
roomId = params.roomId,
|
||||||
stateEventType = EventType.STATE_ROOM_WIDGET_LEGACY,
|
stateEventType = EventType.STATE_ROOM_WIDGET_LEGACY,
|
||||||
@ -60,5 +61,8 @@ internal class DefaultCreateWidgetTask @Inject constructor(@SessionDatabase priv
|
|||||||
.and()
|
.and()
|
||||||
.equalTo(CurrentStateEventEntityFields.ROOT.SENDER, userId)
|
.equalTo(CurrentStateEventEntityFields.ROOT.SENDER, userId)
|
||||||
}
|
}
|
||||||
|
return response.eventId.also {
|
||||||
|
Timber.d("Widget state event: $it just sent in room ${params.roomId}")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user