mirror of
https://github.com/element-hq/element-android
synced 2024-11-24 18:35:40 +03:00
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:
parent
f368ec15d8
commit
7be01ab7ae
10 changed files with 25 additions and 22 deletions
|
@ -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()
|
||||
)
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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 a new issue