Merge pull request #3531 from vector-im/feature/fga/auto_accept_invite
Feature/fga/auto accept invite
This commit is contained in:
commit
9bbe002988
|
@ -125,6 +125,12 @@ interface RoomService {
|
||||||
*/
|
*/
|
||||||
suspend fun deleteRoomAlias(roomAlias: String)
|
suspend fun deleteRoomAlias(roomAlias: String)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the current local changes membership for the given room.
|
||||||
|
* see [getChangeMembershipsLive] for more details.
|
||||||
|
*/
|
||||||
|
fun getChangeMemberships(roomIdOrAlias: String): ChangeMembershipState
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a live data of all local changes membership that happened since the session has been opened.
|
* Return a live data of all local changes membership that happened since the session has been opened.
|
||||||
* It allows you to track this in your client to known what is currently being processed by the SDK.
|
* It allows you to track this in your client to known what is currently being processed by the SDK.
|
||||||
|
|
|
@ -134,6 +134,10 @@ internal class DefaultRoomService @Inject constructor(
|
||||||
deleteRoomAliasTask.execute(DeleteRoomAliasTask.Params(roomAlias))
|
deleteRoomAliasTask.execute(DeleteRoomAliasTask.Params(roomAlias))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun getChangeMemberships(roomIdOrAlias: String): ChangeMembershipState {
|
||||||
|
return roomChangeMembershipStateDataSource.getState(roomIdOrAlias)
|
||||||
|
}
|
||||||
|
|
||||||
override fun getChangeMembershipsLive(): LiveData<Map<String, ChangeMembershipState>> {
|
override fun getChangeMembershipsLive(): LiveData<Map<String, ChangeMembershipState>> {
|
||||||
return roomChangeMembershipStateDataSource.getLiveStates()
|
return roomChangeMembershipStateDataSource.getLiveStates()
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,7 @@ import androidx.lifecycle.MutableLiveData
|
||||||
import org.matrix.android.sdk.api.session.room.members.ChangeMembershipState
|
import org.matrix.android.sdk.api.session.room.members.ChangeMembershipState
|
||||||
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.internal.session.SessionScope
|
import org.matrix.android.sdk.internal.session.SessionScope
|
||||||
|
import java.util.concurrent.ConcurrentHashMap
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -30,7 +31,7 @@ import javax.inject.Inject
|
||||||
internal class RoomChangeMembershipStateDataSource @Inject constructor() {
|
internal class RoomChangeMembershipStateDataSource @Inject constructor() {
|
||||||
|
|
||||||
private val mutableLiveStates = MutableLiveData<Map<String, ChangeMembershipState>>(emptyMap())
|
private val mutableLiveStates = MutableLiveData<Map<String, ChangeMembershipState>>(emptyMap())
|
||||||
private val states = HashMap<String, ChangeMembershipState>()
|
private val states = ConcurrentHashMap<String, ChangeMembershipState>()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This will update local states to be synced with the server.
|
* This will update local states to be synced with the server.
|
||||||
|
|
|
@ -54,6 +54,10 @@ internal class DefaultJoinRoomTask @Inject constructor(
|
||||||
) : JoinRoomTask {
|
) : JoinRoomTask {
|
||||||
|
|
||||||
override suspend fun execute(params: JoinRoomTask.Params) {
|
override suspend fun execute(params: JoinRoomTask.Params) {
|
||||||
|
val currentState = roomChangeMembershipStateDataSource.getState(params.roomIdOrAlias)
|
||||||
|
if (currentState.isInProgress() || currentState == ChangeMembershipState.Joined) {
|
||||||
|
return
|
||||||
|
}
|
||||||
roomChangeMembershipStateDataSource.updateState(params.roomIdOrAlias, ChangeMembershipState.Joining)
|
roomChangeMembershipStateDataSource.updateState(params.roomIdOrAlias, ChangeMembershipState.Joining)
|
||||||
val joinRoomResponse = try {
|
val joinRoomResponse = try {
|
||||||
executeRequest(globalErrorReceiver) {
|
executeRequest(globalErrorReceiver) {
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Introduces AutoAcceptInvites which can be enabled at compile time.
|
|
@ -49,13 +49,12 @@ fun RoomGroupingMethod.group() = (this as? RoomGroupingMethod.ByLegacyGroup)?.gr
|
||||||
// TODO Keep this class for now, will maybe be used fro Space
|
// TODO Keep this class for now, will maybe be used fro Space
|
||||||
@Singleton
|
@Singleton
|
||||||
class AppStateHandler @Inject constructor(
|
class AppStateHandler @Inject constructor(
|
||||||
sessionDataSource: ActiveSessionDataSource,
|
private val sessionDataSource: ActiveSessionDataSource,
|
||||||
private val uiStateRepository: UiStateRepository,
|
private val uiStateRepository: UiStateRepository,
|
||||||
private val activeSessionHolder: ActiveSessionHolder
|
private val activeSessionHolder: ActiveSessionHolder
|
||||||
) : LifecycleObserver {
|
) : LifecycleObserver {
|
||||||
|
|
||||||
private val compositeDisposable = CompositeDisposable()
|
private val compositeDisposable = CompositeDisposable()
|
||||||
|
|
||||||
private val selectedSpaceDataSource = BehaviorDataSource<Option<RoomGroupingMethod>>(Option.empty())
|
private val selectedSpaceDataSource = BehaviorDataSource<Option<RoomGroupingMethod>>(Option.empty())
|
||||||
|
|
||||||
val selectedRoomGroupingObservable = selectedSpaceDataSource.observe()
|
val selectedRoomGroupingObservable = selectedSpaceDataSource.observe()
|
||||||
|
@ -92,11 +91,11 @@ class AppStateHandler @Inject constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
init {
|
private fun observeActiveSession() {
|
||||||
sessionDataSource.observe()
|
sessionDataSource.observe()
|
||||||
.distinctUntilChanged()
|
.distinctUntilChanged()
|
||||||
.subscribe {
|
.subscribe {
|
||||||
// sessionDataSource could already return a session while acitveSession holder still returns null
|
// sessionDataSource could already return a session while activeSession holder still returns null
|
||||||
it.orNull()?.let { session ->
|
it.orNull()?.let { session ->
|
||||||
if (uiStateRepository.isGroupingMethodSpace(session.sessionId)) {
|
if (uiStateRepository.isGroupingMethodSpace(session.sessionId)) {
|
||||||
setCurrentSpace(uiStateRepository.getSelectedSpace(session.sessionId), session)
|
setCurrentSpace(uiStateRepository.getSelectedSpace(session.sessionId), session)
|
||||||
|
@ -119,6 +118,7 @@ class AppStateHandler @Inject constructor(
|
||||||
|
|
||||||
@OnLifecycleEvent(Lifecycle.Event.ON_RESUME)
|
@OnLifecycleEvent(Lifecycle.Event.ON_RESUME)
|
||||||
fun entersForeground() {
|
fun entersForeground() {
|
||||||
|
observeActiveSession()
|
||||||
}
|
}
|
||||||
|
|
||||||
@OnLifecycleEvent(Lifecycle.Event.ON_PAUSE)
|
@OnLifecycleEvent(Lifecycle.Event.ON_PAUSE)
|
||||||
|
@ -126,7 +126,7 @@ class AppStateHandler @Inject constructor(
|
||||||
compositeDisposable.clear()
|
compositeDisposable.clear()
|
||||||
val session = activeSessionHolder.getSafeActiveSession() ?: return
|
val session = activeSessionHolder.getSafeActiveSession() ?: return
|
||||||
when (val currentMethod = selectedSpaceDataSource.currentValue?.orNull() ?: RoomGroupingMethod.BySpace(null)) {
|
when (val currentMethod = selectedSpaceDataSource.currentValue?.orNull() ?: RoomGroupingMethod.BySpace(null)) {
|
||||||
is RoomGroupingMethod.BySpace -> {
|
is RoomGroupingMethod.BySpace -> {
|
||||||
uiStateRepository.storeGroupingMethod(true, session.sessionId)
|
uiStateRepository.storeGroupingMethod(true, session.sessionId)
|
||||||
uiStateRepository.storeSelectedSpace(currentMethod.spaceSummary?.roomId, session.sessionId)
|
uiStateRepository.storeSelectedSpace(currentMethod.spaceSummary?.roomId, session.sessionId)
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,6 +47,7 @@ import im.vector.app.core.rx.RxConfig
|
||||||
import im.vector.app.features.call.webrtc.WebRtcCallManager
|
import im.vector.app.features.call.webrtc.WebRtcCallManager
|
||||||
import im.vector.app.features.configuration.VectorConfiguration
|
import im.vector.app.features.configuration.VectorConfiguration
|
||||||
import im.vector.app.features.disclaimer.doNotShowDisclaimerDialog
|
import im.vector.app.features.disclaimer.doNotShowDisclaimerDialog
|
||||||
|
import im.vector.app.features.invite.InvitesAcceptor
|
||||||
import im.vector.app.features.lifecycle.VectorActivityLifecycleCallbacks
|
import im.vector.app.features.lifecycle.VectorActivityLifecycleCallbacks
|
||||||
import im.vector.app.features.notifications.NotificationDrawerManager
|
import im.vector.app.features.notifications.NotificationDrawerManager
|
||||||
import im.vector.app.features.notifications.NotificationUtils
|
import im.vector.app.features.notifications.NotificationUtils
|
||||||
|
@ -95,6 +96,7 @@ class VectorApplication :
|
||||||
@Inject lateinit var popupAlertManager: PopupAlertManager
|
@Inject lateinit var popupAlertManager: PopupAlertManager
|
||||||
@Inject lateinit var pinLocker: PinLocker
|
@Inject lateinit var pinLocker: PinLocker
|
||||||
@Inject lateinit var callManager: WebRtcCallManager
|
@Inject lateinit var callManager: WebRtcCallManager
|
||||||
|
@Inject lateinit var invitesAcceptor: InvitesAcceptor
|
||||||
|
|
||||||
lateinit var vectorComponent: VectorComponent
|
lateinit var vectorComponent: VectorComponent
|
||||||
|
|
||||||
|
@ -116,6 +118,7 @@ class VectorApplication :
|
||||||
appContext = this
|
appContext = this
|
||||||
vectorComponent = DaggerVectorComponent.factory().create(this)
|
vectorComponent = DaggerVectorComponent.factory().create(this)
|
||||||
vectorComponent.inject(this)
|
vectorComponent.inject(this)
|
||||||
|
invitesAcceptor.initialize()
|
||||||
vectorUncaughtExceptionHandler.activate(this)
|
vectorUncaughtExceptionHandler.activate(this)
|
||||||
rxConfig.setupRxPlugin()
|
rxConfig.setupRxPlugin()
|
||||||
|
|
||||||
|
|
|
@ -50,6 +50,7 @@ import im.vector.app.features.home.room.detail.widget.RoomWidgetsBottomSheet
|
||||||
import im.vector.app.features.home.room.filtered.FilteredRoomsActivity
|
import im.vector.app.features.home.room.filtered.FilteredRoomsActivity
|
||||||
import im.vector.app.features.home.room.list.RoomListModule
|
import im.vector.app.features.home.room.list.RoomListModule
|
||||||
import im.vector.app.features.home.room.list.actions.RoomListQuickActionsBottomSheet
|
import im.vector.app.features.home.room.list.actions.RoomListQuickActionsBottomSheet
|
||||||
|
import im.vector.app.features.invite.AutoAcceptInvites
|
||||||
import im.vector.app.features.invite.InviteUsersToRoomActivity
|
import im.vector.app.features.invite.InviteUsersToRoomActivity
|
||||||
import im.vector.app.features.invite.VectorInviteView
|
import im.vector.app.features.invite.VectorInviteView
|
||||||
import im.vector.app.features.link.LinkHandlerActivity
|
import im.vector.app.features.link.LinkHandlerActivity
|
||||||
|
@ -122,6 +123,7 @@ interface ScreenComponent {
|
||||||
fun errorFormatter(): ErrorFormatter
|
fun errorFormatter(): ErrorFormatter
|
||||||
fun uiStateRepository(): UiStateRepository
|
fun uiStateRepository(): UiStateRepository
|
||||||
fun unrecognizedCertificateDialog(): UnrecognizedCertificateDialog
|
fun unrecognizedCertificateDialog(): UnrecognizedCertificateDialog
|
||||||
|
fun autoAcceptInvites(): AutoAcceptInvites
|
||||||
|
|
||||||
/* ==========================================================================================
|
/* ==========================================================================================
|
||||||
* Activities
|
* Activities
|
||||||
|
|
|
@ -42,6 +42,7 @@ import im.vector.app.features.home.room.detail.timeline.helper.MatrixItemColorPr
|
||||||
import im.vector.app.features.home.room.detail.timeline.helper.RoomSummariesHolder
|
import im.vector.app.features.home.room.detail.timeline.helper.RoomSummariesHolder
|
||||||
import im.vector.app.features.html.EventHtmlRenderer
|
import im.vector.app.features.html.EventHtmlRenderer
|
||||||
import im.vector.app.features.html.VectorHtmlCompressor
|
import im.vector.app.features.html.VectorHtmlCompressor
|
||||||
|
import im.vector.app.features.invite.AutoAcceptInvites
|
||||||
import im.vector.app.features.login.ReAuthHelper
|
import im.vector.app.features.login.ReAuthHelper
|
||||||
import im.vector.app.features.navigation.Navigator
|
import im.vector.app.features.navigation.Navigator
|
||||||
import im.vector.app.features.notifications.NotifiableEventResolver
|
import im.vector.app.features.notifications.NotifiableEventResolver
|
||||||
|
@ -160,6 +161,8 @@ interface VectorComponent {
|
||||||
|
|
||||||
fun pinLocker(): PinLocker
|
fun pinLocker(): PinLocker
|
||||||
|
|
||||||
|
fun autoAcceptInvites(): AutoAcceptInvites
|
||||||
|
|
||||||
fun webRtcCallManager(): WebRtcCallManager
|
fun webRtcCallManager(): WebRtcCallManager
|
||||||
|
|
||||||
fun roomSummaryHolder(): RoomSummariesHolder
|
fun roomSummaryHolder(): RoomSummariesHolder
|
||||||
|
|
|
@ -25,6 +25,8 @@ import dagger.Module
|
||||||
import dagger.Provides
|
import dagger.Provides
|
||||||
import im.vector.app.core.error.DefaultErrorFormatter
|
import im.vector.app.core.error.DefaultErrorFormatter
|
||||||
import im.vector.app.core.error.ErrorFormatter
|
import im.vector.app.core.error.ErrorFormatter
|
||||||
|
import im.vector.app.features.invite.AutoAcceptInvites
|
||||||
|
import im.vector.app.features.invite.CompileTimeAutoAcceptInvites
|
||||||
import im.vector.app.features.navigation.DefaultNavigator
|
import im.vector.app.features.navigation.DefaultNavigator
|
||||||
import im.vector.app.features.navigation.Navigator
|
import im.vector.app.features.navigation.Navigator
|
||||||
import im.vector.app.features.pin.PinCodeStore
|
import im.vector.app.features.pin.PinCodeStore
|
||||||
|
@ -105,4 +107,7 @@ abstract class VectorModule {
|
||||||
|
|
||||||
@Binds
|
@Binds
|
||||||
abstract fun bindPinCodeStore(store: SharedPrefPinCodeStore): PinCodeStore
|
abstract fun bindPinCodeStore(store: SharedPrefPinCodeStore): PinCodeStore
|
||||||
|
|
||||||
|
@Binds
|
||||||
|
abstract fun bindAutoAcceptInvites(autoAcceptInvites: CompileTimeAutoAcceptInvites): AutoAcceptInvites
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,10 +67,6 @@ class CallUserMapper(private val session: Session, private val protocolsChecker:
|
||||||
// will make sure we know where how to map calls and also allow us know not to display
|
// will make sure we know where how to map calls and also allow us know not to display
|
||||||
// it in the future.
|
// it in the future.
|
||||||
invitedRoom.markVirtual(nativeRoomId)
|
invitedRoom.markVirtual(nativeRoomId)
|
||||||
// also auto-join the virtual room if we have a matching native room
|
|
||||||
// (possibly we should only join if we've also joined the native room, then we'd also have
|
|
||||||
// to make sure we joined virtual rooms on joining a native one)
|
|
||||||
session.joinRoom(invitedRoomId)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,6 +31,8 @@ import im.vector.app.features.call.dialpad.DialPadLookup
|
||||||
import im.vector.app.features.call.lookup.CallProtocolsChecker
|
import im.vector.app.features.call.lookup.CallProtocolsChecker
|
||||||
import im.vector.app.features.call.webrtc.WebRtcCallManager
|
import im.vector.app.features.call.webrtc.WebRtcCallManager
|
||||||
import im.vector.app.features.createdirect.DirectRoomHelper
|
import im.vector.app.features.createdirect.DirectRoomHelper
|
||||||
|
import im.vector.app.features.invite.AutoAcceptInvites
|
||||||
|
import im.vector.app.features.invite.showInvites
|
||||||
import im.vector.app.features.ui.UiStateRepository
|
import im.vector.app.features.ui.UiStateRepository
|
||||||
import io.reactivex.schedulers.Schedulers
|
import io.reactivex.schedulers.Schedulers
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
@ -56,7 +58,8 @@ class HomeDetailViewModel @AssistedInject constructor(@Assisted initialState: Ho
|
||||||
private val uiStateRepository: UiStateRepository,
|
private val uiStateRepository: UiStateRepository,
|
||||||
private val callManager: WebRtcCallManager,
|
private val callManager: WebRtcCallManager,
|
||||||
private val directRoomHelper: DirectRoomHelper,
|
private val directRoomHelper: DirectRoomHelper,
|
||||||
private val appStateHandler: AppStateHandler)
|
private val appStateHandler: AppStateHandler,
|
||||||
|
private val autoAcceptInvites: AutoAcceptInvites)
|
||||||
: VectorViewModel<HomeDetailViewState, HomeDetailAction, HomeDetailViewEvents>(initialState),
|
: VectorViewModel<HomeDetailViewState, HomeDetailAction, HomeDetailViewEvents>(initialState),
|
||||||
CallProtocolsChecker.Listener {
|
CallProtocolsChecker.Listener {
|
||||||
|
|
||||||
|
@ -204,21 +207,25 @@ class HomeDetailViewModel @AssistedInject constructor(@Assisted initialState: Ho
|
||||||
}
|
}
|
||||||
is RoomGroupingMethod.BySpace -> {
|
is RoomGroupingMethod.BySpace -> {
|
||||||
val activeSpaceRoomId = groupingMethod.spaceSummary?.roomId
|
val activeSpaceRoomId = groupingMethod.spaceSummary?.roomId
|
||||||
val dmInvites = session.getRoomSummaries(
|
var dmInvites = 0
|
||||||
roomSummaryQueryParams {
|
var roomsInvite = 0
|
||||||
memberships = listOf(Membership.INVITE)
|
if (autoAcceptInvites.showInvites()) {
|
||||||
roomCategoryFilter = RoomCategoryFilter.ONLY_DM
|
dmInvites = session.getRoomSummaries(
|
||||||
activeSpaceFilter = activeSpaceRoomId?.let { ActiveSpaceFilter.ActiveSpace(it) } ?: ActiveSpaceFilter.None
|
roomSummaryQueryParams {
|
||||||
}
|
memberships = listOf(Membership.INVITE)
|
||||||
).size
|
roomCategoryFilter = RoomCategoryFilter.ONLY_DM
|
||||||
|
activeSpaceFilter = activeSpaceRoomId?.let { ActiveSpaceFilter.ActiveSpace(it) } ?: ActiveSpaceFilter.None
|
||||||
|
}
|
||||||
|
).size
|
||||||
|
|
||||||
val roomsInvite = session.getRoomSummaries(
|
roomsInvite = session.getRoomSummaries(
|
||||||
roomSummaryQueryParams {
|
roomSummaryQueryParams {
|
||||||
memberships = listOf(Membership.INVITE)
|
memberships = listOf(Membership.INVITE)
|
||||||
roomCategoryFilter = RoomCategoryFilter.ONLY_ROOMS
|
roomCategoryFilter = RoomCategoryFilter.ONLY_ROOMS
|
||||||
activeSpaceFilter = ActiveSpaceFilter.ActiveSpace(groupingMethod.spaceSummary?.roomId)
|
activeSpaceFilter = ActiveSpaceFilter.ActiveSpace(groupingMethod.spaceSummary?.roomId)
|
||||||
}
|
}
|
||||||
).size
|
).size
|
||||||
|
}
|
||||||
|
|
||||||
val dmRooms = session.getNotificationCountForRooms(
|
val dmRooms = session.getNotificationCountForRooms(
|
||||||
roomSummaryQueryParams {
|
roomSummaryQueryParams {
|
||||||
|
|
|
@ -29,6 +29,7 @@ import im.vector.app.RoomGroupingMethod
|
||||||
import im.vector.app.core.platform.EmptyAction
|
import im.vector.app.core.platform.EmptyAction
|
||||||
import im.vector.app.core.platform.EmptyViewEvents
|
import im.vector.app.core.platform.EmptyViewEvents
|
||||||
import im.vector.app.core.platform.VectorViewModel
|
import im.vector.app.core.platform.VectorViewModel
|
||||||
|
import im.vector.app.features.invite.AutoAcceptInvites
|
||||||
import im.vector.app.features.settings.VectorPreferences
|
import im.vector.app.features.settings.VectorPreferences
|
||||||
import io.reactivex.Observable
|
import io.reactivex.Observable
|
||||||
import io.reactivex.schedulers.Schedulers
|
import io.reactivex.schedulers.Schedulers
|
||||||
|
@ -54,7 +55,8 @@ data class CountInfo(
|
||||||
class UnreadMessagesSharedViewModel @AssistedInject constructor(@Assisted initialState: UnreadMessagesState,
|
class UnreadMessagesSharedViewModel @AssistedInject constructor(@Assisted initialState: UnreadMessagesState,
|
||||||
session: Session,
|
session: Session,
|
||||||
private val vectorPreferences: VectorPreferences,
|
private val vectorPreferences: VectorPreferences,
|
||||||
appStateHandler: AppStateHandler)
|
appStateHandler: AppStateHandler,
|
||||||
|
private val autoAcceptInvites: AutoAcceptInvites)
|
||||||
: VectorViewModel<UnreadMessagesState, EmptyAction, EmptyViewEvents>(initialState) {
|
: VectorViewModel<UnreadMessagesState, EmptyAction, EmptyViewEvents>(initialState) {
|
||||||
|
|
||||||
@AssistedFactory
|
@AssistedFactory
|
||||||
|
@ -92,12 +94,17 @@ class UnreadMessagesSharedViewModel @AssistedInject constructor(@Assisted initia
|
||||||
this.activeSpaceFilter = ActiveSpaceFilter.ActiveSpace(null)
|
this.activeSpaceFilter = ActiveSpaceFilter.ActiveSpace(null)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
val invites = session.getRoomSummaries(
|
val invites = if (autoAcceptInvites.hideInvites) {
|
||||||
roomSummaryQueryParams {
|
0
|
||||||
this.memberships = listOf(Membership.INVITE)
|
} else {
|
||||||
this.activeSpaceFilter = ActiveSpaceFilter.ActiveSpace(null)
|
session.getRoomSummaries(
|
||||||
}
|
roomSummaryQueryParams {
|
||||||
).size
|
this.memberships = listOf(Membership.INVITE)
|
||||||
|
this.activeSpaceFilter = ActiveSpaceFilter.ActiveSpace(null)
|
||||||
|
}
|
||||||
|
).size
|
||||||
|
}
|
||||||
|
|
||||||
copy(
|
copy(
|
||||||
homeSpaceUnread = RoomAggregateNotificationCount(
|
homeSpaceUnread = RoomAggregateNotificationCount(
|
||||||
counts.notificationCount + invites,
|
counts.notificationCount + invites,
|
||||||
|
@ -129,10 +136,13 @@ class UnreadMessagesSharedViewModel @AssistedInject constructor(@Assisted initia
|
||||||
is RoomGroupingMethod.BySpace -> {
|
is RoomGroupingMethod.BySpace -> {
|
||||||
val selectedSpace = appStateHandler.safeActiveSpaceId()
|
val selectedSpace = appStateHandler.safeActiveSpaceId()
|
||||||
|
|
||||||
val inviteCount = session.getRoomSummaries(
|
val inviteCount = if (autoAcceptInvites.hideInvites) {
|
||||||
roomSummaryQueryParams { this.memberships = listOf(Membership.INVITE) }
|
0
|
||||||
).size
|
} else {
|
||||||
|
session.getRoomSummaries(
|
||||||
|
roomSummaryQueryParams { this.memberships = listOf(Membership.INVITE) }
|
||||||
|
).size
|
||||||
|
}
|
||||||
val totalCount = session.getNotificationCountForRooms(
|
val totalCount = session.getNotificationCountForRooms(
|
||||||
roomSummaryQueryParams {
|
roomSummaryQueryParams {
|
||||||
this.memberships = listOf(Membership.JOIN)
|
this.memberships = listOf(Membership.JOIN)
|
||||||
|
|
|
@ -22,6 +22,8 @@ import im.vector.app.R
|
||||||
import im.vector.app.RoomGroupingMethod
|
import im.vector.app.RoomGroupingMethod
|
||||||
import im.vector.app.core.resources.StringProvider
|
import im.vector.app.core.resources.StringProvider
|
||||||
import im.vector.app.features.home.RoomListDisplayMode
|
import im.vector.app.features.home.RoomListDisplayMode
|
||||||
|
import im.vector.app.features.invite.AutoAcceptInvites
|
||||||
|
import im.vector.app.features.invite.showInvites
|
||||||
import io.reactivex.disposables.Disposable
|
import io.reactivex.disposables.Disposable
|
||||||
import io.reactivex.schedulers.Schedulers
|
import io.reactivex.schedulers.Schedulers
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
|
@ -38,6 +40,7 @@ class GroupRoomListSectionBuilder(
|
||||||
val stringProvider: StringProvider,
|
val stringProvider: StringProvider,
|
||||||
val viewModelScope: CoroutineScope,
|
val viewModelScope: CoroutineScope,
|
||||||
val appStateHandler: AppStateHandler,
|
val appStateHandler: AppStateHandler,
|
||||||
|
private val autoAcceptInvites: AutoAcceptInvites,
|
||||||
val onDisposable: (Disposable) -> Unit,
|
val onDisposable: (Disposable) -> Unit,
|
||||||
val onUdpatable: (UpdatableLivePageResult) -> Unit
|
val onUdpatable: (UpdatableLivePageResult) -> Unit
|
||||||
) : RoomListSectionBuilder {
|
) : RoomListSectionBuilder {
|
||||||
|
@ -48,15 +51,15 @@ class GroupRoomListSectionBuilder(
|
||||||
val actualGroupId = appStateHandler.safeActiveGroupId()
|
val actualGroupId = appStateHandler.safeActiveGroupId()
|
||||||
|
|
||||||
when (mode) {
|
when (mode) {
|
||||||
RoomListDisplayMode.PEOPLE -> {
|
RoomListDisplayMode.PEOPLE -> {
|
||||||
// 3 sections Invites / Fav / Dms
|
// 3 sections Invites / Fav / Dms
|
||||||
buildPeopleSections(sections, activeGroupAwareQueries, actualGroupId)
|
buildPeopleSections(sections, activeGroupAwareQueries, actualGroupId)
|
||||||
}
|
}
|
||||||
RoomListDisplayMode.ROOMS -> {
|
RoomListDisplayMode.ROOMS -> {
|
||||||
// 5 sections invites / Fav / Rooms / Low Priority / Server notice
|
// 5 sections invites / Fav / Rooms / Low Priority / Server notice
|
||||||
buildRoomsSections(sections, activeGroupAwareQueries, actualGroupId)
|
buildRoomsSections(sections, activeGroupAwareQueries, actualGroupId)
|
||||||
}
|
}
|
||||||
RoomListDisplayMode.FILTERED -> {
|
RoomListDisplayMode.FILTERED -> {
|
||||||
// Used when searching for rooms
|
// Used when searching for rooms
|
||||||
withQueryParams(
|
withQueryParams(
|
||||||
{
|
{
|
||||||
|
@ -73,17 +76,18 @@ class GroupRoomListSectionBuilder(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
RoomListDisplayMode.NOTIFICATIONS -> {
|
RoomListDisplayMode.NOTIFICATIONS -> {
|
||||||
addSection(
|
if (autoAcceptInvites.showInvites()) {
|
||||||
sections,
|
addSection(
|
||||||
activeGroupAwareQueries,
|
sections,
|
||||||
R.string.invitations_header,
|
activeGroupAwareQueries,
|
||||||
true
|
R.string.invitations_header,
|
||||||
) {
|
true
|
||||||
it.memberships = listOf(Membership.INVITE)
|
) {
|
||||||
it.roomCategoryFilter = RoomCategoryFilter.ALL
|
it.memberships = listOf(Membership.INVITE)
|
||||||
it.activeGroupId = actualGroupId
|
it.roomCategoryFilter = RoomCategoryFilter.ALL
|
||||||
|
it.activeGroupId = actualGroupId
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
addSection(
|
addSection(
|
||||||
sections,
|
sections,
|
||||||
activeGroupAwareQueries,
|
activeGroupAwareQueries,
|
||||||
|
@ -115,15 +119,17 @@ class GroupRoomListSectionBuilder(
|
||||||
private fun buildRoomsSections(sections: MutableList<RoomsSection>,
|
private fun buildRoomsSections(sections: MutableList<RoomsSection>,
|
||||||
activeSpaceAwareQueries: MutableList<UpdatableLivePageResult>,
|
activeSpaceAwareQueries: MutableList<UpdatableLivePageResult>,
|
||||||
actualGroupId: String?) {
|
actualGroupId: String?) {
|
||||||
addSection(
|
if (autoAcceptInvites.showInvites()) {
|
||||||
sections,
|
addSection(
|
||||||
activeSpaceAwareQueries,
|
sections,
|
||||||
R.string.invitations_header,
|
activeSpaceAwareQueries,
|
||||||
true
|
R.string.invitations_header,
|
||||||
) {
|
true
|
||||||
it.memberships = listOf(Membership.INVITE)
|
) {
|
||||||
it.roomCategoryFilter = RoomCategoryFilter.ONLY_ROOMS
|
it.memberships = listOf(Membership.INVITE)
|
||||||
it.activeGroupId = actualGroupId
|
it.roomCategoryFilter = RoomCategoryFilter.ONLY_ROOMS
|
||||||
|
it.activeGroupId = actualGroupId
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
addSection(
|
addSection(
|
||||||
|
@ -180,14 +186,16 @@ class GroupRoomListSectionBuilder(
|
||||||
activeSpaceAwareQueries: MutableList<UpdatableLivePageResult>,
|
activeSpaceAwareQueries: MutableList<UpdatableLivePageResult>,
|
||||||
actualGroupId: String?
|
actualGroupId: String?
|
||||||
) {
|
) {
|
||||||
addSection(sections,
|
if (autoAcceptInvites.showInvites()) {
|
||||||
activeSpaceAwareQueries,
|
addSection(sections,
|
||||||
R.string.invitations_header,
|
activeSpaceAwareQueries,
|
||||||
true
|
R.string.invitations_header,
|
||||||
) {
|
true
|
||||||
it.memberships = listOf(Membership.INVITE)
|
) {
|
||||||
it.roomCategoryFilter = RoomCategoryFilter.ONLY_DM
|
it.memberships = listOf(Membership.INVITE)
|
||||||
it.activeGroupId = actualGroupId
|
it.roomCategoryFilter = RoomCategoryFilter.ONLY_DM
|
||||||
|
it.activeGroupId = actualGroupId
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
addSection(
|
addSection(
|
||||||
|
|
|
@ -30,6 +30,7 @@ import im.vector.app.RoomGroupingMethod
|
||||||
import im.vector.app.core.extensions.exhaustive
|
import im.vector.app.core.extensions.exhaustive
|
||||||
import im.vector.app.core.platform.VectorViewModel
|
import im.vector.app.core.platform.VectorViewModel
|
||||||
import im.vector.app.core.resources.StringProvider
|
import im.vector.app.core.resources.StringProvider
|
||||||
|
import im.vector.app.features.invite.AutoAcceptInvites
|
||||||
import im.vector.app.features.settings.VectorPreferences
|
import im.vector.app.features.settings.VectorPreferences
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
@ -49,7 +50,8 @@ class RoomListViewModel @Inject constructor(
|
||||||
private val session: Session,
|
private val session: Session,
|
||||||
private val stringProvider: StringProvider,
|
private val stringProvider: StringProvider,
|
||||||
private val appStateHandler: AppStateHandler,
|
private val appStateHandler: AppStateHandler,
|
||||||
private val vectorPreferences: VectorPreferences
|
private val vectorPreferences: VectorPreferences,
|
||||||
|
private val autoAcceptInvites: AutoAcceptInvites
|
||||||
) : VectorViewModel<RoomListViewState, RoomListAction, RoomListViewEvents>(initialState) {
|
) : VectorViewModel<RoomListViewState, RoomListAction, RoomListViewEvents>(initialState) {
|
||||||
|
|
||||||
interface Factory {
|
interface Factory {
|
||||||
|
@ -126,6 +128,7 @@ class RoomListViewModel @Inject constructor(
|
||||||
appStateHandler,
|
appStateHandler,
|
||||||
viewModelScope,
|
viewModelScope,
|
||||||
suggestedRoomJoiningState,
|
suggestedRoomJoiningState,
|
||||||
|
autoAcceptInvites,
|
||||||
{
|
{
|
||||||
it.disposeOnClear()
|
it.disposeOnClear()
|
||||||
},
|
},
|
||||||
|
@ -140,6 +143,7 @@ class RoomListViewModel @Inject constructor(
|
||||||
stringProvider,
|
stringProvider,
|
||||||
viewModelScope,
|
viewModelScope,
|
||||||
appStateHandler,
|
appStateHandler,
|
||||||
|
autoAcceptInvites,
|
||||||
{
|
{
|
||||||
it.disposeOnClear()
|
it.disposeOnClear()
|
||||||
},
|
},
|
||||||
|
|
|
@ -18,6 +18,7 @@ package im.vector.app.features.home.room.list
|
||||||
|
|
||||||
import im.vector.app.AppStateHandler
|
import im.vector.app.AppStateHandler
|
||||||
import im.vector.app.core.resources.StringProvider
|
import im.vector.app.core.resources.StringProvider
|
||||||
|
import im.vector.app.features.invite.AutoAcceptInvites
|
||||||
import im.vector.app.features.settings.VectorPreferences
|
import im.vector.app.features.settings.VectorPreferences
|
||||||
import org.matrix.android.sdk.api.session.Session
|
import org.matrix.android.sdk.api.session.Session
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
@ -26,16 +27,18 @@ import javax.inject.Provider
|
||||||
class RoomListViewModelFactory @Inject constructor(private val session: Provider<Session>,
|
class RoomListViewModelFactory @Inject constructor(private val session: Provider<Session>,
|
||||||
private val appStateHandler: AppStateHandler,
|
private val appStateHandler: AppStateHandler,
|
||||||
private val stringProvider: StringProvider,
|
private val stringProvider: StringProvider,
|
||||||
private val vectorPreferences: VectorPreferences)
|
private val vectorPreferences: VectorPreferences,
|
||||||
|
private val autoAcceptInvites: AutoAcceptInvites)
|
||||||
: RoomListViewModel.Factory {
|
: RoomListViewModel.Factory {
|
||||||
|
|
||||||
override fun create(initialState: RoomListViewState): RoomListViewModel {
|
override fun create(initialState: RoomListViewState): RoomListViewModel {
|
||||||
return RoomListViewModel(
|
return RoomListViewModel(
|
||||||
initialState,
|
initialState = initialState,
|
||||||
session.get(),
|
session = session.get(),
|
||||||
stringProvider,
|
stringProvider = stringProvider,
|
||||||
appStateHandler,
|
appStateHandler = appStateHandler,
|
||||||
vectorPreferences
|
vectorPreferences = vectorPreferences,
|
||||||
|
autoAcceptInvites = autoAcceptInvites
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,8 @@ import im.vector.app.AppStateHandler
|
||||||
import im.vector.app.R
|
import im.vector.app.R
|
||||||
import im.vector.app.core.resources.StringProvider
|
import im.vector.app.core.resources.StringProvider
|
||||||
import im.vector.app.features.home.RoomListDisplayMode
|
import im.vector.app.features.home.RoomListDisplayMode
|
||||||
|
import im.vector.app.features.invite.AutoAcceptInvites
|
||||||
|
import im.vector.app.features.invite.showInvites
|
||||||
import im.vector.app.space
|
import im.vector.app.space
|
||||||
import io.reactivex.Observable
|
import io.reactivex.Observable
|
||||||
import io.reactivex.disposables.Disposable
|
import io.reactivex.disposables.Disposable
|
||||||
|
@ -50,6 +52,7 @@ class SpaceRoomListSectionBuilder(
|
||||||
val appStateHandler: AppStateHandler,
|
val appStateHandler: AppStateHandler,
|
||||||
val viewModelScope: CoroutineScope,
|
val viewModelScope: CoroutineScope,
|
||||||
private val suggestedRoomJoiningState: LiveData<Map<String, Async<Unit>>>,
|
private val suggestedRoomJoiningState: LiveData<Map<String, Async<Unit>>>,
|
||||||
|
private val autoAcceptInvites: AutoAcceptInvites,
|
||||||
val onDisposable: (Disposable) -> Unit,
|
val onDisposable: (Disposable) -> Unit,
|
||||||
val onUdpatable: (UpdatableLivePageResult) -> Unit,
|
val onUdpatable: (UpdatableLivePageResult) -> Unit,
|
||||||
val onlyOrphansInHome: Boolean = false
|
val onlyOrphansInHome: Boolean = false
|
||||||
|
@ -66,13 +69,13 @@ class SpaceRoomListSectionBuilder(
|
||||||
val sections = mutableListOf<RoomsSection>()
|
val sections = mutableListOf<RoomsSection>()
|
||||||
val activeSpaceAwareQueries = mutableListOf<RoomListViewModel.ActiveSpaceQueryUpdater>()
|
val activeSpaceAwareQueries = mutableListOf<RoomListViewModel.ActiveSpaceQueryUpdater>()
|
||||||
when (mode) {
|
when (mode) {
|
||||||
RoomListDisplayMode.PEOPLE -> {
|
RoomListDisplayMode.PEOPLE -> {
|
||||||
buildDmSections(sections, activeSpaceAwareQueries)
|
buildDmSections(sections, activeSpaceAwareQueries)
|
||||||
}
|
}
|
||||||
RoomListDisplayMode.ROOMS -> {
|
RoomListDisplayMode.ROOMS -> {
|
||||||
buildRoomsSections(sections, activeSpaceAwareQueries)
|
buildRoomsSections(sections, activeSpaceAwareQueries)
|
||||||
}
|
}
|
||||||
RoomListDisplayMode.FILTERED -> {
|
RoomListDisplayMode.FILTERED -> {
|
||||||
withQueryParams(
|
withQueryParams(
|
||||||
{
|
{
|
||||||
it.memberships = Membership.activeMemberships()
|
it.memberships = Membership.activeMemberships()
|
||||||
|
@ -88,20 +91,22 @@ class SpaceRoomListSectionBuilder(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
RoomListDisplayMode.NOTIFICATIONS -> {
|
RoomListDisplayMode.NOTIFICATIONS -> {
|
||||||
addSection(
|
if (autoAcceptInvites.showInvites()) {
|
||||||
sections = sections,
|
addSection(
|
||||||
activeSpaceUpdaters = activeSpaceAwareQueries,
|
sections = sections,
|
||||||
nameRes = R.string.invitations_header,
|
activeSpaceUpdaters = activeSpaceAwareQueries,
|
||||||
notifyOfLocalEcho = true,
|
nameRes = R.string.invitations_header,
|
||||||
spaceFilterStrategy = if (onlyOrphansInHome) {
|
notifyOfLocalEcho = true,
|
||||||
RoomListViewModel.SpaceFilterStrategy.ORPHANS_IF_SPACE_NULL
|
spaceFilterStrategy = if (onlyOrphansInHome) {
|
||||||
} else {
|
RoomListViewModel.SpaceFilterStrategy.ORPHANS_IF_SPACE_NULL
|
||||||
RoomListViewModel.SpaceFilterStrategy.ALL_IF_SPACE_NULL
|
} else {
|
||||||
},
|
RoomListViewModel.SpaceFilterStrategy.ALL_IF_SPACE_NULL
|
||||||
countRoomAsNotif = true
|
},
|
||||||
) {
|
countRoomAsNotif = true
|
||||||
it.memberships = listOf(Membership.INVITE)
|
) {
|
||||||
it.roomCategoryFilter = RoomCategoryFilter.ALL
|
it.memberships = listOf(Membership.INVITE)
|
||||||
|
it.roomCategoryFilter = RoomCategoryFilter.ALL
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
addSection(
|
addSection(
|
||||||
|
@ -136,16 +141,18 @@ class SpaceRoomListSectionBuilder(
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun buildRoomsSections(sections: MutableList<RoomsSection>, activeSpaceAwareQueries: MutableList<RoomListViewModel.ActiveSpaceQueryUpdater>) {
|
private fun buildRoomsSections(sections: MutableList<RoomsSection>, activeSpaceAwareQueries: MutableList<RoomListViewModel.ActiveSpaceQueryUpdater>) {
|
||||||
addSection(
|
if (autoAcceptInvites.showInvites()) {
|
||||||
sections = sections,
|
addSection(
|
||||||
activeSpaceUpdaters = activeSpaceAwareQueries,
|
sections = sections,
|
||||||
nameRes = R.string.invitations_header,
|
activeSpaceUpdaters = activeSpaceAwareQueries,
|
||||||
notifyOfLocalEcho = true,
|
nameRes = R.string.invitations_header,
|
||||||
spaceFilterStrategy = RoomListViewModel.SpaceFilterStrategy.ALL_IF_SPACE_NULL,
|
notifyOfLocalEcho = true,
|
||||||
countRoomAsNotif = true
|
spaceFilterStrategy = RoomListViewModel.SpaceFilterStrategy.ALL_IF_SPACE_NULL,
|
||||||
) {
|
countRoomAsNotif = true
|
||||||
it.memberships = listOf(Membership.INVITE)
|
) {
|
||||||
it.roomCategoryFilter = RoomCategoryFilter.ONLY_ROOMS
|
it.memberships = listOf(Membership.INVITE)
|
||||||
|
it.roomCategoryFilter = RoomCategoryFilter.ONLY_ROOMS
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
addSection(
|
addSection(
|
||||||
|
@ -253,15 +260,17 @@ class SpaceRoomListSectionBuilder(
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun buildDmSections(sections: MutableList<RoomsSection>, activeSpaceAwareQueries: MutableList<RoomListViewModel.ActiveSpaceQueryUpdater>) {
|
private fun buildDmSections(sections: MutableList<RoomsSection>, activeSpaceAwareQueries: MutableList<RoomListViewModel.ActiveSpaceQueryUpdater>) {
|
||||||
addSection(sections = sections,
|
if (autoAcceptInvites.showInvites()) {
|
||||||
activeSpaceUpdaters = activeSpaceAwareQueries,
|
addSection(sections = sections,
|
||||||
nameRes = R.string.invitations_header,
|
activeSpaceUpdaters = activeSpaceAwareQueries,
|
||||||
notifyOfLocalEcho = true,
|
nameRes = R.string.invitations_header,
|
||||||
spaceFilterStrategy = RoomListViewModel.SpaceFilterStrategy.ALL_IF_SPACE_NULL,
|
notifyOfLocalEcho = true,
|
||||||
countRoomAsNotif = true
|
spaceFilterStrategy = RoomListViewModel.SpaceFilterStrategy.ALL_IF_SPACE_NULL,
|
||||||
) {
|
countRoomAsNotif = true
|
||||||
it.memberships = listOf(Membership.INVITE)
|
) {
|
||||||
it.roomCategoryFilter = RoomCategoryFilter.ONLY_DM
|
it.memberships = listOf(Membership.INVITE)
|
||||||
|
it.roomCategoryFilter = RoomCategoryFilter.ONLY_DM
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
addSection(sections,
|
addSection(sections,
|
||||||
|
@ -387,7 +396,7 @@ class SpaceRoomListSectionBuilder(
|
||||||
activeSpaceFilter = ActiveSpaceFilter.ActiveSpace(currentSpace)
|
activeSpaceFilter = ActiveSpaceFilter.ActiveSpace(currentSpace)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
RoomListViewModel.SpaceFilterStrategy.ALL_IF_SPACE_NULL -> {
|
RoomListViewModel.SpaceFilterStrategy.ALL_IF_SPACE_NULL -> {
|
||||||
if (currentSpace == null) {
|
if (currentSpace == null) {
|
||||||
copy(
|
copy(
|
||||||
activeSpaceFilter = ActiveSpaceFilter.None
|
activeSpaceFilter = ActiveSpaceFilter.None
|
||||||
|
@ -398,7 +407,7 @@ class SpaceRoomListSectionBuilder(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
RoomListViewModel.SpaceFilterStrategy.NONE -> this
|
RoomListViewModel.SpaceFilterStrategy.NONE -> this
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,45 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2021 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.invite
|
||||||
|
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This interface defines 2 flags so you can handle auto accept invites.
|
||||||
|
* At the moment we only have [CompileTimeAutoAcceptInvites] implementation.
|
||||||
|
*/
|
||||||
|
interface AutoAcceptInvites {
|
||||||
|
/**
|
||||||
|
* Enable auto-accept invites. It means, as soon as you got an invite from the sync, it will try to join it.
|
||||||
|
*/
|
||||||
|
val isEnabled: Boolean
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hide invites from the UI (from notifications, notification count and room list). By default invites are hidden when [isEnabled] is true
|
||||||
|
*/
|
||||||
|
val hideInvites: Boolean
|
||||||
|
get() = isEnabled
|
||||||
|
}
|
||||||
|
|
||||||
|
fun AutoAcceptInvites.showInvites() = !hideInvites
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Simple compile time implementation of AutoAcceptInvites flags.
|
||||||
|
*/
|
||||||
|
class CompileTimeAutoAcceptInvites @Inject constructor() : AutoAcceptInvites {
|
||||||
|
override val isEnabled = false
|
||||||
|
}
|
|
@ -0,0 +1,143 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2021 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.invite
|
||||||
|
|
||||||
|
import im.vector.app.ActiveSessionDataSource
|
||||||
|
import im.vector.app.features.session.coroutineScope
|
||||||
|
import io.reactivex.Observable
|
||||||
|
import io.reactivex.disposables.Disposable
|
||||||
|
import kotlinx.coroutines.async
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlinx.coroutines.sync.Semaphore
|
||||||
|
import kotlinx.coroutines.sync.withPermit
|
||||||
|
import org.matrix.android.sdk.api.extensions.orFalse
|
||||||
|
import org.matrix.android.sdk.api.failure.Failure
|
||||||
|
import org.matrix.android.sdk.api.session.Session
|
||||||
|
import org.matrix.android.sdk.api.session.room.Room
|
||||||
|
import org.matrix.android.sdk.api.session.room.members.ChangeMembershipState
|
||||||
|
import org.matrix.android.sdk.api.session.room.model.Membership
|
||||||
|
import org.matrix.android.sdk.api.session.room.roomSummaryQueryParams
|
||||||
|
import org.matrix.android.sdk.rx.rx
|
||||||
|
import timber.log.Timber
|
||||||
|
import java.util.concurrent.TimeUnit
|
||||||
|
import javax.inject.Inject
|
||||||
|
import javax.inject.Singleton
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class is responsible for auto accepting invites.
|
||||||
|
* It's listening to invites and membershipChanges so it can retry automatically if needed.
|
||||||
|
* This mechanism will be on only if AutoAcceptInvites.isEnabled is true.
|
||||||
|
*/
|
||||||
|
@Singleton
|
||||||
|
class InvitesAcceptor @Inject constructor(
|
||||||
|
private val sessionDataSource: ActiveSessionDataSource,
|
||||||
|
private val autoAcceptInvites: AutoAcceptInvites
|
||||||
|
) : Session.Listener {
|
||||||
|
|
||||||
|
private lateinit var activeSessionDisposable: Disposable
|
||||||
|
private val shouldRejectRoomIds = mutableSetOf<String>()
|
||||||
|
private val invitedRoomDisposables = HashMap<String, Disposable>()
|
||||||
|
private val semaphore = Semaphore(1)
|
||||||
|
|
||||||
|
fun initialize() {
|
||||||
|
observeActiveSession()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun observeActiveSession() {
|
||||||
|
activeSessionDisposable = sessionDataSource.observe()
|
||||||
|
.distinctUntilChanged()
|
||||||
|
.subscribe {
|
||||||
|
it.orNull()?.let { session ->
|
||||||
|
onSessionActive(session)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun onSessionActive(session: Session) {
|
||||||
|
if (!autoAcceptInvites.isEnabled) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (invitedRoomDisposables.containsKey(session.sessionId)) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
session.addListener(this)
|
||||||
|
val roomQueryParams = roomSummaryQueryParams {
|
||||||
|
this.memberships = listOf(Membership.INVITE)
|
||||||
|
}
|
||||||
|
val rxSession = session.rx()
|
||||||
|
Observable
|
||||||
|
.combineLatest(
|
||||||
|
rxSession.liveRoomSummaries(roomQueryParams),
|
||||||
|
rxSession.liveRoomChangeMembershipState().debounce(1, TimeUnit.SECONDS),
|
||||||
|
{ invitedRooms, _ -> invitedRooms.map { it.roomId } }
|
||||||
|
)
|
||||||
|
.filter { it.isNotEmpty() }
|
||||||
|
.subscribe { invitedRoomIds ->
|
||||||
|
session.coroutineScope.launch {
|
||||||
|
semaphore.withPermit {
|
||||||
|
Timber.v("Invited roomIds: $invitedRoomIds")
|
||||||
|
for (roomId in invitedRoomIds) {
|
||||||
|
async { session.joinRoomSafely(roomId) }.start()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.also {
|
||||||
|
invitedRoomDisposables[session.sessionId] = it
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private suspend fun Session.joinRoomSafely(roomId: String) {
|
||||||
|
if (shouldRejectRoomIds.contains(roomId)) {
|
||||||
|
getRoom(roomId)?.rejectInviteSafely()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
val roomMembershipChanged = getChangeMemberships(roomId)
|
||||||
|
if (roomMembershipChanged != ChangeMembershipState.Joined && !roomMembershipChanged.isInProgress()) {
|
||||||
|
try {
|
||||||
|
Timber.v("Try auto join room: $roomId")
|
||||||
|
joinRoom(roomId)
|
||||||
|
} catch (failure: Throwable) {
|
||||||
|
Timber.v("Failed auto join room: $roomId")
|
||||||
|
// if we got 404 on invites, the inviting user have left or the hs is off.
|
||||||
|
if (failure is Failure.ServerError && failure.httpCode == 404) {
|
||||||
|
val room = getRoom(roomId) ?: return
|
||||||
|
val inviterId = room.roomSummary()?.inviterId
|
||||||
|
// if the inviting user is on the same HS, there can only be one cause: they left, so we try to reject the invite.
|
||||||
|
if (inviterId?.endsWith(sessionParams.credentials.homeServer.orEmpty()).orFalse()) {
|
||||||
|
shouldRejectRoomIds.add(roomId)
|
||||||
|
room.rejectInviteSafely()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private suspend fun Room.rejectInviteSafely() {
|
||||||
|
try {
|
||||||
|
leave(null)
|
||||||
|
shouldRejectRoomIds.remove(roomId)
|
||||||
|
} catch (failure: Throwable) {
|
||||||
|
Timber.v("Fail rejecting invite for room: $roomId")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onSessionStopped(session: Session) {
|
||||||
|
session.removeListener(this)
|
||||||
|
invitedRoomDisposables.remove(session.sessionId)?.dispose()
|
||||||
|
}
|
||||||
|
}
|
|
@ -27,6 +27,7 @@ import im.vector.app.BuildConfig
|
||||||
import im.vector.app.R
|
import im.vector.app.R
|
||||||
import im.vector.app.core.resources.StringProvider
|
import im.vector.app.core.resources.StringProvider
|
||||||
import im.vector.app.core.utils.FirstThrottler
|
import im.vector.app.core.utils.FirstThrottler
|
||||||
|
import im.vector.app.features.invite.AutoAcceptInvites
|
||||||
import im.vector.app.features.settings.VectorPreferences
|
import im.vector.app.features.settings.VectorPreferences
|
||||||
import me.gujun.android.span.span
|
import me.gujun.android.span.span
|
||||||
import org.matrix.android.sdk.api.session.Session
|
import org.matrix.android.sdk.api.session.Session
|
||||||
|
@ -50,7 +51,8 @@ class NotificationDrawerManager @Inject constructor(private val context: Context
|
||||||
private val activeSessionDataSource: ActiveSessionDataSource,
|
private val activeSessionDataSource: ActiveSessionDataSource,
|
||||||
private val iconLoader: IconLoader,
|
private val iconLoader: IconLoader,
|
||||||
private val bitmapLoader: BitmapLoader,
|
private val bitmapLoader: BitmapLoader,
|
||||||
private val outdatedDetector: OutdatedEventDetector?) {
|
private val outdatedDetector: OutdatedEventDetector?,
|
||||||
|
private val autoAcceptInvites: AutoAcceptInvites) {
|
||||||
|
|
||||||
private val handlerThread: HandlerThread = HandlerThread("NotificationDrawerManager", Thread.MIN_PRIORITY)
|
private val handlerThread: HandlerThread = HandlerThread("NotificationDrawerManager", Thread.MIN_PRIORITY)
|
||||||
private var backgroundHandler: Handler
|
private var backgroundHandler: Handler
|
||||||
|
@ -253,7 +255,14 @@ class NotificationDrawerManager @Inject constructor(private val context: Context
|
||||||
roomEvents.add(event)
|
roomEvents.add(event)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
is InviteNotifiableEvent -> invitationEvents.add(event)
|
is InviteNotifiableEvent -> {
|
||||||
|
if (autoAcceptInvites.hideInvites) {
|
||||||
|
// Forget this event
|
||||||
|
eventIterator.remove()
|
||||||
|
} else {
|
||||||
|
invitationEvents.add(event)
|
||||||
|
}
|
||||||
|
}
|
||||||
is SimpleNotifiableEvent -> simpleEvents.add(event)
|
is SimpleNotifiableEvent -> simpleEvents.add(event)
|
||||||
else -> Timber.w("Type not handled")
|
else -> Timber.w("Type not handled")
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,7 @@ import dagger.assisted.AssistedInject
|
||||||
import im.vector.app.AppStateHandler
|
import im.vector.app.AppStateHandler
|
||||||
import im.vector.app.RoomGroupingMethod
|
import im.vector.app.RoomGroupingMethod
|
||||||
import im.vector.app.core.platform.VectorViewModel
|
import im.vector.app.core.platform.VectorViewModel
|
||||||
|
import im.vector.app.features.invite.AutoAcceptInvites
|
||||||
import im.vector.app.features.session.coroutineScope
|
import im.vector.app.features.session.coroutineScope
|
||||||
import im.vector.app.features.settings.VectorPreferences
|
import im.vector.app.features.settings.VectorPreferences
|
||||||
import im.vector.app.group
|
import im.vector.app.group
|
||||||
|
@ -61,7 +62,8 @@ import java.util.concurrent.TimeUnit
|
||||||
class SpacesListViewModel @AssistedInject constructor(@Assisted initialState: SpaceListViewState,
|
class SpacesListViewModel @AssistedInject constructor(@Assisted initialState: SpaceListViewState,
|
||||||
private val appStateHandler: AppStateHandler,
|
private val appStateHandler: AppStateHandler,
|
||||||
private val session: Session,
|
private val session: Session,
|
||||||
private val vectorPreferences: VectorPreferences
|
private val vectorPreferences: VectorPreferences,
|
||||||
|
private val autoAcceptInvites: AutoAcceptInvites
|
||||||
) : VectorViewModel<SpaceListViewState, SpaceListAction, SpaceListViewEvents>(initialState) {
|
) : VectorViewModel<SpaceListViewState, SpaceListAction, SpaceListViewEvents>(initialState) {
|
||||||
|
|
||||||
@AssistedFactory
|
@AssistedFactory
|
||||||
|
@ -126,10 +128,13 @@ class SpacesListViewModel @AssistedInject constructor(@Assisted initialState: Sp
|
||||||
.throttleFirst(300, TimeUnit.MILLISECONDS)
|
.throttleFirst(300, TimeUnit.MILLISECONDS)
|
||||||
.observeOn(Schedulers.computation())
|
.observeOn(Schedulers.computation())
|
||||||
.subscribe {
|
.subscribe {
|
||||||
val inviteCount = session.getRoomSummaries(
|
val inviteCount = if (autoAcceptInvites.hideInvites) {
|
||||||
roomSummaryQueryParams { this.memberships = listOf(Membership.INVITE) }
|
0
|
||||||
).size
|
} else {
|
||||||
|
session.getRoomSummaries(
|
||||||
|
roomSummaryQueryParams { this.memberships = listOf(Membership.INVITE) }
|
||||||
|
).size
|
||||||
|
}
|
||||||
val totalCount = session.getNotificationCountForRooms(
|
val totalCount = session.getNotificationCountForRooms(
|
||||||
roomSummaryQueryParams {
|
roomSummaryQueryParams {
|
||||||
this.memberships = listOf(Membership.JOIN)
|
this.memberships = listOf(Membership.JOIN)
|
||||||
|
|
Loading…
Reference in New Issue