Merge pull request #7154 from vector-im/bugfix/fre/start_dm_app_layout
Deferred DMs - Handle the local rooms within the new AppLayout
This commit is contained in:
commit
8624199be3
1
changelog.d/7153.wip
Normal file
1
changelog.d/7153.wip
Normal file
@ -0,0 +1 @@
|
|||||||
|
Create DM room only on first message - Handle the local rooms within the new AppLayout
|
@ -33,6 +33,11 @@ internal fun ReadReceiptEntity.Companion.whereUserId(realm: Realm, userId: Strin
|
|||||||
.equalTo(ReadReceiptEntityFields.USER_ID, userId)
|
.equalTo(ReadReceiptEntityFields.USER_ID, userId)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal fun ReadReceiptEntity.Companion.whereRoomId(realm: Realm, roomId: String): RealmQuery<ReadReceiptEntity> {
|
||||||
|
return realm.where<ReadReceiptEntity>()
|
||||||
|
.equalTo(ReadReceiptEntityFields.ROOM_ID, roomId)
|
||||||
|
}
|
||||||
|
|
||||||
internal fun ReadReceiptEntity.Companion.createUnmanaged(roomId: String, eventId: String, userId: String, originServerTs: Double): ReadReceiptEntity {
|
internal fun ReadReceiptEntity.Companion.createUnmanaged(roomId: String, eventId: String, userId: String, originServerTs: Double): ReadReceiptEntity {
|
||||||
return ReadReceiptEntity().apply {
|
return ReadReceiptEntity().apply {
|
||||||
this.primaryKey = "${roomId}_$userId"
|
this.primaryKey = "${roomId}_$userId"
|
||||||
|
@ -34,6 +34,7 @@ import org.matrix.android.sdk.api.session.room.model.Membership
|
|||||||
import org.matrix.android.sdk.api.session.room.model.RoomMemberSummary
|
import org.matrix.android.sdk.api.session.room.model.RoomMemberSummary
|
||||||
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.create.CreateRoomParams
|
import org.matrix.android.sdk.api.session.room.model.create.CreateRoomParams
|
||||||
|
import org.matrix.android.sdk.api.session.room.model.localecho.RoomLocalEcho
|
||||||
import org.matrix.android.sdk.api.session.room.peeking.PeekResult
|
import org.matrix.android.sdk.api.session.room.peeking.PeekResult
|
||||||
import org.matrix.android.sdk.api.session.room.roomSummaryQueryParams
|
import org.matrix.android.sdk.api.session.room.roomSummaryQueryParams
|
||||||
import org.matrix.android.sdk.api.session.room.summary.RoomAggregateNotificationCount
|
import org.matrix.android.sdk.api.session.room.summary.RoomAggregateNotificationCount
|
||||||
@ -178,7 +179,10 @@ internal class DefaultRoomService @Inject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun onRoomDisplayed(roomId: String) {
|
override suspend fun onRoomDisplayed(roomId: String) {
|
||||||
updateBreadcrumbsTask.execute(UpdateBreadcrumbsTask.Params(roomId))
|
// Do not add local rooms to the recent rooms list as they should not be known by the server
|
||||||
|
if (!RoomLocalEcho.isLocalEchoId(roomId)) {
|
||||||
|
updateBreadcrumbsTask.execute(UpdateBreadcrumbsTask.Params(roomId))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun joinRoom(roomIdOrAlias: String, reason: String?, viaServers: List<String>) {
|
override suspend fun joinRoom(roomIdOrAlias: String, reason: String?, viaServers: List<String>) {
|
||||||
|
@ -22,12 +22,15 @@ import org.matrix.android.sdk.internal.database.model.ChunkEntity
|
|||||||
import org.matrix.android.sdk.internal.database.model.CurrentStateEventEntity
|
import org.matrix.android.sdk.internal.database.model.CurrentStateEventEntity
|
||||||
import org.matrix.android.sdk.internal.database.model.EventEntity
|
import org.matrix.android.sdk.internal.database.model.EventEntity
|
||||||
import org.matrix.android.sdk.internal.database.model.LocalRoomSummaryEntity
|
import org.matrix.android.sdk.internal.database.model.LocalRoomSummaryEntity
|
||||||
|
import org.matrix.android.sdk.internal.database.model.ReadReceiptEntity
|
||||||
|
import org.matrix.android.sdk.internal.database.model.ReadReceiptsSummaryEntity
|
||||||
import org.matrix.android.sdk.internal.database.model.RoomEntity
|
import org.matrix.android.sdk.internal.database.model.RoomEntity
|
||||||
import org.matrix.android.sdk.internal.database.model.RoomMemberSummaryEntity
|
import org.matrix.android.sdk.internal.database.model.RoomMemberSummaryEntity
|
||||||
import org.matrix.android.sdk.internal.database.model.RoomSummaryEntity
|
import org.matrix.android.sdk.internal.database.model.RoomSummaryEntity
|
||||||
import org.matrix.android.sdk.internal.database.model.TimelineEventEntity
|
import org.matrix.android.sdk.internal.database.model.TimelineEventEntity
|
||||||
import org.matrix.android.sdk.internal.database.model.deleteOnCascade
|
import org.matrix.android.sdk.internal.database.model.deleteOnCascade
|
||||||
import org.matrix.android.sdk.internal.database.query.where
|
import org.matrix.android.sdk.internal.database.query.where
|
||||||
|
import org.matrix.android.sdk.internal.database.query.whereInRoom
|
||||||
import org.matrix.android.sdk.internal.database.query.whereRoomId
|
import org.matrix.android.sdk.internal.database.query.whereRoomId
|
||||||
import org.matrix.android.sdk.internal.di.SessionDatabase
|
import org.matrix.android.sdk.internal.di.SessionDatabase
|
||||||
import org.matrix.android.sdk.internal.session.room.delete.DeleteLocalRoomTask.Params
|
import org.matrix.android.sdk.internal.session.room.delete.DeleteLocalRoomTask.Params
|
||||||
@ -50,6 +53,12 @@ internal class DefaultDeleteLocalRoomTask @Inject constructor(
|
|||||||
if (RoomLocalEcho.isLocalEchoId(roomId)) {
|
if (RoomLocalEcho.isLocalEchoId(roomId)) {
|
||||||
monarchy.awaitTransaction { realm ->
|
monarchy.awaitTransaction { realm ->
|
||||||
Timber.i("## DeleteLocalRoomTask - delete local room id $roomId")
|
Timber.i("## DeleteLocalRoomTask - delete local room id $roomId")
|
||||||
|
ReadReceiptsSummaryEntity.whereInRoom(realm, roomId = roomId).findAll()
|
||||||
|
?.also { Timber.i("## DeleteLocalRoomTask - ReadReceiptsSummaryEntity - delete ${it.size} entries") }
|
||||||
|
?.deleteAllFromRealm()
|
||||||
|
ReadReceiptEntity.whereRoomId(realm, roomId = roomId).findAll()
|
||||||
|
?.also { Timber.i("## DeleteLocalRoomTask - ReadReceiptEntity - delete ${it.size} entries") }
|
||||||
|
?.deleteAllFromRealm()
|
||||||
RoomMemberSummaryEntity.where(realm, roomId = roomId).findAll()
|
RoomMemberSummaryEntity.where(realm, roomId = roomId).findAll()
|
||||||
?.also { Timber.i("## DeleteLocalRoomTask - RoomMemberSummaryEntity - delete ${it.size} entries") }
|
?.also { Timber.i("## DeleteLocalRoomTask - RoomMemberSummaryEntity - delete ${it.size} entries") }
|
||||||
?.deleteAllFromRealm()
|
?.deleteAllFromRealm()
|
||||||
|
@ -31,4 +31,5 @@ sealed class RoomListAction : VectorViewModelAction {
|
|||||||
data class LeaveRoom(val roomId: String) : RoomListAction()
|
data class LeaveRoom(val roomId: String) : RoomListAction()
|
||||||
data class JoinSuggestedRoom(val roomId: String, val viaServers: List<String>?) : RoomListAction()
|
data class JoinSuggestedRoom(val roomId: String, val viaServers: List<String>?) : RoomListAction()
|
||||||
data class ShowRoomDetails(val roomId: String, val viaServers: List<String>?) : RoomListAction()
|
data class ShowRoomDetails(val roomId: String, val viaServers: List<String>?) : RoomListAction()
|
||||||
|
object DeleteAllLocalRoom : RoomListAction()
|
||||||
}
|
}
|
||||||
|
@ -149,10 +149,13 @@ class RoomListFragment :
|
|||||||
(it.contentEpoxyController as? RoomSummaryPagedController)?.roomChangeMembershipStates = ms
|
(it.contentEpoxyController as? RoomSummaryPagedController)?.roomChangeMembershipStates = ms
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
roomListViewModel.onEach(RoomListViewState::localRoomIds) {
|
}
|
||||||
// Local rooms should not exist anymore when the room list is shown
|
|
||||||
roomListViewModel.deleteLocalRooms(it)
|
override fun onStart() {
|
||||||
}
|
super.onStart()
|
||||||
|
|
||||||
|
// Local rooms should not exist anymore when the room list is shown
|
||||||
|
roomListViewModel.handle(RoomListAction.DeleteAllLocalRoom)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun refreshCollapseStates() {
|
private fun refreshCollapseStates() {
|
||||||
|
@ -97,7 +97,6 @@ class RoomListViewModel @AssistedInject constructor(
|
|||||||
|
|
||||||
init {
|
init {
|
||||||
observeMembershipChanges()
|
observeMembershipChanges()
|
||||||
observeLocalRooms()
|
|
||||||
|
|
||||||
spaceStateHandler.getSelectedSpaceFlow()
|
spaceStateHandler.getSelectedSpaceFlow()
|
||||||
.distinctUntilChanged()
|
.distinctUntilChanged()
|
||||||
@ -125,16 +124,6 @@ class RoomListViewModel @AssistedInject constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun observeLocalRooms() {
|
|
||||||
session
|
|
||||||
.flow()
|
|
||||||
.liveRoomSummaries(roomSummaryQueryParams {
|
|
||||||
roomId = QueryStringValue.Contains(RoomLocalEcho.PREFIX)
|
|
||||||
})
|
|
||||||
.map { page -> page.map { it.roomId } }
|
|
||||||
.setOnEach { copy(localRoomIds = it) }
|
|
||||||
}
|
|
||||||
|
|
||||||
companion object : MavericksViewModelFactory<RoomListViewModel, RoomListViewState> by hiltMavericksViewModelFactory()
|
companion object : MavericksViewModelFactory<RoomListViewModel, RoomListViewState> by hiltMavericksViewModelFactory()
|
||||||
|
|
||||||
private val roomListSectionBuilder = RoomListSectionBuilder(
|
private val roomListSectionBuilder = RoomListSectionBuilder(
|
||||||
@ -166,6 +155,7 @@ class RoomListViewModel @AssistedInject constructor(
|
|||||||
is RoomListAction.ToggleSection -> handleToggleSection(action.section)
|
is RoomListAction.ToggleSection -> handleToggleSection(action.section)
|
||||||
is RoomListAction.JoinSuggestedRoom -> handleJoinSuggestedRoom(action)
|
is RoomListAction.JoinSuggestedRoom -> handleJoinSuggestedRoom(action)
|
||||||
is RoomListAction.ShowRoomDetails -> handleShowRoomDetails(action)
|
is RoomListAction.ShowRoomDetails -> handleShowRoomDetails(action)
|
||||||
|
RoomListAction.DeleteAllLocalRoom -> handleDeleteLocalRooms()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -173,14 +163,6 @@ class RoomListViewModel @AssistedInject constructor(
|
|||||||
return session.getRoom(roomId)?.stateService()?.isPublic().orFalse()
|
return session.getRoom(roomId)?.stateService()?.isPublic().orFalse()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun deleteLocalRooms(roomsIds: Iterable<String>) {
|
|
||||||
viewModelScope.launch {
|
|
||||||
roomsIds.forEach {
|
|
||||||
session.roomService().deleteLocalRoom(it)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// PRIVATE METHODS *****************************************************************************
|
// PRIVATE METHODS *****************************************************************************
|
||||||
|
|
||||||
private fun handleSelectRoom(action: RoomListAction.SelectRoom) = withState {
|
private fun handleSelectRoom(action: RoomListAction.SelectRoom) = withState {
|
||||||
@ -338,4 +320,16 @@ class RoomListViewModel @AssistedInject constructor(
|
|||||||
_viewEvents.post(value)
|
_viewEvents.post(value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun handleDeleteLocalRooms() {
|
||||||
|
val localRoomIds = session.roomService()
|
||||||
|
.getRoomSummaries(roomSummaryQueryParams { roomId = QueryStringValue.Contains(RoomLocalEcho.PREFIX) })
|
||||||
|
.map { it.roomId }
|
||||||
|
|
||||||
|
viewModelScope.launch {
|
||||||
|
localRoomIds.forEach {
|
||||||
|
session.roomService().deleteLocalRoom(it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -31,7 +31,6 @@ data class RoomListViewState(
|
|||||||
val asyncSuggestedRooms: Async<List<SpaceChildInfo>> = Uninitialized,
|
val asyncSuggestedRooms: Async<List<SpaceChildInfo>> = Uninitialized,
|
||||||
val currentUserName: String? = null,
|
val currentUserName: String? = null,
|
||||||
val asyncSelectedSpace: Async<RoomSummary?> = Uninitialized,
|
val asyncSelectedSpace: Async<RoomSummary?> = Uninitialized,
|
||||||
val localRoomIds: List<String> = emptyList()
|
|
||||||
) : MavericksState {
|
) : MavericksState {
|
||||||
|
|
||||||
constructor(args: RoomListParams) : this(displayMode = args.displayMode)
|
constructor(args: RoomListParams) : this(displayMode = args.displayMode)
|
||||||
|
@ -27,4 +27,5 @@ sealed class HomeRoomListAction : VectorViewModelAction {
|
|||||||
data class ToggleTag(val roomId: String, val tag: String) : HomeRoomListAction()
|
data class ToggleTag(val roomId: String, val tag: String) : HomeRoomListAction()
|
||||||
data class LeaveRoom(val roomId: String) : HomeRoomListAction()
|
data class LeaveRoom(val roomId: String) : HomeRoomListAction()
|
||||||
data class ChangeRoomFilter(val filter: HomeRoomFilter) : HomeRoomListAction()
|
data class ChangeRoomFilter(val filter: HomeRoomFilter) : HomeRoomListAction()
|
||||||
|
object DeleteAllLocalRoom : HomeRoomListAction()
|
||||||
}
|
}
|
||||||
|
@ -83,6 +83,13 @@ class HomeRoomListFragment :
|
|||||||
setupRecyclerView()
|
setupRecyclerView()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onStart() {
|
||||||
|
super.onStart()
|
||||||
|
|
||||||
|
// Local rooms should not exist anymore when the room list is shown
|
||||||
|
roomListViewModel.handle(HomeRoomListAction.DeleteAllLocalRoom)
|
||||||
|
}
|
||||||
|
|
||||||
private fun setupObservers() {
|
private fun setupObservers() {
|
||||||
sharedQuickActionsViewModel = activityViewModelProvider[RoomListQuickActionsSharedActionViewModel::class.java]
|
sharedQuickActionsViewModel = activityViewModelProvider[RoomListQuickActionsSharedActionViewModel::class.java]
|
||||||
sharedQuickActionsViewModel
|
sharedQuickActionsViewModel
|
||||||
|
@ -49,6 +49,7 @@ import kotlinx.coroutines.flow.onEach
|
|||||||
import kotlinx.coroutines.flow.onStart
|
import kotlinx.coroutines.flow.onStart
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import org.matrix.android.sdk.api.extensions.orFalse
|
import org.matrix.android.sdk.api.extensions.orFalse
|
||||||
|
import org.matrix.android.sdk.api.query.QueryStringValue
|
||||||
import org.matrix.android.sdk.api.query.RoomCategoryFilter
|
import org.matrix.android.sdk.api.query.RoomCategoryFilter
|
||||||
import org.matrix.android.sdk.api.query.RoomTagQueryFilter
|
import org.matrix.android.sdk.api.query.RoomTagQueryFilter
|
||||||
import org.matrix.android.sdk.api.query.toActiveSpaceOrNoFilter
|
import org.matrix.android.sdk.api.query.toActiveSpaceOrNoFilter
|
||||||
@ -60,6 +61,7 @@ import org.matrix.android.sdk.api.session.room.RoomSummaryQueryParams
|
|||||||
import org.matrix.android.sdk.api.session.room.UpdatableLivePageResult
|
import org.matrix.android.sdk.api.session.room.UpdatableLivePageResult
|
||||||
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.localecho.RoomLocalEcho
|
||||||
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.roomSummaryQueryParams
|
import org.matrix.android.sdk.api.session.room.roomSummaryQueryParams
|
||||||
import org.matrix.android.sdk.api.session.room.state.isPublic
|
import org.matrix.android.sdk.api.session.room.state.isPublic
|
||||||
@ -329,6 +331,7 @@ class HomeRoomListViewModel @AssistedInject constructor(
|
|||||||
is HomeRoomListAction.ChangeRoomNotificationState -> handleChangeNotificationMode(action)
|
is HomeRoomListAction.ChangeRoomNotificationState -> handleChangeNotificationMode(action)
|
||||||
is HomeRoomListAction.ToggleTag -> handleToggleTag(action)
|
is HomeRoomListAction.ToggleTag -> handleToggleTag(action)
|
||||||
is HomeRoomListAction.ChangeRoomFilter -> handleChangeRoomFilter(action.filter)
|
is HomeRoomListAction.ChangeRoomFilter -> handleChangeRoomFilter(action.filter)
|
||||||
|
HomeRoomListAction.DeleteAllLocalRoom -> handleDeleteLocalRooms()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -399,6 +402,18 @@ class HomeRoomListViewModel @AssistedInject constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun handleDeleteLocalRooms() = withState {
|
||||||
|
val localRoomIds = session.roomService()
|
||||||
|
.getRoomSummaries(roomSummaryQueryParams { roomId = QueryStringValue.Contains(RoomLocalEcho.PREFIX) })
|
||||||
|
.map { it.roomId }
|
||||||
|
|
||||||
|
viewModelScope.launch {
|
||||||
|
localRoomIds.forEach {
|
||||||
|
session.roomService().deleteLocalRoom(it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun String.otherTag(): String? {
|
private fun String.otherTag(): String? {
|
||||||
return when (this) {
|
return when (this) {
|
||||||
RoomTag.ROOM_TAG_FAVOURITE -> RoomTag.ROOM_TAG_LOW_PRIORITY
|
RoomTag.ROOM_TAG_FAVOURITE -> RoomTag.ROOM_TAG_LOW_PRIORITY
|
||||||
|
@ -26,5 +26,5 @@ import org.matrix.android.sdk.api.session.room.model.RoomSummary
|
|||||||
data class HomeRoomListViewState(
|
data class HomeRoomListViewState(
|
||||||
val state: StateView.State = StateView.State.Content,
|
val state: StateView.State = StateView.State.Content,
|
||||||
val headersData: RoomsHeadersData = RoomsHeadersData(),
|
val headersData: RoomsHeadersData = RoomsHeadersData(),
|
||||||
val roomsLivePagedList: LiveData<PagedList<RoomSummary>>? = null
|
val roomsLivePagedList: LiveData<PagedList<RoomSummary>>? = null,
|
||||||
) : MavericksState
|
) : MavericksState
|
||||||
|
Loading…
Reference in New Issue
Block a user