Merge pull request #4895 from vector-im/feature/bma/empty_state_key

Avoid allowing null String for state_key.
This commit is contained in:
Benoit Marty 2022-01-13 12:00:48 +01:00 committed by GitHub
commit 1b24b9d764
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 27 additions and 23 deletions

1
changelog.d/4895.removal Normal file
View File

@ -0,0 +1 @@
`StateService.sendStateEvent()` now takes a non-nullable String for the parameter `stateKey`. If null was used, just now use an empty string.

View File

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

View File

@ -550,7 +550,7 @@ class SpaceHierarchyTest : InstrumentedTest {
?.setUserPowerLevel(aliceSession.myUserId, Role.Admin.value) ?.setUserPowerLevel(aliceSession.myUserId, Role.Admin.value)
?.toContent() ?.toContent()
room.sendStateEvent(EventType.STATE_ROOM_POWER_LEVELS, null, newPowerLevelsContent!!) room.sendStateEvent(EventType.STATE_ROOM_POWER_LEVELS, stateKey = "", newPowerLevelsContent!!)
it.countDown() it.countDown()
} }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -574,7 +574,7 @@ class MessageComposerViewModel @AssistedInject constructor(
?: return ?: return
launchSlashCommandFlowSuspendable { launchSlashCommandFlowSuspendable {
room.sendStateEvent(EventType.STATE_ROOM_POWER_LEVELS, null, newPowerLevelsContent) room.sendStateEvent(EventType.STATE_ROOM_POWER_LEVELS, stateKey = "", newPowerLevelsContent)
} }
} }
@ -641,7 +641,7 @@ class MessageComposerViewModel @AssistedInject constructor(
private fun handleChangeRoomAvatarSlashCommand(changeAvatar: ParsedCommand.ChangeRoomAvatar) { private fun handleChangeRoomAvatarSlashCommand(changeAvatar: ParsedCommand.ChangeRoomAvatar) {
launchSlashCommandFlowSuspendable { 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

@ -211,7 +211,7 @@ class RoomMemberProfileViewModel @AssistedInject constructor(
viewModelScope.launch { viewModelScope.launch {
_viewEvents.post(RoomMemberProfileViewEvents.Loading()) _viewEvents.post(RoomMemberProfileViewEvents.Loading())
try { try {
room.sendStateEvent(EventType.STATE_ROOM_POWER_LEVELS, null, newPowerLevelsContent) room.sendStateEvent(EventType.STATE_ROOM_POWER_LEVELS, stateKey = "", newPowerLevelsContent)
_viewEvents.post(RoomMemberProfileViewEvents.OnSetPowerLevelSuccess) _viewEvents.post(RoomMemberProfileViewEvents.OnSetPowerLevelSuccess)
} catch (failure: Throwable) { } catch (failure: Throwable) {
_viewEvents.post(RoomMemberProfileViewEvents.Failure(failure)) _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 { setState {
copy( copy(
isLoading = false isLoading = false

View File

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