Avoid allowing null String for state_key. Should always be an empty String according to the Matrix specification.

There is no functional change, just a change in the SDK API for clarity regarding the Matrix specs.
This commit is contained in:
Benoit Marty 2022-01-10 17:47:27 +01:00
parent f368ec15d8
commit 7be01ab7ae
10 changed files with 25 additions and 22 deletions

View file

@ -62,7 +62,7 @@ class EncryptionTest : InstrumentedTest {
// Send an encryption Event as a State Event
room.sendStateEvent(
eventType = EventType.STATE_ROOM_ENCRYPTION,
stateKey = null,
stateKey = "",
body = EncryptionEventContent(algorithm = MXCRYPTO_ALGORITHM_MEGOLM).toContent()
)
}

View file

@ -68,8 +68,11 @@ interface StateService {
/**
* Send a state event to the room
* @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)
/**
* Get a state event of the room

View file

@ -130,7 +130,7 @@ internal class DefaultRoom(override val roomId: String,
else -> {
val params = SendStateTask.Params(
roomId = roomId,
stateKey = null,
stateKey = "",
eventType = EventType.STATE_ROOM_ENCRYPTION,
body = mapOf(
"algorithm" to algorithm

View file

@ -68,7 +68,7 @@ internal class DefaultStateService @AssistedInject constructor(@Assisted private
override suspend fun sendStateEvent(
eventType: String,
stateKey: String?,
stateKey: String,
body: JsonDict
) {
val params = SendStateTask.Params(
@ -92,7 +92,7 @@ internal class DefaultStateService @AssistedInject constructor(@Assisted private
sendStateEvent(
eventType = EventType.STATE_ROOM_TOPIC,
body = mapOf("topic" to topic),
stateKey = null
stateKey = ""
)
}
@ -100,7 +100,7 @@ internal class DefaultStateService @AssistedInject constructor(@Assisted private
sendStateEvent(
eventType = EventType.STATE_ROOM_NAME,
body = mapOf("name" to name),
stateKey = null
stateKey = ""
)
}
@ -117,7 +117,7 @@ internal class DefaultStateService @AssistedInject constructor(@Assisted private
// Sort for the cleanup
.sorted()
).toContent(),
stateKey = null
stateKey = ""
)
}
@ -125,7 +125,7 @@ internal class DefaultStateService @AssistedInject constructor(@Assisted private
sendStateEvent(
eventType = EventType.STATE_ROOM_HISTORY_VISIBILITY,
body = mapOf("history_visibility" to readability),
stateKey = null
stateKey = ""
)
}
@ -142,14 +142,14 @@ internal class DefaultStateService @AssistedInject constructor(@Assisted private
sendStateEvent(
eventType = EventType.STATE_ROOM_JOIN_RULES,
body = body,
stateKey = null
stateKey = ""
)
}
if (guestAccess != null) {
sendStateEvent(
eventType = EventType.STATE_ROOM_GUEST_ACCESS,
body = mapOf("guest_access" to guestAccess),
stateKey = null
stateKey = ""
)
}
}
@ -159,7 +159,7 @@ internal class DefaultStateService @AssistedInject constructor(@Assisted private
sendStateEvent(
eventType = EventType.STATE_ROOM_AVATAR,
body = mapOf("url" to response.contentUri),
stateKey = null
stateKey = ""
)
}
@ -167,7 +167,7 @@ internal class DefaultStateService @AssistedInject constructor(@Assisted private
sendStateEvent(
eventType = EventType.STATE_ROOM_AVATAR,
body = emptyMap(),
stateKey = null
stateKey = ""
)
}

View file

@ -26,7 +26,7 @@ import javax.inject.Inject
internal interface SendStateTask : Task<SendStateTask.Params, Unit> {
data class Params(
val roomId: String,
val stateKey: String?,
val stateKey: String,
val eventType: String,
val body: JsonDict
)
@ -39,7 +39,7 @@ internal class DefaultSendStateTask @Inject constructor(
override suspend fun execute(params: SendStateTask.Params) {
return executeRequest(globalErrorReceiver) {
if (params.stateKey == null) {
if (params.stateKey.isEmpty()) {
roomAPI.sendStateEvent(
roomId = params.roomId,
stateEventType = params.eventType,

View file

@ -174,8 +174,8 @@ class RoomDevToolViewModel @AssistedInject constructor(
?: throw IllegalArgumentException(stringProvider.getString(R.string.dev_tools_error_no_content))
room.sendStateEvent(
state.selectedEvent?.type ?: "",
state.selectedEvent?.stateKey,
state.selectedEvent?.type.orEmpty(),
state.selectedEvent?.stateKey.orEmpty(),
json
)
@ -213,7 +213,7 @@ class RoomDevToolViewModel @AssistedInject constructor(
if (isState) {
room.sendStateEvent(
eventType,
state.sendEventDraft.stateKey,
state.sendEventDraft.stateKey.orEmpty(),
json
)
} else {

View file

@ -552,7 +552,7 @@ class MessageComposerViewModel @AssistedInject constructor(
?: return
launchSlashCommandFlowSuspendable {
room.sendStateEvent(EventType.STATE_ROOM_POWER_LEVELS, null, newPowerLevelsContent)
room.sendStateEvent(EventType.STATE_ROOM_POWER_LEVELS, stateKey = "", newPowerLevelsContent)
}
}
@ -619,7 +619,7 @@ class MessageComposerViewModel @AssistedInject constructor(
private fun handleChangeRoomAvatarSlashCommand(changeAvatar: ParsedCommand.ChangeRoomAvatar) {
launchSlashCommandFlowSuspendable {
room.sendStateEvent(EventType.STATE_ROOM_AVATAR, null, RoomAvatarContent(changeAvatar.url).toContent())
room.sendStateEvent(EventType.STATE_ROOM_AVATAR, stateKey = "", RoomAvatarContent(changeAvatar.url).toContent())
}
}

View file

@ -210,7 +210,7 @@ class RoomMemberProfileViewModel @AssistedInject constructor(
viewModelScope.launch {
_viewEvents.post(RoomMemberProfileViewEvents.Loading())
try {
room.sendStateEvent(EventType.STATE_ROOM_POWER_LEVELS, null, newPowerLevelsContent)
room.sendStateEvent(EventType.STATE_ROOM_POWER_LEVELS, stateKey = "", newPowerLevelsContent)
_viewEvents.post(RoomMemberProfileViewEvents.OnSetPowerLevelSuccess)
} catch (failure: Throwable) {
_viewEvents.post(RoomMemberProfileViewEvents.Failure(failure))

View file

@ -124,7 +124,7 @@ class RoomPermissionsViewModel @AssistedInject constructor(@Assisted initialStat
}
)
}
room.sendStateEvent(EventType.STATE_ROOM_POWER_LEVELS, null, newPowerLevelsContent.toContent())
room.sendStateEvent(EventType.STATE_ROOM_POWER_LEVELS, stateKey = "", newPowerLevelsContent.toContent())
setState {
copy(
isLoading = false

View file

@ -319,7 +319,7 @@ class WidgetPostAPIHandler @AssistedInject constructor(@Assisted private val roo
launchWidgetAPIAction(widgetPostAPIMediator, eventData) {
room.sendStateEvent(
eventType = EventType.PLUMBING,
stateKey = null,
stateKey = "",
body = params
)
}