mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-11-24 10:25:51 +03:00
Mavericks 2: remove matrix-sdk-android-flow as it will be easier when entirely migrating to flow
This commit is contained in:
parent
fadbb60f90
commit
d9b02a20d8
57 changed files with 370 additions and 767 deletions
1
matrix-sdk-android-flow/.gitignore
vendored
1
matrix-sdk-android-flow/.gitignore
vendored
|
@ -1 +0,0 @@
|
||||||
/build
|
|
|
@ -1,49 +0,0 @@
|
||||||
|
|
||||||
plugins {
|
|
||||||
id 'com.android.library'
|
|
||||||
id 'org.jetbrains.kotlin.android'
|
|
||||||
}
|
|
||||||
|
|
||||||
android {
|
|
||||||
compileSdk 31
|
|
||||||
|
|
||||||
defaultConfig {
|
|
||||||
minSdk 21
|
|
||||||
targetSdk 31
|
|
||||||
|
|
||||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
|
||||||
consumerProguardFiles "consumer-rules.pro"
|
|
||||||
}
|
|
||||||
|
|
||||||
buildTypes {
|
|
||||||
release {
|
|
||||||
minifyEnabled false
|
|
||||||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
compileOptions {
|
|
||||||
sourceCompatibility JavaVersion.VERSION_1_8
|
|
||||||
targetCompatibility JavaVersion.VERSION_1_8
|
|
||||||
}
|
|
||||||
kotlinOptions {
|
|
||||||
jvmTarget = '1.8'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
dependencies {
|
|
||||||
|
|
||||||
implementation project(":matrix-sdk-android")
|
|
||||||
implementation libs.androidx.appCompat
|
|
||||||
|
|
||||||
implementation libs.jetbrains.kotlinStdlibJdk7
|
|
||||||
implementation libs.jetbrains.coroutinesCore
|
|
||||||
implementation libs.jetbrains.coroutinesAndroid
|
|
||||||
implementation libs.androidx.lifecycleLivedata
|
|
||||||
|
|
||||||
// Paging
|
|
||||||
implementation libs.androidx.pagingRuntimeKtx
|
|
||||||
|
|
||||||
// Logging
|
|
||||||
implementation libs.jakewharton.timber
|
|
||||||
|
|
||||||
}
|
|
21
matrix-sdk-android-flow/proguard-rules.pro
vendored
21
matrix-sdk-android-flow/proguard-rules.pro
vendored
|
@ -1,21 +0,0 @@
|
||||||
# Add project specific ProGuard rules here.
|
|
||||||
# You can control the set of applied configuration files using the
|
|
||||||
# proguardFiles setting in build.gradle.
|
|
||||||
#
|
|
||||||
# For more details, see
|
|
||||||
# http://developer.android.com/guide/developing/tools/proguard.html
|
|
||||||
|
|
||||||
# If your project uses WebView with JS, uncomment the following
|
|
||||||
# and specify the fully qualified class name to the JavaScript interface
|
|
||||||
# class:
|
|
||||||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
|
|
||||||
# public *;
|
|
||||||
#}
|
|
||||||
|
|
||||||
# Uncomment this to preserve the line number information for
|
|
||||||
# debugging stack traces.
|
|
||||||
#-keepattributes SourceFile,LineNumberTable
|
|
||||||
|
|
||||||
# If you keep the line number information, uncomment this to
|
|
||||||
# hide the original source file name.
|
|
||||||
#-renamesourcefileattribute SourceFile
|
|
|
@ -1,40 +0,0 @@
|
||||||
/*
|
|
||||||
* 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 org.matrix.android.sdk.flow
|
|
||||||
|
|
||||||
import androidx.test.platform.app.InstrumentationRegistry
|
|
||||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
|
||||||
|
|
||||||
import org.junit.Test
|
|
||||||
import org.junit.runner.RunWith
|
|
||||||
|
|
||||||
import org.junit.Assert.*
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Instrumented test, which will execute on an Android device.
|
|
||||||
*
|
|
||||||
* See [testing documentation](http://d.android.com/tools/testing).
|
|
||||||
*/
|
|
||||||
@RunWith(AndroidJUnit4::class)
|
|
||||||
class ExampleInstrumentedTest {
|
|
||||||
@Test
|
|
||||||
fun useAppContext() {
|
|
||||||
// Context of the app under test.
|
|
||||||
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
|
|
||||||
assertEquals("org.matrix.android.sdk.flow.test", appContext.packageName)
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,5 +0,0 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
package="org.matrix.android.sdk.flow">
|
|
||||||
|
|
||||||
</manifest>
|
|
|
@ -1,83 +0,0 @@
|
||||||
/*
|
|
||||||
* 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.flow
|
|
||||||
|
|
||||||
import androidx.lifecycle.asFlow
|
|
||||||
import kotlinx.coroutines.flow.Flow
|
|
||||||
import org.matrix.android.sdk.api.query.QueryStringValue
|
|
||||||
import org.matrix.android.sdk.api.session.events.model.Event
|
|
||||||
import org.matrix.android.sdk.api.session.room.Room
|
|
||||||
import org.matrix.android.sdk.api.session.room.members.RoomMemberQueryParams
|
|
||||||
import org.matrix.android.sdk.api.session.room.model.EventAnnotationsSummary
|
|
||||||
import org.matrix.android.sdk.api.session.room.model.ReadReceipt
|
|
||||||
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.notification.RoomNotificationState
|
|
||||||
import org.matrix.android.sdk.api.session.room.send.UserDraft
|
|
||||||
import org.matrix.android.sdk.api.session.room.timeline.TimelineEvent
|
|
||||||
import org.matrix.android.sdk.api.util.Optional
|
|
||||||
|
|
||||||
class FlowRoom(private val room: Room) {
|
|
||||||
|
|
||||||
fun liveRoomSummary(): Flow<Optional<RoomSummary>> {
|
|
||||||
return room.getRoomSummaryLive().asFlow()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun liveRoomMembers(queryParams: RoomMemberQueryParams): Flow<List<RoomMemberSummary>> {
|
|
||||||
return room.getRoomMembersLive(queryParams).asFlow()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun liveAnnotationSummary(eventId: String): Flow<Optional<EventAnnotationsSummary>> {
|
|
||||||
return room.getEventAnnotationsSummaryLive(eventId).asFlow()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun liveTimelineEvent(eventId: String): Flow<Optional<TimelineEvent>> {
|
|
||||||
return room.getTimeLineEventLive(eventId).asFlow()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun liveStateEvent(eventType: String, stateKey: QueryStringValue): Flow<Optional<Event>> {
|
|
||||||
return room.getStateEventLive(eventType, stateKey).asFlow()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun liveStateEvents(eventTypes: Set<String>): Flow<List<Event>> {
|
|
||||||
return room.getStateEventsLive(eventTypes).asFlow()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun liveReadMarker(): Flow<Optional<String>> {
|
|
||||||
return room.getReadMarkerLive().asFlow()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun liveReadReceipt(): Flow<Optional<String>> {
|
|
||||||
return room.getMyReadReceiptLive().asFlow()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun liveEventReadReceipts(eventId: String): Flow<List<ReadReceipt>> {
|
|
||||||
return room.getEventReadReceiptsLive(eventId).asFlow()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun liveDraft(): Flow<Optional<UserDraft>> {
|
|
||||||
return room.getDraftLive().asFlow()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun liveNotificationState(): Flow<RoomNotificationState> {
|
|
||||||
return room.getLiveRoomNotificationState().asFlow()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun Room.flow(): FlowRoom {
|
|
||||||
return FlowRoom(this)
|
|
||||||
}
|
|
|
@ -1,138 +0,0 @@
|
||||||
/*
|
|
||||||
* 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.flow
|
|
||||||
|
|
||||||
import androidx.lifecycle.asFlow
|
|
||||||
import androidx.paging.PagedList
|
|
||||||
import kotlinx.coroutines.flow.Flow
|
|
||||||
import org.matrix.android.sdk.api.query.QueryStringValue
|
|
||||||
import org.matrix.android.sdk.api.session.Session
|
|
||||||
import org.matrix.android.sdk.api.session.accountdata.UserAccountDataEvent
|
|
||||||
import org.matrix.android.sdk.api.session.crypto.crosssigning.MXCrossSigningInfo
|
|
||||||
import org.matrix.android.sdk.api.session.group.GroupSummaryQueryParams
|
|
||||||
import org.matrix.android.sdk.api.session.group.model.GroupSummary
|
|
||||||
import org.matrix.android.sdk.api.session.identity.ThreePid
|
|
||||||
import org.matrix.android.sdk.api.session.pushers.Pusher
|
|
||||||
import org.matrix.android.sdk.api.session.room.RoomSummaryQueryParams
|
|
||||||
import org.matrix.android.sdk.api.session.room.accountdata.RoomAccountDataEvent
|
|
||||||
import org.matrix.android.sdk.api.session.room.members.ChangeMembershipState
|
|
||||||
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.space.SpaceSummaryQueryParams
|
|
||||||
import org.matrix.android.sdk.api.session.sync.SyncState
|
|
||||||
import org.matrix.android.sdk.api.session.user.model.User
|
|
||||||
import org.matrix.android.sdk.api.session.widgets.model.Widget
|
|
||||||
import org.matrix.android.sdk.api.util.Optional
|
|
||||||
import org.matrix.android.sdk.internal.crypto.model.CryptoDeviceInfo
|
|
||||||
import org.matrix.android.sdk.internal.crypto.model.rest.DeviceInfo
|
|
||||||
import org.matrix.android.sdk.internal.crypto.store.PrivateKeysInfo
|
|
||||||
|
|
||||||
class RxFlow(private val session: Session) {
|
|
||||||
|
|
||||||
fun liveRoomSummaries(queryParams: RoomSummaryQueryParams): Flow<List<RoomSummary>> {
|
|
||||||
return session.getRoomSummariesLive(queryParams).asFlow()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun liveGroupSummaries(queryParams: GroupSummaryQueryParams): Flow<List<GroupSummary>> {
|
|
||||||
return session.getGroupSummariesLive(queryParams).asFlow()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun liveSpaceSummaries(queryParams: SpaceSummaryQueryParams): Flow<List<RoomSummary>> {
|
|
||||||
return session.spaceService().getSpaceSummariesLive(queryParams).asFlow()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun liveBreadcrumbs(queryParams: RoomSummaryQueryParams): Flow<List<RoomSummary>> {
|
|
||||||
return session.getBreadcrumbsLive(queryParams).asFlow()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun liveMyDevicesInfo(): Flow<List<DeviceInfo>> {
|
|
||||||
return session.cryptoService().getLiveMyDevicesInfo().asFlow()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun liveSyncState(): Flow<SyncState> {
|
|
||||||
return session.getSyncStateLive().asFlow()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun livePushers(): Flow<List<Pusher>> {
|
|
||||||
return session.getPushersLive().asFlow()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun liveUser(userId: String): Flow<Optional<User>> {
|
|
||||||
return session.getUserLive(userId).asFlow()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun liveRoomMember(userId: String, roomId: String): Flow<Optional<RoomMemberSummary>> {
|
|
||||||
return session.getRoomMemberLive(userId, roomId).asFlow()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun liveUsers(): Flow<List<User>> {
|
|
||||||
return session.getUsersLive().asFlow()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun liveIgnoredUsers(): Flow<List<User>> {
|
|
||||||
return session.getIgnoredUsersLive().asFlow()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun livePagedUsers(filter: String? = null, excludedUserIds: Set<String>? = null): Flow<PagedList<User>> {
|
|
||||||
return session.getPagedUsersLive(filter, excludedUserIds).asFlow()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun liveThreePIds(refreshData: Boolean): Flow<List<ThreePid>> {
|
|
||||||
return session.getThreePidsLive(refreshData).asFlow()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun livePendingThreePIds(): Flow<List<ThreePid>> {
|
|
||||||
return session.getPendingThreePidsLive().asFlow()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun liveUserCryptoDevices(userId: String): Flow<List<CryptoDeviceInfo>> {
|
|
||||||
return session.cryptoService().getLiveCryptoDeviceInfo(userId).asFlow()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun liveCrossSigningInfo(userId: String): Flow<Optional<MXCrossSigningInfo>> {
|
|
||||||
return session.cryptoService().crossSigningService().getLiveCrossSigningKeys(userId).asFlow()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun liveCrossSigningPrivateKeys(): Flow<Optional<PrivateKeysInfo>> {
|
|
||||||
return session.cryptoService().crossSigningService().getLiveCrossSigningPrivateKeys().asFlow()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun liveUserAccountData(types: Set<String>): Flow<List<UserAccountDataEvent>> {
|
|
||||||
return session.accountDataService().getLiveUserAccountDataEvents(types).asFlow()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun liveRoomAccountData(types: Set<String>): Flow<List<RoomAccountDataEvent>> {
|
|
||||||
return session.accountDataService().getLiveRoomAccountDataEvents(types).asFlow()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun liveRoomWidgets(
|
|
||||||
roomId: String,
|
|
||||||
widgetId: QueryStringValue,
|
|
||||||
widgetTypes: Set<String>? = null,
|
|
||||||
excludedTypes: Set<String>? = null
|
|
||||||
): Flow<List<Widget>> {
|
|
||||||
return session.widgetService().getRoomWidgetsLive(roomId, widgetId, widgetTypes, excludedTypes).asFlow()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun liveRoomChangeMembershipState(): Flow<Map<String, ChangeMembershipState>> {
|
|
||||||
return session.getChangeMembershipsLive().asFlow()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun Session.flow(): RxFlow {
|
|
||||||
return RxFlow(this)
|
|
||||||
}
|
|
|
@ -1,33 +0,0 @@
|
||||||
/*
|
|
||||||
* 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 org.matrix.android.sdk.flow
|
|
||||||
|
|
||||||
import org.junit.Test
|
|
||||||
|
|
||||||
import org.junit.Assert.*
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Example local unit test, which will execute on the development machine (host).
|
|
||||||
*
|
|
||||||
* See [testing documentation](http://d.android.com/tools/testing).
|
|
||||||
*/
|
|
||||||
class ExampleUnitTest {
|
|
||||||
@Test
|
|
||||||
fun addition_isCorrect() {
|
|
||||||
assertEquals(4, 2 + 2)
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -5,4 +5,3 @@ include ':diff-match-patch'
|
||||||
include ':attachment-viewer'
|
include ':attachment-viewer'
|
||||||
include ':multipicker'
|
include ':multipicker'
|
||||||
include ':library:ui-styles'
|
include ':library:ui-styles'
|
||||||
include ':matrix-sdk-android-flow'
|
|
||||||
|
|
|
@ -323,7 +323,6 @@ dependencies {
|
||||||
|
|
||||||
implementation project(":matrix-sdk-android")
|
implementation project(":matrix-sdk-android")
|
||||||
implementation project(":matrix-sdk-android-rx")
|
implementation project(":matrix-sdk-android-rx")
|
||||||
implementation project(":matrix-sdk-android-flow")
|
|
||||||
implementation project(":diff-match-patch")
|
implementation project(":diff-match-patch")
|
||||||
implementation project(":multipicker")
|
implementation project(":multipicker")
|
||||||
implementation project(":attachment-viewer")
|
implementation project(":attachment-viewer")
|
||||||
|
|
|
@ -16,16 +16,10 @@
|
||||||
|
|
||||||
package im.vector.app.core.platform
|
package im.vector.app.core.platform
|
||||||
|
|
||||||
import com.airbnb.mvrx.Async
|
|
||||||
import com.airbnb.mvrx.BaseMvRxViewModel
|
import com.airbnb.mvrx.BaseMvRxViewModel
|
||||||
import com.airbnb.mvrx.Fail
|
|
||||||
import com.airbnb.mvrx.Loading
|
|
||||||
import com.airbnb.mvrx.MavericksState
|
import com.airbnb.mvrx.MavericksState
|
||||||
import com.airbnb.mvrx.Success
|
|
||||||
import im.vector.app.core.utils.DataSource
|
import im.vector.app.core.utils.DataSource
|
||||||
import im.vector.app.core.utils.PublishDataSource
|
import im.vector.app.core.utils.PublishDataSource
|
||||||
import io.reactivex.Observable
|
|
||||||
import io.reactivex.Single
|
|
||||||
|
|
||||||
abstract class VectorViewModel<S : MavericksState, VA : VectorViewModelAction, VE : VectorViewEvents>(initialState: S)
|
abstract class VectorViewModel<S : MavericksState, VA : VectorViewModelAction, VE : VectorViewEvents>(initialState: S)
|
||||||
: BaseMvRxViewModel<S>(initialState) {
|
: BaseMvRxViewModel<S>(initialState) {
|
||||||
|
@ -38,31 +32,5 @@ abstract class VectorViewModel<S : MavericksState, VA : VectorViewModelAction, V
|
||||||
protected val _viewEvents = PublishDataSource<VE>()
|
protected val _viewEvents = PublishDataSource<VE>()
|
||||||
val viewEvents: DataSource<VE> = _viewEvents
|
val viewEvents: DataSource<VE> = _viewEvents
|
||||||
|
|
||||||
/**
|
|
||||||
* This method does the same thing as the execute function, but it doesn't subscribe to the stream
|
|
||||||
* so you can use this in a switchMap or a flatMap
|
|
||||||
*/
|
|
||||||
// False positive
|
|
||||||
@Suppress("USELESS_CAST", "NULLABLE_TYPE_PARAMETER_AGAINST_NOT_NULL_TYPE_PARAMETER")
|
|
||||||
fun <T> Single<T>.toAsync(stateReducer: S.(Async<T>) -> S): Single<Async<T>> {
|
|
||||||
setState { stateReducer(Loading()) }
|
|
||||||
return map { Success(it) as Async<T> }
|
|
||||||
.onErrorReturn { Fail(it) }
|
|
||||||
.doOnSuccess { setState { stateReducer(it) } }
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This method does the same thing as the execute function, but it doesn't subscribe to the stream
|
|
||||||
* so you can use this in a switchMap or a flatMap
|
|
||||||
*/
|
|
||||||
// False positive
|
|
||||||
@Suppress("USELESS_CAST", "NULLABLE_TYPE_PARAMETER_AGAINST_NOT_NULL_TYPE_PARAMETER")
|
|
||||||
fun <T> Observable<T>.toAsync(stateReducer: S.(Async<T>) -> S): Observable<Async<T>> {
|
|
||||||
setState { stateReducer(Loading()) }
|
|
||||||
return map { Success(it) as Async<T> }
|
|
||||||
.onErrorReturn { Fail(it) }
|
|
||||||
.doOnNext { setState { stateReducer(it) } }
|
|
||||||
}
|
|
||||||
|
|
||||||
abstract fun handle(action: VA)
|
abstract fun handle(action: VA)
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.matrix.android.sdk.flow
|
package im.vector.app.core.utils
|
||||||
|
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
import kotlinx.coroutines.flow.filter
|
import kotlinx.coroutines.flow.filter
|
|
@ -16,6 +16,7 @@
|
||||||
|
|
||||||
package im.vector.app.features.crypto.quads
|
package im.vector.app.features.crypto.quads
|
||||||
|
|
||||||
|
import androidx.lifecycle.asFlow
|
||||||
import androidx.lifecycle.viewModelScope
|
import androidx.lifecycle.viewModelScope
|
||||||
import com.airbnb.mvrx.Async
|
import com.airbnb.mvrx.Async
|
||||||
import com.airbnb.mvrx.Fail
|
import com.airbnb.mvrx.Fail
|
||||||
|
@ -43,9 +44,7 @@ import org.matrix.android.sdk.api.session.Session
|
||||||
import org.matrix.android.sdk.api.session.securestorage.IntegrityResult
|
import org.matrix.android.sdk.api.session.securestorage.IntegrityResult
|
||||||
import org.matrix.android.sdk.api.session.securestorage.KeyInfoResult
|
import org.matrix.android.sdk.api.session.securestorage.KeyInfoResult
|
||||||
import org.matrix.android.sdk.api.session.securestorage.RawBytesKeySpec
|
import org.matrix.android.sdk.api.session.securestorage.RawBytesKeySpec
|
||||||
import org.matrix.android.sdk.flow.flow
|
|
||||||
import org.matrix.android.sdk.internal.crypto.crosssigning.toBase64NoPadding
|
import org.matrix.android.sdk.internal.crypto.crosssigning.toBase64NoPadding
|
||||||
import org.matrix.android.sdk.rx.rx
|
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
import java.io.ByteArrayOutputStream
|
import java.io.ByteArrayOutputStream
|
||||||
|
|
||||||
|
@ -116,8 +115,9 @@ class SharedSecureStorageViewModel @AssistedInject constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
session.flow()
|
session.cryptoService()
|
||||||
.liveUserCryptoDevices(session.myUserId)
|
.getLiveCryptoDeviceInfo(session.myUserId)
|
||||||
|
.asFlow()
|
||||||
.distinctUntilChanged()
|
.distinctUntilChanged()
|
||||||
.execute {
|
.execute {
|
||||||
copy(
|
copy(
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
|
|
||||||
package im.vector.app.features.devtools
|
package im.vector.app.features.devtools
|
||||||
|
|
||||||
|
import androidx.lifecycle.asFlow
|
||||||
import androidx.lifecycle.viewModelScope
|
import androidx.lifecycle.viewModelScope
|
||||||
import com.airbnb.mvrx.ActivityViewModelContext
|
import com.airbnb.mvrx.ActivityViewModelContext
|
||||||
import com.airbnb.mvrx.Fail
|
import com.airbnb.mvrx.Fail
|
||||||
|
@ -40,9 +41,7 @@ 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.events.model.toModel
|
||||||
import org.matrix.android.sdk.api.session.room.model.message.MessageContent
|
import org.matrix.android.sdk.api.session.room.model.message.MessageContent
|
||||||
import org.matrix.android.sdk.api.util.JsonDict
|
import org.matrix.android.sdk.api.util.JsonDict
|
||||||
import org.matrix.android.sdk.flow.flow
|
|
||||||
import org.matrix.android.sdk.internal.di.MoshiProvider
|
import org.matrix.android.sdk.internal.di.MoshiProvider
|
||||||
import org.matrix.android.sdk.rx.rx
|
|
||||||
|
|
||||||
class RoomDevToolViewModel @AssistedInject constructor(
|
class RoomDevToolViewModel @AssistedInject constructor(
|
||||||
@Assisted val initialState: RoomDevToolViewState,
|
@Assisted val initialState: RoomDevToolViewState,
|
||||||
|
@ -70,8 +69,8 @@ class RoomDevToolViewModel @AssistedInject constructor(
|
||||||
|
|
||||||
init {
|
init {
|
||||||
session.getRoom(initialState.roomId)
|
session.getRoom(initialState.roomId)
|
||||||
?.flow()
|
?.getStateEventsLive(emptySet())
|
||||||
?.liveStateEvents(emptySet())
|
?.asFlow()
|
||||||
?.execute { async ->
|
?.execute { async ->
|
||||||
copy(stateEvents = async)
|
copy(stateEvents = async)
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
*/
|
*/
|
||||||
package im.vector.app.features.discovery
|
package im.vector.app.features.discovery
|
||||||
|
|
||||||
|
import androidx.lifecycle.asFlow
|
||||||
import com.airbnb.mvrx.Async
|
import com.airbnb.mvrx.Async
|
||||||
import com.airbnb.mvrx.Fail
|
import com.airbnb.mvrx.Fail
|
||||||
import com.airbnb.mvrx.FragmentViewModelContext
|
import com.airbnb.mvrx.FragmentViewModelContext
|
||||||
|
@ -36,7 +37,6 @@ import org.matrix.android.sdk.api.session.identity.IdentityServiceError
|
||||||
import org.matrix.android.sdk.api.session.identity.IdentityServiceListener
|
import org.matrix.android.sdk.api.session.identity.IdentityServiceListener
|
||||||
import org.matrix.android.sdk.api.session.identity.SharedState
|
import org.matrix.android.sdk.api.session.identity.SharedState
|
||||||
import org.matrix.android.sdk.api.session.identity.ThreePid
|
import org.matrix.android.sdk.api.session.identity.ThreePid
|
||||||
import org.matrix.android.sdk.flow.flow
|
|
||||||
|
|
||||||
class DiscoverySettingsViewModel @AssistedInject constructor(
|
class DiscoverySettingsViewModel @AssistedInject constructor(
|
||||||
@Assisted initialState: DiscoverySettingsState,
|
@Assisted initialState: DiscoverySettingsState,
|
||||||
|
@ -85,8 +85,9 @@ class DiscoverySettingsViewModel @AssistedInject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun observeThreePids() {
|
private fun observeThreePids() {
|
||||||
session.flow()
|
session
|
||||||
.liveThreePIds(true)
|
.getThreePidsLive(true)
|
||||||
|
.asFlow()
|
||||||
.onEach {
|
.onEach {
|
||||||
retrieveBinding(it)
|
retrieveBinding(it)
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,12 +47,9 @@ import org.matrix.android.sdk.api.session.initsync.SyncStatusService
|
||||||
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.roomSummaryQueryParams
|
import org.matrix.android.sdk.api.session.room.roomSummaryQueryParams
|
||||||
import org.matrix.android.sdk.api.util.toMatrixItem
|
import org.matrix.android.sdk.api.util.toMatrixItem
|
||||||
import org.matrix.android.sdk.flow.flow
|
|
||||||
import org.matrix.android.sdk.internal.crypto.model.CryptoDeviceInfo
|
import org.matrix.android.sdk.internal.crypto.model.CryptoDeviceInfo
|
||||||
import org.matrix.android.sdk.internal.crypto.model.MXUsersDevicesMap
|
import org.matrix.android.sdk.internal.crypto.model.MXUsersDevicesMap
|
||||||
import org.matrix.android.sdk.internal.util.awaitCallback
|
import org.matrix.android.sdk.internal.util.awaitCallback
|
||||||
import org.matrix.android.sdk.rx.asObservable
|
|
||||||
import org.matrix.android.sdk.rx.rx
|
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
import kotlin.coroutines.Continuation
|
import kotlin.coroutines.Continuation
|
||||||
import kotlin.coroutines.resume
|
import kotlin.coroutines.resume
|
||||||
|
@ -104,8 +101,10 @@ class HomeActivityViewModel @AssistedInject constructor(
|
||||||
.crossSigningService().allPrivateKeysKnown()
|
.crossSigningService().allPrivateKeysKnown()
|
||||||
|
|
||||||
safeActiveSession
|
safeActiveSession
|
||||||
.flow()
|
.cryptoService()
|
||||||
.liveCrossSigningInfo(safeActiveSession.myUserId)
|
.crossSigningService()
|
||||||
|
.getLiveCrossSigningKeys(safeActiveSession.myUserId)
|
||||||
|
.asFlow()
|
||||||
.onEach {
|
.onEach {
|
||||||
val isVerified = it.getOrNull()?.isTrusted() ?: false
|
val isVerified = it.getOrNull()?.isTrusted() ?: false
|
||||||
if (!isVerified && onceTrusted) {
|
if (!isVerified && onceTrusted) {
|
||||||
|
|
|
@ -48,7 +48,6 @@ import org.matrix.android.sdk.api.session.room.RoomSortOrder
|
||||||
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.roomSummaryQueryParams
|
import org.matrix.android.sdk.api.session.room.roomSummaryQueryParams
|
||||||
import org.matrix.android.sdk.api.util.toMatrixItem
|
import org.matrix.android.sdk.api.util.toMatrixItem
|
||||||
import org.matrix.android.sdk.flow.flow
|
|
||||||
import org.matrix.android.sdk.rx.asObservable
|
import org.matrix.android.sdk.rx.asObservable
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
import java.util.concurrent.TimeUnit
|
import java.util.concurrent.TimeUnit
|
||||||
|
@ -96,11 +95,13 @@ class HomeDetailViewModel @AssistedInject constructor(@Assisted initialState: Ho
|
||||||
updateShowDialPadTab()
|
updateShowDialPadTab()
|
||||||
observeDataStore()
|
observeDataStore()
|
||||||
callManager.addProtocolsCheckerListener(this)
|
callManager.addProtocolsCheckerListener(this)
|
||||||
session.flow().liveUser(session.myUserId).execute {
|
session.getUserLive(session.myUserId)
|
||||||
copy(
|
.asFlow()
|
||||||
myMatrixItem = it.invoke()?.getOrNull()?.toMatrixItem()
|
.execute {
|
||||||
)
|
copy(
|
||||||
}
|
myMatrixItem = it.invoke()?.getOrNull()?.toMatrixItem()
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun observeDataStore() {
|
private fun observeDataStore() {
|
||||||
|
@ -183,8 +184,8 @@ class HomeDetailViewModel @AssistedInject constructor(@Assisted initialState: Ho
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun observeSyncState() {
|
private fun observeSyncState() {
|
||||||
session.flow()
|
session.getSyncStateLive()
|
||||||
.liveSyncState()
|
.asFlow()
|
||||||
.setOnEach { syncState ->
|
.setOnEach { syncState ->
|
||||||
copy(syncState = syncState)
|
copy(syncState = syncState)
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
|
|
||||||
package im.vector.app.features.home
|
package im.vector.app.features.home
|
||||||
|
|
||||||
|
import androidx.lifecycle.asFlow
|
||||||
import com.airbnb.mvrx.ActivityViewModelContext
|
import com.airbnb.mvrx.ActivityViewModelContext
|
||||||
import com.airbnb.mvrx.Async
|
import com.airbnb.mvrx.Async
|
||||||
import com.airbnb.mvrx.FragmentViewModelContext
|
import com.airbnb.mvrx.FragmentViewModelContext
|
||||||
|
@ -41,7 +42,6 @@ import org.matrix.android.sdk.api.extensions.orFalse
|
||||||
import org.matrix.android.sdk.api.session.Session
|
import org.matrix.android.sdk.api.session.Session
|
||||||
import org.matrix.android.sdk.api.util.MatrixItem
|
import org.matrix.android.sdk.api.util.MatrixItem
|
||||||
import org.matrix.android.sdk.api.util.toMatrixItem
|
import org.matrix.android.sdk.api.util.toMatrixItem
|
||||||
import org.matrix.android.sdk.flow.flow
|
|
||||||
import org.matrix.android.sdk.internal.crypto.model.rest.DeviceInfo
|
import org.matrix.android.sdk.internal.crypto.model.rest.DeviceInfo
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
|
|
||||||
|
@ -99,9 +99,9 @@ class UnknownDeviceDetectorSharedViewModel @AssistedInject constructor(@Assisted
|
||||||
)
|
)
|
||||||
|
|
||||||
combine(
|
combine(
|
||||||
session.flow().liveUserCryptoDevices(session.myUserId),
|
session.cryptoService().getLiveCryptoDeviceInfo(session.myUserId).asFlow(),
|
||||||
session.flow().liveMyDevicesInfo(),
|
session.cryptoService().getLiveMyDevicesInfo().asFlow(),
|
||||||
session.flow().liveCrossSigningPrivateKeys()
|
session.cryptoService().crossSigningService().getLiveCrossSigningPrivateKeys().asFlow()
|
||||||
)
|
)
|
||||||
{ cryptoList, infoList, pInfo ->
|
{ cryptoList, infoList, pInfo ->
|
||||||
// Timber.v("## Detector trigger ${cryptoList.map { "${it.deviceId} ${it.trustLevel}" }}")
|
// Timber.v("## Detector trigger ${cryptoList.map { "${it.deviceId} ${it.trustLevel}" }}")
|
||||||
|
@ -132,7 +132,7 @@ class UnknownDeviceDetectorSharedViewModel @AssistedInject constructor(@Assisted
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
session.flow().liveUserCryptoDevices(session.myUserId)
|
session.cryptoService().getLiveCryptoDeviceInfo(session.myUserId).asFlow()
|
||||||
.distinctUntilChanged()
|
.distinctUntilChanged()
|
||||||
.sample(5_000)
|
.sample(5_000)
|
||||||
.onEach {
|
.onEach {
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
|
|
||||||
package im.vector.app.features.home.room.breadcrumbs
|
package im.vector.app.features.home.room.breadcrumbs
|
||||||
|
|
||||||
|
import androidx.lifecycle.asFlow
|
||||||
import com.airbnb.mvrx.FragmentViewModelContext
|
import com.airbnb.mvrx.FragmentViewModelContext
|
||||||
import com.airbnb.mvrx.MavericksViewModelFactory
|
import com.airbnb.mvrx.MavericksViewModelFactory
|
||||||
import com.airbnb.mvrx.ViewModelContext
|
import com.airbnb.mvrx.ViewModelContext
|
||||||
|
@ -25,13 +26,10 @@ import dagger.assisted.AssistedFactory
|
||||||
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 io.reactivex.schedulers.Schedulers
|
|
||||||
import org.matrix.android.sdk.api.query.QueryStringValue
|
import org.matrix.android.sdk.api.query.QueryStringValue
|
||||||
import org.matrix.android.sdk.api.session.Session
|
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.roomSummaryQueryParams
|
import org.matrix.android.sdk.api.session.room.roomSummaryQueryParams
|
||||||
import org.matrix.android.sdk.flow.flow
|
|
||||||
import org.matrix.android.sdk.rx.rx
|
|
||||||
|
|
||||||
class BreadcrumbsViewModel @AssistedInject constructor(@Assisted initialState: BreadcrumbsViewState,
|
class BreadcrumbsViewModel @AssistedInject constructor(@Assisted initialState: BreadcrumbsViewState,
|
||||||
private val session: Session)
|
private val session: Session)
|
||||||
|
@ -62,11 +60,11 @@ class BreadcrumbsViewModel @AssistedInject constructor(@Assisted initialState: B
|
||||||
// PRIVATE METHODS *****************************************************************************
|
// PRIVATE METHODS *****************************************************************************
|
||||||
|
|
||||||
private fun observeBreadcrumbs() {
|
private fun observeBreadcrumbs() {
|
||||||
session.flow()
|
session.getBreadcrumbsLive(roomSummaryQueryParams {
|
||||||
.liveBreadcrumbs(roomSummaryQueryParams {
|
|
||||||
displayName = QueryStringValue.NoCondition
|
displayName = QueryStringValue.NoCondition
|
||||||
memberships = listOf(Membership.JOIN)
|
memberships = listOf(Membership.JOIN)
|
||||||
})
|
})
|
||||||
|
.asFlow()
|
||||||
.execute { asyncBreadcrumbs ->
|
.execute { asyncBreadcrumbs ->
|
||||||
copy(asyncBreadcrumbs = asyncBreadcrumbs)
|
copy(asyncBreadcrumbs = asyncBreadcrumbs)
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,6 +37,7 @@ import im.vector.app.core.extensions.exhaustive
|
||||||
import im.vector.app.core.mvrx.runCatchingToAsync
|
import im.vector.app.core.mvrx.runCatchingToAsync
|
||||||
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.core.utils.unwrap
|
||||||
import im.vector.app.features.attachments.toContentAttachmentData
|
import im.vector.app.features.attachments.toContentAttachmentData
|
||||||
import im.vector.app.features.call.conference.ConferenceEvent
|
import im.vector.app.features.call.conference.ConferenceEvent
|
||||||
import im.vector.app.features.call.conference.JitsiActiveConferenceHolder
|
import im.vector.app.features.call.conference.JitsiActiveConferenceHolder
|
||||||
|
@ -108,8 +109,6 @@ import org.matrix.android.sdk.api.session.room.timeline.getTextEditableContent
|
||||||
import org.matrix.android.sdk.api.session.space.CreateSpaceParams
|
import org.matrix.android.sdk.api.session.space.CreateSpaceParams
|
||||||
import org.matrix.android.sdk.api.session.widgets.model.WidgetType
|
import org.matrix.android.sdk.api.session.widgets.model.WidgetType
|
||||||
import org.matrix.android.sdk.api.util.toOptional
|
import org.matrix.android.sdk.api.util.toOptional
|
||||||
import org.matrix.android.sdk.flow.flow
|
|
||||||
import org.matrix.android.sdk.flow.unwrap
|
|
||||||
import org.matrix.android.sdk.internal.crypto.model.event.WithHeldCode
|
import org.matrix.android.sdk.internal.crypto.model.event.WithHeldCode
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
import java.util.concurrent.TimeUnit
|
import java.util.concurrent.TimeUnit
|
||||||
|
@ -254,11 +253,12 @@ class RoomDetailViewModel @AssistedInject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun observeActiveRoomWidgets() {
|
private fun observeActiveRoomWidgets() {
|
||||||
session.flow()
|
session.widgetService()
|
||||||
.liveRoomWidgets(
|
.getRoomWidgetsLive(
|
||||||
roomId = initialState.roomId,
|
roomId = initialState.roomId,
|
||||||
widgetId = QueryStringValue.NoCondition
|
widgetId = QueryStringValue.NoCondition
|
||||||
)
|
)
|
||||||
|
.asFlow()
|
||||||
.map { widgets ->
|
.map { widgets ->
|
||||||
widgets.filter { it.isActive }
|
widgets.filter { it.isActive }
|
||||||
}
|
}
|
||||||
|
@ -287,8 +287,9 @@ class RoomDetailViewModel @AssistedInject constructor(
|
||||||
val queryParams = roomMemberQueryParams {
|
val queryParams = roomMemberQueryParams {
|
||||||
this.userId = QueryStringValue.Equals(session.myUserId, QueryStringValue.Case.SENSITIVE)
|
this.userId = QueryStringValue.Equals(session.myUserId, QueryStringValue.Case.SENSITIVE)
|
||||||
}
|
}
|
||||||
room.flow()
|
room
|
||||||
.liveRoomMembers(queryParams)
|
.getRoomMembersLive(queryParams)
|
||||||
|
.asFlow()
|
||||||
.map {
|
.map {
|
||||||
it.firstOrNull().toOptional()
|
it.firstOrNull().toOptional()
|
||||||
}
|
}
|
||||||
|
@ -1505,8 +1506,8 @@ class RoomDetailViewModel @AssistedInject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun observeSyncState() {
|
private fun observeSyncState() {
|
||||||
session.flow()
|
session.getSyncStateLive()
|
||||||
.liveSyncState()
|
.asFlow()
|
||||||
.setOnEach { syncState ->
|
.setOnEach { syncState ->
|
||||||
copy(syncState = syncState)
|
copy(syncState = syncState)
|
||||||
}
|
}
|
||||||
|
@ -1520,7 +1521,8 @@ class RoomDetailViewModel @AssistedInject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun observeRoomSummary() {
|
private fun observeRoomSummary() {
|
||||||
room.flow().liveRoomSummary()
|
room.getRoomSummaryLive()
|
||||||
|
.asFlow()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.execute { async ->
|
.execute { async ->
|
||||||
copy(
|
copy(
|
||||||
|
@ -1532,7 +1534,7 @@ class RoomDetailViewModel @AssistedInject constructor(
|
||||||
private fun getUnreadState() {
|
private fun getUnreadState() {
|
||||||
combine(
|
combine(
|
||||||
timelineEvents,
|
timelineEvents,
|
||||||
room.flow().liveRoomSummary().unwrap()
|
room.getRoomSummaryLive().asFlow().unwrap()
|
||||||
) { timelineEvents, roomSummary ->
|
) { timelineEvents, roomSummary ->
|
||||||
computeUnreadState(timelineEvents, roomSummary)
|
computeUnreadState(timelineEvents, roomSummary)
|
||||||
}
|
}
|
||||||
|
@ -1579,8 +1581,8 @@ class RoomDetailViewModel @AssistedInject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun observeMembershipChanges() {
|
private fun observeMembershipChanges() {
|
||||||
session.flow()
|
session.getChangeMembershipsLive()
|
||||||
.liveRoomChangeMembershipState()
|
.asFlow()
|
||||||
.map {
|
.map {
|
||||||
it[initialState.roomId] ?: ChangeMembershipState.Unknown
|
it[initialState.roomId] ?: ChangeMembershipState.Unknown
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
*/
|
*/
|
||||||
package im.vector.app.features.home.room.detail.timeline.action
|
package im.vector.app.features.home.room.detail.timeline.action
|
||||||
|
|
||||||
|
import androidx.lifecycle.asFlow
|
||||||
import com.airbnb.mvrx.FragmentViewModelContext
|
import com.airbnb.mvrx.FragmentViewModelContext
|
||||||
import com.airbnb.mvrx.MavericksViewModelFactory
|
import com.airbnb.mvrx.MavericksViewModelFactory
|
||||||
import com.airbnb.mvrx.ViewModelContext
|
import com.airbnb.mvrx.ViewModelContext
|
||||||
|
@ -28,6 +29,7 @@ import im.vector.app.core.extensions.canReact
|
||||||
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.core.resources.StringProvider
|
import im.vector.app.core.resources.StringProvider
|
||||||
|
import im.vector.app.core.utils.unwrap
|
||||||
import im.vector.app.features.home.room.detail.timeline.format.NoticeEventFormatter
|
import im.vector.app.features.home.room.detail.timeline.format.NoticeEventFormatter
|
||||||
import im.vector.app.features.html.EventHtmlRenderer
|
import im.vector.app.features.html.EventHtmlRenderer
|
||||||
import im.vector.app.features.html.PillsPostProcessor
|
import im.vector.app.features.html.PillsPostProcessor
|
||||||
|
@ -58,8 +60,6 @@ import org.matrix.android.sdk.api.session.room.send.SendState
|
||||||
import org.matrix.android.sdk.api.session.room.timeline.TimelineEvent
|
import org.matrix.android.sdk.api.session.room.timeline.TimelineEvent
|
||||||
import org.matrix.android.sdk.api.session.room.timeline.getLastMessageContent
|
import org.matrix.android.sdk.api.session.room.timeline.getLastMessageContent
|
||||||
import org.matrix.android.sdk.api.session.room.timeline.hasBeenEdited
|
import org.matrix.android.sdk.api.session.room.timeline.hasBeenEdited
|
||||||
import org.matrix.android.sdk.flow.flow
|
|
||||||
import org.matrix.android.sdk.flow.unwrap
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Information related to an event and used to display preview in contextual bottom sheet.
|
* Information related to an event and used to display preview in contextual bottom sheet.
|
||||||
|
@ -137,8 +137,8 @@ class MessageActionsViewModel @AssistedInject constructor(@Assisted
|
||||||
|
|
||||||
private fun observeEvent() {
|
private fun observeEvent() {
|
||||||
if (room == null) return
|
if (room == null) return
|
||||||
room.flow()
|
room.getTimeLineEventLive(initialState.eventId)
|
||||||
.liveTimelineEvent(initialState.eventId)
|
.asFlow()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.execute {
|
.execute {
|
||||||
copy(timelineEvent = it)
|
copy(timelineEvent = it)
|
||||||
|
@ -149,8 +149,8 @@ class MessageActionsViewModel @AssistedInject constructor(@Assisted
|
||||||
if (room == null) return
|
if (room == null) return
|
||||||
eventIdFlow
|
eventIdFlow
|
||||||
.flatMapLatest { eventId ->
|
.flatMapLatest { eventId ->
|
||||||
room.flow()
|
room.getEventAnnotationsSummaryLive(eventId)
|
||||||
.liveAnnotationSummary(eventId)
|
.asFlow()
|
||||||
.map { annotations ->
|
.map { annotations ->
|
||||||
EmojiDataSource.quickEmojis.map { emoji ->
|
EmojiDataSource.quickEmojis.map { emoji ->
|
||||||
ToggleState(emoji, annotations.getOrNull()?.reactionsSummary?.firstOrNull { it.key == emoji }?.addedByMe ?: false)
|
ToggleState(emoji, annotations.getOrNull()?.reactionsSummary?.firstOrNull { it.key == emoji }?.addedByMe ?: false)
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
package im.vector.app.features.home.room.list
|
package im.vector.app.features.home.room.list
|
||||||
|
|
||||||
import androidx.lifecycle.MutableLiveData
|
import androidx.lifecycle.MutableLiveData
|
||||||
|
import androidx.lifecycle.asFlow
|
||||||
import com.airbnb.mvrx.Async
|
import com.airbnb.mvrx.Async
|
||||||
import com.airbnb.mvrx.Fail
|
import com.airbnb.mvrx.Fail
|
||||||
import com.airbnb.mvrx.FragmentViewModelContext
|
import com.airbnb.mvrx.FragmentViewModelContext
|
||||||
|
@ -42,7 +43,6 @@ import org.matrix.android.sdk.api.session.room.UpdatableLivePageResult
|
||||||
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.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.api.session.room.state.isPublic
|
||||||
import org.matrix.android.sdk.flow.flow
|
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
@ -95,7 +95,8 @@ class RoomListViewModel @Inject constructor(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
session.flow().liveUser(session.myUserId)
|
session.getUserLive(session.myUserId)
|
||||||
|
.asFlow()
|
||||||
.map { it.getOrNull()?.getBestName() }
|
.map { it.getOrNull()?.getBestName() }
|
||||||
.distinctUntilChanged()
|
.distinctUntilChanged()
|
||||||
.execute {
|
.execute {
|
||||||
|
@ -106,8 +107,8 @@ class RoomListViewModel @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun observeMembershipChanges() {
|
private fun observeMembershipChanges() {
|
||||||
session.flow()
|
session.getChangeMembershipsLive()
|
||||||
.liveRoomChangeMembershipState()
|
.asFlow()
|
||||||
.setOnEach {
|
.setOnEach {
|
||||||
copy(roomMembershipChanges = it)
|
copy(roomMembershipChanges = it)
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
|
|
||||||
package im.vector.app.features.invite
|
package im.vector.app.features.invite
|
||||||
|
|
||||||
|
import androidx.lifecycle.asFlow
|
||||||
import im.vector.app.ActiveSessionDataSource
|
import im.vector.app.ActiveSessionDataSource
|
||||||
import im.vector.app.features.session.coroutineScope
|
import im.vector.app.features.session.coroutineScope
|
||||||
import io.reactivex.disposables.Disposable
|
import io.reactivex.disposables.Disposable
|
||||||
|
@ -35,7 +36,6 @@ 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.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.api.session.room.roomSummaryQueryParams
|
import org.matrix.android.sdk.api.session.room.roomSummaryQueryParams
|
||||||
import org.matrix.android.sdk.flow.flow
|
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import javax.inject.Singleton
|
import javax.inject.Singleton
|
||||||
|
@ -82,10 +82,9 @@ class InvitesAcceptor @Inject constructor(
|
||||||
val roomQueryParams = roomSummaryQueryParams {
|
val roomQueryParams = roomSummaryQueryParams {
|
||||||
this.memberships = listOf(Membership.INVITE)
|
this.memberships = listOf(Membership.INVITE)
|
||||||
}
|
}
|
||||||
val flowSession = session.flow()
|
|
||||||
combine(
|
combine(
|
||||||
flowSession.liveRoomSummaries(roomQueryParams),
|
session.getRoomSummariesLive(roomQueryParams).asFlow(),
|
||||||
flowSession.liveRoomChangeMembershipState().debounce(1000)
|
session.getChangeMembershipsLive().asFlow().debounce(1000)
|
||||||
) { invitedRooms, _ -> invitedRooms.map { it.roomId } }
|
) { invitedRooms, _ -> invitedRooms.map { it.roomId } }
|
||||||
.filter { it.isNotEmpty() }
|
.filter { it.isNotEmpty() }
|
||||||
.onEach { invitedRoomIds ->
|
.onEach { invitedRoomIds ->
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
|
|
||||||
package im.vector.app.features.login2.created
|
package im.vector.app.features.login2.created
|
||||||
|
|
||||||
import androidx.lifecycle.viewModelScope
|
import androidx.lifecycle.asFlow
|
||||||
import com.airbnb.mvrx.FragmentViewModelContext
|
import com.airbnb.mvrx.FragmentViewModelContext
|
||||||
import com.airbnb.mvrx.MavericksViewModelFactory
|
import com.airbnb.mvrx.MavericksViewModelFactory
|
||||||
import com.airbnb.mvrx.ViewModelContext
|
import com.airbnb.mvrx.ViewModelContext
|
||||||
|
@ -24,13 +24,13 @@ import dagger.assisted.Assisted
|
||||||
import dagger.assisted.AssistedFactory
|
import dagger.assisted.AssistedFactory
|
||||||
import dagger.assisted.AssistedInject
|
import dagger.assisted.AssistedInject
|
||||||
import im.vector.app.core.platform.VectorViewModel
|
import im.vector.app.core.platform.VectorViewModel
|
||||||
|
import im.vector.app.core.utils.unwrap
|
||||||
|
import kotlinx.coroutines.flow.map
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import org.matrix.android.sdk.api.MatrixPatterns
|
import org.matrix.android.sdk.api.MatrixPatterns
|
||||||
import org.matrix.android.sdk.api.session.Session
|
import org.matrix.android.sdk.api.session.Session
|
||||||
import org.matrix.android.sdk.api.util.MatrixItem
|
import org.matrix.android.sdk.api.util.MatrixItem
|
||||||
import org.matrix.android.sdk.api.util.toMatrixItem
|
import org.matrix.android.sdk.api.util.toMatrixItem
|
||||||
import org.matrix.android.sdk.rx.rx
|
|
||||||
import org.matrix.android.sdk.rx.unwrap
|
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
|
|
||||||
class AccountCreatedViewModel @AssistedInject constructor(
|
class AccountCreatedViewModel @AssistedInject constructor(
|
||||||
|
@ -62,8 +62,8 @@ class AccountCreatedViewModel @AssistedInject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun observeUser() {
|
private fun observeUser() {
|
||||||
session.rx()
|
session.getUserLive(session.myUserId)
|
||||||
.liveUser(session.myUserId)
|
.asFlow()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.map {
|
.map {
|
||||||
if (MatrixPatterns.isUserId(it.userId)) {
|
if (MatrixPatterns.isUserId(it.userId)) {
|
||||||
|
|
|
@ -16,6 +16,9 @@
|
||||||
|
|
||||||
package im.vector.app.features.powerlevel
|
package im.vector.app.features.powerlevel
|
||||||
|
|
||||||
|
import androidx.lifecycle.asFlow
|
||||||
|
import im.vector.app.core.utils.mapOptional
|
||||||
|
import im.vector.app.core.utils.unwrap
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
import kotlinx.coroutines.flow.flowOn
|
import kotlinx.coroutines.flow.flowOn
|
||||||
|
@ -24,15 +27,13 @@ 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.events.model.toModel
|
||||||
import org.matrix.android.sdk.api.session.room.Room
|
import org.matrix.android.sdk.api.session.room.Room
|
||||||
import org.matrix.android.sdk.api.session.room.model.PowerLevelsContent
|
import org.matrix.android.sdk.api.session.room.model.PowerLevelsContent
|
||||||
import org.matrix.android.sdk.flow.flow
|
|
||||||
import org.matrix.android.sdk.flow.mapOptional
|
|
||||||
import org.matrix.android.sdk.flow.unwrap
|
|
||||||
|
|
||||||
class PowerLevelsFlowFactory(private val room: Room) {
|
class PowerLevelsFlowFactory(private val room: Room) {
|
||||||
|
|
||||||
fun createFlow(): Flow<PowerLevelsContent> {
|
fun createFlow(): Flow<PowerLevelsContent> {
|
||||||
return room.flow()
|
return room
|
||||||
.liveStateEvent(EventType.STATE_ROOM_POWER_LEVELS, QueryStringValue.NoCondition)
|
.getStateEventLive(EventType.STATE_ROOM_POWER_LEVELS, QueryStringValue.NoCondition)
|
||||||
|
.asFlow()
|
||||||
.flowOn(Dispatchers.Default)
|
.flowOn(Dispatchers.Default)
|
||||||
.mapOptional { it.content.toModel<PowerLevelsContent>() }
|
.mapOptional { it.content.toModel<PowerLevelsContent>() }
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
|
|
||||||
package im.vector.app.features.room
|
package im.vector.app.features.room
|
||||||
|
|
||||||
|
import androidx.lifecycle.asFlow
|
||||||
import com.airbnb.mvrx.ActivityViewModelContext
|
import com.airbnb.mvrx.ActivityViewModelContext
|
||||||
import com.airbnb.mvrx.FragmentViewModelContext
|
import com.airbnb.mvrx.FragmentViewModelContext
|
||||||
import com.airbnb.mvrx.MavericksViewModelFactory
|
import com.airbnb.mvrx.MavericksViewModelFactory
|
||||||
|
@ -27,6 +28,7 @@ import im.vector.app.R
|
||||||
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.core.utils.unwrap
|
||||||
import io.reactivex.Observable
|
import io.reactivex.Observable
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
@ -47,8 +49,6 @@ import org.matrix.android.sdk.api.session.room.Room
|
||||||
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.util.Optional
|
import org.matrix.android.sdk.api.util.Optional
|
||||||
import org.matrix.android.sdk.flow.flow
|
|
||||||
import org.matrix.android.sdk.flow.unwrap
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This ViewModel observe a room summary and notify when the room is left
|
* This ViewModel observe a room summary and notify when the room is left
|
||||||
|
@ -90,8 +90,8 @@ class RequireActiveMembershipViewModel @AssistedInject constructor(
|
||||||
val emptyResult = Optional.empty<RequireActiveMembershipViewEvents.RoomLeft>()
|
val emptyResult = Optional.empty<RequireActiveMembershipViewEvents.RoomLeft>()
|
||||||
emit(emptyResult)
|
emit(emptyResult)
|
||||||
}
|
}
|
||||||
room.flow()
|
room.getRoomSummaryLive()
|
||||||
.liveRoomSummary()
|
.asFlow()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.flowOn(Dispatchers.Default)
|
.flowOn(Dispatchers.Default)
|
||||||
.map { mapToLeftViewEvent(room, it) }
|
.map { mapToLeftViewEvent(room, it) }
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
|
|
||||||
package im.vector.app.features.roomdirectory
|
package im.vector.app.features.roomdirectory
|
||||||
|
|
||||||
|
import androidx.lifecycle.asFlow
|
||||||
import com.airbnb.mvrx.ActivityViewModelContext
|
import com.airbnb.mvrx.ActivityViewModelContext
|
||||||
import com.airbnb.mvrx.Fail
|
import com.airbnb.mvrx.Fail
|
||||||
import com.airbnb.mvrx.Loading
|
import com.airbnb.mvrx.Loading
|
||||||
|
@ -38,7 +39,6 @@ import org.matrix.android.sdk.api.session.room.model.Membership
|
||||||
import org.matrix.android.sdk.api.session.room.model.roomdirectory.PublicRoomsFilter
|
import org.matrix.android.sdk.api.session.room.model.roomdirectory.PublicRoomsFilter
|
||||||
import org.matrix.android.sdk.api.session.room.model.roomdirectory.PublicRoomsParams
|
import org.matrix.android.sdk.api.session.room.model.roomdirectory.PublicRoomsParams
|
||||||
import org.matrix.android.sdk.api.session.room.roomSummaryQueryParams
|
import org.matrix.android.sdk.api.session.room.roomSummaryQueryParams
|
||||||
import org.matrix.android.sdk.flow.flow
|
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
|
|
||||||
class RoomDirectoryViewModel @AssistedInject constructor(
|
class RoomDirectoryViewModel @AssistedInject constructor(
|
||||||
|
@ -80,8 +80,8 @@ class RoomDirectoryViewModel @AssistedInject constructor(
|
||||||
memberships = listOf(Membership.JOIN)
|
memberships = listOf(Membership.JOIN)
|
||||||
}
|
}
|
||||||
session
|
session
|
||||||
.flow()
|
.getRoomSummariesLive(queryParams)
|
||||||
.liveRoomSummaries(queryParams)
|
.asFlow()
|
||||||
.map { roomSummaries ->
|
.map { roomSummaries ->
|
||||||
roomSummaries
|
roomSummaries
|
||||||
.map { it.roomId }
|
.map { it.roomId }
|
||||||
|
@ -93,8 +93,8 @@ class RoomDirectoryViewModel @AssistedInject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun observeMembershipChanges() {
|
private fun observeMembershipChanges() {
|
||||||
session.flow()
|
session.getChangeMembershipsLive()
|
||||||
.liveRoomChangeMembershipState()
|
.asFlow()
|
||||||
.setOnEach {
|
.setOnEach {
|
||||||
copy(changeMembershipStates = it)
|
copy(changeMembershipStates = it)
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
|
|
||||||
package im.vector.app.features.roomdirectory.roompreview
|
package im.vector.app.features.roomdirectory.roompreview
|
||||||
|
|
||||||
|
import androidx.lifecycle.asFlow
|
||||||
import androidx.lifecycle.viewModelScope
|
import androidx.lifecycle.viewModelScope
|
||||||
import com.airbnb.mvrx.FragmentViewModelContext
|
import com.airbnb.mvrx.FragmentViewModelContext
|
||||||
import com.airbnb.mvrx.Loading
|
import com.airbnb.mvrx.Loading
|
||||||
|
@ -42,8 +43,6 @@ 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.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.flow.flow
|
|
||||||
import org.matrix.android.sdk.rx.rx
|
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
|
|
||||||
class RoomPreviewViewModel @AssistedInject constructor(@Assisted private val initialState: RoomPreviewViewState,
|
class RoomPreviewViewModel @AssistedInject constructor(@Assisted private val initialState: RoomPreviewViewState,
|
||||||
|
@ -168,8 +167,8 @@ class RoomPreviewViewModel @AssistedInject constructor(@Assisted private val ini
|
||||||
excludeType = null
|
excludeType = null
|
||||||
}
|
}
|
||||||
session
|
session
|
||||||
.flow()
|
.getRoomSummariesLive(queryParams)
|
||||||
.liveRoomSummaries(queryParams)
|
.asFlow()
|
||||||
.onEach { list ->
|
.onEach { list ->
|
||||||
val isRoomJoined = list.any {
|
val isRoomJoined = list.any {
|
||||||
it.membership == Membership.JOIN
|
it.membership == Membership.JOIN
|
||||||
|
@ -187,8 +186,8 @@ class RoomPreviewViewModel @AssistedInject constructor(@Assisted private val ini
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun observeMembershipChanges() {
|
private fun observeMembershipChanges() {
|
||||||
session.flow()
|
session.getChangeMembershipsLive()
|
||||||
.liveRoomChangeMembershipState()
|
.asFlow()
|
||||||
.onEach {
|
.onEach {
|
||||||
val changeMembership = it[initialState.roomId] ?: ChangeMembershipState.Unknown
|
val changeMembership = it[initialState.roomId] ?: ChangeMembershipState.Unknown
|
||||||
val joinState = when (changeMembership) {
|
val joinState = when (changeMembership) {
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
|
|
||||||
package im.vector.app.features.roommemberprofile
|
package im.vector.app.features.roommemberprofile
|
||||||
|
|
||||||
|
import androidx.lifecycle.asFlow
|
||||||
import com.airbnb.mvrx.Fail
|
import com.airbnb.mvrx.Fail
|
||||||
import com.airbnb.mvrx.FragmentViewModelContext
|
import com.airbnb.mvrx.FragmentViewModelContext
|
||||||
import com.airbnb.mvrx.Loading
|
import com.airbnb.mvrx.Loading
|
||||||
|
@ -31,6 +32,7 @@ import im.vector.app.R
|
||||||
import im.vector.app.core.mvrx.runCatchingToAsync
|
import im.vector.app.core.mvrx.runCatchingToAsync
|
||||||
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.core.utils.unwrap
|
||||||
import im.vector.app.features.powerlevel.PowerLevelsFlowFactory
|
import im.vector.app.features.powerlevel.PowerLevelsFlowFactory
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.flow.combine
|
import kotlinx.coroutines.flow.combine
|
||||||
|
@ -53,8 +55,6 @@ import org.matrix.android.sdk.api.session.room.powerlevels.Role
|
||||||
import org.matrix.android.sdk.api.util.MatrixItem
|
import org.matrix.android.sdk.api.util.MatrixItem
|
||||||
import org.matrix.android.sdk.api.util.toMatrixItem
|
import org.matrix.android.sdk.api.util.toMatrixItem
|
||||||
import org.matrix.android.sdk.api.util.toOptional
|
import org.matrix.android.sdk.api.util.toOptional
|
||||||
import org.matrix.android.sdk.flow.flow
|
|
||||||
import org.matrix.android.sdk.flow.unwrap
|
|
||||||
|
|
||||||
class RoomMemberProfileViewModel @AssistedInject constructor(@Assisted private val initialState: RoomMemberProfileViewState,
|
class RoomMemberProfileViewModel @AssistedInject constructor(@Assisted private val initialState: RoomMemberProfileViewState,
|
||||||
private val stringProvider: StringProvider,
|
private val stringProvider: StringProvider,
|
||||||
|
@ -107,7 +107,7 @@ class RoomMemberProfileViewModel @AssistedInject constructor(@Assisted private v
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
session.flow().liveUserCryptoDevices(initialState.userId)
|
session.cryptoService().getLiveCryptoDeviceInfo(initialState.userId).asFlow()
|
||||||
.map {
|
.map {
|
||||||
Pair(
|
Pair(
|
||||||
it.fold(true, { prev, dev -> prev && dev.isVerified }),
|
it.fold(true, { prev, dev -> prev && dev.isVerified }),
|
||||||
|
@ -121,14 +121,14 @@ class RoomMemberProfileViewModel @AssistedInject constructor(@Assisted private v
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
session.flow().liveCrossSigningInfo(initialState.userId)
|
session.cryptoService().crossSigningService().getLiveCrossSigningKeys(initialState.userId).asFlow()
|
||||||
.execute {
|
.execute {
|
||||||
copy(userMXCrossSigningInfo = it.invoke()?.getOrNull())
|
copy(userMXCrossSigningInfo = it.invoke()?.getOrNull())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun observeIgnoredState() {
|
private fun observeIgnoredState() {
|
||||||
session.flow().liveIgnoredUsers()
|
session.getIgnoredUsersLive().asFlow()
|
||||||
.map { ignored ->
|
.map { ignored ->
|
||||||
ignored.find {
|
ignored.find {
|
||||||
it.userId == initialState.userId
|
it.userId == initialState.userId
|
||||||
|
@ -245,7 +245,7 @@ class RoomMemberProfileViewModel @AssistedInject constructor(@Assisted private v
|
||||||
val queryParams = roomMemberQueryParams {
|
val queryParams = roomMemberQueryParams {
|
||||||
this.userId = QueryStringValue.Equals(initialState.userId, QueryStringValue.Case.SENSITIVE)
|
this.userId = QueryStringValue.Equals(initialState.userId, QueryStringValue.Case.SENSITIVE)
|
||||||
}
|
}
|
||||||
room.flow().liveRoomMembers(queryParams)
|
room.getRoomMembersLive(queryParams).asFlow()
|
||||||
.map { it.firstOrNull().toOptional() }
|
.map { it.firstOrNull().toOptional() }
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.execute {
|
.execute {
|
||||||
|
@ -285,7 +285,7 @@ class RoomMemberProfileViewModel @AssistedInject constructor(@Assisted private v
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun observeRoomSummaryAndPowerLevels(room: Room) {
|
private fun observeRoomSummaryAndPowerLevels(room: Room) {
|
||||||
val roomSummaryLive = room.flow().liveRoomSummary().unwrap()
|
val roomSummaryLive = room.getRoomSummaryLive().asFlow().unwrap()
|
||||||
val powerLevelsContentLive = PowerLevelsFlowFactory(room).createFlow()
|
val powerLevelsContentLive = PowerLevelsFlowFactory(room).createFlow()
|
||||||
|
|
||||||
powerLevelsContentLive
|
powerLevelsContentLive
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
*/
|
*/
|
||||||
package im.vector.app.features.roommemberprofile.devices
|
package im.vector.app.features.roommemberprofile.devices
|
||||||
|
|
||||||
|
import androidx.lifecycle.asFlow
|
||||||
import com.airbnb.mvrx.Async
|
import com.airbnb.mvrx.Async
|
||||||
import com.airbnb.mvrx.FragmentViewModelContext
|
import com.airbnb.mvrx.FragmentViewModelContext
|
||||||
import com.airbnb.mvrx.Loading
|
import com.airbnb.mvrx.Loading
|
||||||
|
@ -33,9 +34,7 @@ import org.matrix.android.sdk.api.session.crypto.crosssigning.MXCrossSigningInfo
|
||||||
import org.matrix.android.sdk.api.session.crypto.verification.VerificationMethod
|
import org.matrix.android.sdk.api.session.crypto.verification.VerificationMethod
|
||||||
import org.matrix.android.sdk.api.util.MatrixItem
|
import org.matrix.android.sdk.api.util.MatrixItem
|
||||||
import org.matrix.android.sdk.api.util.toMatrixItem
|
import org.matrix.android.sdk.api.util.toMatrixItem
|
||||||
import org.matrix.android.sdk.flow.flow
|
|
||||||
import org.matrix.android.sdk.internal.crypto.model.CryptoDeviceInfo
|
import org.matrix.android.sdk.internal.crypto.model.CryptoDeviceInfo
|
||||||
import org.matrix.android.sdk.rx.rx
|
|
||||||
|
|
||||||
data class DeviceListViewState(
|
data class DeviceListViewState(
|
||||||
val userItem: MatrixItem? = null,
|
val userItem: MatrixItem? = null,
|
||||||
|
@ -56,14 +55,17 @@ class DeviceListBottomSheetViewModel @AssistedInject constructor(@Assisted priva
|
||||||
}
|
}
|
||||||
|
|
||||||
init {
|
init {
|
||||||
session.flow().liveUserCryptoDevices(args.userId)
|
session.cryptoService().getLiveCryptoDeviceInfo(args.userId)
|
||||||
|
.asFlow()
|
||||||
.execute {
|
.execute {
|
||||||
copy(cryptoDevices = it).also {
|
copy(cryptoDevices = it).also {
|
||||||
refreshSelectedId()
|
refreshSelectedId()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
session.flow().liveCrossSigningInfo(args.userId)
|
session.cryptoService().crossSigningService()
|
||||||
|
.getLiveCrossSigningKeys(args.userId)
|
||||||
|
.asFlow()
|
||||||
.execute {
|
.execute {
|
||||||
copy(memberCrossSigningKey = it.invoke()?.getOrNull())
|
copy(memberCrossSigningKey = it.invoke()?.getOrNull())
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
|
|
||||||
package im.vector.app.features.roomprofile
|
package im.vector.app.features.roomprofile
|
||||||
|
|
||||||
|
import androidx.lifecycle.asFlow
|
||||||
import com.airbnb.mvrx.FragmentViewModelContext
|
import com.airbnb.mvrx.FragmentViewModelContext
|
||||||
import com.airbnb.mvrx.MavericksViewModelFactory
|
import com.airbnb.mvrx.MavericksViewModelFactory
|
||||||
import com.airbnb.mvrx.ViewModelContext
|
import com.airbnb.mvrx.ViewModelContext
|
||||||
|
@ -27,6 +28,8 @@ import im.vector.app.R
|
||||||
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.core.utils.mapOptional
|
||||||
|
import im.vector.app.core.utils.unwrap
|
||||||
import im.vector.app.features.home.ShortcutCreator
|
import im.vector.app.features.home.ShortcutCreator
|
||||||
import im.vector.app.features.powerlevel.PowerLevelsFlowFactory
|
import im.vector.app.features.powerlevel.PowerLevelsFlowFactory
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
@ -40,10 +43,6 @@ import org.matrix.android.sdk.api.session.room.model.Membership
|
||||||
import org.matrix.android.sdk.api.session.room.model.create.RoomCreateContent
|
import org.matrix.android.sdk.api.session.room.model.create.RoomCreateContent
|
||||||
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.api.session.room.state.isPublic
|
||||||
import org.matrix.android.sdk.flow.FlowRoom
|
|
||||||
import org.matrix.android.sdk.flow.flow
|
|
||||||
import org.matrix.android.sdk.flow.mapOptional
|
|
||||||
import org.matrix.android.sdk.flow.unwrap
|
|
||||||
|
|
||||||
class RoomProfileViewModel @AssistedInject constructor(
|
class RoomProfileViewModel @AssistedInject constructor(
|
||||||
@Assisted private val initialState: RoomProfileViewState,
|
@Assisted private val initialState: RoomProfileViewState,
|
||||||
|
@ -69,15 +68,14 @@ class RoomProfileViewModel @AssistedInject constructor(
|
||||||
private val room = session.getRoom(initialState.roomId)!!
|
private val room = session.getRoom(initialState.roomId)!!
|
||||||
|
|
||||||
init {
|
init {
|
||||||
val flowRoom = room.flow()
|
observeRoomSummary()
|
||||||
observeRoomSummary(flowRoom)
|
observeRoomCreateContent()
|
||||||
observeRoomCreateContent(flowRoom)
|
observeBannedRoomMembers()
|
||||||
observeBannedRoomMembers(flowRoom)
|
|
||||||
observePermissions()
|
observePermissions()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun observeRoomCreateContent(flowRoom: FlowRoom) {
|
private fun observeRoomCreateContent() {
|
||||||
flowRoom.liveStateEvent(EventType.STATE_ROOM_CREATE, QueryStringValue.NoCondition)
|
room.getStateEventLive(EventType.STATE_ROOM_CREATE, QueryStringValue.NoCondition).asFlow()
|
||||||
.mapOptional { it.content.toModel<RoomCreateContent>() }
|
.mapOptional { it.content.toModel<RoomCreateContent>() }
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.execute { async ->
|
.execute { async ->
|
||||||
|
@ -92,16 +90,16 @@ class RoomProfileViewModel @AssistedInject constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun observeRoomSummary(flowRoom: FlowRoom) {
|
private fun observeRoomSummary() {
|
||||||
flowRoom.liveRoomSummary()
|
room.getRoomSummaryLive().asFlow()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.execute {
|
.execute {
|
||||||
copy(roomSummary = it)
|
copy(roomSummary = it)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun observeBannedRoomMembers(flowRoom: FlowRoom) {
|
private fun observeBannedRoomMembers() {
|
||||||
flowRoom.liveRoomMembers(roomMemberQueryParams { memberships = listOf(Membership.BAN) })
|
room.getRoomMembersLive(roomMemberQueryParams { memberships = listOf(Membership.BAN) }).asFlow()
|
||||||
.execute {
|
.execute {
|
||||||
copy(bannedMembership = it)
|
copy(bannedMembership = it)
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
|
|
||||||
package im.vector.app.features.roomprofile.alias
|
package im.vector.app.features.roomprofile.alias
|
||||||
|
|
||||||
|
import androidx.lifecycle.asFlow
|
||||||
import com.airbnb.mvrx.Fail
|
import com.airbnb.mvrx.Fail
|
||||||
import com.airbnb.mvrx.FragmentViewModelContext
|
import com.airbnb.mvrx.FragmentViewModelContext
|
||||||
import com.airbnb.mvrx.Loading
|
import com.airbnb.mvrx.Loading
|
||||||
|
@ -28,6 +29,8 @@ import dagger.assisted.AssistedFactory
|
||||||
import dagger.assisted.AssistedInject
|
import dagger.assisted.AssistedInject
|
||||||
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.utils.mapOptional
|
||||||
|
import im.vector.app.core.utils.unwrap
|
||||||
import im.vector.app.features.powerlevel.PowerLevelsFlowFactory
|
import im.vector.app.features.powerlevel.PowerLevelsFlowFactory
|
||||||
import kotlinx.coroutines.flow.launchIn
|
import kotlinx.coroutines.flow.launchIn
|
||||||
import kotlinx.coroutines.flow.onEach
|
import kotlinx.coroutines.flow.onEach
|
||||||
|
@ -39,11 +42,6 @@ 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.events.model.toModel
|
||||||
import org.matrix.android.sdk.api.session.room.model.RoomCanonicalAliasContent
|
import org.matrix.android.sdk.api.session.room.model.RoomCanonicalAliasContent
|
||||||
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.flow.flow
|
|
||||||
import org.matrix.android.sdk.flow.mapOptional
|
|
||||||
import org.matrix.android.sdk.flow.unwrap
|
|
||||||
import org.matrix.android.sdk.rx.rx
|
|
||||||
import org.matrix.android.sdk.rx.unwrap
|
|
||||||
|
|
||||||
class RoomAliasViewModel @AssistedInject constructor(@Assisted initialState: RoomAliasViewState,
|
class RoomAliasViewModel @AssistedInject constructor(@Assisted initialState: RoomAliasViewState,
|
||||||
private val session: Session)
|
private val session: Session)
|
||||||
|
@ -131,7 +129,8 @@ class RoomAliasViewModel @AssistedInject constructor(@Assisted initialState: Roo
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun observeRoomSummary() {
|
private fun observeRoomSummary() {
|
||||||
room.flow().liveRoomSummary()
|
room.getRoomSummaryLive()
|
||||||
|
.asFlow()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.execute { async ->
|
.execute { async ->
|
||||||
copy(
|
copy(
|
||||||
|
@ -173,8 +172,8 @@ class RoomAliasViewModel @AssistedInject constructor(@Assisted initialState: Roo
|
||||||
* We do not want to use the fallback avatar url, which can be the other user avatar, or the current user avatar.
|
* We do not want to use the fallback avatar url, which can be the other user avatar, or the current user avatar.
|
||||||
*/
|
*/
|
||||||
private fun observeRoomCanonicalAlias() {
|
private fun observeRoomCanonicalAlias() {
|
||||||
room.flow()
|
room.getStateEventLive(EventType.STATE_ROOM_CANONICAL_ALIAS, QueryStringValue.NoCondition)
|
||||||
.liveStateEvent(EventType.STATE_ROOM_CANONICAL_ALIAS, QueryStringValue.NoCondition)
|
.asFlow()
|
||||||
.mapOptional { it.content.toModel<RoomCanonicalAliasContent>() }
|
.mapOptional { it.content.toModel<RoomCanonicalAliasContent>() }
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.setOnEach {
|
.setOnEach {
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
|
|
||||||
package im.vector.app.features.roomprofile.banned
|
package im.vector.app.features.roomprofile.banned
|
||||||
|
|
||||||
|
import androidx.lifecycle.asFlow
|
||||||
import com.airbnb.mvrx.FragmentViewModelContext
|
import com.airbnb.mvrx.FragmentViewModelContext
|
||||||
import com.airbnb.mvrx.MavericksViewModelFactory
|
import com.airbnb.mvrx.MavericksViewModelFactory
|
||||||
import com.airbnb.mvrx.ViewModelContext
|
import com.airbnb.mvrx.ViewModelContext
|
||||||
|
@ -26,6 +27,7 @@ import im.vector.app.R
|
||||||
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.core.utils.unwrap
|
||||||
import im.vector.app.features.powerlevel.PowerLevelsFlowFactory
|
import im.vector.app.features.powerlevel.PowerLevelsFlowFactory
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
@ -38,10 +40,6 @@ import org.matrix.android.sdk.api.session.room.model.Membership
|
||||||
import org.matrix.android.sdk.api.session.room.model.RoomMemberContent
|
import org.matrix.android.sdk.api.session.room.model.RoomMemberContent
|
||||||
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.powerlevels.PowerLevelsHelper
|
import org.matrix.android.sdk.api.session.room.powerlevels.PowerLevelsHelper
|
||||||
import org.matrix.android.sdk.flow.flow
|
|
||||||
import org.matrix.android.sdk.flow.unwrap
|
|
||||||
import org.matrix.android.sdk.rx.rx
|
|
||||||
import org.matrix.android.sdk.rx.unwrap
|
|
||||||
|
|
||||||
class RoomBannedMemberListViewModel @AssistedInject constructor(@Assisted initialState: RoomBannedMemberListViewState,
|
class RoomBannedMemberListViewModel @AssistedInject constructor(@Assisted initialState: RoomBannedMemberListViewState,
|
||||||
private val stringProvider: StringProvider,
|
private val stringProvider: StringProvider,
|
||||||
|
@ -57,13 +55,15 @@ class RoomBannedMemberListViewModel @AssistedInject constructor(@Assisted initia
|
||||||
|
|
||||||
init {
|
init {
|
||||||
|
|
||||||
room.flow().liveRoomSummary()
|
room.getRoomSummaryLive()
|
||||||
|
.asFlow()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.execute { async ->
|
.execute { async ->
|
||||||
copy(roomSummary = async)
|
copy(roomSummary = async)
|
||||||
}
|
}
|
||||||
|
|
||||||
room.flow().liveRoomMembers(roomMemberQueryParams { memberships = listOf(Membership.BAN) })
|
room.getRoomMembersLive(roomMemberQueryParams { memberships = listOf(Membership.BAN) })
|
||||||
|
.asFlow()
|
||||||
.execute {
|
.execute {
|
||||||
copy(
|
copy(
|
||||||
bannedMemberSummaries = it
|
bannedMemberSummaries = it
|
||||||
|
|
|
@ -27,6 +27,8 @@ import dagger.assisted.AssistedInject
|
||||||
import im.vector.app.core.extensions.exhaustive
|
import im.vector.app.core.extensions.exhaustive
|
||||||
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.core.utils.mapOptional
|
||||||
|
import im.vector.app.core.utils.unwrap
|
||||||
import im.vector.app.features.powerlevel.PowerLevelsFlowFactory
|
import im.vector.app.features.powerlevel.PowerLevelsFlowFactory
|
||||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
@ -51,9 +53,6 @@ import org.matrix.android.sdk.api.session.room.model.PowerLevelsContent
|
||||||
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.powerlevels.PowerLevelsHelper
|
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.session.room.powerlevels.Role
|
||||||
import org.matrix.android.sdk.flow.flow
|
|
||||||
import org.matrix.android.sdk.flow.mapOptional
|
|
||||||
import org.matrix.android.sdk.flow.unwrap
|
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
|
|
||||||
class RoomMemberListViewModel @AssistedInject constructor(@Assisted initialState: RoomMemberListViewState,
|
class RoomMemberListViewModel @AssistedInject constructor(@Assisted initialState: RoomMemberListViewState,
|
||||||
|
@ -94,9 +93,9 @@ class RoomMemberListViewModel @AssistedInject constructor(@Assisted initialState
|
||||||
}
|
}
|
||||||
|
|
||||||
combine(
|
combine(
|
||||||
room.flow().liveRoomMembers(roomMemberQueryParams),
|
room.getRoomMembersLive(roomMemberQueryParams).asFlow(),
|
||||||
room.flow()
|
room.getStateEventLive(EventType.STATE_ROOM_POWER_LEVELS, QueryStringValue.NoCondition)
|
||||||
.liveStateEvent(EventType.STATE_ROOM_POWER_LEVELS, QueryStringValue.NoCondition)
|
.asFlow()
|
||||||
.mapOptional { it.content.toModel<PowerLevelsContent>() }
|
.mapOptional { it.content.toModel<PowerLevelsContent>() }
|
||||||
.unwrap()
|
.unwrap()
|
||||||
)
|
)
|
||||||
|
@ -109,7 +108,8 @@ class RoomMemberListViewModel @AssistedInject constructor(@Assisted initialState
|
||||||
}
|
}
|
||||||
|
|
||||||
if (room.isEncrypted()) {
|
if (room.isEncrypted()) {
|
||||||
room.flow().liveRoomMembers(roomMemberQueryParams)
|
room.getRoomMembersLive(roomMemberQueryParams)
|
||||||
|
.asFlow()
|
||||||
.flowOn(Dispatchers.Main)
|
.flowOn(Dispatchers.Main)
|
||||||
.flatMapLatest { membersSummary ->
|
.flatMapLatest { membersSummary ->
|
||||||
session.cryptoService().getLiveCryptoDeviceInfo(membersSummary.map { it.userId })
|
session.cryptoService().getLiveCryptoDeviceInfo(membersSummary.map { it.userId })
|
||||||
|
@ -153,7 +153,8 @@ class RoomMemberListViewModel @AssistedInject constructor(@Assisted initialState
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun observeRoomSummary() {
|
private fun observeRoomSummary() {
|
||||||
room.flow().liveRoomSummary()
|
room.getRoomSummaryLive()
|
||||||
|
.asFlow()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.execute { async ->
|
.execute { async ->
|
||||||
copy(roomSummary = async)
|
copy(roomSummary = async)
|
||||||
|
@ -161,7 +162,8 @@ class RoomMemberListViewModel @AssistedInject constructor(@Assisted initialState
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun observeThirdPartyInvites() {
|
private fun observeThirdPartyInvites() {
|
||||||
room.flow().liveStateEvents(setOf(EventType.STATE_ROOM_THIRD_PARTY_INVITE))
|
room.getStateEventsLive(setOf(EventType.STATE_ROOM_THIRD_PARTY_INVITE))
|
||||||
|
.asFlow()
|
||||||
.execute { async ->
|
.execute { async ->
|
||||||
copy(threePidInvites = async)
|
copy(threePidInvites = async)
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
|
|
||||||
package im.vector.app.features.roomprofile.notifications
|
package im.vector.app.features.roomprofile.notifications
|
||||||
|
|
||||||
import androidx.lifecycle.viewModelScope
|
import androidx.lifecycle.asFlow
|
||||||
import com.airbnb.mvrx.FragmentViewModelContext
|
import com.airbnb.mvrx.FragmentViewModelContext
|
||||||
import com.airbnb.mvrx.MavericksViewModelFactory
|
import com.airbnb.mvrx.MavericksViewModelFactory
|
||||||
import com.airbnb.mvrx.Success
|
import com.airbnb.mvrx.Success
|
||||||
|
@ -25,13 +25,10 @@ import dagger.assisted.Assisted
|
||||||
import dagger.assisted.AssistedFactory
|
import dagger.assisted.AssistedFactory
|
||||||
import dagger.assisted.AssistedInject
|
import dagger.assisted.AssistedInject
|
||||||
import im.vector.app.core.platform.VectorViewModel
|
import im.vector.app.core.platform.VectorViewModel
|
||||||
|
import im.vector.app.core.utils.unwrap
|
||||||
import im.vector.app.features.home.room.list.actions.RoomListQuickActionsBottomSheet
|
import im.vector.app.features.home.room.list.actions.RoomListQuickActionsBottomSheet
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import org.matrix.android.sdk.api.session.Session
|
import org.matrix.android.sdk.api.session.Session
|
||||||
import org.matrix.android.sdk.flow.flow
|
|
||||||
import org.matrix.android.sdk.flow.unwrap
|
|
||||||
import org.matrix.android.sdk.rx.rx
|
|
||||||
import org.matrix.android.sdk.rx.unwrap
|
|
||||||
|
|
||||||
class RoomNotificationSettingsViewModel @AssistedInject constructor(
|
class RoomNotificationSettingsViewModel @AssistedInject constructor(
|
||||||
@Assisted initialState: RoomNotificationSettingsViewState,
|
@Assisted initialState: RoomNotificationSettingsViewState,
|
||||||
|
@ -66,7 +63,8 @@ class RoomNotificationSettingsViewModel @AssistedInject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun observeSummary() {
|
private fun observeSummary() {
|
||||||
room.flow().liveRoomSummary()
|
room.getRoomSummaryLive()
|
||||||
|
.asFlow()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.execute { async ->
|
.execute { async ->
|
||||||
copy(roomSummary = async)
|
copy(roomSummary = async)
|
||||||
|
@ -74,8 +72,8 @@ class RoomNotificationSettingsViewModel @AssistedInject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun observeNotificationState() {
|
private fun observeNotificationState() {
|
||||||
room.rx()
|
room.getLiveRoomNotificationState()
|
||||||
.liveNotificationState()
|
.asFlow()
|
||||||
.execute {
|
.execute {
|
||||||
copy(notificationState = it)
|
copy(notificationState = it)
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
|
|
||||||
package im.vector.app.features.roomprofile.permissions
|
package im.vector.app.features.roomprofile.permissions
|
||||||
|
|
||||||
|
import androidx.lifecycle.asFlow
|
||||||
import com.airbnb.mvrx.FragmentViewModelContext
|
import com.airbnb.mvrx.FragmentViewModelContext
|
||||||
import com.airbnb.mvrx.MavericksViewModelFactory
|
import com.airbnb.mvrx.MavericksViewModelFactory
|
||||||
import com.airbnb.mvrx.Success
|
import com.airbnb.mvrx.Success
|
||||||
|
@ -25,6 +26,7 @@ import dagger.assisted.AssistedFactory
|
||||||
import dagger.assisted.AssistedInject
|
import dagger.assisted.AssistedInject
|
||||||
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.utils.unwrap
|
||||||
import im.vector.app.features.powerlevel.PowerLevelsFlowFactory
|
import im.vector.app.features.powerlevel.PowerLevelsFlowFactory
|
||||||
import kotlinx.coroutines.flow.launchIn
|
import kotlinx.coroutines.flow.launchIn
|
||||||
import kotlinx.coroutines.flow.onEach
|
import kotlinx.coroutines.flow.onEach
|
||||||
|
@ -34,8 +36,6 @@ import org.matrix.android.sdk.api.session.events.model.EventType
|
||||||
import org.matrix.android.sdk.api.session.events.model.toContent
|
import org.matrix.android.sdk.api.session.events.model.toContent
|
||||||
import org.matrix.android.sdk.api.session.room.model.PowerLevelsContent
|
import org.matrix.android.sdk.api.session.room.model.PowerLevelsContent
|
||||||
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.flow.flow
|
|
||||||
import org.matrix.android.sdk.flow.unwrap
|
|
||||||
|
|
||||||
class RoomPermissionsViewModel @AssistedInject constructor(@Assisted initialState: RoomPermissionsViewState,
|
class RoomPermissionsViewModel @AssistedInject constructor(@Assisted initialState: RoomPermissionsViewState,
|
||||||
private val session: Session)
|
private val session: Session)
|
||||||
|
@ -63,7 +63,8 @@ class RoomPermissionsViewModel @AssistedInject constructor(@Assisted initialStat
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun observeRoomSummary() {
|
private fun observeRoomSummary() {
|
||||||
room.flow().liveRoomSummary()
|
room.getRoomSummaryLive()
|
||||||
|
.asFlow()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.execute { async ->
|
.execute { async ->
|
||||||
copy(
|
copy(
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
package im.vector.app.features.roomprofile.settings
|
package im.vector.app.features.roomprofile.settings
|
||||||
|
|
||||||
import androidx.core.net.toFile
|
import androidx.core.net.toFile
|
||||||
|
import androidx.lifecycle.asFlow
|
||||||
import com.airbnb.mvrx.ActivityViewModelContext
|
import com.airbnb.mvrx.ActivityViewModelContext
|
||||||
import com.airbnb.mvrx.FragmentViewModelContext
|
import com.airbnb.mvrx.FragmentViewModelContext
|
||||||
import com.airbnb.mvrx.MavericksViewModelFactory
|
import com.airbnb.mvrx.MavericksViewModelFactory
|
||||||
|
@ -26,6 +27,8 @@ import dagger.assisted.AssistedFactory
|
||||||
import dagger.assisted.AssistedInject
|
import dagger.assisted.AssistedInject
|
||||||
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.utils.mapOptional
|
||||||
|
import im.vector.app.core.utils.unwrap
|
||||||
import im.vector.app.features.powerlevel.PowerLevelsFlowFactory
|
import im.vector.app.features.powerlevel.PowerLevelsFlowFactory
|
||||||
import im.vector.app.features.settings.VectorPreferences
|
import im.vector.app.features.settings.VectorPreferences
|
||||||
import kotlinx.coroutines.flow.launchIn
|
import kotlinx.coroutines.flow.launchIn
|
||||||
|
@ -43,9 +46,6 @@ import org.matrix.android.sdk.api.session.room.model.RoomGuestAccessContent
|
||||||
import org.matrix.android.sdk.api.session.room.model.RoomHistoryVisibilityContent
|
import org.matrix.android.sdk.api.session.room.model.RoomHistoryVisibilityContent
|
||||||
import org.matrix.android.sdk.api.session.room.model.RoomJoinRulesContent
|
import org.matrix.android.sdk.api.session.room.model.RoomJoinRulesContent
|
||||||
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.flow.flow
|
|
||||||
import org.matrix.android.sdk.flow.mapOptional
|
|
||||||
import org.matrix.android.sdk.flow.unwrap
|
|
||||||
|
|
||||||
class RoomSettingsViewModel @AssistedInject constructor(@Assisted initialState: RoomSettingsViewState,
|
class RoomSettingsViewModel @AssistedInject constructor(@Assisted initialState: RoomSettingsViewState,
|
||||||
private val vectorPreferences: VectorPreferences,
|
private val vectorPreferences: VectorPreferences,
|
||||||
|
@ -125,7 +125,8 @@ class RoomSettingsViewModel @AssistedInject constructor(@Assisted initialState:
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun observeRoomSummary() {
|
private fun observeRoomSummary() {
|
||||||
room.flow().liveRoomSummary()
|
room.getRoomSummaryLive()
|
||||||
|
.asFlow()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.execute { async ->
|
.execute { async ->
|
||||||
val roomSummary = async.invoke()
|
val roomSummary = async.invoke()
|
||||||
|
@ -161,8 +162,8 @@ class RoomSettingsViewModel @AssistedInject constructor(@Assisted initialState:
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun observeRoomHistoryVisibility() {
|
private fun observeRoomHistoryVisibility() {
|
||||||
room.flow()
|
room.getStateEventLive(EventType.STATE_ROOM_HISTORY_VISIBILITY, QueryStringValue.NoCondition)
|
||||||
.liveStateEvent(EventType.STATE_ROOM_HISTORY_VISIBILITY, QueryStringValue.NoCondition)
|
.asFlow()
|
||||||
.mapOptional { it.content.toModel<RoomHistoryVisibilityContent>() }
|
.mapOptional { it.content.toModel<RoomHistoryVisibilityContent>() }
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.mapNotNull { it.historyVisibility }
|
.mapNotNull { it.historyVisibility }
|
||||||
|
@ -172,8 +173,8 @@ class RoomSettingsViewModel @AssistedInject constructor(@Assisted initialState:
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun observeJoinRule() {
|
private fun observeJoinRule() {
|
||||||
room.flow()
|
room.getStateEventLive(EventType.STATE_ROOM_JOIN_RULES, QueryStringValue.NoCondition)
|
||||||
.liveStateEvent(EventType.STATE_ROOM_JOIN_RULES, QueryStringValue.NoCondition)
|
.asFlow()
|
||||||
.mapOptional { it.content.toModel<RoomJoinRulesContent>() }
|
.mapOptional { it.content.toModel<RoomJoinRulesContent>() }
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.mapNotNull { it.joinRules }
|
.mapNotNull { it.joinRules }
|
||||||
|
@ -183,8 +184,8 @@ class RoomSettingsViewModel @AssistedInject constructor(@Assisted initialState:
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun observeGuestAccess() {
|
private fun observeGuestAccess() {
|
||||||
room.flow()
|
room.getStateEventLive(EventType.STATE_ROOM_GUEST_ACCESS, QueryStringValue.NoCondition)
|
||||||
.liveStateEvent(EventType.STATE_ROOM_GUEST_ACCESS, QueryStringValue.NoCondition)
|
.asFlow()
|
||||||
.mapOptional { it.content.toModel<RoomGuestAccessContent>() }
|
.mapOptional { it.content.toModel<RoomGuestAccessContent>() }
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.mapNotNull { it.guestAccess }
|
.mapNotNull { it.guestAccess }
|
||||||
|
@ -197,8 +198,8 @@ class RoomSettingsViewModel @AssistedInject constructor(@Assisted initialState:
|
||||||
* We do not want to use the fallback avatar url, which can be the other user avatar, or the current user avatar.
|
* We do not want to use the fallback avatar url, which can be the other user avatar, or the current user avatar.
|
||||||
*/
|
*/
|
||||||
private fun observeRoomAvatar() {
|
private fun observeRoomAvatar() {
|
||||||
room.flow()
|
room.getStateEventLive(EventType.STATE_ROOM_AVATAR, QueryStringValue.NoCondition)
|
||||||
.liveStateEvent(EventType.STATE_ROOM_AVATAR, QueryStringValue.NoCondition)
|
.asFlow()
|
||||||
.mapOptional { it.content.toModel<RoomAvatarContent>() }
|
.mapOptional { it.content.toModel<RoomAvatarContent>() }
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.setOnEach {
|
.setOnEach {
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
|
|
||||||
package im.vector.app.features.roomprofile.uploads
|
package im.vector.app.features.roomprofile.uploads
|
||||||
|
|
||||||
|
import androidx.lifecycle.asFlow
|
||||||
import com.airbnb.mvrx.ActivityViewModelContext
|
import com.airbnb.mvrx.ActivityViewModelContext
|
||||||
import com.airbnb.mvrx.Fail
|
import com.airbnb.mvrx.Fail
|
||||||
import com.airbnb.mvrx.FragmentViewModelContext
|
import com.airbnb.mvrx.FragmentViewModelContext
|
||||||
|
@ -28,11 +29,10 @@ import dagger.assisted.AssistedFactory
|
||||||
import dagger.assisted.AssistedInject
|
import dagger.assisted.AssistedInject
|
||||||
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.utils.unwrap
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import org.matrix.android.sdk.api.session.Session
|
import org.matrix.android.sdk.api.session.Session
|
||||||
import org.matrix.android.sdk.api.session.room.model.message.MessageType
|
import org.matrix.android.sdk.api.session.room.model.message.MessageType
|
||||||
import org.matrix.android.sdk.flow.flow
|
|
||||||
import org.matrix.android.sdk.flow.unwrap
|
|
||||||
|
|
||||||
class RoomUploadsViewModel @AssistedInject constructor(
|
class RoomUploadsViewModel @AssistedInject constructor(
|
||||||
@Assisted initialState: RoomUploadsViewState,
|
@Assisted initialState: RoomUploadsViewState,
|
||||||
|
@ -65,7 +65,8 @@ class RoomUploadsViewModel @AssistedInject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun observeRoomSummary() {
|
private fun observeRoomSummary() {
|
||||||
room.flow().liveRoomSummary()
|
room.getRoomSummaryLive()
|
||||||
|
.asFlow()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.execute { async ->
|
.execute { async ->
|
||||||
copy(roomSummary = async)
|
copy(roomSummary = async)
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
|
|
||||||
package im.vector.app.features.settings
|
package im.vector.app.features.settings
|
||||||
|
|
||||||
|
import androidx.lifecycle.asFlow
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
import kotlinx.coroutines.flow.combine
|
import kotlinx.coroutines.flow.combine
|
||||||
import kotlinx.coroutines.flow.distinctUntilChanged
|
import kotlinx.coroutines.flow.distinctUntilChanged
|
||||||
|
@ -25,7 +26,6 @@ import org.matrix.android.sdk.api.session.crypto.crosssigning.KEYBACKUP_SECRET_S
|
||||||
import org.matrix.android.sdk.api.session.crypto.crosssigning.MASTER_KEY_SSSS_NAME
|
import org.matrix.android.sdk.api.session.crypto.crosssigning.MASTER_KEY_SSSS_NAME
|
||||||
import org.matrix.android.sdk.api.session.crypto.crosssigning.SELF_SIGNING_KEY_SSSS_NAME
|
import org.matrix.android.sdk.api.session.crypto.crosssigning.SELF_SIGNING_KEY_SSSS_NAME
|
||||||
import org.matrix.android.sdk.api.session.crypto.crosssigning.USER_SIGNING_KEY_SSSS_NAME
|
import org.matrix.android.sdk.api.session.crypto.crosssigning.USER_SIGNING_KEY_SSSS_NAME
|
||||||
import org.matrix.android.sdk.flow.flow
|
|
||||||
import org.matrix.android.sdk.rx.SecretsSynchronisationInfo
|
import org.matrix.android.sdk.rx.SecretsSynchronisationInfo
|
||||||
|
|
||||||
data class SecretsSynchronisationInfo(
|
data class SecretsSynchronisationInfo(
|
||||||
|
@ -39,11 +39,12 @@ data class SecretsSynchronisationInfo(
|
||||||
)
|
)
|
||||||
|
|
||||||
fun Session.liveSecretSynchronisationInfo(): Flow<SecretsSynchronisationInfo> {
|
fun Session.liveSecretSynchronisationInfo(): Flow<SecretsSynchronisationInfo> {
|
||||||
val sessionFlow = flow()
|
|
||||||
return combine(
|
return combine(
|
||||||
sessionFlow.liveUserAccountData(setOf(MASTER_KEY_SSSS_NAME, USER_SIGNING_KEY_SSSS_NAME, SELF_SIGNING_KEY_SSSS_NAME, KEYBACKUP_SECRET_SSSS_NAME)),
|
accountDataService()
|
||||||
sessionFlow.liveCrossSigningInfo(myUserId),
|
.getLiveUserAccountDataEvents(setOf(MASTER_KEY_SSSS_NAME, USER_SIGNING_KEY_SSSS_NAME, SELF_SIGNING_KEY_SSSS_NAME, KEYBACKUP_SECRET_SSSS_NAME))
|
||||||
sessionFlow.liveCrossSigningPrivateKeys()
|
.asFlow(),
|
||||||
|
cryptoService().crossSigningService().getLiveCrossSigningKeys(myUserId).asFlow(),
|
||||||
|
cryptoService().crossSigningService().getLiveCrossSigningPrivateKeys().asFlow()
|
||||||
) { _, crossSigningInfo, pInfo ->
|
) { _, crossSigningInfo, pInfo ->
|
||||||
// first check if 4S is already setup
|
// first check if 4S is already setup
|
||||||
val is4SSetup = sharedSecretStorageService.isRecoverySetup()
|
val is4SSetup = sharedSecretStorageService.isRecoverySetup()
|
||||||
|
|
|
@ -26,6 +26,7 @@ import android.view.ViewGroup
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import androidx.appcompat.app.AlertDialog
|
import androidx.appcompat.app.AlertDialog
|
||||||
import androidx.core.view.isVisible
|
import androidx.core.view.isVisible
|
||||||
|
import androidx.lifecycle.asFlow
|
||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
import androidx.preference.EditTextPreference
|
import androidx.preference.EditTextPreference
|
||||||
import androidx.preference.Preference
|
import androidx.preference.Preference
|
||||||
|
@ -47,6 +48,7 @@ import im.vector.app.core.resources.ColorProvider
|
||||||
import im.vector.app.core.utils.TextUtils
|
import im.vector.app.core.utils.TextUtils
|
||||||
import im.vector.app.core.utils.getSizeOfFiles
|
import im.vector.app.core.utils.getSizeOfFiles
|
||||||
import im.vector.app.core.utils.toast
|
import im.vector.app.core.utils.toast
|
||||||
|
import im.vector.app.core.utils.unwrap
|
||||||
import im.vector.app.databinding.DialogChangePasswordBinding
|
import im.vector.app.databinding.DialogChangePasswordBinding
|
||||||
import im.vector.app.features.MainActivity
|
import im.vector.app.features.MainActivity
|
||||||
import im.vector.app.features.MainActivityArgs
|
import im.vector.app.features.MainActivityArgs
|
||||||
|
@ -62,8 +64,6 @@ import kotlinx.coroutines.withContext
|
||||||
import org.matrix.android.sdk.api.failure.isInvalidPassword
|
import org.matrix.android.sdk.api.failure.isInvalidPassword
|
||||||
import org.matrix.android.sdk.api.session.integrationmanager.IntegrationManagerConfig
|
import org.matrix.android.sdk.api.session.integrationmanager.IntegrationManagerConfig
|
||||||
import org.matrix.android.sdk.api.session.integrationmanager.IntegrationManagerService
|
import org.matrix.android.sdk.api.session.integrationmanager.IntegrationManagerService
|
||||||
import org.matrix.android.sdk.flow.flow
|
|
||||||
import org.matrix.android.sdk.flow.unwrap
|
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.util.UUID
|
import java.util.UUID
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
@ -122,8 +122,8 @@ class VectorSettingsGeneralFragment @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun observeUserAvatar() {
|
private fun observeUserAvatar() {
|
||||||
session.flow()
|
session.getUserLive(session.myUserId)
|
||||||
.liveUser(session.myUserId)
|
.asFlow()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.distinctUntilChangedBy { user -> user.avatarUrl }
|
.distinctUntilChangedBy { user -> user.avatarUrl }
|
||||||
.onEach {
|
.onEach {
|
||||||
|
@ -133,8 +133,8 @@ class VectorSettingsGeneralFragment @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun observeUserDisplayName() {
|
private fun observeUserDisplayName() {
|
||||||
session.flow()
|
session.getUserLive(session.myUserId)
|
||||||
.liveUser(session.myUserId)
|
.asFlow()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.map { it.displayName ?: "" }
|
.map { it.displayName ?: "" }
|
||||||
.distinctUntilChanged()
|
.distinctUntilChanged()
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
*/
|
*/
|
||||||
package im.vector.app.features.settings.crosssigning
|
package im.vector.app.features.settings.crosssigning
|
||||||
|
|
||||||
|
import androidx.lifecycle.asFlow
|
||||||
import com.airbnb.mvrx.FragmentViewModelContext
|
import com.airbnb.mvrx.FragmentViewModelContext
|
||||||
import com.airbnb.mvrx.MavericksViewModelFactory
|
import com.airbnb.mvrx.MavericksViewModelFactory
|
||||||
import com.airbnb.mvrx.ViewModelContext
|
import com.airbnb.mvrx.ViewModelContext
|
||||||
|
@ -37,7 +38,6 @@ import org.matrix.android.sdk.api.auth.data.LoginFlowTypes
|
||||||
import org.matrix.android.sdk.api.auth.registration.RegistrationFlowResponse
|
import org.matrix.android.sdk.api.auth.registration.RegistrationFlowResponse
|
||||||
import org.matrix.android.sdk.api.auth.registration.nextUncompletedStage
|
import org.matrix.android.sdk.api.auth.registration.nextUncompletedStage
|
||||||
import org.matrix.android.sdk.api.session.Session
|
import org.matrix.android.sdk.api.session.Session
|
||||||
import org.matrix.android.sdk.flow.flow
|
|
||||||
import org.matrix.android.sdk.internal.crypto.crosssigning.fromBase64
|
import org.matrix.android.sdk.internal.crypto.crosssigning.fromBase64
|
||||||
import org.matrix.android.sdk.internal.crypto.crosssigning.isVerified
|
import org.matrix.android.sdk.internal.crypto.crosssigning.isVerified
|
||||||
import org.matrix.android.sdk.internal.crypto.model.rest.DefaultBaseAuth
|
import org.matrix.android.sdk.internal.crypto.model.rest.DefaultBaseAuth
|
||||||
|
@ -56,8 +56,8 @@ class CrossSigningSettingsViewModel @AssistedInject constructor(
|
||||||
|
|
||||||
init {
|
init {
|
||||||
combine(
|
combine(
|
||||||
session.flow().liveMyDevicesInfo(),
|
session.cryptoService().getLiveMyDevicesInfo().asFlow(),
|
||||||
session.flow().liveCrossSigningInfo(session.myUserId)
|
session.cryptoService().crossSigningService().getLiveCrossSigningKeys(session.myUserId).asFlow()
|
||||||
)
|
)
|
||||||
{ myDevicesInfo, mxCrossSigningInfo ->
|
{ myDevicesInfo, mxCrossSigningInfo ->
|
||||||
myDevicesInfo to mxCrossSigningInfo
|
myDevicesInfo to mxCrossSigningInfo
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
*/
|
*/
|
||||||
package im.vector.app.features.settings.devices
|
package im.vector.app.features.settings.devices
|
||||||
|
|
||||||
|
import androidx.lifecycle.asFlow
|
||||||
import com.airbnb.mvrx.FragmentViewModelContext
|
import com.airbnb.mvrx.FragmentViewModelContext
|
||||||
import com.airbnb.mvrx.Loading
|
import com.airbnb.mvrx.Loading
|
||||||
import com.airbnb.mvrx.MavericksViewModelFactory
|
import com.airbnb.mvrx.MavericksViewModelFactory
|
||||||
|
@ -27,9 +28,7 @@ import im.vector.app.core.platform.EmptyViewEvents
|
||||||
import im.vector.app.core.platform.VectorViewModel
|
import im.vector.app.core.platform.VectorViewModel
|
||||||
import kotlinx.coroutines.flow.map
|
import kotlinx.coroutines.flow.map
|
||||||
import org.matrix.android.sdk.api.session.Session
|
import org.matrix.android.sdk.api.session.Session
|
||||||
import org.matrix.android.sdk.flow.flow
|
|
||||||
import org.matrix.android.sdk.internal.crypto.model.rest.DeviceInfo
|
import org.matrix.android.sdk.internal.crypto.model.rest.DeviceInfo
|
||||||
import org.matrix.android.sdk.rx.rx
|
|
||||||
|
|
||||||
class DeviceVerificationInfoBottomSheetViewModel @AssistedInject constructor(@Assisted initialState: DeviceVerificationInfoBottomSheetViewState,
|
class DeviceVerificationInfoBottomSheetViewModel @AssistedInject constructor(@Assisted initialState: DeviceVerificationInfoBottomSheetViewState,
|
||||||
@Assisted val deviceId: String,
|
@Assisted val deviceId: String,
|
||||||
|
@ -50,7 +49,8 @@ class DeviceVerificationInfoBottomSheetViewModel @AssistedInject constructor(@As
|
||||||
isRecoverySetup = session.sharedSecretStorageService.isRecoverySetup()
|
isRecoverySetup = session.sharedSecretStorageService.isRecoverySetup()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
session.flow().liveCrossSigningInfo(session.myUserId)
|
session.cryptoService().crossSigningService().getLiveCrossSigningKeys(session.myUserId)
|
||||||
|
.asFlow()
|
||||||
.execute {
|
.execute {
|
||||||
copy(
|
copy(
|
||||||
hasAccountCrossSigning = it.invoke()?.getOrNull() != null,
|
hasAccountCrossSigning = it.invoke()?.getOrNull() != null,
|
||||||
|
@ -58,7 +58,8 @@ class DeviceVerificationInfoBottomSheetViewModel @AssistedInject constructor(@As
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
session.flow().liveUserCryptoDevices(session.myUserId)
|
session.cryptoService().getLiveCryptoDeviceInfo(session.myUserId)
|
||||||
|
.asFlow()
|
||||||
.map { list ->
|
.map { list ->
|
||||||
list.firstOrNull { it.deviceId == deviceId }
|
list.firstOrNull { it.deviceId == deviceId }
|
||||||
}
|
}
|
||||||
|
@ -69,7 +70,7 @@ class DeviceVerificationInfoBottomSheetViewModel @AssistedInject constructor(@As
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
session.flow().liveUserCryptoDevices(session.myUserId)
|
session.cryptoService().getLiveCryptoDeviceInfo(session.myUserId).asFlow()
|
||||||
.map { it.size }
|
.map { it.size }
|
||||||
.execute {
|
.execute {
|
||||||
copy(
|
copy(
|
||||||
|
@ -81,7 +82,8 @@ class DeviceVerificationInfoBottomSheetViewModel @AssistedInject constructor(@As
|
||||||
copy(deviceInfo = Loading())
|
copy(deviceInfo = Loading())
|
||||||
}
|
}
|
||||||
|
|
||||||
session.flow().liveMyDevicesInfo()
|
session.cryptoService().getLiveMyDevicesInfo()
|
||||||
|
.asFlow()
|
||||||
.map { devices ->
|
.map { devices ->
|
||||||
devices.firstOrNull { it.deviceId == deviceId } ?: DeviceInfo(deviceId = deviceId)
|
devices.firstOrNull { it.deviceId == deviceId } ?: DeviceInfo(deviceId = deviceId)
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
|
|
||||||
package im.vector.app.features.settings.devices
|
package im.vector.app.features.settings.devices
|
||||||
|
|
||||||
|
import androidx.lifecycle.asFlow
|
||||||
import com.airbnb.mvrx.Async
|
import com.airbnb.mvrx.Async
|
||||||
import com.airbnb.mvrx.Fail
|
import com.airbnb.mvrx.Fail
|
||||||
import com.airbnb.mvrx.FragmentViewModelContext
|
import com.airbnb.mvrx.FragmentViewModelContext
|
||||||
|
@ -56,7 +57,6 @@ import org.matrix.android.sdk.api.session.crypto.verification.VerificationMethod
|
||||||
import org.matrix.android.sdk.api.session.crypto.verification.VerificationService
|
import org.matrix.android.sdk.api.session.crypto.verification.VerificationService
|
||||||
import org.matrix.android.sdk.api.session.crypto.verification.VerificationTransaction
|
import org.matrix.android.sdk.api.session.crypto.verification.VerificationTransaction
|
||||||
import org.matrix.android.sdk.api.session.crypto.verification.VerificationTxState
|
import org.matrix.android.sdk.api.session.crypto.verification.VerificationTxState
|
||||||
import org.matrix.android.sdk.flow.flow
|
|
||||||
import org.matrix.android.sdk.internal.crypto.crosssigning.DeviceTrustLevel
|
import org.matrix.android.sdk.internal.crypto.crosssigning.DeviceTrustLevel
|
||||||
import org.matrix.android.sdk.internal.crypto.crosssigning.fromBase64
|
import org.matrix.android.sdk.internal.crypto.crosssigning.fromBase64
|
||||||
import org.matrix.android.sdk.internal.crypto.model.CryptoDeviceInfo
|
import org.matrix.android.sdk.internal.crypto.model.CryptoDeviceInfo
|
||||||
|
@ -123,8 +123,14 @@ class DevicesViewModel @AssistedInject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
combine(
|
combine(
|
||||||
session.flow().liveUserCryptoDevices(session.myUserId),
|
session.cryptoService().getLiveCryptoDeviceInfo(session.myUserId).asFlow()
|
||||||
session.flow().liveMyDevicesInfo()
|
.onEach {
|
||||||
|
Timber.v("getLiveCryptoDeviceInfo")
|
||||||
|
},
|
||||||
|
session.cryptoService().getLiveMyDevicesInfo().asFlow()
|
||||||
|
.onEach {
|
||||||
|
Timber.v("getLiveMyDevicesInfo")
|
||||||
|
}
|
||||||
)
|
)
|
||||||
{ cryptoList, infoList ->
|
{ cryptoList, infoList ->
|
||||||
infoList
|
infoList
|
||||||
|
@ -141,7 +147,8 @@ class DevicesViewModel @AssistedInject constructor(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
session.flow().liveCrossSigningInfo(session.myUserId)
|
session.cryptoService().crossSigningService().getLiveCrossSigningKeys(session.myUserId)
|
||||||
|
.asFlow()
|
||||||
.execute {
|
.execute {
|
||||||
copy(
|
copy(
|
||||||
hasAccountCrossSigning = it.invoke()?.getOrNull() != null,
|
hasAccountCrossSigning = it.invoke()?.getOrNull() != null,
|
||||||
|
@ -157,7 +164,8 @@ class DevicesViewModel @AssistedInject constructor(
|
||||||
// )
|
// )
|
||||||
// }
|
// }
|
||||||
|
|
||||||
session.flow().liveUserCryptoDevices(session.myUserId)
|
session.cryptoService().getLiveCryptoDeviceInfo(session.myUserId)
|
||||||
|
.asFlow()
|
||||||
.map { it.size }
|
.map { it.size }
|
||||||
.distinctUntilChanged()
|
.distinctUntilChanged()
|
||||||
.sample(5_000)
|
.sample(5_000)
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
|
|
||||||
package im.vector.app.features.settings.devtools
|
package im.vector.app.features.settings.devtools
|
||||||
|
|
||||||
|
import androidx.lifecycle.asFlow
|
||||||
import com.airbnb.mvrx.Async
|
import com.airbnb.mvrx.Async
|
||||||
import com.airbnb.mvrx.FragmentViewModelContext
|
import com.airbnb.mvrx.FragmentViewModelContext
|
||||||
import com.airbnb.mvrx.MavericksState
|
import com.airbnb.mvrx.MavericksState
|
||||||
|
@ -31,7 +32,6 @@ import im.vector.app.core.platform.VectorViewModel
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import org.matrix.android.sdk.api.session.Session
|
import org.matrix.android.sdk.api.session.Session
|
||||||
import org.matrix.android.sdk.api.session.accountdata.UserAccountDataEvent
|
import org.matrix.android.sdk.api.session.accountdata.UserAccountDataEvent
|
||||||
import org.matrix.android.sdk.flow.flow
|
|
||||||
|
|
||||||
data class AccountDataViewState(
|
data class AccountDataViewState(
|
||||||
val accountData: Async<List<UserAccountDataEvent>> = Uninitialized
|
val accountData: Async<List<UserAccountDataEvent>> = Uninitialized
|
||||||
|
@ -42,7 +42,9 @@ class AccountDataViewModel @AssistedInject constructor(@Assisted initialState: A
|
||||||
: VectorViewModel<AccountDataViewState, AccountDataAction, EmptyViewEvents>(initialState) {
|
: VectorViewModel<AccountDataViewState, AccountDataAction, EmptyViewEvents>(initialState) {
|
||||||
|
|
||||||
init {
|
init {
|
||||||
session.flow().liveUserAccountData(emptySet())
|
session.accountDataService()
|
||||||
|
.getLiveUserAccountDataEvents(emptySet())
|
||||||
|
.asFlow()
|
||||||
.execute {
|
.execute {
|
||||||
copy(accountData = it)
|
copy(accountData = it)
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
|
|
||||||
package im.vector.app.features.settings.ignored
|
package im.vector.app.features.settings.ignored
|
||||||
|
|
||||||
|
import androidx.lifecycle.asFlow
|
||||||
import com.airbnb.mvrx.Async
|
import com.airbnb.mvrx.Async
|
||||||
import com.airbnb.mvrx.Fail
|
import com.airbnb.mvrx.Fail
|
||||||
import com.airbnb.mvrx.FragmentViewModelContext
|
import com.airbnb.mvrx.FragmentViewModelContext
|
||||||
|
@ -33,7 +34,6 @@ import im.vector.app.core.platform.VectorViewModelAction
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import org.matrix.android.sdk.api.session.Session
|
import org.matrix.android.sdk.api.session.Session
|
||||||
import org.matrix.android.sdk.api.session.user.model.User
|
import org.matrix.android.sdk.api.session.user.model.User
|
||||||
import org.matrix.android.sdk.flow.flow
|
|
||||||
|
|
||||||
data class IgnoredUsersViewState(
|
data class IgnoredUsersViewState(
|
||||||
val ignoredUsers: List<User> = emptyList(),
|
val ignoredUsers: List<User> = emptyList(),
|
||||||
|
@ -67,8 +67,8 @@ class IgnoredUsersViewModel @AssistedInject constructor(@Assisted initialState:
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun observeIgnoredUsers() {
|
private fun observeIgnoredUsers() {
|
||||||
session.flow()
|
session.getIgnoredUsersLive()
|
||||||
.liveIgnoredUsers()
|
.asFlow()
|
||||||
.execute { async ->
|
.execute { async ->
|
||||||
copy(
|
copy(
|
||||||
ignoredUsers = async.invoke().orEmpty()
|
ignoredUsers = async.invoke().orEmpty()
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
|
|
||||||
package im.vector.app.features.settings.threepids
|
package im.vector.app.features.settings.threepids
|
||||||
|
|
||||||
|
import androidx.lifecycle.asFlow
|
||||||
import com.airbnb.mvrx.ActivityViewModelContext
|
import com.airbnb.mvrx.ActivityViewModelContext
|
||||||
import com.airbnb.mvrx.Fail
|
import com.airbnb.mvrx.Fail
|
||||||
import com.airbnb.mvrx.FragmentViewModelContext
|
import com.airbnb.mvrx.FragmentViewModelContext
|
||||||
|
@ -38,7 +39,6 @@ import org.matrix.android.sdk.api.auth.UserPasswordAuth
|
||||||
import org.matrix.android.sdk.api.auth.registration.RegistrationFlowResponse
|
import org.matrix.android.sdk.api.auth.registration.RegistrationFlowResponse
|
||||||
import org.matrix.android.sdk.api.session.Session
|
import org.matrix.android.sdk.api.session.Session
|
||||||
import org.matrix.android.sdk.api.session.identity.ThreePid
|
import org.matrix.android.sdk.api.session.identity.ThreePid
|
||||||
import org.matrix.android.sdk.flow.flow
|
|
||||||
import org.matrix.android.sdk.internal.crypto.crosssigning.fromBase64
|
import org.matrix.android.sdk.internal.crypto.crosssigning.fromBase64
|
||||||
import org.matrix.android.sdk.internal.crypto.model.rest.DefaultBaseAuth
|
import org.matrix.android.sdk.internal.crypto.model.rest.DefaultBaseAuth
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
|
@ -101,8 +101,8 @@ class ThreePidsSettingsViewModel @AssistedInject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun observeThreePids() {
|
private fun observeThreePids() {
|
||||||
session.flow()
|
session.getThreePidsLive(true)
|
||||||
.liveThreePIds(true)
|
.asFlow()
|
||||||
.execute {
|
.execute {
|
||||||
copy(
|
copy(
|
||||||
threePids = it
|
threePids = it
|
||||||
|
@ -111,8 +111,8 @@ class ThreePidsSettingsViewModel @AssistedInject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun observePendingThreePids() {
|
private fun observePendingThreePids() {
|
||||||
session.flow()
|
session.getPendingThreePidsLive()
|
||||||
.livePendingThreePIds()
|
.asFlow()
|
||||||
.execute {
|
.execute {
|
||||||
copy(
|
copy(
|
||||||
pendingThreePids = it,
|
pendingThreePids = it,
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
|
|
||||||
package im.vector.app.features.share
|
package im.vector.app.features.share
|
||||||
|
|
||||||
|
import androidx.lifecycle.asFlow
|
||||||
import com.airbnb.mvrx.FragmentViewModelContext
|
import com.airbnb.mvrx.FragmentViewModelContext
|
||||||
import com.airbnb.mvrx.MavericksViewModelFactory
|
import com.airbnb.mvrx.MavericksViewModelFactory
|
||||||
import com.airbnb.mvrx.ViewModelContext
|
import com.airbnb.mvrx.ViewModelContext
|
||||||
|
@ -37,7 +38,6 @@ import org.matrix.android.sdk.api.session.Session
|
||||||
import org.matrix.android.sdk.api.session.content.ContentAttachmentData
|
import org.matrix.android.sdk.api.session.content.ContentAttachmentData
|
||||||
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.roomSummaryQueryParams
|
import org.matrix.android.sdk.api.session.room.roomSummaryQueryParams
|
||||||
import org.matrix.android.sdk.flow.flow
|
|
||||||
|
|
||||||
class IncomingShareViewModel @AssistedInject constructor(
|
class IncomingShareViewModel @AssistedInject constructor(
|
||||||
@Assisted initialState: IncomingShareViewState,
|
@Assisted initialState: IncomingShareViewState,
|
||||||
|
@ -69,8 +69,8 @@ class IncomingShareViewModel @AssistedInject constructor(
|
||||||
val queryParams = roomSummaryQueryParams {
|
val queryParams = roomSummaryQueryParams {
|
||||||
memberships = listOf(Membership.JOIN)
|
memberships = listOf(Membership.JOIN)
|
||||||
}
|
}
|
||||||
session
|
session.getRoomSummariesLive(queryParams)
|
||||||
.flow().liveRoomSummaries(queryParams)
|
.asFlow()
|
||||||
.execute {
|
.execute {
|
||||||
copy(roomSummaries = it)
|
copy(roomSummaries = it)
|
||||||
}
|
}
|
||||||
|
@ -86,7 +86,7 @@ class IncomingShareViewModel @AssistedInject constructor(
|
||||||
displayName = displayNameQuery
|
displayName = displayNameQuery
|
||||||
memberships = listOf(Membership.JOIN)
|
memberships = listOf(Membership.JOIN)
|
||||||
}
|
}
|
||||||
session.flow().liveRoomSummaries(filterQueryParams)
|
session.getRoomSummariesLive(filterQueryParams).asFlow()
|
||||||
}
|
}
|
||||||
.sample(300)
|
.sample(300)
|
||||||
.map { it.sortedWith(breadcrumbsRoomComparator) }
|
.map { it.sortedWith(breadcrumbsRoomComparator) }
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
|
|
||||||
package im.vector.app.features.spaces
|
package im.vector.app.features.spaces
|
||||||
|
|
||||||
|
import androidx.lifecycle.asFlow
|
||||||
import com.airbnb.mvrx.ActivityViewModelContext
|
import com.airbnb.mvrx.ActivityViewModelContext
|
||||||
import com.airbnb.mvrx.Fail
|
import com.airbnb.mvrx.Fail
|
||||||
import com.airbnb.mvrx.FragmentViewModelContext
|
import com.airbnb.mvrx.FragmentViewModelContext
|
||||||
|
@ -42,8 +43,6 @@ 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.powerlevels.Role
|
import org.matrix.android.sdk.api.session.room.powerlevels.Role
|
||||||
import org.matrix.android.sdk.api.session.room.roomSummaryQueryParams
|
import org.matrix.android.sdk.api.session.room.roomSummaryQueryParams
|
||||||
import org.matrix.android.sdk.flow.flow
|
|
||||||
import org.matrix.android.sdk.rx.rx
|
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
|
|
||||||
class SpaceMenuViewModel @AssistedInject constructor(
|
class SpaceMenuViewModel @AssistedInject constructor(
|
||||||
|
@ -78,17 +77,19 @@ class SpaceMenuViewModel @AssistedInject constructor(
|
||||||
|
|
||||||
session.getRoom(initialState.spaceId)?.let { room ->
|
session.getRoom(initialState.spaceId)?.let { room ->
|
||||||
|
|
||||||
room.flow().liveRoomSummary().onEach {
|
room.getRoomSummaryLive()
|
||||||
it.getOrNull()?.let {
|
.asFlow()
|
||||||
if (it.membership == Membership.LEAVE) {
|
.onEach {
|
||||||
setState { copy(leavingState = Success(Unit)) }
|
it.getOrNull()?.let {
|
||||||
if (appStateHandler.safeActiveSpaceId() == initialState.spaceId) {
|
if (it.membership == Membership.LEAVE) {
|
||||||
// switch to home?
|
setState { copy(leavingState = Success(Unit)) }
|
||||||
appStateHandler.setCurrentSpace(null, session)
|
if (appStateHandler.safeActiveSpaceId() == initialState.spaceId) {
|
||||||
|
// switch to home?
|
||||||
|
appStateHandler.setCurrentSpace(null, session)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}.launchIn(viewModelScope)
|
||||||
}
|
|
||||||
}.launchIn(viewModelScope)
|
|
||||||
|
|
||||||
PowerLevelsFlowFactory(room)
|
PowerLevelsFlowFactory(room)
|
||||||
.createFlow()
|
.createFlow()
|
||||||
|
|
|
@ -53,7 +53,6 @@ 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.SpaceOrderContent
|
||||||
import org.matrix.android.sdk.api.session.space.model.TopLevelSpaceComparator
|
import org.matrix.android.sdk.api.session.space.model.TopLevelSpaceComparator
|
||||||
import org.matrix.android.sdk.api.util.toMatrixItem
|
import org.matrix.android.sdk.api.util.toMatrixItem
|
||||||
import org.matrix.android.sdk.flow.flow
|
|
||||||
import org.matrix.android.sdk.rx.asObservable
|
import org.matrix.android.sdk.rx.asObservable
|
||||||
import java.util.concurrent.TimeUnit
|
import java.util.concurrent.TimeUnit
|
||||||
|
|
||||||
|
@ -82,14 +81,13 @@ class SpacesListViewModel @AssistedInject constructor(@Assisted initialState: Sp
|
||||||
|
|
||||||
init {
|
init {
|
||||||
|
|
||||||
session.getUserLive(session.myUserId).asObservable()
|
session.getUserLive(session.myUserId)
|
||||||
.subscribe {
|
.asFlow()
|
||||||
setState {
|
.setOnEach {
|
||||||
copy(
|
copy(
|
||||||
myMxItem = it?.getOrNull()?.toMatrixItem()?.let { Success(it) } ?: Loading()
|
myMxItem = it.getOrNull()?.toMatrixItem()?.let { Success(it) } ?: Loading()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}.disposeOnClear()
|
|
||||||
|
|
||||||
observeSpaceSummaries()
|
observeSpaceSummaries()
|
||||||
// observeSelectionState()
|
// observeSelectionState()
|
||||||
|
@ -284,16 +282,13 @@ class SpacesListViewModel @AssistedInject constructor(@Assisted initialState: Sp
|
||||||
null)
|
null)
|
||||||
}
|
}
|
||||||
|
|
||||||
val flowSession = session.flow()
|
|
||||||
|
|
||||||
combine(
|
combine(
|
||||||
flowSession
|
session.getUserLive(session.myUserId)
|
||||||
.liveUser(session.myUserId)
|
.asFlow()
|
||||||
.map {
|
.map {
|
||||||
it.getOrNull()
|
it.getOrNull()
|
||||||
},
|
},
|
||||||
flowSession
|
session.spaceService().getSpaceSummariesLive(spaceSummaryQueryParams).asFlow(),
|
||||||
.liveSpaceSummaries(spaceSummaryQueryParams),
|
|
||||||
session
|
session
|
||||||
.accountDataService()
|
.accountDataService()
|
||||||
.getLiveRoomAccountDataEvents(setOf(RoomAccountDataTypes.EVENT_TYPE_SPACE_ORDER))
|
.getLiveRoomAccountDataEvents(setOf(RoomAccountDataTypes.EVENT_TYPE_SPACE_ORDER))
|
||||||
|
@ -319,7 +314,8 @@ class SpacesListViewModel @AssistedInject constructor(@Assisted initialState: Sp
|
||||||
// clear local echos on update
|
// clear local echos on update
|
||||||
session.accountDataService()
|
session.accountDataService()
|
||||||
.getLiveRoomAccountDataEvents(setOf(RoomAccountDataTypes.EVENT_TYPE_SPACE_ORDER))
|
.getLiveRoomAccountDataEvents(setOf(RoomAccountDataTypes.EVENT_TYPE_SPACE_ORDER))
|
||||||
.asObservable().execute {
|
.asFlow()
|
||||||
|
.execute {
|
||||||
copy(
|
copy(
|
||||||
spaceOrderLocalEchos = emptyMap()
|
spaceOrderLocalEchos = emptyMap()
|
||||||
)
|
)
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
|
|
||||||
package im.vector.app.features.spaces.explore
|
package im.vector.app.features.spaces.explore
|
||||||
|
|
||||||
|
import androidx.lifecycle.asFlow
|
||||||
import com.airbnb.mvrx.ActivityViewModelContext
|
import com.airbnb.mvrx.ActivityViewModelContext
|
||||||
import com.airbnb.mvrx.Fail
|
import com.airbnb.mvrx.Fail
|
||||||
import com.airbnb.mvrx.FragmentViewModelContext
|
import com.airbnb.mvrx.FragmentViewModelContext
|
||||||
|
@ -43,7 +44,6 @@ import org.matrix.android.sdk.api.session.room.model.RoomType
|
||||||
import org.matrix.android.sdk.api.session.room.model.SpaceChildInfo
|
import org.matrix.android.sdk.api.session.room.model.SpaceChildInfo
|
||||||
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.roomSummaryQueryParams
|
import org.matrix.android.sdk.api.session.room.roomSummaryQueryParams
|
||||||
import org.matrix.android.sdk.flow.flow
|
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
|
|
||||||
class SpaceDirectoryViewModel @AssistedInject constructor(
|
class SpaceDirectoryViewModel @AssistedInject constructor(
|
||||||
|
@ -147,9 +147,8 @@ class SpaceDirectoryViewModel @AssistedInject constructor(
|
||||||
memberships = listOf(Membership.JOIN)
|
memberships = listOf(Membership.JOIN)
|
||||||
excludeType = null
|
excludeType = null
|
||||||
}
|
}
|
||||||
session
|
session.getRoomSummariesLive(queryParams)
|
||||||
.flow()
|
.asFlow()
|
||||||
.liveRoomSummaries(queryParams)
|
|
||||||
.map {
|
.map {
|
||||||
it.map { it.roomId }.toSet()
|
it.map { it.roomId }.toSet()
|
||||||
}
|
}
|
||||||
|
@ -159,8 +158,8 @@ class SpaceDirectoryViewModel @AssistedInject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun observeMembershipChanges() {
|
private fun observeMembershipChanges() {
|
||||||
session.flow()
|
session.getChangeMembershipsLive()
|
||||||
.liveRoomChangeMembershipState()
|
.asFlow()
|
||||||
.setOnEach {
|
.setOnEach {
|
||||||
copy(changeMembershipStates = it)
|
copy(changeMembershipStates = it)
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
|
|
||||||
package im.vector.app.features.spaces.leave
|
package im.vector.app.features.spaces.leave
|
||||||
|
|
||||||
|
import androidx.lifecycle.asFlow
|
||||||
import com.airbnb.mvrx.ActivityViewModelContext
|
import com.airbnb.mvrx.ActivityViewModelContext
|
||||||
import com.airbnb.mvrx.Fail
|
import com.airbnb.mvrx.Fail
|
||||||
import com.airbnb.mvrx.FragmentViewModelContext
|
import com.airbnb.mvrx.FragmentViewModelContext
|
||||||
|
@ -30,6 +31,7 @@ import dagger.assisted.AssistedInject
|
||||||
import im.vector.app.AppStateHandler
|
import im.vector.app.AppStateHandler
|
||||||
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.core.utils.unwrap
|
||||||
import kotlinx.coroutines.flow.launchIn
|
import kotlinx.coroutines.flow.launchIn
|
||||||
import kotlinx.coroutines.flow.onEach
|
import kotlinx.coroutines.flow.onEach
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
@ -39,8 +41,6 @@ import org.matrix.android.sdk.api.query.RoomCategoryFilter
|
||||||
import org.matrix.android.sdk.api.session.Session
|
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.roomSummaryQueryParams
|
import org.matrix.android.sdk.api.session.room.roomSummaryQueryParams
|
||||||
import org.matrix.android.sdk.flow.flow
|
|
||||||
import org.matrix.android.sdk.flow.unwrap
|
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
|
|
||||||
class SpaceLeaveAdvancedViewModel @AssistedInject constructor(
|
class SpaceLeaveAdvancedViewModel @AssistedInject constructor(
|
||||||
|
@ -97,7 +97,8 @@ class SpaceLeaveAdvancedViewModel @AssistedInject constructor(
|
||||||
val spaceSummary = session.getRoomSummary(initialState.spaceId)
|
val spaceSummary = session.getRoomSummary(initialState.spaceId)
|
||||||
setState { copy(spaceSummary = spaceSummary) }
|
setState { copy(spaceSummary = spaceSummary) }
|
||||||
session.getRoom(initialState.spaceId)?.let { room ->
|
session.getRoom(initialState.spaceId)?.let { room ->
|
||||||
room.flow().liveRoomSummary()
|
room.getRoomSummaryLive()
|
||||||
|
.asFlow()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.onEach {
|
.onEach {
|
||||||
if (it.membership == Membership.LEAVE) {
|
if (it.membership == Membership.LEAVE) {
|
||||||
|
|
|
@ -16,12 +16,12 @@
|
||||||
|
|
||||||
package im.vector.app.features.userdirectory
|
package im.vector.app.features.userdirectory
|
||||||
|
|
||||||
|
import androidx.lifecycle.asFlow
|
||||||
import com.airbnb.mvrx.ActivityViewModelContext
|
import com.airbnb.mvrx.ActivityViewModelContext
|
||||||
import com.airbnb.mvrx.FragmentViewModelContext
|
import com.airbnb.mvrx.FragmentViewModelContext
|
||||||
import com.airbnb.mvrx.MavericksViewModelFactory
|
import com.airbnb.mvrx.MavericksViewModelFactory
|
||||||
import com.airbnb.mvrx.Uninitialized
|
import com.airbnb.mvrx.Uninitialized
|
||||||
import com.airbnb.mvrx.ViewModelContext
|
import com.airbnb.mvrx.ViewModelContext
|
||||||
import com.jakewharton.rxrelay2.BehaviorRelay
|
|
||||||
import dagger.assisted.Assisted
|
import dagger.assisted.Assisted
|
||||||
import dagger.assisted.AssistedFactory
|
import dagger.assisted.AssistedFactory
|
||||||
import dagger.assisted.AssistedInject
|
import dagger.assisted.AssistedInject
|
||||||
|
@ -29,21 +29,23 @@ import im.vector.app.core.extensions.exhaustive
|
||||||
import im.vector.app.core.extensions.isEmail
|
import im.vector.app.core.extensions.isEmail
|
||||||
import im.vector.app.core.extensions.toggle
|
import im.vector.app.core.extensions.toggle
|
||||||
import im.vector.app.core.platform.VectorViewModel
|
import im.vector.app.core.platform.VectorViewModel
|
||||||
import io.reactivex.Single
|
import kotlinx.coroutines.Dispatchers
|
||||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
|
import kotlinx.coroutines.flow.debounce
|
||||||
|
import kotlinx.coroutines.flow.filter
|
||||||
|
import kotlinx.coroutines.flow.flatMapLatest
|
||||||
|
import kotlinx.coroutines.flow.flowOn
|
||||||
|
import kotlinx.coroutines.flow.launchIn
|
||||||
|
import kotlinx.coroutines.flow.onEach
|
||||||
|
import kotlinx.coroutines.flow.sample
|
||||||
import org.matrix.android.sdk.api.MatrixPatterns
|
import org.matrix.android.sdk.api.MatrixPatterns
|
||||||
|
import org.matrix.android.sdk.api.extensions.tryOrNull
|
||||||
import org.matrix.android.sdk.api.session.Session
|
import org.matrix.android.sdk.api.session.Session
|
||||||
import org.matrix.android.sdk.api.session.identity.IdentityServiceListener
|
import org.matrix.android.sdk.api.session.identity.IdentityServiceListener
|
||||||
import org.matrix.android.sdk.api.session.identity.ThreePid
|
import org.matrix.android.sdk.api.session.identity.ThreePid
|
||||||
import org.matrix.android.sdk.api.session.profile.ProfileService
|
import org.matrix.android.sdk.api.session.profile.ProfileService
|
||||||
import org.matrix.android.sdk.api.session.user.model.User
|
import org.matrix.android.sdk.api.session.user.model.User
|
||||||
import org.matrix.android.sdk.api.util.toMatrixItem
|
import org.matrix.android.sdk.api.util.toMatrixItem
|
||||||
import org.matrix.android.sdk.api.util.toOptional
|
|
||||||
import org.matrix.android.sdk.rx.rx
|
|
||||||
import java.util.concurrent.TimeUnit
|
|
||||||
|
|
||||||
private typealias KnownUsersSearch = String
|
|
||||||
private typealias DirectoryUsersSearch = String
|
|
||||||
|
|
||||||
data class ThreePidUser(
|
data class ThreePidUser(
|
||||||
val email: String,
|
val email: String,
|
||||||
|
@ -54,9 +56,9 @@ class UserListViewModel @AssistedInject constructor(@Assisted initialState: User
|
||||||
private val session: Session)
|
private val session: Session)
|
||||||
: VectorViewModel<UserListViewState, UserListAction, UserListViewEvents>(initialState) {
|
: VectorViewModel<UserListViewState, UserListAction, UserListViewEvents>(initialState) {
|
||||||
|
|
||||||
private val knownUsersSearch = BehaviorRelay.create<KnownUsersSearch>()
|
private val knownUsersSearch = MutableStateFlow("")
|
||||||
private val directoryUsersSearch = BehaviorRelay.create<DirectoryUsersSearch>()
|
private val directoryUsersSearch = MutableStateFlow("")
|
||||||
private val identityServerUsersSearch = BehaviorRelay.create<String>()
|
private val identityServerUsersSearch = MutableStateFlow("")
|
||||||
|
|
||||||
@AssistedFactory
|
@AssistedFactory
|
||||||
interface Factory {
|
interface Factory {
|
||||||
|
@ -77,11 +79,10 @@ class UserListViewModel @AssistedInject constructor(@Assisted initialState: User
|
||||||
private val identityServerListener = object : IdentityServiceListener {
|
private val identityServerListener = object : IdentityServiceListener {
|
||||||
override fun onIdentityServerChange() {
|
override fun onIdentityServerChange() {
|
||||||
withState {
|
withState {
|
||||||
identityServerUsersSearch.accept(it.searchTerm)
|
identityServerUsersSearch.tryEmit(it.searchTerm)
|
||||||
|
val identityServerURL = cleanISURL(session.identityService().getCurrentIdentityServerUrl())
|
||||||
setState {
|
setState {
|
||||||
copy(
|
copy(configuredIdentityServer = identityServerURL)
|
||||||
configuredIdentityServer = cleanISURL(session.identityService().getCurrentIdentityServerUrl())
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -120,7 +121,7 @@ class UserListViewModel @AssistedInject constructor(@Assisted initialState: User
|
||||||
private fun handleISUpdateConsent(action: UserListAction.UpdateUserConsent) {
|
private fun handleISUpdateConsent(action: UserListAction.UpdateUserConsent) {
|
||||||
session.identityService().setUserConsent(action.consent)
|
session.identityService().setUserConsent(action.consent)
|
||||||
withState {
|
withState {
|
||||||
identityServerUsersSearch.accept(it.searchTerm)
|
identityServerUsersSearch.tryEmit(it.searchTerm)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -139,9 +140,9 @@ class UserListViewModel @AssistedInject constructor(@Assisted initialState: User
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
identityServerUsersSearch.accept(searchTerm)
|
identityServerUsersSearch.tryEmit(searchTerm)
|
||||||
knownUsersSearch.accept(searchTerm)
|
knownUsersSearch.tryEmit(searchTerm)
|
||||||
directoryUsersSearch.accept(searchTerm)
|
directoryUsersSearch.tryEmit(searchTerm)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun handleShareMyMatrixToLink() {
|
private fun handleShareMyMatrixToLink() {
|
||||||
|
@ -151,9 +152,9 @@ class UserListViewModel @AssistedInject constructor(@Assisted initialState: User
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun handleClearSearchUsers() {
|
private fun handleClearSearchUsers() {
|
||||||
knownUsersSearch.accept("")
|
knownUsersSearch.tryEmit("")
|
||||||
directoryUsersSearch.accept("")
|
directoryUsersSearch.tryEmit("")
|
||||||
identityServerUsersSearch.accept("")
|
identityServerUsersSearch.tryEmit("")
|
||||||
setState {
|
setState {
|
||||||
copy(searchTerm = "")
|
copy(searchTerm = "")
|
||||||
}
|
}
|
||||||
|
@ -162,103 +163,82 @@ class UserListViewModel @AssistedInject constructor(@Assisted initialState: User
|
||||||
private fun observeUsers() = withState { state ->
|
private fun observeUsers() = withState { state ->
|
||||||
identityServerUsersSearch
|
identityServerUsersSearch
|
||||||
.filter { it.isEmail() }
|
.filter { it.isEmail() }
|
||||||
.throttleLast(300, TimeUnit.MILLISECONDS)
|
.sample(300)
|
||||||
.switchMapSingle { search ->
|
.onEach { search ->
|
||||||
val flowSession = session.rx()
|
executeSearchEmail(search)
|
||||||
val stream =
|
}.launchIn(viewModelScope)
|
||||||
flowSession.lookupThreePid(ThreePid.Email(search)).flatMap {
|
|
||||||
it.getOrNull()?.let { foundThreePid ->
|
|
||||||
flowSession.getProfileInfo(foundThreePid.matrixId)
|
|
||||||
.map { json ->
|
|
||||||
ThreePidUser(
|
|
||||||
email = search,
|
|
||||||
user = User(
|
|
||||||
userId = foundThreePid.matrixId,
|
|
||||||
displayName = json[ProfileService.DISPLAY_NAME_KEY] as? String,
|
|
||||||
avatarUrl = json[ProfileService.AVATAR_URL_KEY] as? String
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
.onErrorResumeNext {
|
|
||||||
Single.just(ThreePidUser(email = search, user = User(foundThreePid.matrixId)))
|
|
||||||
}
|
|
||||||
} ?: Single.just(ThreePidUser(email = search, user = null))
|
|
||||||
}
|
|
||||||
stream.toAsync {
|
|
||||||
copy(matchingEmail = it)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.subscribe()
|
|
||||||
.disposeOnClear()
|
|
||||||
|
|
||||||
knownUsersSearch
|
knownUsersSearch
|
||||||
.throttleLast(300, TimeUnit.MILLISECONDS)
|
.sample(300)
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
.flowOn(Dispatchers.Main)
|
||||||
.switchMap {
|
.flatMapLatest { search ->
|
||||||
session.rx().livePagedUsers(it, state.excludedUserIds)
|
session.getPagedUsersLive(search, state.excludedUserIds).asFlow()
|
||||||
}
|
}.execute {
|
||||||
.execute { async ->
|
copy(knownUsers = it)
|
||||||
copy(knownUsers = async)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
directoryUsersSearch
|
directoryUsersSearch
|
||||||
.debounce(300, TimeUnit.MILLISECONDS)
|
.debounce(300)
|
||||||
.switchMapSingle { search ->
|
.onEach { search ->
|
||||||
val stream = if (search.isBlank()) {
|
executeSearchDirectory(state, search)
|
||||||
Single.just(emptyList<User>())
|
}.launchIn(viewModelScope)
|
||||||
} else {
|
}
|
||||||
val searchObservable = session.rx()
|
|
||||||
.searchUsersDirectory(search, 50, state.excludedUserIds.orEmpty())
|
|
||||||
.map { users ->
|
|
||||||
users.sortedBy { it.toMatrixItem().firstLetterOfDisplayName() }
|
|
||||||
}
|
|
||||||
// If it's a valid user id try to use Profile API
|
|
||||||
// because directory only returns users that are in public rooms or share a room with you, where as
|
|
||||||
// profile will work other federations
|
|
||||||
if (!MatrixPatterns.isUserId(search)) {
|
|
||||||
searchObservable
|
|
||||||
} else {
|
|
||||||
val profileObservable = session.rx().getProfileInfo(search)
|
|
||||||
.map { json ->
|
|
||||||
User(
|
|
||||||
userId = search,
|
|
||||||
displayName = json[ProfileService.DISPLAY_NAME_KEY] as? String,
|
|
||||||
avatarUrl = json[ProfileService.AVATAR_URL_KEY] as? String
|
|
||||||
).toOptional()
|
|
||||||
}
|
|
||||||
.onErrorResumeNext {
|
|
||||||
// Profile API can be restricted and doesn't have to return result.
|
|
||||||
// In this case allow inviting valid user ids.
|
|
||||||
Single.just(
|
|
||||||
User(
|
|
||||||
userId = search,
|
|
||||||
displayName = null,
|
|
||||||
avatarUrl = null
|
|
||||||
).toOptional()
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
Single.zip(
|
private suspend fun executeSearchEmail(search: String) {
|
||||||
searchObservable,
|
suspend {
|
||||||
profileObservable,
|
val params = listOf(ThreePid.Email(search))
|
||||||
{ searchResults, optionalProfile ->
|
val foundThreePid = tryOrNull {
|
||||||
val profile = optionalProfile.getOrNull() ?: return@zip searchResults
|
session.identityService().lookUp(params).firstOrNull()
|
||||||
val searchContainsProfile = searchResults.any { it.userId == profile.userId }
|
}
|
||||||
if (searchContainsProfile) {
|
if (foundThreePid == null) {
|
||||||
searchResults
|
null
|
||||||
} else {
|
} else {
|
||||||
listOf(profile) + searchResults
|
try {
|
||||||
}
|
val json = session.getProfile(foundThreePid.matrixId)
|
||||||
}
|
ThreePidUser(
|
||||||
|
email = search,
|
||||||
|
user = User(
|
||||||
|
userId = foundThreePid.matrixId,
|
||||||
|
displayName = json[ProfileService.DISPLAY_NAME_KEY] as? String,
|
||||||
|
avatarUrl = json[ProfileService.AVATAR_URL_KEY] as? String
|
||||||
)
|
)
|
||||||
}
|
)
|
||||||
}
|
} catch (failure: Throwable) {
|
||||||
stream.toAsync {
|
ThreePidUser(email = search, user = User(foundThreePid.matrixId))
|
||||||
copy(directoryUsers = it)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
.subscribe()
|
}
|
||||||
.disposeOnClear()
|
}.execute {
|
||||||
|
copy(matchingEmail = it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private suspend fun executeSearchDirectory(state: UserListViewState, search: String) {
|
||||||
|
suspend {
|
||||||
|
if (search.isBlank()) {
|
||||||
|
emptyList()
|
||||||
|
} else {
|
||||||
|
val searchResult = session
|
||||||
|
.searchUsersDirectory(search, 50, state.excludedUserIds.orEmpty())
|
||||||
|
.sortedBy { it.toMatrixItem().firstLetterOfDisplayName() }
|
||||||
|
val userProfile = if (MatrixPatterns.isUserId(search)) {
|
||||||
|
val json = tryOrNull { session.getProfile(search) }
|
||||||
|
User(
|
||||||
|
userId = search,
|
||||||
|
displayName = json?.get(ProfileService.DISPLAY_NAME_KEY) as? String,
|
||||||
|
avatarUrl = json?.get(ProfileService.AVATAR_URL_KEY) as? String
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
if (userProfile == null || searchResult.any { it.userId == userProfile.userId }) {
|
||||||
|
searchResult
|
||||||
|
} else {
|
||||||
|
listOf(userProfile) + searchResult
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}.execute {
|
||||||
|
copy(directoryUsers = it)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun handleSelectUser(action: UserListAction.AddPendingSelection) = withState { state ->
|
private fun handleSelectUser(action: UserListAction.AddPendingSelection) = withState { state ->
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
package im.vector.app.features.widgets
|
package im.vector.app.features.widgets
|
||||||
|
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
|
import androidx.lifecycle.asFlow
|
||||||
import com.airbnb.mvrx.ActivityViewModelContext
|
import com.airbnb.mvrx.ActivityViewModelContext
|
||||||
import com.airbnb.mvrx.Fail
|
import com.airbnb.mvrx.Fail
|
||||||
import com.airbnb.mvrx.FragmentViewModelContext
|
import com.airbnb.mvrx.FragmentViewModelContext
|
||||||
|
@ -29,6 +30,8 @@ import dagger.assisted.AssistedFactory
|
||||||
import dagger.assisted.AssistedInject
|
import dagger.assisted.AssistedInject
|
||||||
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.core.utils.mapOptional
|
||||||
|
import im.vector.app.core.utils.unwrap
|
||||||
import im.vector.app.features.widgets.permissions.WidgetPermissionsHelper
|
import im.vector.app.features.widgets.permissions.WidgetPermissionsHelper
|
||||||
import kotlinx.coroutines.flow.filter
|
import kotlinx.coroutines.flow.filter
|
||||||
import kotlinx.coroutines.flow.map
|
import kotlinx.coroutines.flow.map
|
||||||
|
@ -42,9 +45,6 @@ import org.matrix.android.sdk.api.session.integrationmanager.IntegrationManagerS
|
||||||
import org.matrix.android.sdk.api.session.room.model.PowerLevelsContent
|
import org.matrix.android.sdk.api.session.room.model.PowerLevelsContent
|
||||||
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.widgets.WidgetManagementFailure
|
import org.matrix.android.sdk.api.session.widgets.WidgetManagementFailure
|
||||||
import org.matrix.android.sdk.flow.flow
|
|
||||||
import org.matrix.android.sdk.flow.mapOptional
|
|
||||||
import org.matrix.android.sdk.flow.unwrap
|
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
import javax.net.ssl.HttpsURLConnection
|
import javax.net.ssl.HttpsURLConnection
|
||||||
|
|
||||||
|
@ -119,7 +119,8 @@ class WidgetViewModel @AssistedInject constructor(@Assisted val initialState: Wi
|
||||||
if (room == null) {
|
if (room == null) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
room.flow().liveStateEvent(EventType.STATE_ROOM_POWER_LEVELS, QueryStringValue.NoCondition)
|
room.getStateEventLive(EventType.STATE_ROOM_POWER_LEVELS, QueryStringValue.NoCondition)
|
||||||
|
.asFlow()
|
||||||
.mapOptional { it.content.toModel<PowerLevelsContent>() }
|
.mapOptional { it.content.toModel<PowerLevelsContent>() }
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.map {
|
.map {
|
||||||
|
@ -135,8 +136,9 @@ class WidgetViewModel @AssistedInject constructor(@Assisted val initialState: Wi
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
val widgetId = initialState.widgetId ?: return
|
val widgetId = initialState.widgetId ?: return
|
||||||
session.flow()
|
session.widgetService()
|
||||||
.liveRoomWidgets(initialState.roomId, QueryStringValue.Equals(widgetId))
|
.getRoomWidgetsLive(initialState.roomId, QueryStringValue.Equals(widgetId))
|
||||||
|
.asFlow()
|
||||||
.filter { it.isNotEmpty() }
|
.filter { it.isNotEmpty() }
|
||||||
.map { it.first() }
|
.map { it.first() }
|
||||||
.execute {
|
.execute {
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
*/
|
*/
|
||||||
package im.vector.app.features.widgets.permissions
|
package im.vector.app.features.widgets.permissions
|
||||||
|
|
||||||
|
import androidx.lifecycle.asFlow
|
||||||
import com.airbnb.mvrx.ActivityViewModelContext
|
import com.airbnb.mvrx.ActivityViewModelContext
|
||||||
import com.airbnb.mvrx.FragmentViewModelContext
|
import com.airbnb.mvrx.FragmentViewModelContext
|
||||||
import com.airbnb.mvrx.MavericksViewModelFactory
|
import com.airbnb.mvrx.MavericksViewModelFactory
|
||||||
|
@ -32,7 +33,6 @@ import org.matrix.android.sdk.api.extensions.tryOrNull
|
||||||
import org.matrix.android.sdk.api.query.QueryStringValue
|
import org.matrix.android.sdk.api.query.QueryStringValue
|
||||||
import org.matrix.android.sdk.api.session.Session
|
import org.matrix.android.sdk.api.session.Session
|
||||||
import org.matrix.android.sdk.api.session.widgets.model.WidgetType
|
import org.matrix.android.sdk.api.session.widgets.model.WidgetType
|
||||||
import org.matrix.android.sdk.flow.flow
|
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
import java.net.URL
|
import java.net.URL
|
||||||
|
|
||||||
|
@ -49,8 +49,9 @@ class RoomWidgetPermissionViewModel @AssistedInject constructor(@Assisted val in
|
||||||
|
|
||||||
private fun observeWidget() {
|
private fun observeWidget() {
|
||||||
val widgetId = initialState.widgetId ?: return
|
val widgetId = initialState.widgetId ?: return
|
||||||
session.flow()
|
session.widgetService()
|
||||||
.liveRoomWidgets(initialState.roomId, QueryStringValue.Equals(widgetId))
|
.getRoomWidgetsLive(initialState.roomId, QueryStringValue.Equals(widgetId))
|
||||||
|
.asFlow()
|
||||||
.filter { it.isNotEmpty() }
|
.filter { it.isNotEmpty() }
|
||||||
.map {
|
.map {
|
||||||
val widget = it.first()
|
val widget = it.first()
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
package im.vector.app.features.workers.signout
|
package im.vector.app.features.workers.signout
|
||||||
|
|
||||||
import androidx.lifecycle.MutableLiveData
|
import androidx.lifecycle.MutableLiveData
|
||||||
|
import androidx.lifecycle.asFlow
|
||||||
import com.airbnb.mvrx.ActivityViewModelContext
|
import com.airbnb.mvrx.ActivityViewModelContext
|
||||||
import com.airbnb.mvrx.Async
|
import com.airbnb.mvrx.Async
|
||||||
import com.airbnb.mvrx.FragmentViewModelContext
|
import com.airbnb.mvrx.FragmentViewModelContext
|
||||||
|
@ -41,7 +42,6 @@ import org.matrix.android.sdk.api.session.crypto.crosssigning.SELF_SIGNING_KEY_S
|
||||||
import org.matrix.android.sdk.api.session.crypto.crosssigning.USER_SIGNING_KEY_SSSS_NAME
|
import org.matrix.android.sdk.api.session.crypto.crosssigning.USER_SIGNING_KEY_SSSS_NAME
|
||||||
import org.matrix.android.sdk.api.session.crypto.keysbackup.KeysBackupState
|
import org.matrix.android.sdk.api.session.crypto.keysbackup.KeysBackupState
|
||||||
import org.matrix.android.sdk.api.session.crypto.keysbackup.KeysBackupStateListener
|
import org.matrix.android.sdk.api.session.crypto.keysbackup.KeysBackupStateListener
|
||||||
import org.matrix.android.sdk.flow.flow
|
|
||||||
|
|
||||||
data class ServerBackupStatusViewState(
|
data class ServerBackupStatusViewState(
|
||||||
val bannerState: Async<BannerState> = Uninitialized
|
val bannerState: Async<BannerState> = Uninitialized
|
||||||
|
@ -92,9 +92,19 @@ class ServerBackupStatusViewModel @AssistedInject constructor(@Assisted initialS
|
||||||
init {
|
init {
|
||||||
session.cryptoService().keysBackupService().addListener(this)
|
session.cryptoService().keysBackupService().addListener(this)
|
||||||
keysBackupState.value = session.cryptoService().keysBackupService().state
|
keysBackupState.value = session.cryptoService().keysBackupService().state
|
||||||
val liveUserAccountData = session.flow().liveUserAccountData(setOf(MASTER_KEY_SSSS_NAME, USER_SIGNING_KEY_SSSS_NAME, SELF_SIGNING_KEY_SSSS_NAME))
|
val liveUserAccountData = session.accountDataService()
|
||||||
val liveCrossSigningInfo = session.flow().liveCrossSigningInfo(session.myUserId)
|
.getLiveUserAccountDataEvents(setOf(MASTER_KEY_SSSS_NAME, USER_SIGNING_KEY_SSSS_NAME, SELF_SIGNING_KEY_SSSS_NAME))
|
||||||
val liveCrossSigningPrivateKeys = session.flow().liveCrossSigningPrivateKeys()
|
.asFlow()
|
||||||
|
val liveCrossSigningInfo = session.cryptoService()
|
||||||
|
.crossSigningService()
|
||||||
|
.getLiveCrossSigningKeys(session.myUserId)
|
||||||
|
.asFlow()
|
||||||
|
val liveCrossSigningPrivateKeys = session.cryptoService()
|
||||||
|
.crossSigningService()
|
||||||
|
.getLiveCrossSigningPrivateKeys()
|
||||||
|
.asFlow()
|
||||||
|
|
||||||
|
|
||||||
combine(liveUserAccountData, liveCrossSigningInfo, keyBackupFlow, liveCrossSigningPrivateKeys) { _, crossSigningInfo, keyBackupState, pInfo ->
|
combine(liveUserAccountData, liveCrossSigningInfo, keyBackupFlow, liveCrossSigningPrivateKeys) { _, crossSigningInfo, keyBackupState, pInfo ->
|
||||||
// first check if 4S is already setup
|
// first check if 4S is already setup
|
||||||
if (session.sharedSecretStorageService.isRecoverySetup()) {
|
if (session.sharedSecretStorageService.isRecoverySetup()) {
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
package im.vector.app.features.workers.signout
|
package im.vector.app.features.workers.signout
|
||||||
|
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
|
import androidx.lifecycle.asFlow
|
||||||
import com.airbnb.mvrx.ActivityViewModelContext
|
import com.airbnb.mvrx.ActivityViewModelContext
|
||||||
import com.airbnb.mvrx.Async
|
import com.airbnb.mvrx.Async
|
||||||
import com.airbnb.mvrx.FragmentViewModelContext
|
import com.airbnb.mvrx.FragmentViewModelContext
|
||||||
|
@ -43,7 +44,6 @@ import org.matrix.android.sdk.api.session.crypto.crosssigning.SELF_SIGNING_KEY_S
|
||||||
import org.matrix.android.sdk.api.session.crypto.crosssigning.USER_SIGNING_KEY_SSSS_NAME
|
import org.matrix.android.sdk.api.session.crypto.crosssigning.USER_SIGNING_KEY_SSSS_NAME
|
||||||
import org.matrix.android.sdk.api.session.crypto.keysbackup.KeysBackupState
|
import org.matrix.android.sdk.api.session.crypto.keysbackup.KeysBackupState
|
||||||
import org.matrix.android.sdk.api.session.crypto.keysbackup.KeysBackupStateListener
|
import org.matrix.android.sdk.api.session.crypto.keysbackup.KeysBackupStateListener
|
||||||
import org.matrix.android.sdk.flow.flow
|
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
|
|
||||||
data class SignoutCheckViewState(
|
data class SignoutCheckViewState(
|
||||||
|
@ -98,7 +98,9 @@ class SignoutCheckViewModel @AssistedInject constructor(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
session.flow().liveUserAccountData(setOf(MASTER_KEY_SSSS_NAME, USER_SIGNING_KEY_SSSS_NAME, SELF_SIGNING_KEY_SSSS_NAME))
|
session.accountDataService()
|
||||||
|
.getLiveUserAccountDataEvents(setOf(MASTER_KEY_SSSS_NAME, USER_SIGNING_KEY_SSSS_NAME, SELF_SIGNING_KEY_SSSS_NAME))
|
||||||
|
.asFlow()
|
||||||
.map {
|
.map {
|
||||||
session.sharedSecretStorageService.isRecoverySetup()
|
session.sharedSecretStorageService.isRecoverySetup()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue