mirror of
https://github.com/element-hq/element-android
synced 2024-11-24 18:35:40 +03:00
Merge pull request #3062 from vector-im/feature/bma/enum
Be more robust when parsing some enums
This commit is contained in:
commit
ebc2017fe0
9 changed files with 62 additions and 50 deletions
|
@ -11,6 +11,7 @@ Improvements 🙌:
|
|||
- Improve message with Emoji only detection (#3017)
|
||||
- Picture preview when replying. Also add the image preview in the message detail bottomsheet (#2916)
|
||||
- Api interceptor to allow app developers peek responses (#2986)
|
||||
- Be more robust when parsing some enums
|
||||
|
||||
Bugfix 🐛:
|
||||
- Fix bad theme change for the MainActivity
|
||||
|
|
|
@ -23,24 +23,13 @@ import com.squareup.moshi.JsonClass
|
|||
* Represents the membership of a user on a room
|
||||
*/
|
||||
@JsonClass(generateAdapter = false)
|
||||
enum class Membership(val value: String) {
|
||||
|
||||
NONE("none"),
|
||||
|
||||
@Json(name = "invite")
|
||||
INVITE("invite"),
|
||||
|
||||
@Json(name = "join")
|
||||
JOIN("join"),
|
||||
|
||||
@Json(name = "knock")
|
||||
KNOCK("knock"),
|
||||
|
||||
@Json(name = "leave")
|
||||
LEAVE("leave"),
|
||||
|
||||
@Json(name = "ban")
|
||||
BAN("ban");
|
||||
enum class Membership {
|
||||
NONE,
|
||||
@Json(name = "invite") INVITE,
|
||||
@Json(name = "join") JOIN,
|
||||
@Json(name = "knock") KNOCK,
|
||||
@Json(name = "leave") LEAVE,
|
||||
@Json(name = "ban") BAN;
|
||||
|
||||
fun isLeft(): Boolean {
|
||||
return this == KNOCK || this == LEAVE || this == BAN
|
||||
|
|
|
@ -18,6 +18,7 @@ package org.matrix.android.sdk.api.session.room.model
|
|||
|
||||
import com.squareup.moshi.Json
|
||||
import com.squareup.moshi.JsonClass
|
||||
import timber.log.Timber
|
||||
|
||||
/**
|
||||
* Class representing the EventType.STATE_ROOM_GUEST_ACCESS state event content
|
||||
|
@ -26,14 +27,20 @@ import com.squareup.moshi.JsonClass
|
|||
@JsonClass(generateAdapter = true)
|
||||
data class RoomGuestAccessContent(
|
||||
// Required. Whether guests can join the room. One of: ["can_join", "forbidden"]
|
||||
@Json(name = "guest_access") val guestAccess: GuestAccess? = null
|
||||
)
|
||||
@Json(name = "guest_access") val _guestAccess: String? = null
|
||||
) {
|
||||
val guestAccess: GuestAccess? = when (_guestAccess) {
|
||||
"can_join" -> GuestAccess.CanJoin
|
||||
"forbidden" -> GuestAccess.Forbidden
|
||||
else -> {
|
||||
Timber.w("Invalid value for GuestAccess: `$_guestAccess`")
|
||||
null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@JsonClass(generateAdapter = false)
|
||||
enum class GuestAccess(val value: String) {
|
||||
@Json(name = "can_join")
|
||||
CanJoin("can_join"),
|
||||
|
||||
@Json(name = "forbidden")
|
||||
Forbidden("forbidden")
|
||||
enum class GuestAccess {
|
||||
@Json(name = "can_join") CanJoin,
|
||||
@Json(name = "forbidden") Forbidden
|
||||
}
|
||||
|
|
|
@ -18,8 +18,20 @@ package org.matrix.android.sdk.api.session.room.model
|
|||
|
||||
import com.squareup.moshi.Json
|
||||
import com.squareup.moshi.JsonClass
|
||||
import timber.log.Timber
|
||||
|
||||
@JsonClass(generateAdapter = true)
|
||||
data class RoomHistoryVisibilityContent(
|
||||
@Json(name = "history_visibility") val historyVisibility: RoomHistoryVisibility? = null
|
||||
)
|
||||
@Json(name = "history_visibility") val _historyVisibility: String? = null
|
||||
) {
|
||||
val historyVisibility: RoomHistoryVisibility? = when (_historyVisibility) {
|
||||
"world_readable" -> RoomHistoryVisibility.WORLD_READABLE
|
||||
"shared" -> RoomHistoryVisibility.SHARED
|
||||
"invited" -> RoomHistoryVisibility.INVITED
|
||||
"joined" -> RoomHistoryVisibility.JOINED
|
||||
else -> {
|
||||
Timber.w("Invalid value for RoomHistoryVisibility: `$_historyVisibility`")
|
||||
null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,17 +24,9 @@ import com.squareup.moshi.JsonClass
|
|||
* Enum for [RoomJoinRulesContent] : https://matrix.org/docs/spec/client_server/r0.4.0#m-room-join-rules
|
||||
*/
|
||||
@JsonClass(generateAdapter = false)
|
||||
enum class RoomJoinRules(val value: String) {
|
||||
|
||||
@Json(name = "public")
|
||||
PUBLIC("public"),
|
||||
|
||||
@Json(name = "invite")
|
||||
INVITE("invite"),
|
||||
|
||||
@Json(name = "knock")
|
||||
KNOCK("knock"),
|
||||
|
||||
@Json(name = "private")
|
||||
PRIVATE("private")
|
||||
enum class RoomJoinRules {
|
||||
@Json(name = "public") PUBLIC,
|
||||
@Json(name = "invite") INVITE,
|
||||
@Json(name = "knock") KNOCK,
|
||||
@Json(name = "private") PRIVATE
|
||||
}
|
||||
|
|
|
@ -19,11 +19,23 @@ package org.matrix.android.sdk.api.session.room.model
|
|||
|
||||
import com.squareup.moshi.Json
|
||||
import com.squareup.moshi.JsonClass
|
||||
import timber.log.Timber
|
||||
|
||||
/**
|
||||
* Class representing the EventType.STATE_ROOM_JOIN_RULES state event content
|
||||
*/
|
||||
@JsonClass(generateAdapter = true)
|
||||
data class RoomJoinRulesContent(
|
||||
@Json(name = "join_rule") val joinRules: RoomJoinRules? = null
|
||||
)
|
||||
@Json(name = "join_rule") val _joinRules: String? = null
|
||||
) {
|
||||
val joinRules: RoomJoinRules? = when (_joinRules) {
|
||||
"public" -> RoomJoinRules.PUBLIC
|
||||
"invite" -> RoomJoinRules.INVITE
|
||||
"knock" -> RoomJoinRules.KNOCK
|
||||
"private" -> RoomJoinRules.PRIVATE
|
||||
else -> {
|
||||
Timber.w("Invalid value for RoomJoinRules: `$_joinRules`")
|
||||
null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@ package org.matrix.android.sdk.internal.session.room
|
|||
|
||||
import org.matrix.android.sdk.api.session.events.model.Content
|
||||
import org.matrix.android.sdk.api.session.events.model.Event
|
||||
import org.matrix.android.sdk.api.session.room.model.Membership
|
||||
import org.matrix.android.sdk.api.session.room.model.roomdirectory.PublicRoomsParams
|
||||
import org.matrix.android.sdk.api.session.room.model.roomdirectory.PublicRoomsResponse
|
||||
import org.matrix.android.sdk.api.util.JsonDict
|
||||
|
@ -100,8 +101,8 @@ internal interface RoomAPI {
|
|||
@GET(NetworkConstants.URI_API_PREFIX_PATH_R0 + "rooms/{roomId}/members")
|
||||
fun getMembers(@Path("roomId") roomId: String,
|
||||
@Query("at") syncToken: String?,
|
||||
@Query("membership") membership: String?,
|
||||
@Query("not_membership") notMembership: String?
|
||||
@Query("membership") membership: Membership?,
|
||||
@Query("not_membership") notMembership: Membership?
|
||||
): Call<RoomMembersResponse>
|
||||
|
||||
/**
|
||||
|
|
|
@ -91,7 +91,7 @@ internal class DefaultLoadRoomMembersTask @Inject constructor(
|
|||
val lastToken = syncTokenStore.getLastToken()
|
||||
val response = try {
|
||||
executeRequest<RoomMembersResponse>(globalErrorReceiver) {
|
||||
apiCall = roomAPI.getMembers(params.roomId, lastToken, null, params.excludeMembership?.value)
|
||||
apiCall = roomAPI.getMembers(params.roomId, lastToken, null, params.excludeMembership)
|
||||
}
|
||||
} catch (throwable: Throwable) {
|
||||
// Revert status to NONE
|
||||
|
|
|
@ -27,10 +27,8 @@ import org.matrix.android.sdk.api.session.events.model.EventType
|
|||
import org.matrix.android.sdk.api.session.events.model.toContent
|
||||
import org.matrix.android.sdk.api.session.room.model.GuestAccess
|
||||
import org.matrix.android.sdk.api.session.room.model.RoomCanonicalAliasContent
|
||||
import org.matrix.android.sdk.api.session.room.model.RoomGuestAccessContent
|
||||
import org.matrix.android.sdk.api.session.room.model.RoomHistoryVisibility
|
||||
import org.matrix.android.sdk.api.session.room.model.RoomJoinRules
|
||||
import org.matrix.android.sdk.api.session.room.model.RoomJoinRulesContent
|
||||
import org.matrix.android.sdk.api.session.room.state.StateService
|
||||
import org.matrix.android.sdk.api.util.JsonDict
|
||||
import org.matrix.android.sdk.api.util.MimeTypes
|
||||
|
@ -131,14 +129,14 @@ internal class DefaultStateService @AssistedInject constructor(@Assisted private
|
|||
if (joinRules != null) {
|
||||
sendStateEvent(
|
||||
eventType = EventType.STATE_ROOM_JOIN_RULES,
|
||||
body = RoomJoinRulesContent(joinRules).toContent(),
|
||||
body = mapOf("join_rule" to joinRules),
|
||||
stateKey = null
|
||||
)
|
||||
}
|
||||
if (guestAccess != null) {
|
||||
sendStateEvent(
|
||||
eventType = EventType.STATE_ROOM_GUEST_ACCESS,
|
||||
body = RoomGuestAccessContent(guestAccess).toContent(),
|
||||
body = mapOf("guest_access" to guestAccess),
|
||||
stateKey = null
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue