Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SDK] Add missing return type in RoomApi.sendStateEvent() #5912

Merged
merged 3 commits into from
May 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/5855.sdk
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Add return type to RoomApi.sendStateEvent() to retrieve the created event id
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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}")
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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}")
}
}
}