mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-11-24 18:36:21 +03:00
Observe the spaces invites
This commit is contained in:
parent
c36869cd03
commit
c74cdb9540
3 changed files with 57 additions and 7 deletions
|
@ -25,16 +25,20 @@ import im.vector.app.core.di.hiltMavericksViewModelFactory
|
|||
import im.vector.app.core.platform.EmptyAction
|
||||
import im.vector.app.core.platform.EmptyViewEvents
|
||||
import im.vector.app.core.platform.VectorViewModel
|
||||
import im.vector.app.features.roomprofile.polls.RoomPollsViewModel
|
||||
import im.vector.app.features.roomprofile.polls.RoomPollsViewState
|
||||
import im.vector.app.features.spaces.GetSpacesUseCase
|
||||
import im.vector.app.features.spaces.notification.GetNotificationCountForSpacesUseCase
|
||||
import kotlinx.coroutines.flow.launchIn
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
import org.matrix.android.sdk.api.query.QueryStringValue
|
||||
import org.matrix.android.sdk.api.query.SpaceFilter
|
||||
import org.matrix.android.sdk.api.session.room.model.Membership
|
||||
import org.matrix.android.sdk.api.session.room.spaceSummaryQueryParams
|
||||
|
||||
// TODO add unit tests
|
||||
class NewHomeDetailViewModel @AssistedInject constructor(
|
||||
@Assisted initialState: NewHomeDetailViewState,
|
||||
private val getNotificationCountForSpacesUseCase: GetNotificationCountForSpacesUseCase,
|
||||
private val getSpacesUseCase: GetSpacesUseCase,
|
||||
) : VectorViewModel<NewHomeDetailViewState, EmptyAction, EmptyViewEvents>(initialState) {
|
||||
|
||||
@AssistedFactory
|
||||
|
@ -46,6 +50,7 @@ class NewHomeDetailViewModel @AssistedInject constructor(
|
|||
|
||||
init {
|
||||
observeSpacesNotificationCount()
|
||||
observeSpacesInvite()
|
||||
}
|
||||
|
||||
private fun observeSpacesNotificationCount() {
|
||||
|
@ -54,6 +59,16 @@ class NewHomeDetailViewModel @AssistedInject constructor(
|
|||
.launchIn(viewModelScope)
|
||||
}
|
||||
|
||||
private fun observeSpacesInvite() {
|
||||
val params = spaceSummaryQueryParams {
|
||||
memberships = listOf(Membership.INVITE)
|
||||
displayName = QueryStringValue.IsNotEmpty
|
||||
}
|
||||
getSpacesUseCase.execute(params)
|
||||
.onEach { setState { copy(hasPendingSpaceInvites = it.isNotEmpty()) } }
|
||||
.launchIn(viewModelScope)
|
||||
}
|
||||
|
||||
override fun handle(action: EmptyAction) {
|
||||
// do nothing
|
||||
}
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
* Copyright (c) 2023 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.
|
||||
*/
|
||||
|
||||
package im.vector.app.features.spaces
|
||||
|
||||
import im.vector.app.core.di.ActiveSessionHolder
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.emptyFlow
|
||||
import org.matrix.android.sdk.api.session.room.model.RoomSummary
|
||||
import org.matrix.android.sdk.api.session.space.SpaceSummaryQueryParams
|
||||
import org.matrix.android.sdk.flow.flow
|
||||
import javax.inject.Inject
|
||||
|
||||
// TODO add unit tests
|
||||
class GetSpacesUseCase @Inject constructor(
|
||||
private val activeSessionHolder: ActiveSessionHolder,
|
||||
) {
|
||||
|
||||
fun execute(params: SpaceSummaryQueryParams): Flow<List<RoomSummary>> {
|
||||
val session = activeSessionHolder.getSafeActiveSession()
|
||||
|
||||
return session?.flow()?.liveSpaceSummaries(params) ?: emptyFlow()
|
||||
}
|
||||
}
|
|
@ -29,7 +29,6 @@ import im.vector.app.core.di.hiltMavericksViewModelFactory
|
|||
import im.vector.app.core.platform.VectorViewModel
|
||||
import im.vector.app.features.analytics.AnalyticsTracker
|
||||
import im.vector.app.features.analytics.plan.Interaction
|
||||
import im.vector.app.features.invite.AutoAcceptInvites
|
||||
import im.vector.app.features.session.coroutineScope
|
||||
import im.vector.app.features.settings.VectorPreferences
|
||||
import im.vector.app.features.spaces.notification.GetNotificationCountForSpacesUseCase
|
||||
|
@ -53,16 +52,15 @@ import org.matrix.android.sdk.api.session.space.SpaceOrderUtils
|
|||
import org.matrix.android.sdk.api.session.space.model.SpaceOrderContent
|
||||
import org.matrix.android.sdk.api.session.space.model.TopLevelSpaceComparator
|
||||
import org.matrix.android.sdk.api.util.toMatrixItem
|
||||
import org.matrix.android.sdk.flow.flow
|
||||
|
||||
class SpaceListViewModel @AssistedInject constructor(
|
||||
@Assisted initialState: SpaceListViewState,
|
||||
private val spaceStateHandler: SpaceStateHandler,
|
||||
private val session: Session,
|
||||
private val vectorPreferences: VectorPreferences,
|
||||
private val autoAcceptInvites: AutoAcceptInvites,
|
||||
private val analyticsTracker: AnalyticsTracker,
|
||||
private val getNotificationCountForSpacesUseCase: GetNotificationCountForSpacesUseCase,
|
||||
getNotificationCountForSpacesUseCase: GetNotificationCountForSpacesUseCase,
|
||||
private val getSpacesUseCase: GetSpacesUseCase,
|
||||
) : VectorViewModel<SpaceListViewState, SpaceListAction, SpaceListViewEvents>(initialState) {
|
||||
|
||||
@AssistedFactory
|
||||
|
@ -238,7 +236,7 @@ class SpaceListViewModel @AssistedInject constructor(
|
|||
}
|
||||
|
||||
combine(
|
||||
session.flow().liveSpaceSummaries(params),
|
||||
getSpacesUseCase.execute(params),
|
||||
session.accountDataService()
|
||||
.getLiveRoomAccountDataEvents(setOf(RoomAccountDataTypes.EVENT_TYPE_SPACE_ORDER))
|
||||
.asFlow()
|
||||
|
|
Loading…
Reference in a new issue