mirror of
https://github.com/vector-im/element-android.git
synced 2024-11-15 01:35:07 +08:00
Merge pull request #4895 from vector-im/feature/bma/empty_state_key
Avoid allowing null String for state_key.
This commit is contained in:
commit
1b24b9d764
1
changelog.d/4895.removal
Normal file
1
changelog.d/4895.removal
Normal 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.
|
@ -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()
|
||||
)
|
||||
}
|
||||
|
@ -550,7 +550,7 @@ class SpaceHierarchyTest : InstrumentedTest {
|
||||
?.setUserPowerLevel(aliceSession.myUserId, Role.Admin.value)
|
||||
?.toContent()
|
||||
|
||||
room.sendStateEvent(EventType.STATE_ROOM_POWER_LEVELS, null, newPowerLevelsContent!!)
|
||||
room.sendStateEvent(EventType.STATE_ROOM_POWER_LEVELS, stateKey = "", newPowerLevelsContent!!)
|
||||
it.countDown()
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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 = ""
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -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,
|
||||
|
@ -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 {
|
||||
|
@ -574,7 +574,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)
|
||||
}
|
||||
}
|
||||
|
||||
@ -641,7 +641,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())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -211,7 +211,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))
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user