Merge pull request #3369 from vector-im/feature/bca/spaces_quick_fixes

Feature/bca/spaces quick fixes
This commit is contained in:
Benoit Marty 2021-05-21 14:50:36 +02:00 committed by GitHub
commit ebd28e98bd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 128 additions and 18 deletions

View file

@ -13,6 +13,9 @@ Bugfix 🐛:
- Fix a problem with database migration on nightly builds (#3335)
- Implement a workaround to render <del> and <u> in the timeline (#1817)
- Make sure the SDK can retrieve the secret storage if the system is upgraded (#3304)
- Spaces | Personal spaces add DM - Web Parity (#3271)
- Spaces | Improve 'Leave Space' UX/UI (#3359)
- Don't create private spaces with encryption enabled (#3363)
- #+ button on lower right when looking at an empty space goes to an empty 'Explore rooms' (#3327)
Translations 🗣:

View file

@ -344,10 +344,9 @@ internal class RoomSummaryUpdater @Inject constructor(
if (it != null) addAll(it)
}
}.distinct()
if (flattenRelated.isEmpty()) {
dmRoom.flattenParentIds = null
} else {
dmRoom.flattenParentIds = "|${flattenRelated.joinToString("|")}|"
if (flattenRelated.isNotEmpty()) {
// we keep real m.child/m.parent relations and add the one for common memberships
dmRoom.flattenParentIds += "|${flattenRelated.joinToString("|")}|"
}
// Timber.v("## SPACES: flatten of ${dmRoom.otherMemberIds.joinToString(",")} is ${dmRoom.flattenParentIds}")
}

View file

@ -81,7 +81,6 @@ internal class DefaultSpaceService @Inject constructor(
} else {
this.preset = CreateRoomPreset.PRESET_PRIVATE_CHAT
visibility = RoomDirectoryVisibility.PRIVATE
enableEncryption()
}
})
}

View file

@ -16,6 +16,7 @@
package im.vector.app.features.spaces
import android.content.DialogInterface
import android.os.Bundle
import android.os.Parcelable
import android.view.LayoutInflater
@ -27,8 +28,10 @@ import com.airbnb.mvrx.args
import im.vector.app.R
import im.vector.app.core.di.ActiveSessionHolder
import im.vector.app.core.di.ScreenComponent
import im.vector.app.core.dialogs.withColoredButton
import im.vector.app.core.extensions.setTextOrHide
import im.vector.app.core.platform.VectorBaseBottomSheetDialogFragment
import im.vector.app.core.resources.ColorProvider
import im.vector.app.databinding.BottomSheetSpaceSettingsBinding
import im.vector.app.features.home.AvatarRenderer
import im.vector.app.features.navigation.Navigator
@ -43,9 +46,11 @@ import im.vector.app.features.spaces.manage.SpaceManageActivity
import io.reactivex.android.schedulers.AndroidSchedulers
import kotlinx.coroutines.launch
import kotlinx.parcelize.Parcelize
import me.gujun.android.span.span
import org.matrix.android.sdk.api.extensions.orFalse
import org.matrix.android.sdk.api.session.events.model.EventType
import org.matrix.android.sdk.api.session.room.powerlevels.PowerLevelsHelper
import org.matrix.android.sdk.api.session.room.powerlevels.Role
import org.matrix.android.sdk.api.util.toMatrixItem
import timber.log.Timber
import javax.inject.Inject
@ -55,6 +60,7 @@ data class SpaceBottomSheetSettingsArgs(
val spaceId: String
) : Parcelable
// XXX make proper view model before leaving beta
class SpaceSettingsMenuBottomSheet : VectorBaseBottomSheetDialogFragment<BottomSheetSpaceSettingsBinding>() {
@Inject lateinit var navigator: Navigator
@ -62,6 +68,7 @@ class SpaceSettingsMenuBottomSheet : VectorBaseBottomSheetDialogFragment<BottomS
@Inject lateinit var avatarRenderer: AvatarRenderer
@Inject lateinit var vectorPreferences: VectorPreferences
@Inject lateinit var bugReporter: BugReporter
@Inject lateinit var colorProvider: ColorProvider
private val spaceArgs: SpaceBottomSheetSettingsArgs by args()
@ -71,10 +78,14 @@ class SpaceSettingsMenuBottomSheet : VectorBaseBottomSheetDialogFragment<BottomS
var interactionListener: InteractionListener? = null
override val showExpanded = true
override fun injectWith(injector: ScreenComponent) {
injector.inject(this)
}
var isLastAdmin: Boolean = false
override fun getBinding(inflater: LayoutInflater, container: ViewGroup?): BottomSheetSpaceSettingsBinding {
return BottomSheetSpaceSettingsBinding.inflate(inflater, container, false)
}
@ -108,6 +119,13 @@ class SpaceSettingsMenuBottomSheet : VectorBaseBottomSheetDialogFragment<BottomS
views.invitePeople.isVisible = canInvite || roomSummary?.isPublic.orFalse()
views.addRooms.isVisible = canAddChild
val isAdmin = powerLevelsHelper.getUserRole(session.myUserId) is Role.Admin
val otherAdminCount = roomSummary?.otherMemberIds
?.map { powerLevelsHelper.getUserRole(it) }
?.count { it is Role.Admin }
?: 0
isLastAdmin = isAdmin && otherAdminCount == 0
}.disposeOnDestroyView()
views.spaceBetaTag.setOnClickListener {
@ -138,8 +156,27 @@ class SpaceSettingsMenuBottomSheet : VectorBaseBottomSheetDialogFragment<BottomS
}
views.leaveSpace.views.bottomSheetActionClickableZone.debouncedClicks {
val spaceSummary = activeSessionHolder.getSafeActiveSession()?.getRoomSummary(spaceArgs.spaceId)
?: return@debouncedClicks
val warningMessage: CharSequence? = if (spaceSummary.otherMemberIds.isEmpty()) {
span(getString(R.string.space_leave_prompt_msg_only_you)) {
textColor = colorProvider.getColor(R.color.riotx_destructive_accent)
}
} else if (isLastAdmin) {
span(getString(R.string.space_leave_prompt_msg_as_admin)) {
textColor = colorProvider.getColor(R.color.riotx_destructive_accent)
}
} else if (!spaceSummary.isPublic) {
span(getString(R.string.space_leave_prompt_msg_private)) {
textColor = colorProvider.getColor(R.color.riotx_destructive_accent)
}
} else {
null
}
AlertDialog.Builder(requireContext())
.setMessage(getString(R.string.space_leave_prompt_msg))
.setMessage(warningMessage)
.setTitle(getString(R.string.space_leave_prompt_msg))
.setPositiveButton(R.string.leave) { _, _ ->
session.coroutineScope.launch {
try {
@ -152,6 +189,7 @@ class SpaceSettingsMenuBottomSheet : VectorBaseBottomSheetDialogFragment<BottomS
}
.setNegativeButton(R.string.cancel, null)
.show()
.withColoredButton(DialogInterface.BUTTON_POSITIVE)
}
}

View file

@ -62,6 +62,22 @@ class AddRoomListController @Inject constructor(
var initialLoadOccurred = false
var expanded: Boolean = true
set(value) {
if (value != field) {
field = value
requestForcedModelBuild()
}
}
var disabled: Boolean = false
set(value) {
if (value != field) {
field = value
requestForcedModelBuild()
}
}
fun boundaryChange(boundary: ResultBoundaries) {
val boundaryHasLoadedSomething = boundary.frontLoaded || boundary.zeroItemLoaded
if (initialLoadOccurred != boundaryHasLoadedSomething) {
@ -88,6 +104,10 @@ class AddRoomListController @Inject constructor(
}
override fun addModels(models: List<EpoxyModel<*>>) {
if (disabled) {
super.addModels(emptyList())
return
}
val host = this
val filteredModel = if (ignoreRooms == null) {
models
@ -102,10 +122,13 @@ class AddRoomListController @Inject constructor(
RoomCategoryItem_().apply {
id("header")
title(host.sectionName ?: "")
expanded(true)
expanded(host.expanded)
listener {
host.expanded = !host.expanded
}
}
)
if (subHeaderText != null) {
if (expanded && subHeaderText != null) {
add(
GenericPillItem_().apply {
id("sub_header")
@ -115,11 +138,13 @@ class AddRoomListController @Inject constructor(
)
}
}
super.addModels(filteredModel)
if (!initialLoadOccurred) {
add(
RoomSelectionPlaceHolderItem_().apply { id("loading") }
)
if (expanded) {
super.addModels(filteredModel)
if (!initialLoadOccurred) {
add(
RoomSelectionPlaceHolderItem_().apply { id("loading") }
)
}
}
}
@ -129,7 +154,7 @@ class AddRoomListController @Inject constructor(
return RoomSelectionItem_().apply {
id(item.roomId)
matrixItem(item.toMatrixItem())
avatarRenderer(this@AddRoomListController.avatarRenderer)
avatarRenderer(host.avatarRenderer)
space(item.roomType == RoomType.SPACE)
selected(host.selectedItems[item.roomId] ?: false)
itemClickListener(DebouncedClickListener({

View file

@ -42,6 +42,7 @@ import javax.inject.Inject
class SpaceAddRoomFragment @Inject constructor(
private val spaceEpoxyController: AddRoomListController,
private val roomEpoxyController: AddRoomListController,
private val dmEpoxyController: AddRoomListController,
private val viewModelFactory: SpaceAddRoomsViewModel.Factory
) : VectorBaseFragment<FragmentSpaceAddRoomsBinding>(),
OnBackPressed, AddRoomListController.Listener, SpaceAddRoomsViewModel.Factory {
@ -84,6 +85,7 @@ class SpaceAddRoomFragment @Inject constructor(
viewModel.selectionListLiveData.observe(viewLifecycleOwner) {
spaceEpoxyController.selectedItems = it
roomEpoxyController.selectedItems = it
dmEpoxyController.selectedItems = it
saveNeeded = it.values.any { it }
invalidateOptionsMenu()
}
@ -95,6 +97,7 @@ class SpaceAddRoomFragment @Inject constructor(
viewModel.selectSubscribe(this, SpaceAddRoomsState::ignoreRooms) {
spaceEpoxyController.ignoreRooms = it
roomEpoxyController.ignoreRooms = it
dmEpoxyController.ignoreRooms = it
}.disposeOnDestroyView()
viewModel.selectSubscribe(this, SpaceAddRoomsState::isSaving) {
@ -105,6 +108,10 @@ class SpaceAddRoomFragment @Inject constructor(
}
}.disposeOnDestroyView()
viewModel.selectSubscribe(this, SpaceAddRoomsState::shouldShowDMs) {
dmEpoxyController.disabled = !it
}.disposeOnDestroyView()
views.createNewRoom.debouncedClicks {
sharedViewModel.handle(SpaceManagedSharedAction.CreateRoom)
}
@ -121,11 +128,11 @@ class SpaceAddRoomFragment @Inject constructor(
.setNegativeButton(R.string.cancel, null)
.show()
}
is SpaceAddRoomsViewEvents.SaveFailed -> {
is SpaceAddRoomsViewEvents.SaveFailed -> {
showErrorInSnackbar(it.reason)
invalidateOptionsMenu()
}
SpaceAddRoomsViewEvents.SavedDone -> {
SpaceAddRoomsViewEvents.SavedDone -> {
sharedViewModel.handle(SpaceManagedSharedAction.HandleBack)
}
}
@ -149,6 +156,7 @@ class SpaceAddRoomFragment @Inject constructor(
views.roomList.cleanup()
spaceEpoxyController.listener = null
roomEpoxyController.listener = null
dmEpoxyController.listener = null
super.onDestroyView()
}
@ -181,6 +189,19 @@ class SpaceAddRoomFragment @Inject constructor(
concatAdapter.addAdapter(roomEpoxyController.adapter)
concatAdapter.addAdapter(spaceEpoxyController.adapter)
// This controller can be disabled depending on the space type (public or not)
viewModel.updatableDMLivePageResult.liveBoundaries.observe(viewLifecycleOwner) {
dmEpoxyController.boundaryChange(it)
}
viewModel.updatableDMLivePageResult.livePagedList.observe(viewLifecycleOwner) {
dmEpoxyController.totalSize = it.size
dmEpoxyController.submitList(it)
}
dmEpoxyController.sectionName = getString(R.string.direct_chats_header)
dmEpoxyController.listener = this
concatAdapter.addAdapter(dmEpoxyController.adapter)
views.roomList.adapter = concatAdapter
}

View file

@ -26,7 +26,8 @@ data class SpaceAddRoomsState(
val currentFilter: String = "",
val spaceName: String = "",
val ignoreRooms: List<String> = emptyList(),
val isSaving: Async<List<String>> = Uninitialized
val isSaving: Async<List<String>> = Uninitialized,
val shouldShowDMs : Boolean = false
// val selectionList: Map<String, Boolean> = emptyMap()
) : MvRxState {
constructor(args: SpaceManageArgs) : this(

View file

@ -98,6 +98,26 @@ class SpaceAddRoomsViewModel @AssistedInject constructor(
)
}
val updatableDMLivePageResult: UpdatableLivePageResult by lazy {
session.getFilteredPagedRoomSummariesLive(
roomSummaryQueryParams {
this.memberships = listOf(Membership.JOIN)
this.excludeType = listOf(RoomType.SPACE)
this.includeType = null
this.roomCategoryFilter = RoomCategoryFilter.ONLY_DM
this.activeSpaceFilter = ActiveSpaceFilter.ExcludeSpace(initialState.spaceId)
this.displayName = QueryStringValue.Contains(initialState.currentFilter, QueryStringValue.Case.INSENSITIVE)
},
pagedListConfig = PagedList.Config.Builder()
.setPageSize(10)
.setInitialLoadSizeHint(20)
.setEnablePlaceholders(true)
.setPrefetchDistance(10)
.build(),
sortOrder = RoomSortOrder.NAME
)
}
private val selectionList = mutableMapOf<String, Boolean>()
val selectionListLiveData = MutableLiveData<Map<String, Boolean>>()
@ -106,7 +126,8 @@ class SpaceAddRoomsViewModel @AssistedInject constructor(
setState {
copy(
spaceName = spaceSummary?.displayName ?: "",
ignoreRooms = (spaceSummary?.flattenParentIds ?: emptyList()) + listOf(initialState.spaceId)
ignoreRooms = (spaceSummary?.flattenParentIds ?: emptyList()) + listOf(initialState.spaceId),
shouldShowDMs = spaceSummary?.isPublic == false
)
}
}

View file

@ -3353,6 +3353,9 @@
<string name="space_add_child_title">Add rooms</string>
<string name="leave_space">Leave Space</string>
<string name="space_leave_prompt_msg">Are you sure you want to leave the space?</string>
<string name="space_leave_prompt_msg_only_you">You are the only person here. If you leave, no one will be able to join in the future, including you.</string>
<string name="space_leave_prompt_msg_private">This space is not public. You will not be able to rejoin without an invite.</string>
<string name="space_leave_prompt_msg_as_admin">You are admin of this space, ensure that you have transferred admin right to another member before leaving.</string>
<string name="space_add_existing_rooms">Add existing rooms and space</string>