RoomSettingsViewState.kt 3.92 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
/*
 * Copyright 2020 New Vector Ltd
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

17
package im.vector.app.features.roomprofile.settings
18

19
import android.net.Uri
20
21
22
import com.airbnb.mvrx.Async
import com.airbnb.mvrx.MvRxState
import com.airbnb.mvrx.Uninitialized
Valere's avatar
Valere committed
23
24
import im.vector.app.R
import im.vector.app.core.resources.StringProvider
Benoit Marty's avatar
Benoit Marty committed
25
import im.vector.app.features.roomprofile.RoomProfileArgs
26
import org.matrix.android.sdk.api.session.room.model.GuestAccess
Benoît Marty's avatar
Benoît Marty committed
27
import org.matrix.android.sdk.api.session.room.model.RoomHistoryVisibility
28
import org.matrix.android.sdk.api.session.room.model.RoomJoinRules
Benoît Marty's avatar
Benoît Marty committed
29
import org.matrix.android.sdk.api.session.room.model.RoomSummary
30
31
32

data class RoomSettingsViewState(
        val roomId: String,
33
34
        // Default value: https://matrix.org/docs/spec/client_server/r0.6.1#id88
        val currentHistoryVisibility: RoomHistoryVisibility = RoomHistoryVisibility.SHARED,
35
36
        val currentRoomJoinRules: RoomJoinRules = RoomJoinRules.INVITE,
        val currentGuestAccess: GuestAccess? = null,
37
        val roomSummary: Async<RoomSummary> = Uninitialized,
38
        val isLoading: Boolean = false,
39
        val currentRoomAvatarUrl: String? = null,
40
        val avatarAction: AvatarAction = AvatarAction.None,
41
        val newName: String? = null,
42
        val newTopic: String? = null,
43
        val newHistoryVisibility: RoomHistoryVisibility? = null,
44
        val newRoomJoinRules: NewJoinRule = NewJoinRule(),
45
46
        val showSaveAction: Boolean = false,
        val actionPermissions: ActionPermissions = ActionPermissions()
47
48
49
) : MvRxState {

    constructor(args: RoomProfileArgs) : this(roomId = args.roomId)
50
51

    data class ActionPermissions(
52
            val canChangeAvatar: Boolean = false,
53
54
            val canChangeName: Boolean = false,
            val canChangeTopic: Boolean = false,
55
            val canChangeHistoryVisibility: Boolean = false,
Valere's avatar
Valere committed
56
57
            val canChangeJoinRule: Boolean = false,
            val canAddChildren: Boolean = false
58
    )
59
60
61
62
63
64
65

    sealed class AvatarAction {
        object None : AvatarAction()
        object DeleteAvatar : AvatarAction()
        data class UpdateAvatar(val newAvatarUri: Uri,
                                val newAvatarFileName: String) : AvatarAction()
    }
66
67
68
69
70
71
72

    data class NewJoinRule(
            val newJoinRules: RoomJoinRules? = null,
            val newGuestAccess: GuestAccess? = null
    ) {
        fun hasChanged() = newJoinRules != null || newGuestAccess != null
    }
Valere's avatar
Valere committed
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94

    companion object {
        fun RoomSettingsViewState.getJoinRuleWording(stringProvider: StringProvider): String {
            return when (val joinRule = newRoomJoinRules.newJoinRules ?: currentRoomJoinRules) {
                RoomJoinRules.INVITE -> {
                    stringProvider.getString(R.string.room_settings_room_access_private_title)
                }
                RoomJoinRules.PUBLIC -> {
                    stringProvider.getString(R.string.room_settings_room_access_public_title)
                }
                RoomJoinRules.KNOCK -> {
                    stringProvider.getString(R.string.room_settings_room_access_entry_knock)
                }
                RoomJoinRules.RESTRICTED -> {
                    stringProvider.getString(R.string.room_settings_room_access_restricted_title)
                }
                else                     -> {
                    stringProvider.getString(R.string.room_settings_room_access_entry_unknown, joinRule.value)
                }
            }
        }
    }
95
}