Merge pull request #2622 from vector-im/feature/bma/leave_private

Warn user when he is leaving a not public room (#1460)
This commit is contained in:
Benoit Marty 2021-01-07 15:18:35 +01:00 committed by GitHub
commit 0cf485d873
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 89 additions and 11 deletions

View File

@ -5,7 +5,8 @@ Features ✨:
- Enable url previews for notices (#2562) - Enable url previews for notices (#2562)
Improvements 🙌: 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 🐛: Bugfix 🐛:
- Unspecced msgType field in m.sticker (#2580) - 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 package im.vector.app.features.home.room.list
import android.content.DialogInterface
import android.os.Bundle import android.os.Bundle
import android.os.Parcelable import android.os.Parcelable
import android.view.LayoutInflater import android.view.LayoutInflater
@ -36,6 +37,7 @@ import com.airbnb.mvrx.args
import com.airbnb.mvrx.fragmentViewModel import com.airbnb.mvrx.fragmentViewModel
import com.airbnb.mvrx.withState import com.airbnb.mvrx.withState
import im.vector.app.R import im.vector.app.R
import im.vector.app.core.dialogs.withColoredButton
import im.vector.app.core.epoxy.LayoutManagerStateRestorer import im.vector.app.core.epoxy.LayoutManagerStateRestorer
import im.vector.app.core.extensions.cleanup import im.vector.app.core.extensions.cleanup
import im.vector.app.core.extensions.exhaustive import im.vector.app.core.extensions.exhaustive
@ -246,17 +248,33 @@ class RoomListFragment @Inject constructor(
roomListViewModel.handle(RoomListAction.ToggleTag(quickAction.roomId, RoomTag.ROOM_TAG_LOW_PRIORITY)) roomListViewModel.handle(RoomListAction.ToggleTag(quickAction.roomId, RoomTag.ROOM_TAG_LOW_PRIORITY))
} }
is RoomListQuickActionsSharedAction.Leave -> { is RoomListQuickActionsSharedAction.Leave -> {
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()) AlertDialog.Builder(requireContext())
.setTitle(R.string.room_participants_leave_prompt_title) .setTitle(R.string.room_participants_leave_prompt_title)
.setMessage(R.string.room_participants_leave_prompt_msg) .setMessage(message)
.setPositiveButton(R.string.leave) { _, _ -> .setPositiveButton(R.string.leave) { _, _ ->
roomListViewModel.handle(RoomListAction.LeaveRoom(quickAction.roomId)) roomListViewModel.handle(RoomListAction.LeaveRoom(roomId))
} }
.setNegativeButton(R.string.cancel, null) .setNegativeButton(R.string.cancel, null)
.show() .show()
Unit .apply {
if (!isPublicRoom) {
withColoredButton(DialogInterface.BUTTON_POSITIVE)
}
} }
}.exhaustive
} }
override fun invalidate() = withState(roomListViewModel) { state -> override fun invalidate() = withState(roomListViewModel) { state ->

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

View File

@ -17,6 +17,7 @@
package im.vector.app.features.roomprofile package im.vector.app.features.roomprofile
import android.content.DialogInterface
import android.os.Bundle import android.os.Bundle
import android.os.Parcelable import android.os.Parcelable
import android.view.LayoutInflater import android.view.LayoutInflater
@ -34,6 +35,7 @@ import com.airbnb.mvrx.withState
import im.vector.app.R import im.vector.app.R
import im.vector.app.core.animations.AppBarStateChangeListener import im.vector.app.core.animations.AppBarStateChangeListener
import im.vector.app.core.animations.MatrixItemAppBarStateChangeListener 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.cleanup
import im.vector.app.core.extensions.configureWith import im.vector.app.core.extensions.configureWith
import im.vector.app.core.extensions.copyOnLongClick import im.vector.app.core.extensions.copyOnLongClick
@ -247,14 +249,27 @@ class RoomProfileFragment @Inject constructor(
} }
override fun onLeaveRoomClicked() { 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()) AlertDialog.Builder(requireContext())
.setTitle(R.string.room_participants_leave_prompt_title) .setTitle(R.string.room_participants_leave_prompt_title)
.setMessage(R.string.room_participants_leave_prompt_msg) .setMessage(message)
.setPositiveButton(R.string.leave) { _, _ -> .setPositiveButton(R.string.leave) { _, _ ->
roomProfileViewModel.handle(RoomProfileAction.LeaveRoom) roomProfileViewModel.handle(RoomProfileAction.LeaveRoom)
} }
.setNegativeButton(R.string.cancel, null) .setNegativeButton(R.string.cancel, null)
.show() .show()
.apply {
if (!isPublicRoom) {
withColoredButton(DialogInterface.BUTTON_POSITIVE)
}
}
} }
override fun onRoomIdClicked() { 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.members.roomMemberQueryParams
import org.matrix.android.sdk.api.session.room.model.Membership 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.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.RxRoom
import org.matrix.android.sdk.rx.rx import org.matrix.android.sdk.rx.rx
import org.matrix.android.sdk.rx.unwrap import org.matrix.android.sdk.rx.unwrap
@ -109,6 +110,10 @@ class RoomProfileViewModel @AssistedInject constructor(
}.exhaustive }.exhaustive
} }
fun isPublicRoom(): Boolean {
return room.isPublic()
}
private fun handleEnableEncryption() { private fun handleEnableEncryption() {
postLoading(true) postLoading(true)

View File

@ -491,6 +491,7 @@
<!-- Chat participants --> <!-- Chat participants -->
<string name="room_participants_leave_prompt_title">Leave room</string> <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_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_remove_prompt_msg">Are you sure you want to remove %s from this chat?</string>
<string name="room_participants_create">Create</string> <string name="room_participants_create">Create</string>