|
| 1 | +/* |
| 2 | + * Copyright 2021 The Matrix.org Foundation C.I.C. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | +package org.matrix.android.sdk.api.session.room.model |
| 17 | + |
| 18 | +import com.squareup.moshi.Json |
| 19 | +import com.squareup.moshi.JsonClass |
| 20 | + |
| 21 | +/** |
| 22 | + * These are the same fields as those returned by /publicRooms, with a few additions: room_type, membership and is_encrypted. |
| 23 | + */ |
| 24 | +@JsonClass(generateAdapter = true) |
| 25 | +data class RoomStrippedState( |
| 26 | + /** |
| 27 | + * Aliases of the room. May be empty. |
| 28 | + */ |
| 29 | + @Json(name = "aliases") |
| 30 | + val aliases: List<String>? = null, |
| 31 | + |
| 32 | + /** |
| 33 | + * The canonical alias of the room, if any. |
| 34 | + */ |
| 35 | + @Json(name = "canonical_alias") |
| 36 | + val canonicalAlias: String? = null, |
| 37 | + |
| 38 | + /** |
| 39 | + * The name of the room, if any. |
| 40 | + */ |
| 41 | + @Json(name = "name") |
| 42 | + val name: String? = null, |
| 43 | + |
| 44 | + /** |
| 45 | + * Required. The number of members joined to the room. |
| 46 | + */ |
| 47 | + @Json(name = "num_joined_members") |
| 48 | + val numJoinedMembers: Int = 0, |
| 49 | + |
| 50 | + /** |
| 51 | + * Required. The ID of the room. |
| 52 | + */ |
| 53 | + @Json(name = "room_id") |
| 54 | + val roomId: String, |
| 55 | + |
| 56 | + /** |
| 57 | + * The topic of the room, if any. |
| 58 | + */ |
| 59 | + @Json(name = "topic") |
| 60 | + val topic: String? = null, |
| 61 | + |
| 62 | + /** |
| 63 | + * Required. Whether the room may be viewed by guest users without joining. |
| 64 | + */ |
| 65 | + @Json(name = "world_readable") |
| 66 | + val worldReadable: Boolean = false, |
| 67 | + |
| 68 | + /** |
| 69 | + * Required. Whether guest users may join the room and participate in it. If they can, |
| 70 | + * they will be subject to ordinary power level rules like any other user. |
| 71 | + */ |
| 72 | + @Json(name = "guest_can_join") |
| 73 | + val guestCanJoin: Boolean = false, |
| 74 | + |
| 75 | + /** |
| 76 | + * The URL for the room's avatar, if one is set. |
| 77 | + */ |
| 78 | + @Json(name = "avatar_url") |
| 79 | + val avatarUrl: String? = null, |
| 80 | + |
| 81 | + /** |
| 82 | + * Undocumented item |
| 83 | + */ |
| 84 | + @Json(name = "m.federate") |
| 85 | + val isFederated: Boolean = false, |
| 86 | + |
| 87 | + /** |
| 88 | + * Optional. If the room is encrypted. This is already accessible as stripped state. |
| 89 | + */ |
| 90 | + @Json(name = "is_encrypted") |
| 91 | + val isEncrypted: Boolean?, |
| 92 | + |
| 93 | + /** |
| 94 | + * Optional. Type of the room, if any, i.e. m.space |
| 95 | + */ |
| 96 | + @Json(name = "room_type") |
| 97 | + val roomType: String?, |
| 98 | + |
| 99 | + /** |
| 100 | + * The current membership of this user in the room. Usually leave if the room is fetched over federation. |
| 101 | + */ |
| 102 | + @Json(name = "membership") |
| 103 | + val membership: String? |
| 104 | +) { |
| 105 | + /** |
| 106 | + * Return the canonical alias, or the first alias from the list of aliases, or null |
| 107 | + */ |
| 108 | + fun getPrimaryAlias(): String? { |
| 109 | + return canonicalAlias ?: aliases?.firstOrNull() |
| 110 | + } |
| 111 | +} |
0 commit comments