Cleanup some Enums

This commit is contained in:
Benoit Marty 2021-03-26 13:41:10 +01:00
parent 2e23fec82b
commit 297fff1394
5 changed files with 19 additions and 40 deletions

View File

@ -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

View File

@ -40,10 +40,7 @@ data class RoomGuestAccessContent(
}
@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
}

View File

@ -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
}

View File

@ -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>
/**

View File

@ -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