Warn user when he is leaving a not public room (#1460)

This commit is contained in:
Benoit Marty 2021-01-05 11:46:59 +01:00
parent 78c1a0acf4
commit 3a9b80127f
7 changed files with 89 additions and 11 deletions

View File

@ -5,7 +5,8 @@ Features ✨:
- Enable url previews for notices (#2562)
Improvements 🙌:
- Add System theme option and set as default (#904) (#2387)
- Add System theme option and set as default (#904, #2387)
- Warn user when he is leaving a not public room (#1460)
Bugfix 🐛:
- Unspecced msgType field in m.sticker (#2580)

View File

@ -0,0 +1,33 @@
/*
* Copyright 2020 The Matrix.org Foundation C.I.C.
*
* 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.
*/
package org.matrix.android.sdk.api.session.room.state
import org.matrix.android.sdk.api.query.QueryStringValue
import org.matrix.android.sdk.api.session.events.model.EventType
import org.matrix.android.sdk.api.session.events.model.toModel
import org.matrix.android.sdk.api.session.room.model.RoomJoinRules
import org.matrix.android.sdk.api.session.room.model.RoomJoinRulesContent
/**
* Return true if a room can be joined by anyone (RoomJoinRules.PUBLIC)
*/
fun StateService.isPublic(): Boolean {
return getStateEvent(EventType.STATE_ROOM_JOIN_RULES, QueryStringValue.NoCondition)
?.content
?.toModel<RoomJoinRulesContent>()
?.joinRules == RoomJoinRules.PUBLIC
}

View File

@ -16,6 +16,7 @@
package im.vector.app.features.home.room.list
import android.content.DialogInterface
import android.os.Bundle
import android.os.Parcelable
import android.view.LayoutInflater
@ -36,6 +37,7 @@ import com.airbnb.mvrx.args
import com.airbnb.mvrx.fragmentViewModel
import com.airbnb.mvrx.withState
import im.vector.app.R
import im.vector.app.core.dialogs.withColoredButton
import im.vector.app.core.epoxy.LayoutManagerStateRestorer
import im.vector.app.core.extensions.cleanup
import im.vector.app.core.extensions.exhaustive
@ -246,19 +248,35 @@ class RoomListFragment @Inject constructor(
roomListViewModel.handle(RoomListAction.ToggleTag(quickAction.roomId, RoomTag.ROOM_TAG_LOW_PRIORITY))
}
is RoomListQuickActionsSharedAction.Leave -> {
AlertDialog.Builder(requireContext())
.setTitle(R.string.room_participants_leave_prompt_title)
.setMessage(R.string.room_participants_leave_prompt_msg)
.setPositiveButton(R.string.leave) { _, _ ->
roomListViewModel.handle(RoomListAction.LeaveRoom(quickAction.roomId))
}
.setNegativeButton(R.string.cancel, null)
.show()
Unit
promptLeaveRoom(quickAction.roomId)
}
}.exhaustive
}
private fun promptLeaveRoom(roomId: String) {
val isPublicRoom = roomListViewModel.isPublicRoom(roomId)
val message = buildString {
append(getString(R.string.room_participants_leave_prompt_msg))
if (!isPublicRoom) {
append("\n\n")
append(getString(R.string.room_participants_leave_private_warning))
}
}
AlertDialog.Builder(requireContext())
.setTitle(R.string.room_participants_leave_prompt_title)
.setMessage(message)
.setPositiveButton(R.string.leave) { _, _ ->
roomListViewModel.handle(RoomListAction.LeaveRoom(roomId))
}
.setNegativeButton(R.string.cancel, null)
.show()
.apply {
if (!isPublicRoom) {
withColoredButton(DialogInterface.BUTTON_POSITIVE)
}
}
}
override fun invalidate() = withState(roomListViewModel) { state ->
when (state.asyncFilteredRooms) {
is Incomplete -> renderLoading()

View File

@ -33,6 +33,7 @@ import org.matrix.android.sdk.api.session.Session
import org.matrix.android.sdk.api.session.room.model.Membership
import org.matrix.android.sdk.api.session.room.model.RoomSummary
import org.matrix.android.sdk.api.session.room.model.tag.RoomTag
import org.matrix.android.sdk.api.session.room.state.isPublic
import org.matrix.android.sdk.rx.rx
import timber.log.Timber
import java.lang.Exception
@ -78,6 +79,10 @@ class RoomListViewModel @Inject constructor(initialState: RoomListViewState,
}.exhaustive
}
fun isPublicRoom(roomId: String): Boolean {
return session.getRoom(roomId)?.isPublic().orFalse()
}
// PRIVATE METHODS *****************************************************************************
private fun handleSelectRoom(action: RoomListAction.SelectRoom) = withState {

View File

@ -17,6 +17,7 @@
package im.vector.app.features.roomprofile
import android.content.DialogInterface
import android.os.Bundle
import android.os.Parcelable
import android.view.LayoutInflater
@ -34,6 +35,7 @@ import com.airbnb.mvrx.withState
import im.vector.app.R
import im.vector.app.core.animations.AppBarStateChangeListener
import im.vector.app.core.animations.MatrixItemAppBarStateChangeListener
import im.vector.app.core.dialogs.withColoredButton
import im.vector.app.core.extensions.cleanup
import im.vector.app.core.extensions.configureWith
import im.vector.app.core.extensions.copyOnLongClick
@ -247,14 +249,27 @@ class RoomProfileFragment @Inject constructor(
}
override fun onLeaveRoomClicked() {
val isPublicRoom = roomProfileViewModel.isPublicRoom()
val message = buildString {
append(getString(R.string.room_participants_leave_prompt_msg))
if (!isPublicRoom) {
append("\n\n")
append(getString(R.string.room_participants_leave_private_warning))
}
}
AlertDialog.Builder(requireContext())
.setTitle(R.string.room_participants_leave_prompt_title)
.setMessage(R.string.room_participants_leave_prompt_msg)
.setMessage(message)
.setPositiveButton(R.string.leave) { _, _ ->
roomProfileViewModel.handle(RoomProfileAction.LeaveRoom)
}
.setNegativeButton(R.string.cancel, null)
.show()
.apply {
if (!isPublicRoom) {
withColoredButton(DialogInterface.BUTTON_POSITIVE)
}
}
}
override fun onRoomIdClicked() {

View File

@ -37,6 +37,7 @@ import org.matrix.android.sdk.api.session.events.model.EventType
import org.matrix.android.sdk.api.session.room.members.roomMemberQueryParams
import org.matrix.android.sdk.api.session.room.model.Membership
import org.matrix.android.sdk.api.session.room.powerlevels.PowerLevelsHelper
import org.matrix.android.sdk.api.session.room.state.isPublic
import org.matrix.android.sdk.rx.RxRoom
import org.matrix.android.sdk.rx.rx
import org.matrix.android.sdk.rx.unwrap
@ -109,6 +110,10 @@ class RoomProfileViewModel @AssistedInject constructor(
}.exhaustive
}
fun isPublicRoom(): Boolean {
return room.isPublic()
}
private fun handleEnableEncryption() {
postLoading(true)

View File

@ -491,6 +491,7 @@
<!-- Chat participants -->
<string name="room_participants_leave_prompt_title">Leave room</string>
<string name="room_participants_leave_prompt_msg">Are you sure you want to leave the room?</string>
<string name="room_participants_leave_private_warning">This room is not public. You will not be able to rejoin without an invite.</string>
<string name="room_participants_remove_prompt_msg">Are you sure you want to remove %s from this chat?</string>
<string name="room_participants_create">Create</string>