From 0092a7057ef443a9856af62066629e3877ef194e Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Thu, 21 Apr 2022 17:17:32 +0200 Subject: [PATCH] Access the various services with a getter --- .../matrix/android/sdk/flow/FlowSession.kt | 42 +++--- .../android/sdk/account/ChangePasswordTest.kt | 2 +- .../sdk/account/DeactivateAccountTest.kt | 2 +- .../android/sdk/common/CommonTestHelper.kt | 2 +- .../android/sdk/common/CryptoTestHelper.kt | 23 ++-- .../sdk/internal/crypto/E2eeSanityTests.kt | 6 +- .../sdk/internal/crypto/PreShareKeysTest.kt | 1 + .../sdk/internal/crypto/UnwedgingTest.kt | 1 + .../crypto/encryption/EncryptionTest.kt | 1 + .../crypto/gossiping/KeyShareTests.kt | 7 +- .../crypto/gossiping/WithHeldTests.kt | 1 + .../crypto/keysbackup/KeysBackupTest.kt | 1 + .../sdk/internal/crypto/ssss/QuadSTests.kt | 24 ++-- .../room/threads/ThreadMessagingTest.kt | 1 + .../room/timeline/PollAggregationTest.kt | 1 + .../timeline/TimelineForwardPaginationTest.kt | 1 + .../TimelinePreviousLastForwardTest.kt | 1 + .../TimelineSimpleBackPaginationTest.kt | 1 + .../timeline/TimelineWithManyMembersTest.kt | 1 + .../sdk/session/search/SearchMessagesTest.kt | 1 + .../sdk/session/space/SpaceCreationTest.kt | 4 +- .../sdk/session/space/SpaceHierarchyTest.kt | 37 +++--- .../matrix/android/sdk/api/session/Session.kt | 124 ++++++++++++++---- .../sdk/api/session/SessionExtensions.kt | 36 +++++ .../sdk/internal/session/DefaultSession.kt | 61 +++------ .../EventRelationsAggregationProcessor.kt | 2 +- .../sdk/internal/session/sync/SyncTask.kt | 2 +- .../im/vector/app/SecurityBootstrapTest.kt | 4 +- .../troubleshoot/TestTokenRegistration.kt | 2 +- .../fcm/VectorFirebaseMessagingService.kt | 3 +- .../java/im/vector/app/AppStateHandler.kt | 10 +- .../main/java/im/vector/app/AutoRageShaker.kt | 8 +- .../im/vector/app/core/extensions/Session.kt | 6 +- .../vector/app/core/pushers/PushersManager.kt | 12 +- .../im/vector/app/features/MainActivity.kt | 2 +- .../AnalyticsAccountDataViewModel.kt | 2 +- .../app/features/auth/ReAuthViewModel.kt | 2 +- .../group/AutocompleteGroupPresenter.kt | 2 +- .../member/AutocompleteMemberPresenter.kt | 3 +- .../room/AutocompleteRoomPresenter.kt | 2 +- .../app/features/call/VectorCallViewModel.kt | 1 + .../features/call/conference/JitsiService.kt | 3 +- .../features/call/dialpad/DialPadLookup.kt | 2 +- .../features/call/lookup/CallUserMapper.kt | 7 +- .../app/features/call/webrtc/WebRtcCall.kt | 2 +- .../app/features/call/webrtc/WebRtcCallExt.kt | 1 + .../createdirect/CreateDirectRoomViewModel.kt | 11 +- .../features/createdirect/DirectRoomHelper.kt | 4 +- .../KeysBackupRestoreSharedViewModel.kt | 4 +- .../quads/SharedSecureStorageViewModel.kt | 18 +-- .../recover/BackupToQuadSMigrationTask.kt | 2 +- .../recover/BootstrapCrossSigningTask.kt | 2 +- .../recover/BootstrapSharedViewModel.kt | 3 +- .../IncomingVerificationRequestHandler.kt | 4 +- .../VerificationBottomSheetViewModel.kt | 9 +- .../emoji/VerificationEmojiCodeViewModel.kt | 1 + .../features/devtools/RoomDevToolViewModel.kt | 1 + .../discovery/DiscoverySettingsViewModel.kt | 2 +- .../app/features/discovery/Extensions.kt | 4 +- .../change/SetIdentityServerViewModel.kt | 2 +- .../features/home/HomeActivityViewModel.kt | 8 +- .../app/features/home/HomeDetailViewModel.kt | 18 +-- .../app/features/home/HomeDrawerFragment.kt | 2 +- .../UnknownDeviceDetectorSharedViewModel.kt | 1 + .../home/UnreadMessagesSharedViewModel.kt | 16 ++- .../home/room/detail/TimelineViewModel.kt | 15 ++- .../composer/MessageComposerViewModel.kt | 14 +- .../detail/search/SearchResultController.kt | 2 +- .../room/detail/search/SearchViewModel.kt | 1 + .../action/MessageActionsViewModel.kt | 3 +- .../edithistory/ViewEditHistoryViewModel.kt | 1 + .../timeline/factory/EncryptionItemFactory.kt | 1 + .../factory/MergedHeaderItemFactory.kt | 1 + .../timeline/factory/MessageItemFactory.kt | 2 +- .../timeline/factory/TimelineFactory.kt | 1 + .../factory/VerificationItemFactory.kt | 1 + .../timeline/helper/LocationPinProvider.kt | 1 + .../reactions/ViewReactionsViewModel.kt | 1 + .../timeline/render/EventTextRenderer.kt | 2 +- .../detail/upgrade/MigrateRoomViewModel.kt | 2 + .../upgrade/UpgradeRoomViewModelTask.kt | 1 + .../room/list/RoomListSectionBuilderGroup.kt | 10 +- .../room/list/RoomListSectionBuilderSpace.kt | 11 +- .../home/room/list/RoomListViewModel.kt | 7 +- .../list/viewmodel/ThreadListController.kt | 2 +- .../list/viewmodel/ThreadListViewModel.kt | 5 +- .../HomeServerCapabilitiesViewModel.kt | 2 +- .../app/features/html/PillsPostProcessor.kt | 6 +- .../invite/InviteUsersToRoomViewModel.kt | 1 + .../app/features/invite/InvitesAcceptor.kt | 7 +- .../app/features/link/LinkHandlerActivity.kt | 2 +- .../location/LocationSharingService.kt | 1 + .../location/LocationSharingViewModel.kt | 2 + .../login2/created/AccountCreatedViewModel.kt | 4 +- .../matrixto/MatrixToBottomSheetViewModel.kt | 13 +- .../media/VectorAttachmentViewerActivity.kt | 1 + .../features/navigation/DefaultNavigator.kt | 2 + .../notifications/NotifiableEventResolver.kt | 7 +- .../NotificationBroadcastReceiver.kt | 7 +- .../NotificationDrawerManager.kt | 1 + .../NotificationEventPersistence.kt | 4 +- .../notifications/OutdatedEventDetector.kt | 1 + .../notifications/PushRuleTriggerListener.kt | 4 +- .../onboarding/OnboardingViewModel.kt | 6 +- .../features/permalink/PermalinkHandler.kt | 4 +- .../poll/create/CreatePollViewModel.kt | 1 + .../room/RequireActiveMembershipViewModel.kt | 1 + .../roomdirectory/RoomDirectoryViewModel.kt | 4 +- .../createroom/CreateRoomViewModel.kt | 8 +- .../picker/RoomDirectoryPickerViewModel.kt | 2 +- .../roompreview/RoomPreviewViewModel.kt | 7 +- .../RoomMemberProfileViewModel.kt | 8 +- .../devices/DeviceListBottomSheetViewModel.kt | 1 + .../roomprofile/RoomProfileViewModel.kt | 3 +- .../roomprofile/alias/RoomAliasViewModel.kt | 7 +- .../banned/RoomBannedMemberListViewModel.kt | 1 + .../members/RoomMemberListViewModel.kt | 1 + .../RoomNotificationSettingsViewModel.kt | 1 + .../permissions/RoomPermissionsViewModel.kt | 1 + .../settings/RoomSettingsViewModel.kt | 3 +- .../RoomJoinRuleChooseRestrictedViewModel.kt | 6 +- .../uploads/RoomUploadsViewModel.kt | 1 + .../settings/SecretsSynchronisationInfo.kt | 4 +- .../settings/VectorSettingsGeneralFragment.kt | 9 +- .../settings/VectorSettingsLabsFragment.kt | 2 +- .../VectorSettingsPreferencesFragment.kt | 2 +- .../DeactivateAccountViewModel.kt | 5 +- .../CrossSigningSettingsViewModel.kt | 3 +- ...iceVerificationInfoBottomSheetViewModel.kt | 2 +- .../settings/devices/DevicesViewModel.kt | 3 +- .../homeserver/HomeserverSettingsViewModel.kt | 6 +- .../settings/ignored/IgnoredUsersViewModel.kt | 2 +- ...sAdvancedNotificationPreferenceFragment.kt | 4 +- ...dMentionsNotificationPreferenceFragment.kt | 10 +- ...rSettingsNotificationPreferenceFragment.kt | 16 +-- ...sPushRuleNotificationPreferenceFragment.kt | 4 +- .../settings/push/PushGatewaysViewModel.kt | 6 +- .../settings/push/PushRulesViewModel.kt | 2 +- .../threepids/ThreePidsSettingsViewModel.kt | 15 ++- .../troubleshoot/TestAccountSettings.kt | 4 +- .../troubleshoot/TestPushRulesSettings.kt | 2 +- .../features/share/IncomingShareFragment.kt | 1 + .../features/share/IncomingShareViewModel.kt | 1 + .../signout/soft/SoftLogoutViewModel.kt | 5 +- .../app/features/spaces/SpaceListViewModel.kt | 11 +- .../app/features/spaces/SpaceMenuViewModel.kt | 4 +- .../spaces/create/CreateSpaceViewModel.kt | 2 +- .../spaces/create/CreateSpaceViewModelTask.kt | 7 +- .../spaces/explore/SpaceDirectoryViewModel.kt | 4 +- .../invite/SpaceInviteBottomSheetViewModel.kt | 6 +- .../leave/SpaceLeaveAdvancedViewModel.kt | 6 +- .../spaces/manage/SpaceAddRoomsViewModel.kt | 15 ++- .../manage/SpaceManageRoomsViewModel.kt | 1 + .../spaces/people/SpacePeopleViewModel.kt | 4 +- .../spaces/preview/SpacePreviewViewModel.kt | 1 + .../spaces/share/ShareSpaceViewModel.kt | 2 + .../features/terms/ReviewTermsViewModel.kt | 4 +- .../usercode/UserCodeSharedViewModel.kt | 3 +- .../userdirectory/UserListViewModel.kt | 7 +- .../features/widgets/WidgetPostAPIHandler.kt | 1 + .../app/features/widgets/WidgetViewModel.kt | 1 + .../signout/ServerBackupStatusViewModel.kt | 2 +- .../workers/signout/SignoutCheckViewModel.kt | 4 +- .../im/vector/app/test/fakes/FakeSession.kt | 13 +- 164 files changed, 610 insertions(+), 383 deletions(-) create mode 100644 matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/SessionExtensions.kt diff --git a/matrix-sdk-android-flow/src/main/java/org/matrix/android/sdk/flow/FlowSession.kt b/matrix-sdk-android-flow/src/main/java/org/matrix/android/sdk/flow/FlowSession.kt index 18753f0705..9f260858f6 100644 --- a/matrix-sdk-android-flow/src/main/java/org/matrix/android/sdk/flow/FlowSession.kt +++ b/matrix-sdk-android-flow/src/main/java/org/matrix/android/sdk/flow/FlowSession.kt @@ -46,16 +46,16 @@ import org.matrix.android.sdk.api.util.toOptional class FlowSession(private val session: Session) { fun liveRoomSummaries(queryParams: RoomSummaryQueryParams, sortOrder: RoomSortOrder = RoomSortOrder.NONE): Flow> { - return session.getRoomSummariesLive(queryParams, sortOrder).asFlow() + return session.roomService().getRoomSummariesLive(queryParams, sortOrder).asFlow() .startWith(session.coroutineDispatchers.io) { - session.getRoomSummaries(queryParams, sortOrder) + session.roomService().getRoomSummaries(queryParams, sortOrder) } } fun liveGroupSummaries(queryParams: GroupSummaryQueryParams): Flow> { - return session.getGroupSummariesLive(queryParams).asFlow() + return session.groupService().getGroupSummariesLive(queryParams).asFlow() .startWith(session.coroutineDispatchers.io) { - session.getGroupSummaries(queryParams) + session.groupService().getGroupSummaries(queryParams) } } @@ -67,9 +67,9 @@ class FlowSession(private val session: Session) { } fun liveBreadcrumbs(queryParams: RoomSummaryQueryParams): Flow> { - return session.getBreadcrumbsLive(queryParams).asFlow() + return session.roomService().getBreadcrumbsLive(queryParams).asFlow() .startWith(session.coroutineDispatchers.io) { - session.getBreadcrumbs(queryParams) + session.roomService().getBreadcrumbs(queryParams) } } @@ -85,43 +85,47 @@ class FlowSession(private val session: Session) { } fun livePushers(): Flow> { - return session.getPushersLive().asFlow() + return session.pushersService().getPushersLive().asFlow() } fun liveUser(userId: String): Flow> { - return session.getUserLive(userId).asFlow() + return session.userService().getUserLive(userId).asFlow() .startWith(session.coroutineDispatchers.io) { - session.getUser(userId).toOptional() + session.userService().getUser(userId).toOptional() } } fun liveRoomMember(userId: String, roomId: String): Flow> { - return session.getRoomMemberLive(userId, roomId).asFlow() + return session.roomService().getRoomMemberLive(userId, roomId).asFlow() .startWith(session.coroutineDispatchers.io) { - session.getRoomMember(userId, roomId).toOptional() + session.roomService().getRoomMember(userId, roomId).toOptional() } } fun liveUsers(): Flow> { - return session.getUsersLive().asFlow() + return session.userService().getUsersLive().asFlow() } fun liveIgnoredUsers(): Flow> { - return session.getIgnoredUsersLive().asFlow() + return session.userService().getIgnoredUsersLive().asFlow() } fun livePagedUsers(filter: String? = null, excludedUserIds: Set? = null): Flow> { - return session.getPagedUsersLive(filter, excludedUserIds).asFlow() + return session.userService().getPagedUsersLive(filter, excludedUserIds).asFlow() } fun liveThreePIds(refreshData: Boolean): Flow> { - return session.getThreePidsLive(refreshData).asFlow() - .startWith(session.coroutineDispatchers.io) { session.getThreePids() } + return session.profileService().getThreePidsLive(refreshData).asFlow() + .startWith(session.coroutineDispatchers.io) { + session.profileService().getThreePids() + } } fun livePendingThreePIds(): Flow> { - return session.getPendingThreePidsLive().asFlow() - .startWith(session.coroutineDispatchers.io) { session.getPendingThreePids() } + return session.profileService().getPendingThreePidsLive().asFlow() + .startWith(session.coroutineDispatchers.io) { + session.profileService().getPendingThreePids() + } } fun liveUserCryptoDevices(userId: String): Flow> { @@ -179,7 +183,7 @@ class FlowSession(private val session: Session) { } fun liveRoomChangeMembershipState(): Flow> { - return session.getChangeMembershipsLive().asFlow() + return session.roomService().getChangeMembershipsLive().asFlow() } } diff --git a/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/account/ChangePasswordTest.kt b/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/account/ChangePasswordTest.kt index 933074cdce..6d740c5a34 100644 --- a/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/account/ChangePasswordTest.kt +++ b/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/account/ChangePasswordTest.kt @@ -46,7 +46,7 @@ class ChangePasswordTest : InstrumentedTest { // Change password commonTestHelper.runBlockingTest { - session.changePassword(TestConstants.PASSWORD, NEW_PASSWORD) + session.accountService().changePassword(TestConstants.PASSWORD, NEW_PASSWORD) } // Try to login with the previous password, it will fail diff --git a/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/account/DeactivateAccountTest.kt b/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/account/DeactivateAccountTest.kt index f8d108fb73..52dbfc7155 100644 --- a/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/account/DeactivateAccountTest.kt +++ b/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/account/DeactivateAccountTest.kt @@ -47,7 +47,7 @@ class DeactivateAccountTest : InstrumentedTest { // Deactivate the account commonTestHelper.runBlockingTest { - session.deactivateAccount( + session.accountService().deactivateAccount( eraseAllData = false, userInteractiveAuthInterceptor = object : UserInteractiveAuthInterceptor { override fun performStage(flowResponse: RegistrationFlowResponse, errCode: String?, promise: Continuation) { diff --git a/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/common/CommonTestHelper.kt b/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/common/CommonTestHelper.kt index ac4ccf56d1..63922f0226 100644 --- a/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/common/CommonTestHelper.kt +++ b/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/common/CommonTestHelper.kt @@ -431,7 +431,7 @@ class CommonTestHelper(context: Context) { fun signOutAndClose(session: Session) { runBlockingTest(timeout = 60_000) { - session.signOut(true) + session.signOutService().signOut(true) } // no need signout will close // session.close() diff --git a/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/common/CryptoTestHelper.kt b/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/common/CryptoTestHelper.kt index e3ab1a4921..ecb279cdc2 100644 --- a/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/common/CryptoTestHelper.kt +++ b/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/common/CryptoTestHelper.kt @@ -40,6 +40,7 @@ import org.matrix.android.sdk.api.session.crypto.verification.VerificationTxStat import org.matrix.android.sdk.api.session.events.model.Event 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.getRoom 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.RoomSummary @@ -64,7 +65,7 @@ class CryptoTestHelper(private val testHelper: CommonTestHelper) { val aliceSession = testHelper.createAccount(TestConstants.USER_ALICE, defaultSessionParams) val roomId = testHelper.runBlockingTest { - aliceSession.createRoom(CreateRoomParams().apply { name = "MyRoom" }) + aliceSession.roomService().createRoom(CreateRoomParams().apply { name = "MyRoom" }) } if (encryptedRoom) { testHelper.waitWithLatch { latch -> @@ -98,7 +99,7 @@ class CryptoTestHelper(private val testHelper: CommonTestHelper) { val bobSession = testHelper.createAccount(TestConstants.USER_BOB, defaultSessionParams) testHelper.waitWithLatch { latch -> - val bobRoomSummariesLive = bobSession.getRoomSummariesLive(roomSummaryQueryParams { }) + val bobRoomSummariesLive = bobSession.roomService().getRoomSummariesLive(roomSummaryQueryParams { }) val newRoomObserver = object : Observer> { override fun onChanged(t: List?) { if (t?.isNotEmpty() == true) { @@ -112,7 +113,7 @@ class CryptoTestHelper(private val testHelper: CommonTestHelper) { } testHelper.waitWithLatch { latch -> - val bobRoomSummariesLive = bobSession.getRoomSummariesLive(roomSummaryQueryParams { }) + val bobRoomSummariesLive = bobSession.roomService().getRoomSummariesLive(roomSummaryQueryParams { }) val roomJoinedObserver = object : Observer> { override fun onChanged(t: List?) { if (bobSession.getRoom(aliceRoomId) @@ -124,7 +125,7 @@ class CryptoTestHelper(private val testHelper: CommonTestHelper) { } } bobRoomSummariesLive.observeForever(roomJoinedObserver) - bobSession.joinRoom(aliceRoomId) + bobSession.roomService().joinRoom(aliceRoomId) } // Ensure bob can send messages to the room // val roomFromBobPOV = bobSession.getRoom(aliceRoomId)!! @@ -164,7 +165,7 @@ class CryptoTestHelper(private val testHelper: CommonTestHelper) { } testHelper.runBlockingTest { - samSession.joinRoom(room.roomId, null, emptyList()) + samSession.roomService().joinRoom(room.roomId, null, emptyList()) } return samSession @@ -242,8 +243,8 @@ class CryptoTestHelper(private val testHelper: CommonTestHelper) { fun createDM(alice: Session, bob: Session): String { var roomId: String = "" testHelper.waitWithLatch { latch -> - roomId = alice.createDirectRoom(bob.myUserId) - val bobRoomSummariesLive = bob.getRoomSummariesLive(roomSummaryQueryParams { }) + roomId = alice.roomService().createDirectRoom(bob.myUserId) + val bobRoomSummariesLive = bob.roomService().getRoomSummariesLive(roomSummaryQueryParams { }) val newRoomObserver = object : Observer> { override fun onChanged(t: List?) { if (t?.any { it.roomId == roomId }.orFalse()) { @@ -256,7 +257,7 @@ class CryptoTestHelper(private val testHelper: CommonTestHelper) { } testHelper.waitWithLatch { latch -> - val bobRoomSummariesLive = bob.getRoomSummariesLive(roomSummaryQueryParams { }) + val bobRoomSummariesLive = bob.roomService().getRoomSummariesLive(roomSummaryQueryParams { }) val newRoomObserver = object : Observer> { override fun onChanged(t: List?) { if (bob.getRoom(roomId) @@ -268,7 +269,7 @@ class CryptoTestHelper(private val testHelper: CommonTestHelper) { } } bobRoomSummariesLive.observeForever(newRoomObserver) - bob.joinRoom(roomId) + bob.roomService().joinRoom(roomId) } return roomId @@ -367,7 +368,7 @@ class CryptoTestHelper(private val testHelper: CommonTestHelper) { aliceSession.cryptoService().setWarnOnUnknownDevices(false) val roomId = testHelper.runBlockingTest { - aliceSession.createRoom(CreateRoomParams().apply { name = "MyRoom" }) + aliceSession.roomService().createRoom(CreateRoomParams().apply { name = "MyRoom" }) } val room = aliceSession.getRoom(roomId)!! @@ -380,7 +381,7 @@ class CryptoTestHelper(private val testHelper: CommonTestHelper) { val session = testHelper.createAccount("User_$index", defaultSessionParams) testHelper.runBlockingTest(timeout = 600_000) { room.invite(session.myUserId, null) } println("TEST -> " + session.myUserId + " invited") - testHelper.runBlockingTest { session.joinRoom(room.roomId, null, emptyList()) } + testHelper.runBlockingTest { session.roomService().joinRoom(room.roomId, null, emptyList()) } println("TEST -> " + session.myUserId + " joined") sessions.add(session) } diff --git a/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/internal/crypto/E2eeSanityTests.kt b/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/internal/crypto/E2eeSanityTests.kt index 3884683151..fbd0905261 100644 --- a/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/internal/crypto/E2eeSanityTests.kt +++ b/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/internal/crypto/E2eeSanityTests.kt @@ -38,6 +38,8 @@ import org.matrix.android.sdk.api.session.crypto.model.OlmDecryptionResult import org.matrix.android.sdk.api.session.events.model.EventType import org.matrix.android.sdk.api.session.events.model.content.EncryptedEventContent import org.matrix.android.sdk.api.session.events.model.toModel +import org.matrix.android.sdk.api.session.getRoom +import org.matrix.android.sdk.api.session.getRoomSummary import org.matrix.android.sdk.api.session.room.Room import org.matrix.android.sdk.api.session.room.failure.JoinRoomFailure import org.matrix.android.sdk.api.session.room.model.Membership @@ -551,7 +553,7 @@ class E2eeSanityTests : InstrumentedTest { testHelper.waitWithLatch { latch -> testHelper.retryPeriodicallyWithLatch(latch) { otherAccounts.map { - aliceSession.getRoomMember(it.myUserId, e2eRoomID)?.membership + aliceSession.roomService().getRoomMember(it.myUserId, e2eRoomID)?.membership }.all { it == Membership.JOIN } @@ -574,7 +576,7 @@ class E2eeSanityTests : InstrumentedTest { testHelper.runBlockingTest(60_000) { Log.v("#E2E TEST", "${otherSession.myUserId} tries to join room $e2eRoomID") try { - otherSession.joinRoom(e2eRoomID) + otherSession.roomService().joinRoom(e2eRoomID) } catch (ex: JoinRoomFailure.JoinedWithTimeout) { // it's ok we will wait after } diff --git a/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/internal/crypto/PreShareKeysTest.kt b/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/internal/crypto/PreShareKeysTest.kt index aa9f09314f..f8ce7ae357 100644 --- a/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/internal/crypto/PreShareKeysTest.kt +++ b/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/internal/crypto/PreShareKeysTest.kt @@ -29,6 +29,7 @@ import org.matrix.android.sdk.api.session.events.model.EventType import org.matrix.android.sdk.api.session.events.model.content.EncryptedEventContent import org.matrix.android.sdk.api.session.events.model.content.RoomKeyContent import org.matrix.android.sdk.api.session.events.model.toModel +import org.matrix.android.sdk.api.session.getRoom import org.matrix.android.sdk.common.CommonTestHelper import org.matrix.android.sdk.common.CryptoTestHelper diff --git a/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/internal/crypto/UnwedgingTest.kt b/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/internal/crypto/UnwedgingTest.kt index 8346430530..8e9f651f4c 100644 --- a/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/internal/crypto/UnwedgingTest.kt +++ b/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/internal/crypto/UnwedgingTest.kt @@ -34,6 +34,7 @@ import org.matrix.android.sdk.api.session.crypto.MXCryptoError import org.matrix.android.sdk.api.session.events.model.EventType import org.matrix.android.sdk.api.session.events.model.content.EncryptedEventContent import org.matrix.android.sdk.api.session.events.model.toModel +import org.matrix.android.sdk.api.session.getRoom import org.matrix.android.sdk.api.session.room.timeline.Timeline import org.matrix.android.sdk.api.session.room.timeline.TimelineEvent import org.matrix.android.sdk.api.session.room.timeline.TimelineSettings diff --git a/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/internal/crypto/encryption/EncryptionTest.kt b/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/internal/crypto/encryption/EncryptionTest.kt index 84c9487e03..f130918bd8 100644 --- a/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/internal/crypto/encryption/EncryptionTest.kt +++ b/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/internal/crypto/encryption/EncryptionTest.kt @@ -28,6 +28,7 @@ import org.matrix.android.sdk.api.crypto.MXCRYPTO_ALGORITHM_MEGOLM import org.matrix.android.sdk.api.session.events.model.EventType import org.matrix.android.sdk.api.session.events.model.content.EncryptionEventContent import org.matrix.android.sdk.api.session.events.model.toContent +import org.matrix.android.sdk.api.session.getRoom import org.matrix.android.sdk.api.session.room.Room import org.matrix.android.sdk.api.session.room.send.SendState import org.matrix.android.sdk.api.session.room.timeline.Timeline diff --git a/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/internal/crypto/gossiping/KeyShareTests.kt b/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/internal/crypto/gossiping/KeyShareTests.kt index 5e271c6910..ed30691175 100644 --- a/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/internal/crypto/gossiping/KeyShareTests.kt +++ b/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/internal/crypto/gossiping/KeyShareTests.kt @@ -50,6 +50,7 @@ import org.matrix.android.sdk.api.session.crypto.verification.VerificationTransa import org.matrix.android.sdk.api.session.crypto.verification.VerificationTxState import org.matrix.android.sdk.api.session.events.model.content.EncryptedEventContent import org.matrix.android.sdk.api.session.events.model.toModel +import org.matrix.android.sdk.api.session.getRoom import org.matrix.android.sdk.api.session.room.model.RoomDirectoryVisibility import org.matrix.android.sdk.api.session.room.model.create.CreateRoomParams import org.matrix.android.sdk.api.session.room.model.message.MessageContent @@ -73,7 +74,7 @@ class KeyShareTests : InstrumentedTest { // Create an encrypted room and add a message val roomId = commonTestHelper.runBlockingTest { - aliceSession.createRoom( + aliceSession.roomService().createRoom( CreateRoomParams().apply { visibility = RoomDirectoryVisibility.PRIVATE enableEncryption() @@ -340,7 +341,7 @@ class KeyShareTests : InstrumentedTest { // Create an encrypted room and send a couple of messages val roomId = commonTestHelper.runBlockingTest { - aliceSession.createRoom( + aliceSession.roomService().createRoom( CreateRoomParams().apply { visibility = RoomDirectoryVisibility.PRIVATE enableEncryption() @@ -378,7 +379,7 @@ class KeyShareTests : InstrumentedTest { } commonTestHelper.runBlockingTest { - bobSession.joinRoom(roomAlicePov.roomId, null, emptyList()) + bobSession.roomService().joinRoom(roomAlicePov.roomId, null, emptyList()) } // we want to discard alice outbound session diff --git a/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/internal/crypto/gossiping/WithHeldTests.kt b/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/internal/crypto/gossiping/WithHeldTests.kt index 55bb03278c..8f906c56a7 100644 --- a/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/internal/crypto/gossiping/WithHeldTests.kt +++ b/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/internal/crypto/gossiping/WithHeldTests.kt @@ -33,6 +33,7 @@ import org.matrix.android.sdk.api.session.events.model.EventType import org.matrix.android.sdk.api.session.events.model.content.EncryptedEventContent import org.matrix.android.sdk.api.session.events.model.content.WithHeldCode import org.matrix.android.sdk.api.session.events.model.toModel +import org.matrix.android.sdk.api.session.getRoom import org.matrix.android.sdk.common.CommonTestHelper import org.matrix.android.sdk.common.CryptoTestHelper import org.matrix.android.sdk.common.MockOkHttpInterceptor diff --git a/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/internal/crypto/keysbackup/KeysBackupTest.kt b/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/internal/crypto/keysbackup/KeysBackupTest.kt index 063c0c0ca3..3220f161fa 100644 --- a/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/internal/crypto/keysbackup/KeysBackupTest.kt +++ b/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/internal/crypto/keysbackup/KeysBackupTest.kt @@ -41,6 +41,7 @@ import org.matrix.android.sdk.api.session.crypto.keysbackup.KeysVersion import org.matrix.android.sdk.api.session.crypto.keysbackup.MegolmBackupCreationInfo import org.matrix.android.sdk.api.session.crypto.keysbackup.toKeysVersionResult import org.matrix.android.sdk.api.session.crypto.model.ImportRoomKeysResult +import org.matrix.android.sdk.api.session.getRoom import org.matrix.android.sdk.common.CommonTestHelper import org.matrix.android.sdk.common.CryptoTestHelper import org.matrix.android.sdk.common.TestConstants diff --git a/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/internal/crypto/ssss/QuadSTests.kt b/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/internal/crypto/ssss/QuadSTests.kt index d6baa4b1e0..a882f69013 100644 --- a/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/internal/crypto/ssss/QuadSTests.kt +++ b/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/internal/crypto/ssss/QuadSTests.kt @@ -60,7 +60,7 @@ class QuadSTests : InstrumentedTest { val aliceSession = testHelper.createAccount(TestConstants.USER_ALICE, SessionTestParams(true)) - val quadS = aliceSession.sharedSecretStorageService + val quadS = aliceSession.sharedSecretStorageService() val TEST_KEY_ID = "my.test.Key" @@ -120,7 +120,7 @@ class QuadSTests : InstrumentedTest { // Store a secret val clearSecret = "42".toByteArray().toBase64NoPadding() testHelper.runBlockingTest { - aliceSession.sharedSecretStorageService.storeSecret( + aliceSession.sharedSecretStorageService().storeSecret( "secret.of.life", clearSecret, listOf(SharedSecretStorageService.KeyRef(null, keySpec)) // default key @@ -141,7 +141,7 @@ class QuadSTests : InstrumentedTest { // Try to decrypt?? val decryptedSecret = testHelper.runBlockingTest { - aliceSession.sharedSecretStorageService.getSecret( + aliceSession.sharedSecretStorageService().getSecret( "secret.of.life", null, // default key keySpec!! @@ -158,7 +158,7 @@ class QuadSTests : InstrumentedTest { val aliceSession = testHelper.createAccount(TestConstants.USER_ALICE, SessionTestParams(true)) - val quadS = aliceSession.sharedSecretStorageService + val quadS = aliceSession.sharedSecretStorageService() val TEST_KEY_ID = "my.test.Key" @@ -187,7 +187,7 @@ class QuadSTests : InstrumentedTest { val mySecretText = "Lorem ipsum dolor sit amet, consectetur adipiscing elit" testHelper.runBlockingTest { - aliceSession.sharedSecretStorageService.storeSecret( + aliceSession.sharedSecretStorageService().storeSecret( "my.secret", mySecretText.toByteArray().toBase64NoPadding(), listOf( @@ -207,14 +207,14 @@ class QuadSTests : InstrumentedTest { // Assert that can decrypt with both keys testHelper.runBlockingTest { - aliceSession.sharedSecretStorageService.getSecret("my.secret", + aliceSession.sharedSecretStorageService().getSecret("my.secret", keyId1, RawBytesKeySpec.fromRecoveryKey(key1Info.recoveryKey)!! ) } testHelper.runBlockingTest { - aliceSession.sharedSecretStorageService.getSecret("my.secret", + aliceSession.sharedSecretStorageService().getSecret("my.secret", keyId2, RawBytesKeySpec.fromRecoveryKey(key2Info.recoveryKey)!! ) @@ -236,7 +236,7 @@ class QuadSTests : InstrumentedTest { val mySecretText = "Lorem ipsum dolor sit amet, consectetur adipiscing elit" testHelper.runBlockingTest { - aliceSession.sharedSecretStorageService.storeSecret( + aliceSession.sharedSecretStorageService().storeSecret( "my.secret", mySecretText.toByteArray().toBase64NoPadding(), listOf(SharedSecretStorageService.KeyRef(keyId1, RawBytesKeySpec.fromRecoveryKey(key1Info.recoveryKey))) @@ -245,7 +245,7 @@ class QuadSTests : InstrumentedTest { testHelper.runBlockingTest { try { - aliceSession.sharedSecretStorageService.getSecret("my.secret", + aliceSession.sharedSecretStorageService().getSecret("my.secret", keyId1, RawBytesKeySpec.fromPassphrase( "A bad passphrase", @@ -260,7 +260,7 @@ class QuadSTests : InstrumentedTest { // Now try with correct key testHelper.runBlockingTest { - aliceSession.sharedSecretStorageService.getSecret("my.secret", + aliceSession.sharedSecretStorageService().getSecret("my.secret", keyId1, RawBytesKeySpec.fromPassphrase( passphrase, @@ -292,7 +292,7 @@ class QuadSTests : InstrumentedTest { } private fun generatedSecret(session: Session, keyId: String, asDefault: Boolean = true): SsssKeyCreationInfo { - val quadS = session.sharedSecretStorageService + val quadS = session.sharedSecretStorageService() val testHelper = CommonTestHelper(context()) val creationInfo = testHelper.runBlockingTest { @@ -312,7 +312,7 @@ class QuadSTests : InstrumentedTest { } private fun generatedSecretFromPassphrase(session: Session, passphrase: String, keyId: String, asDefault: Boolean = true): SsssKeyCreationInfo { - val quadS = session.sharedSecretStorageService + val quadS = session.sharedSecretStorageService() val testHelper = CommonTestHelper(context()) val creationInfo = testHelper.runBlockingTest { diff --git a/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/session/room/threads/ThreadMessagingTest.kt b/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/session/room/threads/ThreadMessagingTest.kt index dcb181f0c1..8dac12e2df 100644 --- a/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/session/room/threads/ThreadMessagingTest.kt +++ b/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/session/room/threads/ThreadMessagingTest.kt @@ -31,6 +31,7 @@ import org.matrix.android.sdk.InstrumentedTest import org.matrix.android.sdk.api.session.events.model.getRootThreadEventId import org.matrix.android.sdk.api.session.events.model.isTextMessage import org.matrix.android.sdk.api.session.events.model.isThread +import org.matrix.android.sdk.api.session.getRoom import org.matrix.android.sdk.api.session.room.timeline.Timeline import org.matrix.android.sdk.api.session.room.timeline.TimelineSettings import org.matrix.android.sdk.common.CommonTestHelper diff --git a/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/session/room/timeline/PollAggregationTest.kt b/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/session/room/timeline/PollAggregationTest.kt index 6792d6ddfd..5700e6e040 100644 --- a/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/session/room/timeline/PollAggregationTest.kt +++ b/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/session/room/timeline/PollAggregationTest.kt @@ -30,6 +30,7 @@ import org.junit.runners.MethodSorters import org.matrix.android.sdk.InstrumentedTest 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.getRoom import org.matrix.android.sdk.api.session.room.model.PollResponseAggregatedSummary import org.matrix.android.sdk.api.session.room.model.PollSummaryContent import org.matrix.android.sdk.api.session.room.model.message.MessagePollContent diff --git a/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/session/room/timeline/TimelineForwardPaginationTest.kt b/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/session/room/timeline/TimelineForwardPaginationTest.kt index ee44af58b3..b57afca502 100644 --- a/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/session/room/timeline/TimelineForwardPaginationTest.kt +++ b/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/session/room/timeline/TimelineForwardPaginationTest.kt @@ -30,6 +30,7 @@ import org.matrix.android.sdk.InstrumentedTest import org.matrix.android.sdk.api.extensions.orFalse import org.matrix.android.sdk.api.session.events.model.EventType import org.matrix.android.sdk.api.session.events.model.toModel +import org.matrix.android.sdk.api.session.getRoom import org.matrix.android.sdk.api.session.room.model.message.MessageContent import org.matrix.android.sdk.api.session.room.timeline.Timeline import org.matrix.android.sdk.api.session.room.timeline.TimelineSettings diff --git a/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/session/room/timeline/TimelinePreviousLastForwardTest.kt b/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/session/room/timeline/TimelinePreviousLastForwardTest.kt index c6d40bcaa2..3adc19b031 100644 --- a/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/session/room/timeline/TimelinePreviousLastForwardTest.kt +++ b/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/session/room/timeline/TimelinePreviousLastForwardTest.kt @@ -28,6 +28,7 @@ import org.matrix.android.sdk.InstrumentedTest import org.matrix.android.sdk.api.extensions.orFalse import org.matrix.android.sdk.api.session.events.model.EventType import org.matrix.android.sdk.api.session.events.model.toModel +import org.matrix.android.sdk.api.session.getRoom import org.matrix.android.sdk.api.session.room.model.message.MessageContent import org.matrix.android.sdk.api.session.room.timeline.Timeline import org.matrix.android.sdk.api.session.room.timeline.TimelineSettings diff --git a/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/session/room/timeline/TimelineSimpleBackPaginationTest.kt b/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/session/room/timeline/TimelineSimpleBackPaginationTest.kt index 53f76f1c46..59546f244e 100644 --- a/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/session/room/timeline/TimelineSimpleBackPaginationTest.kt +++ b/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/session/room/timeline/TimelineSimpleBackPaginationTest.kt @@ -28,6 +28,7 @@ import org.matrix.android.sdk.InstrumentedTest import org.matrix.android.sdk.api.extensions.orFalse import org.matrix.android.sdk.api.session.events.model.isTextMessage import org.matrix.android.sdk.api.session.events.model.toModel +import org.matrix.android.sdk.api.session.getRoom import org.matrix.android.sdk.api.session.room.model.message.MessageTextContent import org.matrix.android.sdk.api.session.room.timeline.Timeline import org.matrix.android.sdk.api.session.room.timeline.TimelineSettings diff --git a/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/session/room/timeline/TimelineWithManyMembersTest.kt b/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/session/room/timeline/TimelineWithManyMembersTest.kt index ce02b2b527..3e87d68f22 100644 --- a/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/session/room/timeline/TimelineWithManyMembersTest.kt +++ b/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/session/room/timeline/TimelineWithManyMembersTest.kt @@ -27,6 +27,7 @@ import org.junit.runners.MethodSorters import org.matrix.android.sdk.InstrumentedTest import org.matrix.android.sdk.api.extensions.orFalse import org.matrix.android.sdk.api.session.events.model.toModel +import org.matrix.android.sdk.api.session.getRoom import org.matrix.android.sdk.api.session.room.model.message.MessageContent import org.matrix.android.sdk.api.session.room.timeline.TimelineSettings import org.matrix.android.sdk.common.CommonTestHelper diff --git a/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/session/search/SearchMessagesTest.kt b/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/session/search/SearchMessagesTest.kt index fa07cf5a02..c0191aad68 100644 --- a/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/session/search/SearchMessagesTest.kt +++ b/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/session/search/SearchMessagesTest.kt @@ -24,6 +24,7 @@ import org.junit.runners.JUnit4 import org.junit.runners.MethodSorters import org.matrix.android.sdk.InstrumentedTest import org.matrix.android.sdk.api.extensions.orFalse +import org.matrix.android.sdk.api.session.getRoom import org.matrix.android.sdk.api.session.search.SearchResult import org.matrix.android.sdk.common.CommonTestHelper import org.matrix.android.sdk.common.CryptoTestData diff --git a/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/session/space/SpaceCreationTest.kt b/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/session/space/SpaceCreationTest.kt index 3b0f7586cc..906f724bbe 100644 --- a/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/session/space/SpaceCreationTest.kt +++ b/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/session/space/SpaceCreationTest.kt @@ -147,7 +147,7 @@ class SpaceCreationTest : InstrumentedTest { // create a room var firstChild: String? = null commonTestHelper.waitWithLatch { - firstChild = aliceSession.createRoom(CreateRoomParams().apply { + firstChild = aliceSession.roomService().createRoom(CreateRoomParams().apply { this.name = "FirstRoom" this.topic = "Description of first room" this.preset = CreateRoomPreset.PRESET_PUBLIC_CHAT @@ -162,7 +162,7 @@ class SpaceCreationTest : InstrumentedTest { var secondChild: String? = null commonTestHelper.waitWithLatch { - secondChild = aliceSession.createRoom(CreateRoomParams().apply { + secondChild = aliceSession.roomService().createRoom(CreateRoomParams().apply { this.name = "SecondRoom" this.topic = "Description of second room" this.preset = CreateRoomPreset.PRESET_PUBLIC_CHAT diff --git a/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/session/space/SpaceHierarchyTest.kt b/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/session/space/SpaceHierarchyTest.kt index 20faa81bb6..50e9f49770 100644 --- a/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/session/space/SpaceHierarchyTest.kt +++ b/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/session/space/SpaceHierarchyTest.kt @@ -35,6 +35,8 @@ import org.matrix.android.sdk.api.session.Session 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.toModel +import org.matrix.android.sdk.api.session.getRoom +import org.matrix.android.sdk.api.session.getRoomSummary import org.matrix.android.sdk.api.session.room.model.PowerLevelsContent import org.matrix.android.sdk.api.session.room.model.RoomJoinRulesAllowEntry import org.matrix.android.sdk.api.session.room.model.RoomSummary @@ -68,7 +70,7 @@ class SpaceHierarchyTest : InstrumentedTest { var roomId = "" commonTestHelper.waitWithLatch { - roomId = session.createRoom(CreateRoomParams().apply { name = "General" }) + roomId = session.roomService().createRoom(CreateRoomParams().apply { name = "General" }) it.countDown() } @@ -203,27 +205,27 @@ class SpaceHierarchyTest : InstrumentedTest { var orphan1 = "" commonTestHelper.waitWithLatch { - orphan1 = session.createRoom(CreateRoomParams().apply { name = "O1" }) + orphan1 = session.roomService().createRoom(CreateRoomParams().apply { name = "O1" }) it.countDown() } var orphan2 = "" commonTestHelper.waitWithLatch { - orphan2 = session.createRoom(CreateRoomParams().apply { name = "O2" }) + orphan2 = session.roomService().createRoom(CreateRoomParams().apply { name = "O2" }) it.countDown() } - val allRooms = session.getRoomSummaries(roomSummaryQueryParams { excludeType = listOf(RoomType.SPACE) }) + val allRooms = session.roomService().getRoomSummaries(roomSummaryQueryParams { excludeType = listOf(RoomType.SPACE) }) assertEquals("Unexpected number of rooms", 9, allRooms.size) - val orphans = session.getFlattenRoomSummaryChildrenOf(null) + val orphans = session.roomService().getFlattenRoomSummaryChildrenOf(null) assertEquals("Unexpected number of orphan rooms", 2, orphans.size) assertTrue("O1 should be an orphan", orphans.any { it.roomId == orphan1 }) assertTrue("O2 should be an orphan ${orphans.map { it.name }}", orphans.any { it.roomId == orphan2 }) - val aChildren = session.getFlattenRoomSummaryChildrenOf(spaceAInfo.spaceId) + val aChildren = session.roomService().getFlattenRoomSummaryChildrenOf(spaceAInfo.spaceId) assertEquals("Unexpected number of flatten child rooms", 4, aChildren.size) assertTrue("A1 should be a child of A", aChildren.any { it.name == "A1" }) @@ -233,13 +235,13 @@ class SpaceHierarchyTest : InstrumentedTest { // Add a non canonical child and check that it does not appear as orphan commonTestHelper.waitWithLatch { - val a3 = session.createRoom(CreateRoomParams().apply { name = "A3" }) + val a3 = session.roomService().createRoom(CreateRoomParams().apply { name = "A3" }) spaceA!!.addChildren(a3, viaServers, null, false) it.countDown() } Thread.sleep(6_000) - val orphansUpdate = session.getRoomSummaries(roomSummaryQueryParams { + val orphansUpdate = session.roomService().getRoomSummaries(roomSummaryQueryParams { activeSpaceFilter = ActiveSpaceFilter.ActiveSpace(null) }) assertEquals("Unexpected number of orphan rooms ${orphansUpdate.map { it.name }}", 2, orphansUpdate.size) @@ -279,7 +281,7 @@ class SpaceHierarchyTest : InstrumentedTest { // A -> C -> A - val aChildren = session.getFlattenRoomSummaryChildrenOf(spaceAInfo.spaceId) + val aChildren = session.roomService().getFlattenRoomSummaryChildrenOf(spaceAInfo.spaceId) assertEquals("Unexpected number of flatten child rooms ${aChildren.map { it.name }}", 4, aChildren.size) assertTrue("A1 should be a child of A", aChildren.any { it.name == "A1" }) @@ -319,7 +321,7 @@ class SpaceHierarchyTest : InstrumentedTest { commonTestHelper.waitWithLatch { latch -> - val flatAChildren = session.getFlattenRoomSummaryChildrenOfLive(spaceAInfo.spaceId) + val flatAChildren = session.roomService().getFlattenRoomSummaryChildrenOfLive(spaceAInfo.spaceId) val childObserver = object : Observer> { override fun onChanged(children: List?) { // Log.d("## TEST", "Space A flat children update : ${children?.map { it.name }}") @@ -346,7 +348,7 @@ class SpaceHierarchyTest : InstrumentedTest { val bRoomId = spaceBInfo.roomIds.first() commonTestHelper.waitWithLatch { latch -> - val flatAChildren = session.getFlattenRoomSummaryChildrenOfLive(spaceAInfo.spaceId) + val flatAChildren = session.roomService().getFlattenRoomSummaryChildrenOfLive(spaceAInfo.spaceId) val childObserver = object : Observer> { override fun onChanged(children: List?) { System.out.println("## TEST | Space A flat children update : ${children?.map { it.name }}") @@ -359,7 +361,7 @@ class SpaceHierarchyTest : InstrumentedTest { } // part from b room - session.leaveRoom(bRoomId) + session.roomService().leaveRoom(bRoomId) // The room should have disapear from flat children flatAChildren.observeForever(childObserver) } @@ -385,7 +387,7 @@ class SpaceHierarchyTest : InstrumentedTest { val viaServers = listOf(session.sessionParams.homeServerHost ?: "") roomIds = childInfo.map { entry -> - session.createRoom(CreateRoomParams().apply { name = entry.first }) + session.roomService().createRoom(CreateRoomParams().apply { name = entry.first }) } roomIds.forEachIndexed { index, roomId -> syncedSpace!!.addChildren(roomId, viaServers, null, childInfo[index].second) @@ -414,8 +416,9 @@ class SpaceHierarchyTest : InstrumentedTest { roomIds = childInfo.map { entry -> val homeServerCapabilities = session + .homeServerCapabilitiesService() .getHomeServerCapabilities() - session.createRoom(CreateRoomParams().apply { + session.roomService().createRoom(CreateRoomParams().apply { name = entry.first this.featurePreset = RestrictedRoomPreset( homeServerCapabilities, @@ -498,18 +501,18 @@ class SpaceHierarchyTest : InstrumentedTest { } commonTestHelper.runBlockingTest { - bobSession.joinRoom(spaceAInfo.spaceId, null, emptyList()) + bobSession.roomService().joinRoom(spaceAInfo.spaceId, null, emptyList()) } var bobRoomId = "" commonTestHelper.waitWithLatch { - bobRoomId = bobSession.createRoom(CreateRoomParams().apply { name = "A Bob Room" }) + bobRoomId = bobSession.roomService().createRoom(CreateRoomParams().apply { name = "A Bob Room" }) bobSession.getRoom(bobRoomId)!!.invite(aliceSession.myUserId) it.countDown() } commonTestHelper.runBlockingTest { - aliceSession.joinRoom(bobRoomId) + aliceSession.roomService().joinRoom(bobRoomId) } commonTestHelper.waitWithLatch { latch -> diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/Session.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/Session.kt index 207afd50cc..19502f0b46 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/Session.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/Session.kt @@ -26,7 +26,6 @@ import org.matrix.android.sdk.api.failure.GlobalError import org.matrix.android.sdk.api.federation.FederationService import org.matrix.android.sdk.api.session.account.AccountService import org.matrix.android.sdk.api.session.accountdata.SessionAccountDataService -import org.matrix.android.sdk.api.session.cache.CacheService import org.matrix.android.sdk.api.session.call.CallSignalingService import org.matrix.android.sdk.api.session.content.ContentUploadStateTracker import org.matrix.android.sdk.api.session.content.ContentUrlResolver @@ -68,26 +67,7 @@ import org.matrix.android.sdk.api.session.widgets.WidgetService * This interface defines interactions with a session. * An instance of a session will be provided by the SDK. */ -interface Session : - RoomService, - RoomDirectoryService, - GroupService, - UserService, - CacheService, - SignOutService, - FilterService, - TermsService, - EventService, - ProfileService, - PresenceService, - PushRuleService, - PushersService, - SyncStatusService, - HomeServerCapabilitiesService, - SecureStorageService, - AccountService, - ToDeviceService, - EventStreamService { +interface Session { val coroutineDispatchers: MatrixCoroutineDispatchers @@ -144,6 +124,11 @@ interface Session : */ fun stopSync() + /** + * Clear cache of the session + */ + suspend fun clearCache() + /** * This method allows to listen the sync state. * @return a [LiveData] of [SyncState]. @@ -206,6 +191,96 @@ interface Session : */ fun identityService(): IdentityService + /** + * Returns the HomeServerCapabilities service associated with the session + */ + fun homeServerCapabilitiesService(): HomeServerCapabilitiesService + + /** + * Returns the RoomService associated with the session + */ + fun roomService(): RoomService + + /** + * Returns the RoomDirectoryService associated with the session + */ + fun roomDirectoryService(): RoomDirectoryService + + /** + * Returns the GroupService associated with the session + */ + fun groupService(): GroupService + + /** + * Returns the UserService associated with the session + */ + fun userService(): UserService + + /** + * Returns the SignOutService associated with the session + */ + fun signOutService(): SignOutService + + /** + * Returns the FilterService associated with the session + */ + fun filterService(): FilterService + + /** + * Returns the PushRuleService associated with the session + */ + fun pushRuleService(): PushRuleService + + /** + * Returns the PushersService associated with the session + */ + fun pushersService(): PushersService + + /** + * Returns the EventService associated with the session + */ + fun eventService(): EventService + + /** + * Returns the TermsService associated with the session + */ + fun termsService(): TermsService + + /** + * Returns the SyncStatusService associated with the session + */ + fun syncStatusService(): SyncStatusService + + /** + * Returns the SecureStorageService associated with the session + */ + fun secureStorageService(): SecureStorageService + + /** + * Returns the ProfileService associated with the session + */ + fun profileService(): ProfileService + + /** + * Returns the PresenceService associated with the session + */ + fun presenceService(): PresenceService + + /** + * Returns the AccountService associated with the session + */ + fun accountService(): AccountService + + /** + * Returns the ToDeviceService associated with the session + */ + fun toDeviceService(): ToDeviceService + + /** + * Returns the EventStreamService associated with the session + */ + fun eventStreamService(): EventStreamService + /** * Returns the widget service associated with the session */ @@ -266,6 +341,11 @@ interface Session : */ fun accountDataService(): SessionAccountDataService + /** + * Returns the SharedSecretStorageService associated with the session + */ + fun sharedSecretStorageService(): SharedSecretStorageService + /** * Add a listener to the session. * @param listener the listener to add. @@ -303,8 +383,6 @@ interface Session : fun onGlobalError(session: Session, globalError: GlobalError) = Unit } - val sharedSecretStorageService: SharedSecretStorageService - fun getUiaSsoFallbackUrl(authenticationSessionId: String): String /** diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/SessionExtensions.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/SessionExtensions.kt new file mode 100644 index 0000000000..aeb0e7e4ee --- /dev/null +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/SessionExtensions.kt @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2022 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.api.session + +import org.matrix.android.sdk.api.session.room.Room +import org.matrix.android.sdk.api.session.room.model.RoomSummary +import org.matrix.android.sdk.api.session.user.model.User + +/** + * Get a room using the RoomService of a Session + */ +fun Session.getRoom(roomId: String): Room? = roomService().getRoom(roomId) + +/** + * Get a room summary using the RoomService of a Session + */ +fun Session.getRoomSummary(roomIdOrAlias: String): RoomSummary? = roomService().getRoomSummary(roomIdOrAlias) + +/** + * Get a user using the UserService of a Session + */ +fun Session.getUser(userId: String): User? = userService().getUser(userId) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/DefaultSession.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/DefaultSession.kt index 826225cc08..5f77cfb23a 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/DefaultSession.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/DefaultSession.kt @@ -124,7 +124,7 @@ internal class DefaultSession @Inject constructor( private val syncStatusService: Lazy, private val homeServerCapabilitiesService: Lazy, private val accountDataService: Lazy, - private val _sharedSecretStorageService: Lazy, + private val sharedSecretStorageService: Lazy, private val accountService: Lazy, private val eventService: Lazy, private val contentScannerService: Lazy, @@ -140,28 +140,7 @@ internal class DefaultSession @Inject constructor( @UnauthenticatedWithCertificate private val unauthenticatedWithCertificateOkHttpClient: Lazy ) : Session, - GlobalErrorHandler.Listener, - RoomService by roomService.get(), - RoomDirectoryService by roomDirectoryService.get(), - GroupService by groupService.get(), - UserService by userService.get(), - SignOutService by signOutService.get(), - FilterService by filterService.get(), - PushRuleService by pushRuleService.get(), - PushersService by pushersService.get(), - EventService by eventService.get(), - TermsService by termsService.get(), - SyncStatusService by syncStatusService.get(), - SecureStorageService by secureStorageService.get(), - HomeServerCapabilitiesService by homeServerCapabilitiesService.get(), - ProfileService by profileService.get(), - PresenceService by presenceService.get(), - AccountService by accountService.get(), - ToDeviceService by toDeviceService.get(), - EventStreamService by eventStreamService.get() { - - override val sharedSecretStorageService: SharedSecretStorageService - get() = _sharedSecretStorageService.get() + GlobalErrorHandler.Listener { private var isOpen = false @@ -274,42 +253,44 @@ internal class DefaultSession @Inject constructor( } override fun contentUrlResolver() = contentUrlResolver - override fun contentUploadProgressTracker() = contentUploadProgressTracker - override fun typingUsersTracker() = typingUsersTracker - override fun contentDownloadProgressTracker(): ContentDownloadStateTracker = contentDownloadStateTracker override fun cryptoService(): CryptoService = cryptoService.get() - override fun contentScannerService(): ContentScannerService = contentScannerService.get() - override fun identityService(): IdentityService = identityService.get() - + override fun homeServerCapabilitiesService(): HomeServerCapabilitiesService = homeServerCapabilitiesService.get() + override fun roomService(): RoomService = roomService.get() + override fun roomDirectoryService(): RoomDirectoryService = roomDirectoryService.get() + override fun groupService(): GroupService = groupService.get() + override fun userService(): UserService = userService.get() + override fun signOutService(): SignOutService = signOutService.get() + override fun filterService(): FilterService = filterService.get() + override fun pushRuleService(): PushRuleService = pushRuleService.get() + override fun pushersService(): PushersService = pushersService.get() + override fun eventService(): EventService = eventService.get() + override fun termsService(): TermsService = termsService.get() + override fun syncStatusService(): SyncStatusService = syncStatusService.get() + override fun secureStorageService(): SecureStorageService = secureStorageService.get() + override fun profileService(): ProfileService = profileService.get() + override fun presenceService(): PresenceService = presenceService.get() + override fun accountService(): AccountService = accountService.get() + override fun toDeviceService(): ToDeviceService = toDeviceService.get() + override fun eventStreamService(): EventStreamService = eventStreamService.get() override fun fileService(): FileService = defaultFileService.get() - override fun permalinkService(): PermalinkService = permalinkService.get() - override fun widgetService(): WidgetService = widgetService.get() - override fun mediaService(): MediaService = mediaService.get() - override fun integrationManagerService(): IntegrationManagerService = integrationManagerService.get() - override fun callSignalingService(): CallSignalingService = callSignalingService.get() - override fun searchService(): SearchService = searchService.get() - override fun federationService(): FederationService = federationService.get() - override fun thirdPartyService(): ThirdPartyService = thirdPartyService.get() - override fun spaceService(): SpaceService = spaceService.get() - override fun openIdService(): OpenIdService = openIdService.get() - override fun accountDataService(): SessionAccountDataService = accountDataService.get() + override fun sharedSecretStorageService(): SharedSecretStorageService = sharedSecretStorageService.get() override fun getOkHttpClient(): OkHttpClient { return unauthenticatedWithCertificateOkHttpClient.get() diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/EventRelationsAggregationProcessor.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/EventRelationsAggregationProcessor.kt index 15ce5810c8..ac944ea8a7 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/EventRelationsAggregationProcessor.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/EventRelationsAggregationProcessor.kt @@ -542,7 +542,7 @@ internal class EventRelationsAggregationProcessor @Inject constructor( private fun getPollEvent(roomId: String, eventId: String): TimelineEvent? { val session = sessionManager.getSessionComponent(sessionId)?.session() - return session?.getRoom(roomId)?.getTimelineEvent(eventId) ?: return null.also { + return session?.roomService()?.getRoom(roomId)?.getTimelineEvent(eventId) ?: return null.also { Timber.v("## POLL target poll event $eventId not found in room $roomId") } } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/sync/SyncTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/sync/SyncTask.kt index bb0197a38d..197037f1cf 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/sync/SyncTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/sync/SyncTask.kt @@ -107,7 +107,7 @@ internal class DefaultSyncTask @Inject constructor( val isInitialSync = token == null if (isInitialSync) { // We might want to get the user information in parallel too - val user = tryOrNull { session.getProfileAsUser(userId) } + val user = tryOrNull { session.profileService().getProfileAsUser(userId) } userStore.createOrUpdate( userId = userId, displayName = user?.displayName, diff --git a/vector/src/androidTest/java/im/vector/app/SecurityBootstrapTest.kt b/vector/src/androidTest/java/im/vector/app/SecurityBootstrapTest.kt index 69fe63fb7b..a84aae9994 100644 --- a/vector/src/androidTest/java/im/vector/app/SecurityBootstrapTest.kt +++ b/vector/src/androidTest/java/im/vector/app/SecurityBootstrapTest.kt @@ -166,7 +166,7 @@ class SecurityBootstrapTest : VerificationTestBase() { assert(uiSession.cryptoService().crossSigningService().allPrivateKeysKnown()) assert(uiSession.cryptoService().keysBackupService().isEnabled) assert(uiSession.cryptoService().keysBackupService().currentBackupVersion != null) - assert(uiSession.sharedSecretStorageService.isRecoverySetup()) - assert(uiSession.sharedSecretStorageService.isMegolmKeyInBackup()) + assert(uiSession.sharedSecretStorageService().isRecoverySetup()) + assert(uiSession.sharedSecretStorageService().isMegolmKeyInBackup()) } } diff --git a/vector/src/gplay/java/im/vector/app/gplay/features/settings/troubleshoot/TestTokenRegistration.kt b/vector/src/gplay/java/im/vector/app/gplay/features/settings/troubleshoot/TestTokenRegistration.kt index f0199ad390..ec1b9ca7a2 100644 --- a/vector/src/gplay/java/im/vector/app/gplay/features/settings/troubleshoot/TestTokenRegistration.kt +++ b/vector/src/gplay/java/im/vector/app/gplay/features/settings/troubleshoot/TestTokenRegistration.kt @@ -49,7 +49,7 @@ class TestTokenRegistration @Inject constructor(private val context: FragmentAct status = TestStatus.FAILED return } - val pushers = session.getPushers().filter { + val pushers = session.pushersService().getPushers().filter { it.pushKey == fcmToken && it.state == PusherState.REGISTERED } if (pushers.isEmpty()) { diff --git a/vector/src/gplay/java/im/vector/app/gplay/push/fcm/VectorFirebaseMessagingService.kt b/vector/src/gplay/java/im/vector/app/gplay/push/fcm/VectorFirebaseMessagingService.kt index 93a82f24f9..8003b63ba0 100755 --- a/vector/src/gplay/java/im/vector/app/gplay/push/fcm/VectorFirebaseMessagingService.kt +++ b/vector/src/gplay/java/im/vector/app/gplay/push/fcm/VectorFirebaseMessagingService.kt @@ -46,6 +46,7 @@ import kotlinx.coroutines.runBlocking import org.matrix.android.sdk.api.extensions.tryOrNull import org.matrix.android.sdk.api.logger.LoggerTag import org.matrix.android.sdk.api.session.Session +import org.matrix.android.sdk.api.session.getRoom import timber.log.Timber import javax.inject.Inject @@ -194,7 +195,7 @@ class VectorFirebaseMessagingService : FirebaseMessagingService() { coroutineScope.launch { Timber.tag(loggerTag.value).d("Fast lane: start request") - val event = tryOrNull { session.getEvent(roomId, eventId) } ?: return@launch + val event = tryOrNull { session.eventService().getEvent(roomId, eventId) } ?: return@launch val resolvedEvent = notifiableEventResolver.resolveInMemoryEvent(session, event, canBeReplaced = true) diff --git a/vector/src/main/java/im/vector/app/AppStateHandler.kt b/vector/src/main/java/im/vector/app/AppStateHandler.kt index cc3aed03fb..86a38ef71e 100644 --- a/vector/src/main/java/im/vector/app/AppStateHandler.kt +++ b/vector/src/main/java/im/vector/app/AppStateHandler.kt @@ -38,6 +38,8 @@ import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.launch import org.matrix.android.sdk.api.extensions.tryOrNull import org.matrix.android.sdk.api.session.Session +import org.matrix.android.sdk.api.session.getRoom +import org.matrix.android.sdk.api.session.getRoomSummary import org.matrix.android.sdk.api.session.group.model.GroupSummary import org.matrix.android.sdk.api.session.initsync.SyncStatusService import org.matrix.android.sdk.api.session.room.model.RoomSummary @@ -78,7 +80,7 @@ class AppStateHandler @Inject constructor( return selectedSpaceDataSource.currentValue?.orNull()?.let { if (it is RoomGroupingMethod.BySpace) { // try to refresh sum? - it.spaceSummary?.roomId?.let { activeSessionHolder.getSafeActiveSession()?.getRoomSummary(it) }?.let { + it.spaceSummary?.roomId?.let { activeSessionHolder.getSafeActiveSession()?.roomService()?.getRoomSummary(it) }?.let { RoomGroupingMethod.BySpace(it) } ?: it } else it @@ -110,12 +112,12 @@ class AppStateHandler @Inject constructor( val uSession = session ?: activeSessionHolder.getSafeActiveSession() ?: return if (selectedSpaceDataSource.currentValue?.orNull() is RoomGroupingMethod.ByLegacyGroup && groupId == selectedSpaceDataSource.currentValue?.orNull()?.group()?.groupId) return - val activeGroup = groupId?.let { uSession.getGroupSummary(groupId) } + val activeGroup = groupId?.let { uSession.groupService().getGroupSummary(groupId) } selectedSpaceDataSource.post(Option.just(RoomGroupingMethod.ByLegacyGroup(activeGroup))) if (groupId != null) { uSession.coroutineScope.launch { tryOrNull { - uSession.getGroup(groupId)?.fetchGroupData() + uSession.groupService().getGroup(groupId)?.fetchGroupData() } } } @@ -139,7 +141,7 @@ class AppStateHandler @Inject constructor( } private fun observeSyncStatus(session: Session) { - session.getSyncStatusLive() + session.syncStatusService().getSyncStatusLive() .asFlow() .filterIsInstance() .map { session.spaceService().getRootSpaceSummaries().size } diff --git a/vector/src/main/java/im/vector/app/AutoRageShaker.kt b/vector/src/main/java/im/vector/app/AutoRageShaker.kt index 195e2f68dc..c77ce2b647 100644 --- a/vector/src/main/java/im/vector/app/AutoRageShaker.kt +++ b/vector/src/main/java/im/vector/app/AutoRageShaker.kt @@ -169,7 +169,7 @@ class AutoRageShaker @Inject constructor( coroutineScope.launch { try { - activeSessionHolder.getSafeActiveSession()?.sendToDevice( + activeSessionHolder.getSafeActiveSession()?.toDeviceService()?.sendToDevice( eventType = AUTO_RS_REQUEST, userId = target.senderUserId, deviceId = target.senderDeviceId, @@ -261,7 +261,7 @@ class AutoRageShaker @Inject constructor( this.currentActiveSessionId = sessionId hasSynced = session.hasAlreadySynced() - session.getSyncStatusLive() + session.syncStatusService().getSyncStatusLive() .asFlow() .onEach { hasSynced = it !is SyncStatusService.Status.InitialSyncProgressing @@ -269,11 +269,11 @@ class AutoRageShaker @Inject constructor( .launchIn(session.coroutineScope) activeSessionIds.add(sessionId) session.addListener(this) - session.addEventStreamListener(detector) + session.eventStreamService().addEventStreamListener(detector) } override fun onSessionStopped(session: Session) { - session.removeEventStreamListener(detector) + session.eventStreamService().removeEventStreamListener(detector) activeSessionIds.remove(session.sessionId) } } diff --git a/vector/src/main/java/im/vector/app/core/extensions/Session.kt b/vector/src/main/java/im/vector/app/core/extensions/Session.kt index f89ba4c47a..9bc1aff868 100644 --- a/vector/src/main/java/im/vector/app/core/extensions/Session.kt +++ b/vector/src/main/java/im/vector/app/core/extensions/Session.kt @@ -30,11 +30,11 @@ import timber.log.Timber fun Session.configureAndStart(context: Context, startSyncing: Boolean = true) { Timber.i("Configure and start session for $myUserId") open() - setFilter(FilterService.FilterPreset.ElementFilter) + filterService().setFilter(FilterService.FilterPreset.ElementFilter) if (startSyncing) { startSyncing(context) } - refreshPushers() + pushersService().refreshPushers() context.singletonEntryPoint().webRtcCallManager().checkForProtocolsSupportIfNeeded() } @@ -75,7 +75,7 @@ fun Session.cannotLogoutSafely(): Boolean { // has local cross signing keys (cryptoService().crossSigningService().allPrivateKeysKnown() && // That are not backed up - !sharedSecretStorageService.isRecoverySetup()) + !sharedSecretStorageService().isRecoverySetup()) } fun Session.vectorStore(context: Context) = VectorSessionStore(context, myUserId) diff --git a/vector/src/main/java/im/vector/app/core/pushers/PushersManager.kt b/vector/src/main/java/im/vector/app/core/pushers/PushersManager.kt index 27d6d05708..b1bb4c7d88 100644 --- a/vector/src/main/java/im/vector/app/core/pushers/PushersManager.kt +++ b/vector/src/main/java/im/vector/app/core/pushers/PushersManager.kt @@ -37,7 +37,7 @@ class PushersManager @Inject constructor( suspend fun testPush(pushKey: String) { val currentSession = activeSessionHolder.getActiveSession() - currentSession.testPush( + currentSession.pushersService().testPush( stringProvider.getString(R.string.pusher_http_url), stringProvider.getString(R.string.pusher_app_id), pushKey, @@ -47,12 +47,12 @@ class PushersManager @Inject constructor( fun enqueueRegisterPusherWithFcmKey(pushKey: String): UUID { val currentSession = activeSessionHolder.getActiveSession() - return currentSession.enqueueAddHttpPusher(createHttpPusher(pushKey)) + return currentSession.pushersService().enqueueAddHttpPusher(createHttpPusher(pushKey)) } suspend fun registerPusherWithFcmKey(pushKey: String) { val currentSession = activeSessionHolder.getActiveSession() - currentSession.addHttpPusher(createHttpPusher(pushKey)) + currentSession.pushersService().addHttpPusher(createHttpPusher(pushKey)) } private fun createHttpPusher(pushKey: String) = PushersService.HttpPusher( @@ -70,7 +70,7 @@ class PushersManager @Inject constructor( suspend fun registerEmailForPush(email: String) { val currentSession = activeSessionHolder.getActiveSession() val appName = appNameProvider.getAppName() - currentSession.addEmailPusher( + currentSession.pushersService().addEmailPusher( email = email, lang = localeProvider.current().language, emailBranding = appName, @@ -81,12 +81,12 @@ class PushersManager @Inject constructor( suspend fun unregisterEmailPusher(email: String) { val currentSession = activeSessionHolder.getSafeActiveSession() ?: return - currentSession.removeEmailPusher(email) + currentSession.pushersService().removeEmailPusher(email) } suspend fun unregisterPusher(pushKey: String) { val currentSession = activeSessionHolder.getSafeActiveSession() ?: return - currentSession.removeHttpPusher(pushKey, stringProvider.getString(R.string.pusher_app_id)) + currentSession.pushersService().removeHttpPusher(pushKey, stringProvider.getString(R.string.pusher_app_id)) } companion object { diff --git a/vector/src/main/java/im/vector/app/features/MainActivity.kt b/vector/src/main/java/im/vector/app/features/MainActivity.kt index 42bd2318b3..121edd4216 100644 --- a/vector/src/main/java/im/vector/app/features/MainActivity.kt +++ b/vector/src/main/java/im/vector/app/features/MainActivity.kt @@ -160,7 +160,7 @@ class MainActivity : VectorBaseActivity(), UnlockedActivity args.clearCredentials -> { lifecycleScope.launch { try { - session.signOut(!args.isUserLoggedOut) + session.signOutService().signOut(!args.isUserLoggedOut) } catch (failure: Throwable) { displayError(failure) return@launch diff --git a/vector/src/main/java/im/vector/app/features/analytics/accountdata/AnalyticsAccountDataViewModel.kt b/vector/src/main/java/im/vector/app/features/analytics/accountdata/AnalyticsAccountDataViewModel.kt index 3b92e7c4de..221a9d8843 100644 --- a/vector/src/main/java/im/vector/app/features/analytics/accountdata/AnalyticsAccountDataViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/analytics/accountdata/AnalyticsAccountDataViewModel.kt @@ -66,7 +66,7 @@ class AnalyticsAccountDataViewModel @AssistedInject constructor( private fun observeInitSync() { combine( - session.getSyncStatusLive().asFlow(), + session.syncStatusService().getSyncStatusLive().asFlow(), analytics.getUserConsent(), analytics.getAnalyticsId() ) { status, userConsent, analyticsId -> diff --git a/vector/src/main/java/im/vector/app/features/auth/ReAuthViewModel.kt b/vector/src/main/java/im/vector/app/features/auth/ReAuthViewModel.kt index 16aca5cfeb..0bd26870e5 100644 --- a/vector/src/main/java/im/vector/app/features/auth/ReAuthViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/auth/ReAuthViewModel.kt @@ -58,7 +58,7 @@ class ReAuthViewModel @AssistedInject constructor( is ReAuthActions.ReAuthWithPass -> { val safeForIntentCypher = ByteArrayOutputStream().also { it.use { - session.securelyStoreObject(action.password, initialState.resultKeyStoreAlias, it) + session.secureStorageService().securelyStoreObject(action.password, initialState.resultKeyStoreAlias, it) } }.toByteArray().toBase64NoPadding() _viewEvents.post(ReAuthEvents.PasswordFinishSuccess(safeForIntentCypher)) diff --git a/vector/src/main/java/im/vector/app/features/autocomplete/group/AutocompleteGroupPresenter.kt b/vector/src/main/java/im/vector/app/features/autocomplete/group/AutocompleteGroupPresenter.kt index a3c276c977..fc7479eb21 100644 --- a/vector/src/main/java/im/vector/app/features/autocomplete/group/AutocompleteGroupPresenter.kt +++ b/vector/src/main/java/im/vector/app/features/autocomplete/group/AutocompleteGroupPresenter.kt @@ -55,7 +55,7 @@ class AutocompleteGroupPresenter @Inject constructor(context: Context, QueryStringValue.Contains(query.toString(), QueryStringValue.Case.INSENSITIVE) } } - val groups = session.getGroupSummaries(queryParams) + val groups = session.groupService().getGroupSummaries(queryParams) .asSequence() .sortedBy { it.displayName } controller.setData(groups.toList()) diff --git a/vector/src/main/java/im/vector/app/features/autocomplete/member/AutocompleteMemberPresenter.kt b/vector/src/main/java/im/vector/app/features/autocomplete/member/AutocompleteMemberPresenter.kt index a62024d99f..54ab3f84ee 100644 --- a/vector/src/main/java/im/vector/app/features/autocomplete/member/AutocompleteMemberPresenter.kt +++ b/vector/src/main/java/im/vector/app/features/autocomplete/member/AutocompleteMemberPresenter.kt @@ -27,6 +27,7 @@ import im.vector.app.features.autocomplete.RecyclerViewPresenter import org.matrix.android.sdk.api.query.QueryStringValue import org.matrix.android.sdk.api.session.Session import org.matrix.android.sdk.api.session.events.model.Event +import org.matrix.android.sdk.api.session.getRoom import org.matrix.android.sdk.api.session.pushrules.SenderNotificationPermissionCondition import org.matrix.android.sdk.api.session.room.members.RoomMemberQueryParams import org.matrix.android.sdk.api.session.room.members.roomMemberQueryParams @@ -147,7 +148,7 @@ class AutocompleteMemberPresenter @AssistedInject constructor(context: Context, AutocompleteMemberItem.Everyone(it) } - private fun canNotifyEveryone() = session.resolveSenderNotificationPermissionCondition( + private fun canNotifyEveryone() = session.pushRuleService().resolveSenderNotificationPermissionCondition( Event( senderId = session.myUserId, roomId = roomId diff --git a/vector/src/main/java/im/vector/app/features/autocomplete/room/AutocompleteRoomPresenter.kt b/vector/src/main/java/im/vector/app/features/autocomplete/room/AutocompleteRoomPresenter.kt index 99f0af7184..d9310e295d 100644 --- a/vector/src/main/java/im/vector/app/features/autocomplete/room/AutocompleteRoomPresenter.kt +++ b/vector/src/main/java/im/vector/app/features/autocomplete/room/AutocompleteRoomPresenter.kt @@ -51,7 +51,7 @@ class AutocompleteRoomPresenter @Inject constructor(context: Context, QueryStringValue.Contains(query.toString(), QueryStringValue.Case.INSENSITIVE) } } - val rooms = session.getRoomSummaries(queryParams) + val rooms = session.roomService().getRoomSummaries(queryParams) .asSequence() .sortedBy { it.displayName } controller.setData(rooms.toList()) diff --git a/vector/src/main/java/im/vector/app/features/call/VectorCallViewModel.kt b/vector/src/main/java/im/vector/app/features/call/VectorCallViewModel.kt index 3b7baef155..55a0219bfe 100644 --- a/vector/src/main/java/im/vector/app/features/call/VectorCallViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/call/VectorCallViewModel.kt @@ -42,6 +42,7 @@ import org.matrix.android.sdk.api.session.Session import org.matrix.android.sdk.api.session.call.CallState import org.matrix.android.sdk.api.session.call.MxCall import org.matrix.android.sdk.api.session.call.MxPeerConnectionState +import org.matrix.android.sdk.api.session.getRoomSummary import org.matrix.android.sdk.api.session.room.model.call.supportCallTransfer import org.matrix.android.sdk.api.util.MatrixItem diff --git a/vector/src/main/java/im/vector/app/features/call/conference/JitsiService.kt b/vector/src/main/java/im/vector/app/features/call/conference/JitsiService.kt index 6fa65bdb7f..07062fc732 100644 --- a/vector/src/main/java/im/vector/app/features/call/conference/JitsiService.kt +++ b/vector/src/main/java/im/vector/app/features/call/conference/JitsiService.kt @@ -31,6 +31,7 @@ import org.jitsi.meet.sdk.JitsiMeetUserInfo import org.matrix.android.sdk.api.extensions.tryOrNull import org.matrix.android.sdk.api.raw.RawService import org.matrix.android.sdk.api.session.Session +import org.matrix.android.sdk.api.session.getRoomSummary import org.matrix.android.sdk.api.session.widgets.model.Widget import org.matrix.android.sdk.api.session.widgets.model.WidgetType import org.matrix.android.sdk.api.util.MatrixJsonParser @@ -99,7 +100,7 @@ class JitsiService @Inject constructor( } suspend fun joinConference(roomId: String, jitsiWidget: Widget, enableVideo: Boolean): JitsiCallViewEvents.JoinConference { - val me = session.getRoomMember(session.myUserId, roomId)?.toMatrixItem() + val me = session.roomService().getRoomMember(session.myUserId, roomId)?.toMatrixItem() val userDisplayName = me?.getBestName() val userAvatar = me?.avatarUrl?.let { session.contentUrlResolver().resolveFullSize(it) } val userInfo = JitsiMeetUserInfo().apply { diff --git a/vector/src/main/java/im/vector/app/features/call/dialpad/DialPadLookup.kt b/vector/src/main/java/im/vector/app/features/call/dialpad/DialPadLookup.kt index 80c4e93306..e835a74fd6 100644 --- a/vector/src/main/java/im/vector/app/features/call/dialpad/DialPadLookup.kt +++ b/vector/src/main/java/im/vector/app/features/call/dialpad/DialPadLookup.kt @@ -47,7 +47,7 @@ class DialPadLookup @Inject constructor( if (nativeUserId == session.myUserId) { throw Failure.NumberIsYours } - session.getExistingDirectRoomWithUser(nativeUserId) + session.roomService().getExistingDirectRoomWithUser(nativeUserId) // if there is not, just create a DM with the sip user ?: directRoomHelper.ensureDMExists(sipUserId) } else { diff --git a/vector/src/main/java/im/vector/app/features/call/lookup/CallUserMapper.kt b/vector/src/main/java/im/vector/app/features/call/lookup/CallUserMapper.kt index 0820b34124..8e3df50817 100644 --- a/vector/src/main/java/im/vector/app/features/call/lookup/CallUserMapper.kt +++ b/vector/src/main/java/im/vector/app/features/call/lookup/CallUserMapper.kt @@ -20,6 +20,7 @@ import org.matrix.android.sdk.api.extensions.tryOrNull import org.matrix.android.sdk.api.session.Session import org.matrix.android.sdk.api.session.events.model.toContent import org.matrix.android.sdk.api.session.events.model.toModel +import org.matrix.android.sdk.api.session.getRoom import org.matrix.android.sdk.api.session.room.Room import org.matrix.android.sdk.api.session.room.accountdata.RoomAccountDataTypes import org.matrix.android.sdk.api.session.room.model.create.CreateRoomParams @@ -61,7 +62,7 @@ class CallUserMapper(private val session: Session, private val protocolsChecker: val nativeLookup = session.sipNativeLookup(inviterId).firstOrNull() ?: return if (nativeLookup.fields.containsKey("is_virtual")) { val nativeUser = nativeLookup.userId - val nativeRoomId = session.getExistingDirectRoomWithUser(nativeUser) + val nativeRoomId = session.roomService().getExistingDirectRoomWithUser(nativeUser) if (nativeRoomId != null) { // It's a virtual room with a matching native room, so set the room account data. This // will make sure we know where how to map calls and also allow us know not to display @@ -82,7 +83,7 @@ class CallUserMapper(private val session: Session, private val protocolsChecker: } private suspend fun ensureVirtualRoomExists(userId: String, nativeRoomId: String): String { - val existingDMRoom = tryOrNull { session.getExistingDirectRoomWithUser(userId) } + val existingDMRoom = tryOrNull { session.roomService().getExistingDirectRoomWithUser(userId) } val roomId: String if (existingDMRoom != null) { roomId = existingDMRoom @@ -92,7 +93,7 @@ class CallUserMapper(private val session: Session, private val protocolsChecker: setDirectMessage() creationContent[RoomAccountDataTypes.EVENT_TYPE_VIRTUAL_ROOM] = nativeRoomId } - roomId = session.createRoom(roomParams) + roomId = session.roomService().createRoom(roomParams) } return roomId } diff --git a/vector/src/main/java/im/vector/app/features/call/webrtc/WebRtcCall.kt b/vector/src/main/java/im/vector/app/features/call/webrtc/WebRtcCall.kt index bc8ae51a88..fed61c3b15 100644 --- a/vector/src/main/java/im/vector/app/features/call/webrtc/WebRtcCall.kt +++ b/vector/src/main/java/im/vector/app/features/call/webrtc/WebRtcCall.kt @@ -989,7 +989,7 @@ class WebRtcCall( val nativeUserId = session.sipNativeLookup(newAssertedIdentity.id!!).firstOrNull()?.userId if (nativeUserId != null) { val resolvedUser = tryOrNull { - session.resolveUser(nativeUserId) + session.userService().resolveUser(nativeUserId) } if (resolvedUser != null) { remoteAssertedIdentity = newAssertedIdentity.copy( diff --git a/vector/src/main/java/im/vector/app/features/call/webrtc/WebRtcCallExt.kt b/vector/src/main/java/im/vector/app/features/call/webrtc/WebRtcCallExt.kt index ac9d169633..5def0a7e50 100644 --- a/vector/src/main/java/im/vector/app/features/call/webrtc/WebRtcCallExt.kt +++ b/vector/src/main/java/im/vector/app/features/call/webrtc/WebRtcCallExt.kt @@ -18,6 +18,7 @@ package im.vector.app.features.call.webrtc import org.matrix.android.sdk.api.extensions.orFalse import org.matrix.android.sdk.api.session.Session +import org.matrix.android.sdk.api.session.getRoom import org.matrix.android.sdk.api.util.MatrixItem import org.matrix.android.sdk.api.util.toMatrixItem diff --git a/vector/src/main/java/im/vector/app/features/createdirect/CreateDirectRoomViewModel.kt b/vector/src/main/java/im/vector/app/features/createdirect/CreateDirectRoomViewModel.kt index 0d67390654..a507f0d099 100644 --- a/vector/src/main/java/im/vector/app/features/createdirect/CreateDirectRoomViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/createdirect/CreateDirectRoomViewModel.kt @@ -36,6 +36,7 @@ import kotlinx.coroutines.launch import org.matrix.android.sdk.api.extensions.orFalse import org.matrix.android.sdk.api.raw.RawService import org.matrix.android.sdk.api.session.Session +import org.matrix.android.sdk.api.session.getUser import org.matrix.android.sdk.api.session.permalinks.PermalinkData import org.matrix.android.sdk.api.session.permalinks.PermalinkParser import org.matrix.android.sdk.api.session.room.model.create.CreateRoomParams @@ -74,7 +75,11 @@ class CreateDirectRoomViewModel @AssistedInject constructor( _viewEvents.post(CreateDirectRoomViewEvents.DmSelf) } else { // Try to get user from known users and fall back to creating a User object from MXID - val qrInvitee = if (session.getUser(mxid) != null) session.getUser(mxid)!! else User(mxid, null, null) + val qrInvitee = if (session.getUser(mxid) != null) { + session.getUser(mxid)!! + } else { + User(mxid, null, null) + } onSubmitInvitees(setOf(PendingSelection.UserPendingSelection(qrInvitee))) } } @@ -85,7 +90,7 @@ class CreateDirectRoomViewModel @AssistedInject constructor( */ private fun onSubmitInvitees(selections: Set) { val existingRoomId = selections.singleOrNull()?.getMxId()?.let { userId -> - session.getExistingDirectRoomWithUser(userId) + session.roomService().getExistingDirectRoomWithUser(userId) } if (existingRoomId != null) { // Do not create a new DM, just tell that the creation is successful by passing the existing roomId @@ -119,7 +124,7 @@ class CreateDirectRoomViewModel @AssistedInject constructor( } val result = runCatchingToAsync { - session.createRoom(roomParams) + session.roomService().createRoom(roomParams) } analyticsTracker.capture(CreatedRoom(isDM = roomParams.isDirect.orFalse())) diff --git a/vector/src/main/java/im/vector/app/features/createdirect/DirectRoomHelper.kt b/vector/src/main/java/im/vector/app/features/createdirect/DirectRoomHelper.kt index e9f0cbfea4..de2027f2a5 100644 --- a/vector/src/main/java/im/vector/app/features/createdirect/DirectRoomHelper.kt +++ b/vector/src/main/java/im/vector/app/features/createdirect/DirectRoomHelper.kt @@ -34,7 +34,7 @@ class DirectRoomHelper @Inject constructor( ) { suspend fun ensureDMExists(userId: String): String { - val existingRoomId = tryOrNull { session.getExistingDirectRoomWithUser(userId) } + val existingRoomId = tryOrNull { session.roomService().getExistingDirectRoomWithUser(userId) } val roomId: String if (existingRoomId != null) { roomId = existingRoomId @@ -48,7 +48,7 @@ class DirectRoomHelper @Inject constructor( setDirectMessage() enableEncryptionIfInvitedUsersSupportIt = adminE2EByDefault } - roomId = session.createRoom(roomParams) + roomId = session.roomService().createRoom(roomParams) analyticsTracker.capture(CreatedRoom(isDM = roomParams.isDirect.orFalse())) } return roomId diff --git a/vector/src/main/java/im/vector/app/features/crypto/keysbackup/restore/KeysBackupRestoreSharedViewModel.kt b/vector/src/main/java/im/vector/app/features/crypto/keysbackup/restore/KeysBackupRestoreSharedViewModel.kt index cf684680ba..6cfe0bf686 100644 --- a/vector/src/main/java/im/vector/app/features/crypto/keysbackup/restore/KeysBackupRestoreSharedViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/crypto/keysbackup/restore/KeysBackupRestoreSharedViewModel.kt @@ -170,7 +170,7 @@ class KeysBackupRestoreSharedViewModel @Inject constructor( fun handleGotSecretFromSSSS(cipherData: String, alias: String) { try { cipherData.fromBase64().inputStream().use { ins -> - val res = session.loadSecureSecret>(ins, alias) + val res = session.secureStorageService().loadSecureSecret>(ins, alias) val secret = res?.get(KEYBACKUP_SECRET_SSSS_NAME) if (secret == null) { _navigateEvent.postValue( @@ -252,7 +252,7 @@ class KeysBackupRestoreSharedViewModel @Inject constructor( ?: return false // Some sanity ? - val defaultKeyResult = session.sharedSecretStorageService.getDefaultKey() + val defaultKeyResult = session.sharedSecretStorageService().getDefaultKey() val keyInfo = (defaultKeyResult as? KeyInfoResult.Success)?.keyInfo ?: return false diff --git a/vector/src/main/java/im/vector/app/features/crypto/quads/SharedSecureStorageViewModel.kt b/vector/src/main/java/im/vector/app/features/crypto/quads/SharedSecureStorageViewModel.kt index 55ab672c43..445cc70527 100644 --- a/vector/src/main/java/im/vector/app/features/crypto/quads/SharedSecureStorageViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/crypto/quads/SharedSecureStorageViewModel.kt @@ -87,7 +87,7 @@ class SharedSecureStorageViewModel @AssistedInject constructor( setState { copy(userId = session.myUserId) } - val integrityResult = session.sharedSecretStorageService.checkShouldBeAbleToAccessSecrets(initialState.requestedSecrets, initialState.keyId) + val integrityResult = session.sharedSecretStorageService().checkShouldBeAbleToAccessSecrets(initialState.requestedSecrets, initialState.keyId) if (integrityResult !is IntegrityResult.Success) { _viewEvents.post( SharedSecureStorageViewEvent.Error( @@ -96,8 +96,8 @@ class SharedSecureStorageViewModel @AssistedInject constructor( ) ) } - val keyResult = initialState.keyId?.let { session.sharedSecretStorageService.getKey(it) } - ?: session.sharedSecretStorageService.getDefaultKey() + val keyResult = initialState.keyId?.let { session.sharedSecretStorageService().getKey(it) } + ?: session.sharedSecretStorageService().getDefaultKey() if (!keyResult.isSuccess()) { _viewEvents.post(SharedSecureStorageViewEvent.Dismiss) @@ -205,7 +205,7 @@ class SharedSecureStorageViewModel @AssistedInject constructor( viewModelScope.launch(Dispatchers.IO) { runCatching { val recoveryKey = action.recoveryKey - val keyInfoResult = session.sharedSecretStorageService.getDefaultKey() + val keyInfoResult = session.sharedSecretStorageService().getDefaultKey() if (!keyInfoResult.isSuccess()) { _viewEvents.post(SharedSecureStorageViewEvent.HideModalLoading) _viewEvents.post(SharedSecureStorageViewEvent.Error(stringProvider.getString(R.string.failed_to_access_secure_storage))) @@ -228,7 +228,7 @@ class SharedSecureStorageViewModel @AssistedInject constructor( withContext(Dispatchers.IO) { initialState.requestedSecrets.forEach { if (session.accountDataService().getUserAccountDataEvent(it) != null) { - val res = session.sharedSecretStorageService.getSecret( + val res = session.sharedSecretStorageService().getSecret( name = it, keyId = keyInfo.id, secretKey = keySpec) @@ -243,7 +243,7 @@ class SharedSecureStorageViewModel @AssistedInject constructor( _viewEvents.post(SharedSecureStorageViewEvent.HideModalLoading) val safeForIntentCypher = ByteArrayOutputStream().also { it.use { - session.securelyStoreObject(decryptedSecretMap as Map, initialState.resultKeyStoreAlias, it) + session.secureStorageService().securelyStoreObject(decryptedSecretMap as Map, initialState.resultKeyStoreAlias, it) } }.toByteArray().toBase64NoPadding() _viewEvents.post(SharedSecureStorageViewEvent.FinishSuccess(safeForIntentCypher)) @@ -262,7 +262,7 @@ class SharedSecureStorageViewModel @AssistedInject constructor( viewModelScope.launch(Dispatchers.IO) { runCatching { val passphrase = action.passphrase - val keyInfoResult = session.sharedSecretStorageService.getDefaultKey() + val keyInfoResult = session.sharedSecretStorageService().getDefaultKey() if (!keyInfoResult.isSuccess()) { _viewEvents.post(SharedSecureStorageViewEvent.HideModalLoading) _viewEvents.post(SharedSecureStorageViewEvent.Error("Cannot find ssss key")) @@ -297,7 +297,7 @@ class SharedSecureStorageViewModel @AssistedInject constructor( withContext(Dispatchers.IO) { initialState.requestedSecrets.forEach { if (session.accountDataService().getUserAccountDataEvent(it) != null) { - val res = session.sharedSecretStorageService.getSecret( + val res = session.sharedSecretStorageService().getSecret( name = it, keyId = keyInfo.id, secretKey = keySpec) @@ -312,7 +312,7 @@ class SharedSecureStorageViewModel @AssistedInject constructor( _viewEvents.post(SharedSecureStorageViewEvent.HideModalLoading) val safeForIntentCypher = ByteArrayOutputStream().also { it.use { - session.securelyStoreObject(decryptedSecretMap as Map, initialState.resultKeyStoreAlias, it) + session.secureStorageService().securelyStoreObject(decryptedSecretMap as Map, initialState.resultKeyStoreAlias, it) } }.toByteArray().toBase64NoPadding() _viewEvents.post(SharedSecureStorageViewEvent.FinishSuccess(safeForIntentCypher)) diff --git a/vector/src/main/java/im/vector/app/features/crypto/recover/BackupToQuadSMigrationTask.kt b/vector/src/main/java/im/vector/app/features/crypto/recover/BackupToQuadSMigrationTask.kt index 1767a9444d..2092fe0f00 100644 --- a/vector/src/main/java/im/vector/app/features/crypto/recover/BackupToQuadSMigrationTask.kt +++ b/vector/src/main/java/im/vector/app/features/crypto/recover/BackupToQuadSMigrationTask.kt @@ -61,7 +61,7 @@ class BackupToQuadSMigrationTask @Inject constructor( // We need to use the current secret for keybackup and use it as the new master key for SSSS // Then we need to put back the backup key in sss val keysBackupService = session.cryptoService().keysBackupService() - val quadS = session.sharedSecretStorageService + val quadS = session.sharedSecretStorageService() val version = keysBackupService.keysBackupVersion ?: return Result.NoKeyBackupVersion diff --git a/vector/src/main/java/im/vector/app/features/crypto/recover/BootstrapCrossSigningTask.kt b/vector/src/main/java/im/vector/app/features/crypto/recover/BootstrapCrossSigningTask.kt index f65999b945..753e9f1942 100644 --- a/vector/src/main/java/im/vector/app/features/crypto/recover/BootstrapCrossSigningTask.kt +++ b/vector/src/main/java/im/vector/app/features/crypto/recover/BootstrapCrossSigningTask.kt @@ -117,7 +117,7 @@ class BootstrapCrossSigningTask @Inject constructor( val keyInfo: SsssKeyCreationInfo - val ssssService = session.sharedSecretStorageService + val ssssService = session.sharedSecretStorageService() params.progressListener?.onProgress( WaitingViewData( diff --git a/vector/src/main/java/im/vector/app/features/crypto/recover/BootstrapSharedViewModel.kt b/vector/src/main/java/im/vector/app/features/crypto/recover/BootstrapSharedViewModel.kt index 1b69b3a919..a85c318a29 100644 --- a/vector/src/main/java/im/vector/app/features/crypto/recover/BootstrapSharedViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/crypto/recover/BootstrapSharedViewModel.kt @@ -246,7 +246,8 @@ class BootstrapSharedViewModel @AssistedInject constructor( uiaContinuation?.resume(DefaultBaseAuth(session = pendingAuth?.session ?: "")) } is BootstrapActions.PasswordAuthDone -> { - val decryptedPass = session.loadSecureSecret(action.password.fromBase64().inputStream(), ReAuthActivity.DEFAULT_RESULT_KEYSTORE_ALIAS) + val decryptedPass = session.secureStorageService() + .loadSecureSecret(action.password.fromBase64().inputStream(), ReAuthActivity.DEFAULT_RESULT_KEYSTORE_ALIAS) uiaContinuation?.resume( UserPasswordAuth( session = pendingAuth?.session, diff --git a/vector/src/main/java/im/vector/app/features/crypto/verification/IncomingVerificationRequestHandler.kt b/vector/src/main/java/im/vector/app/features/crypto/verification/IncomingVerificationRequestHandler.kt index 62affec7b5..2e9fe1bcf9 100644 --- a/vector/src/main/java/im/vector/app/features/crypto/verification/IncomingVerificationRequestHandler.kt +++ b/vector/src/main/java/im/vector/app/features/crypto/verification/IncomingVerificationRequestHandler.kt @@ -63,7 +63,7 @@ class IncomingVerificationRequestHandler @Inject constructor( when (tx.state) { is VerificationTxState.OnStarted -> { // Add a notification for every incoming request - val user = session?.getUser(tx.otherUserId) + val user = session?.userService()?.getUser(tx.otherUserId) val name = user?.toMatrixItem()?.getBestName() ?: tx.otherUserId val alert = VerificationVectorAlert( uid, @@ -127,7 +127,7 @@ class IncomingVerificationRequestHandler @Inject constructor( // XXX this is a bit hard coded :/ popupAlertManager.cancelAlert("review_login") } - val user = session?.getUser(pr.otherUserId)?.toMatrixItem() + val user = session?.userService()?.getUser(pr.otherUserId)?.toMatrixItem() val name = user?.getBestName() ?: pr.otherUserId val description = if (name == pr.otherUserId) { name diff --git a/vector/src/main/java/im/vector/app/features/crypto/verification/VerificationBottomSheetViewModel.kt b/vector/src/main/java/im/vector/app/features/crypto/verification/VerificationBottomSheetViewModel.kt index b389a831da..a7998dc474 100644 --- a/vector/src/main/java/im/vector/app/features/crypto/verification/VerificationBottomSheetViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/crypto/verification/VerificationBottomSheetViewModel.kt @@ -53,6 +53,7 @@ import org.matrix.android.sdk.api.session.crypto.verification.VerificationServic 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.events.model.LocalEcho +import org.matrix.android.sdk.api.session.getUser import org.matrix.android.sdk.api.util.MatrixItem import org.matrix.android.sdk.api.util.awaitCallback import org.matrix.android.sdk.api.util.fromBase64 @@ -149,7 +150,7 @@ class VerificationBottomSheetViewModel @AssistedInject constructor( pendingRequest = if (pr != null) Success(pr) else Uninitialized, isMe = initialState.otherUserId == session.myUserId, currentDeviceCanCrossSign = session.cryptoService().crossSigningService().canCrossSign(), - quadSContainsSecrets = session.sharedSecretStorageService.isRecoverySetup(), + quadSContainsSecrets = session.sharedSecretStorageService().isRecoverySetup(), hasAnyOtherSession = hasAnyOtherSession ) } @@ -231,7 +232,7 @@ class VerificationBottomSheetViewModel @AssistedInject constructor( override fun handle(action: VerificationAction) = withState { state -> val otherUserId = state.otherUserMxItem?.id ?: return@withState val roomId = state.roomId - ?: session.getExistingDirectRoomWithUser(otherUserId) + ?: session.roomService().getExistingDirectRoomWithUser(otherUserId) when (action) { is VerificationAction.RequestVerificationByDM -> { @@ -244,7 +245,7 @@ class VerificationBottomSheetViewModel @AssistedInject constructor( ) } viewModelScope.launch { - val result = runCatching { session.createDirectRoom(otherUserId) } + val result = runCatching { session.roomService().createDirectRoom(otherUserId) } result.fold( { data -> setState { @@ -372,7 +373,7 @@ class VerificationBottomSheetViewModel @AssistedInject constructor( viewModelScope.launch(Dispatchers.IO) { try { action.cypherData.fromBase64().inputStream().use { ins -> - val res = session.loadSecureSecret>(ins, action.alias) + val res = session.secureStorageService().loadSecureSecret>(ins, action.alias) val trustResult = session.cryptoService().crossSigningService().checkTrustFromPrivateKeys( res?.get(MASTER_KEY_SSSS_NAME), res?.get(USER_SIGNING_KEY_SSSS_NAME), diff --git a/vector/src/main/java/im/vector/app/features/crypto/verification/emoji/VerificationEmojiCodeViewModel.kt b/vector/src/main/java/im/vector/app/features/crypto/verification/emoji/VerificationEmojiCodeViewModel.kt index aec28f898e..4b59e2e6fb 100644 --- a/vector/src/main/java/im/vector/app/features/crypto/verification/emoji/VerificationEmojiCodeViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/crypto/verification/emoji/VerificationEmojiCodeViewModel.kt @@ -40,6 +40,7 @@ import org.matrix.android.sdk.api.session.crypto.verification.SasVerificationTra 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.VerificationTxState +import org.matrix.android.sdk.api.session.getUser import org.matrix.android.sdk.api.util.MatrixItem import org.matrix.android.sdk.api.util.toMatrixItem diff --git a/vector/src/main/java/im/vector/app/features/devtools/RoomDevToolViewModel.kt b/vector/src/main/java/im/vector/app/features/devtools/RoomDevToolViewModel.kt index c13ef2f81c..80c1dbeae6 100644 --- a/vector/src/main/java/im/vector/app/features/devtools/RoomDevToolViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/devtools/RoomDevToolViewModel.kt @@ -36,6 +36,7 @@ import org.matrix.android.sdk.api.session.Session import org.matrix.android.sdk.api.session.events.model.Event 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.getRoom 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.MatrixJsonParser diff --git a/vector/src/main/java/im/vector/app/features/discovery/DiscoverySettingsViewModel.kt b/vector/src/main/java/im/vector/app/features/discovery/DiscoverySettingsViewModel.kt index 8c1caaf67a..47151223a4 100644 --- a/vector/src/main/java/im/vector/app/features/discovery/DiscoverySettingsViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/discovery/DiscoverySettingsViewModel.kt @@ -290,7 +290,7 @@ class DiscoverySettingsViewModel @AssistedInject constructor( } private fun retrieveBinding() { - retrieveBinding(session.getThreePids()) + retrieveBinding(session.profileService().getThreePids()) } private fun retrieveBinding(threePids: List) = withState { state -> diff --git a/vector/src/main/java/im/vector/app/features/discovery/Extensions.kt b/vector/src/main/java/im/vector/app/features/discovery/Extensions.kt index 904b152661..dc25a35646 100644 --- a/vector/src/main/java/im/vector/app/features/discovery/Extensions.kt +++ b/vector/src/main/java/im/vector/app/features/discovery/Extensions.kt @@ -24,7 +24,7 @@ import org.matrix.android.sdk.api.session.terms.TermsService suspend fun Session.fetchIdentityServerWithTerms(userLanguage: String): ServerAndPolicies? { return identityService().getCurrentIdentityServerUrl() ?.let { identityServerUrl -> - val termsResponse = getTerms(TermsService.ServiceType.IdentityService, identityServerUrl.ensureProtocol()) + val termsResponse = termsService().getTerms(TermsService.ServiceType.IdentityService, identityServerUrl.ensureProtocol()) .serverResponse buildServerAndPolicies(identityServerUrl, termsResponse, userLanguage) } @@ -32,7 +32,7 @@ suspend fun Session.fetchIdentityServerWithTerms(userLanguage: String): ServerAn suspend fun Session.fetchHomeserverWithTerms(userLanguage: String): ServerAndPolicies { val homeserverUrl = sessionParams.homeServerUrl - val terms = getHomeserverTerms(homeserverUrl.ensureProtocol()) + val terms = termsService().getHomeserverTerms(homeserverUrl.ensureProtocol()) return buildServerAndPolicies(homeserverUrl, terms, userLanguage) } diff --git a/vector/src/main/java/im/vector/app/features/discovery/change/SetIdentityServerViewModel.kt b/vector/src/main/java/im/vector/app/features/discovery/change/SetIdentityServerViewModel.kt index 4249e8d899..ae1c7f7753 100644 --- a/vector/src/main/java/im/vector/app/features/discovery/change/SetIdentityServerViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/discovery/change/SetIdentityServerViewModel.kt @@ -107,7 +107,7 @@ class SetIdentityServerViewModel @AssistedInject constructor( private suspend fun checkTerms(baseUrl: String) { try { - val data = mxSession.getTerms(TermsService.ServiceType.IdentityService, baseUrl) + val data = mxSession.termsService().getTerms(TermsService.ServiceType.IdentityService, baseUrl) // has all been accepted? val resp = data.serverResponse diff --git a/vector/src/main/java/im/vector/app/features/home/HomeActivityViewModel.kt b/vector/src/main/java/im/vector/app/features/home/HomeActivityViewModel.kt index f15e44fef7..f0e27e2ee7 100644 --- a/vector/src/main/java/im/vector/app/features/home/HomeActivityViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/home/HomeActivityViewModel.kt @@ -44,6 +44,7 @@ import org.matrix.android.sdk.api.auth.registration.nextUncompletedStage import org.matrix.android.sdk.api.extensions.tryOrNull import org.matrix.android.sdk.api.session.crypto.model.CryptoDeviceInfo import org.matrix.android.sdk.api.session.crypto.model.MXUsersDevicesMap +import org.matrix.android.sdk.api.session.getUser import org.matrix.android.sdk.api.session.initsync.SyncStatusService import org.matrix.android.sdk.api.session.pushrules.RuleIds import org.matrix.android.sdk.api.session.room.model.Membership @@ -175,7 +176,7 @@ class HomeActivityViewModel @AssistedInject constructor( private fun observeInitialSync() { val session = activeSessionHolder.getSafeActiveSession() ?: return - session.getSyncStatusLive() + session.syncStatusService().getSyncStatusLive() .asFlow() .onEach { status -> when (status) { @@ -215,13 +216,16 @@ class HomeActivityViewModel @AssistedInject constructor( if (!vectorPreferences.areNotificationEnabledForDevice()) { // Check if set at account level val mRuleMaster = activeSessionHolder.getSafeActiveSession() + ?.pushRuleService() ?.getPushRules() ?.getAllRules() ?.find { it.ruleId == RuleIds.RULE_ID_DISABLE_ALL } if (mRuleMaster?.enabled == false) { // So push are enabled at account level but not for this session // Let's check that there are some rooms? - val knownRooms = activeSessionHolder.getSafeActiveSession()?.getRoomSummaries(roomSummaryQueryParams { + val knownRooms = activeSessionHolder.getSafeActiveSession() + ?.roomService() + ?.getRoomSummaries(roomSummaryQueryParams { memberships = Membership.activeMemberships() })?.size ?: 0 diff --git a/vector/src/main/java/im/vector/app/features/home/HomeDetailViewModel.kt b/vector/src/main/java/im/vector/app/features/home/HomeDetailViewModel.kt index 2457dd0eaa..fc39165a7e 100644 --- a/vector/src/main/java/im/vector/app/features/home/HomeDetailViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/home/HomeDetailViewModel.kt @@ -91,7 +91,7 @@ class HomeDetailViewModel @AssistedInject constructor( private val refreshRoomSummariesOnCryptoSessionChange = object : NewSessionListener { override fun onNewSession(roomId: String?, senderKey: String, sessionId: String) { - session.refreshJoinedRoomSummaryPreviews(roomId) + session.roomService().refreshJoinedRoomSummaryPreviews(roomId) } } @@ -176,7 +176,7 @@ class HomeDetailViewModel @AssistedInject constructor( private fun handleMarkAllRoomsRead() = withState { _ -> // questionable to use viewmodelscope viewModelScope.launch(Dispatchers.Default) { - val roomIds = session.getRoomSummaries( + val roomIds = session.roomService().getRoomSummaries( roomSummaryQueryParams { memberships = listOf(Membership.JOIN) roomCategoryFilter = RoomCategoryFilter.ONLY_WITH_NOTIFICATIONS @@ -184,7 +184,7 @@ class HomeDetailViewModel @AssistedInject constructor( ) .map { it.roomId } try { - session.markAllAsRead(roomIds) + session.roomService().markAllAsRead(roomIds) } catch (failure: Throwable) { Timber.d(failure, "Failed to mark all as read") } @@ -198,7 +198,7 @@ class HomeDetailViewModel @AssistedInject constructor( copy(syncState = syncState) } - session.getSyncStatusLive() + session.syncStatusService().getSyncStatusLive() .asFlow() .filterIsInstance() .setOnEach { @@ -219,7 +219,7 @@ class HomeDetailViewModel @AssistedInject constructor( appStateHandler.selectedRoomGroupingFlow.distinctUntilChanged().flatMapLatest { // we use it as a trigger to all changes in room, but do not really load // the actual models - session.getPagedRoomSummariesLive( + session.roomService().getPagedRoomSummariesLive( roomSummaryQueryParams { memberships = Membership.activeMemberships() }, @@ -237,7 +237,7 @@ class HomeDetailViewModel @AssistedInject constructor( var dmInvites = 0 var roomsInvite = 0 if (autoAcceptInvites.showInvites()) { - dmInvites = session.getRoomSummaries( + dmInvites = session.roomService().getRoomSummaries( roomSummaryQueryParams { memberships = listOf(Membership.INVITE) roomCategoryFilter = RoomCategoryFilter.ONLY_DM @@ -245,7 +245,7 @@ class HomeDetailViewModel @AssistedInject constructor( } ).size - roomsInvite = session.getRoomSummaries( + roomsInvite = session.roomService().getRoomSummaries( roomSummaryQueryParams { memberships = listOf(Membership.INVITE) roomCategoryFilter = RoomCategoryFilter.ONLY_ROOMS @@ -254,7 +254,7 @@ class HomeDetailViewModel @AssistedInject constructor( ).size } - val dmRooms = session.getNotificationCountForRooms( + val dmRooms = session.roomService().getNotificationCountForRooms( roomSummaryQueryParams { memberships = listOf(Membership.JOIN) roomCategoryFilter = RoomCategoryFilter.ONLY_DM @@ -262,7 +262,7 @@ class HomeDetailViewModel @AssistedInject constructor( } ) - val otherRooms = session.getNotificationCountForRooms( + val otherRooms = session.roomService().getNotificationCountForRooms( roomSummaryQueryParams { memberships = listOf(Membership.JOIN) roomCategoryFilter = RoomCategoryFilter.ONLY_ROOMS diff --git a/vector/src/main/java/im/vector/app/features/home/HomeDrawerFragment.kt b/vector/src/main/java/im/vector/app/features/home/HomeDrawerFragment.kt index 1aee0257f4..9ce950ba31 100644 --- a/vector/src/main/java/im/vector/app/features/home/HomeDrawerFragment.kt +++ b/vector/src/main/java/im/vector/app/features/home/HomeDrawerFragment.kt @@ -60,7 +60,7 @@ class HomeDrawerFragment @Inject constructor( if (savedInstanceState == null) { replaceChildFragment(R.id.homeDrawerGroupListContainer, SpaceListFragment::class.java) } - session.getUserLive(session.myUserId).observeK(viewLifecycleOwner) { optionalUser -> + session.userService().getUserLive(session.myUserId).observeK(viewLifecycleOwner) { optionalUser -> val user = optionalUser?.getOrNull() if (user != null) { avatarRenderer.render(user.toMatrixItem(), views.homeDrawerHeaderAvatarView) diff --git a/vector/src/main/java/im/vector/app/features/home/UnknownDeviceDetectorSharedViewModel.kt b/vector/src/main/java/im/vector/app/features/home/UnknownDeviceDetectorSharedViewModel.kt index d2617bd1c8..3ca19b39f9 100644 --- a/vector/src/main/java/im/vector/app/features/home/UnknownDeviceDetectorSharedViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/home/UnknownDeviceDetectorSharedViewModel.kt @@ -39,6 +39,7 @@ import org.matrix.android.sdk.api.NoOpMatrixCallback import org.matrix.android.sdk.api.extensions.orFalse import org.matrix.android.sdk.api.session.Session import org.matrix.android.sdk.api.session.crypto.model.DeviceInfo +import org.matrix.android.sdk.api.session.getUser import org.matrix.android.sdk.api.util.MatrixItem import org.matrix.android.sdk.api.util.toMatrixItem import org.matrix.android.sdk.flow.flow diff --git a/vector/src/main/java/im/vector/app/features/home/UnreadMessagesSharedViewModel.kt b/vector/src/main/java/im/vector/app/features/home/UnreadMessagesSharedViewModel.kt index 409eb0b845..c1b3937fee 100644 --- a/vector/src/main/java/im/vector/app/features/home/UnreadMessagesSharedViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/home/UnreadMessagesSharedViewModel.kt @@ -71,9 +71,11 @@ class UnreadMessagesSharedViewModel @AssistedInject constructor(@Assisted initia override fun handle(action: EmptyAction) {} + private val roomService = session.roomService() + init { - session.getPagedRoomSummariesLive( + roomService.getPagedRoomSummariesLive( roomSummaryQueryParams { this.memberships = listOf(Membership.JOIN) this.activeSpaceFilter = ActiveSpaceFilter.ActiveSpace(null) @@ -81,7 +83,7 @@ class UnreadMessagesSharedViewModel @AssistedInject constructor(@Assisted initia ).asFlow() .throttleFirst(300) .execute { - val counts = session.getNotificationCountForRooms( + val counts = roomService.getNotificationCountForRooms( roomSummaryQueryParams { this.memberships = listOf(Membership.JOIN) this.activeSpaceFilter = ActiveSpaceFilter.ActiveSpace(null) @@ -90,7 +92,7 @@ class UnreadMessagesSharedViewModel @AssistedInject constructor(@Assisted initia val invites = if (autoAcceptInvites.hideInvites) { 0 } else { - session.getRoomSummaries( + roomService.getRoomSummaries( roomSummaryQueryParams { this.memberships = listOf(Membership.INVITE) this.activeSpaceFilter = ActiveSpaceFilter.ActiveSpace(null) @@ -109,7 +111,7 @@ class UnreadMessagesSharedViewModel @AssistedInject constructor(@Assisted initia combine( appStateHandler.selectedRoomGroupingFlow.distinctUntilChanged(), appStateHandler.selectedRoomGroupingFlow.flatMapLatest { - session.getPagedRoomSummariesLive( + roomService.getPagedRoomSummariesLive( roomSummaryQueryParams { this.memberships = Membership.activeMemberships() }, sortOrder = RoomSortOrder.NONE @@ -131,7 +133,7 @@ class UnreadMessagesSharedViewModel @AssistedInject constructor(@Assisted initia val inviteCount = if (autoAcceptInvites.hideInvites) { 0 } else { - session.getRoomSummaries( + roomService.getRoomSummaries( roomSummaryQueryParams { this.memberships = listOf(Membership.INVITE) } ).size } @@ -139,14 +141,14 @@ class UnreadMessagesSharedViewModel @AssistedInject constructor(@Assisted initia val spaceInviteCount = if (autoAcceptInvites.hideInvites) { 0 } else { - session.getRoomSummaries( + roomService.getRoomSummaries( spaceSummaryQueryParams { this.memberships = listOf(Membership.INVITE) } ).size } - val totalCount = session.getNotificationCountForRooms( + val totalCount = roomService.getNotificationCountForRooms( roomSummaryQueryParams { this.memberships = listOf(Membership.JOIN) this.activeSpaceFilter = ActiveSpaceFilter.ActiveSpace(null).takeIf { diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/TimelineViewModel.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/TimelineViewModel.kt index b79b55b248..91a4007ca6 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/TimelineViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/TimelineViewModel.kt @@ -86,6 +86,7 @@ import org.matrix.android.sdk.api.session.events.model.isTextMessage import org.matrix.android.sdk.api.session.events.model.toContent import org.matrix.android.sdk.api.session.events.model.toModel import org.matrix.android.sdk.api.session.file.FileService +import org.matrix.android.sdk.api.session.getRoom import org.matrix.android.sdk.api.session.initsync.SyncStatusService import org.matrix.android.sdk.api.session.room.members.ChangeMembershipState import org.matrix.android.sdk.api.session.room.members.roomMemberQueryParams @@ -185,7 +186,7 @@ class TimelineViewModel @AssistedInject constructor( } // Inform the SDK that the room is displayed viewModelScope.launch(Dispatchers.IO) { - tryOrNull { session.onRoomDisplayed(initialState.roomId) } + tryOrNull { session.roomService().onRoomDisplayed(initialState.roomId) } } callManager.addProtocolsCheckerListener(this) callManager.checkForProtocolsSupportIfNeeded() @@ -682,7 +683,7 @@ class TimelineViewModel @AssistedInject constructor( } viewModelScope.launch { val result = runCatchingToAsync { - session.joinRoom(roomId, viaServers = viaServers) + session.roomService().joinRoom(roomId, viaServers = viaServers) roomId } setState { @@ -808,7 +809,7 @@ class TimelineViewModel @AssistedInject constructor( notificationDrawerManager.updateEvents { it.clearMemberShipNotificationForRoom(initialState.roomId) } viewModelScope.launch { try { - session.leaveRoom(room.roomId) + session.roomService().leaveRoom(room.roomId) } catch (throwable: Throwable) { _viewEvents.post(RoomDetailViewEvents.Failure(throwable, showInDialog = true)) } @@ -819,7 +820,7 @@ class TimelineViewModel @AssistedInject constructor( notificationDrawerManager.updateEvents { it.clearMemberShipNotificationForRoom(initialState.roomId) } viewModelScope.launch { try { - session.joinRoom(room.roomId) + session.roomService().joinRoom(room.roomId) analyticsTracker.capture(room.roomSummary().toAnalyticsJoinedRoom()) } catch (throwable: Throwable) { _viewEvents.post(RoomDetailViewEvents.Failure(throwable, showInDialog = true)) @@ -996,7 +997,7 @@ class TimelineViewModel @AssistedInject constructor( viewModelScope.launch { val event = try { - session.ignoreUserIds(listOf(action.userId)) + session.userService().ignoreUserIds(listOf(action.userId)) RoomDetailViewEvents.ActionSuccess(action) } catch (failure: Throwable) { RoomDetailViewEvents.ActionFailure(action, failure) @@ -1086,7 +1087,7 @@ class TimelineViewModel @AssistedInject constructor( copy(syncState = syncState) } - session.getSyncStatusLive() + session.syncStatusService().getSyncStatusLive() .asFlow() .filterIsInstance() .setOnEach { @@ -1190,7 +1191,7 @@ class TimelineViewModel @AssistedInject constructor( } if (summary.membership == Membership.INVITE) { summary.inviterId?.let { inviterId -> - session.getRoomMember(inviterId, summary.roomId) + session.roomService().getRoomMember(inviterId, summary.roomId) }?.also { setState { copy(asyncInviter = Success(it)) } } diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/composer/MessageComposerViewModel.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/composer/MessageComposerViewModel.kt index 9c81a39941..a67333e5d5 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/composer/MessageComposerViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/composer/MessageComposerViewModel.kt @@ -50,6 +50,8 @@ import org.matrix.android.sdk.api.session.events.model.getRootThreadEventId import org.matrix.android.sdk.api.session.events.model.isThread import org.matrix.android.sdk.api.session.events.model.toContent import org.matrix.android.sdk.api.session.events.model.toModel +import org.matrix.android.sdk.api.session.getRoom +import org.matrix.android.sdk.api.session.getRoomSummary import org.matrix.android.sdk.api.session.room.model.PowerLevelsContent import org.matrix.android.sdk.api.session.room.model.RoomAvatarContent import org.matrix.android.sdk.api.session.room.model.RoomEncryptionAlgorithm @@ -445,7 +447,7 @@ class MessageComposerViewModel @AssistedInject constructor( is ParsedCommand.LeaveRoom -> { viewModelScope.launch(Dispatchers.IO) { try { - session.leaveRoom(parsedCommand.roomId) + session.roomService().leaveRoom(parsedCommand.roomId) popDraft() _viewEvents.post(MessageComposerViewEvents.SlashCommandResultOk(parsedCommand)) } catch (failure: Throwable) { @@ -609,7 +611,7 @@ class MessageComposerViewModel @AssistedInject constructor( private fun handleJoinToAnotherRoomSlashCommand(command: ParsedCommand.JoinRoom) { viewModelScope.launch { try { - session.joinRoom(command.roomAlias, command.reason, emptyList()) + session.roomService().joinRoom(command.roomAlias, command.reason, emptyList()) } catch (failure: Throwable) { _viewEvents.post(MessageComposerViewEvents.SlashCommandResultError(failure)) return@launch @@ -676,7 +678,7 @@ class MessageComposerViewModel @AssistedInject constructor( private fun handleChangeDisplayNameSlashCommand(changeDisplayName: ParsedCommand.ChangeDisplayName) { launchSlashCommandFlowSuspendable(changeDisplayName) { - session.setDisplayName(session.myUserId, changeDisplayName.displayName) + session.profileService().setDisplayName(session.myUserId, changeDisplayName.displayName) } } @@ -691,7 +693,7 @@ class MessageComposerViewModel @AssistedInject constructor( ?.let { session.getRoom(it) } } ?.let { - session.leaveRoom(it.roomId) + session.roomService().leaveRoom(it.roomId) } } } @@ -756,7 +758,7 @@ class MessageComposerViewModel @AssistedInject constructor( private fun handleIgnoreSlashCommand(ignore: ParsedCommand.IgnoreUser) { launchSlashCommandFlowSuspendable(ignore) { - session.ignoreUserIds(listOf(ignore.userId)) + session.userService().ignoreUserIds(listOf(ignore.userId)) } } @@ -773,7 +775,7 @@ class MessageComposerViewModel @AssistedInject constructor( private fun handleUnignoreSlashCommandConfirmed(unignore: ParsedCommand.UnignoreUser) { launchSlashCommandFlowSuspendable(unignore) { - session.unIgnoreUserIds(listOf(unignore.userId)) + session.userService().unIgnoreUserIds(listOf(unignore.userId)) } } diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/search/SearchResultController.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/search/SearchResultController.kt index 5b1f17cfe2..4f951dfecb 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/search/SearchResultController.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/search/SearchResultController.kt @@ -125,7 +125,7 @@ class SearchResultController @Inject constructor( .formattedDate(dateFormatter.format(event.originServerTs, DateFormatKind.MESSAGE_SIMPLE)) .spannable(spannable.toEpoxyCharSequence()) .sender(eventAndSender.sender - ?: eventAndSender.event.senderId?.let { session.getRoomMember(it, data.roomId) }?.toMatrixItem()) + ?: eventAndSender.event.senderId?.let { session.roomService().getRoomMember(it, data.roomId) }?.toMatrixItem()) .threadDetails(event.threadDetails) .threadSummaryFormatted(displayableEventFormatter.formatThreadSummary(event.threadDetails?.threadSummaryLatestEvent).toString()) .areThreadMessagesEnabled(userPreferencesProvider.areThreadMessagesEnabled()) diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/search/SearchViewModel.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/search/SearchViewModel.kt index 1702fb95cd..b5496f6fb6 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/search/SearchViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/search/SearchViewModel.kt @@ -30,6 +30,7 @@ import kotlinx.coroutines.CancellationException import kotlinx.coroutines.Job import kotlinx.coroutines.launch import org.matrix.android.sdk.api.session.Session +import org.matrix.android.sdk.api.session.getRoom import org.matrix.android.sdk.api.session.search.SearchResult class SearchViewModel @AssistedInject constructor( diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/action/MessageActionsViewModel.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/action/MessageActionsViewModel.kt index 99c36d1190..df2a1fbe81 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/action/MessageActionsViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/action/MessageActionsViewModel.kt @@ -48,6 +48,7 @@ import org.matrix.android.sdk.api.session.events.model.isAttachmentMessage import org.matrix.android.sdk.api.session.events.model.isTextMessage import org.matrix.android.sdk.api.session.events.model.isThread import org.matrix.android.sdk.api.session.events.model.toModel +import org.matrix.android.sdk.api.session.getRoom import org.matrix.android.sdk.api.session.room.model.message.MessageContent import org.matrix.android.sdk.api.session.room.model.message.MessageFormat import org.matrix.android.sdk.api.session.room.model.message.MessagePollContent @@ -454,7 +455,7 @@ class MessageActionsViewModel @AssistedInject constructor( // if (!vectorPreferences.areThreadMessagesEnabled()) return false // Disable beta prompt if the homeserver do not support threads if (!vectorPreferences.areThreadMessagesEnabled() && - !session.getHomeServerCapabilities().canUseThreading) return false + !session.homeServerCapabilitiesService().getHomeServerCapabilities().canUseThreading) return false if (initialState.isFromThreadTimeline) return false if (event.root.isThread()) return false diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/edithistory/ViewEditHistoryViewModel.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/edithistory/ViewEditHistoryViewModel.kt index e1d4d71c6a..11d7979f21 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/edithistory/ViewEditHistoryViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/edithistory/ViewEditHistoryViewModel.kt @@ -32,6 +32,7 @@ import org.matrix.android.sdk.api.session.Session import org.matrix.android.sdk.api.session.crypto.MXCryptoError import org.matrix.android.sdk.api.session.crypto.model.OlmDecryptionResult import org.matrix.android.sdk.api.session.events.model.isReply +import org.matrix.android.sdk.api.session.getRoom import timber.log.Timber import java.util.UUID diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/EncryptionItemFactory.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/EncryptionItemFactory.kt index 89899a52e0..0cbd92f525 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/EncryptionItemFactory.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/EncryptionItemFactory.kt @@ -29,6 +29,7 @@ import org.matrix.android.sdk.api.extensions.orFalse import org.matrix.android.sdk.api.session.Session import org.matrix.android.sdk.api.session.events.model.content.EncryptionEventContent import org.matrix.android.sdk.api.session.events.model.toModel +import org.matrix.android.sdk.api.session.getRoomSummary import javax.inject.Inject class EncryptionItemFactory @Inject constructor( diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/MergedHeaderItemFactory.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/MergedHeaderItemFactory.kt index c21b67a459..3370473493 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/MergedHeaderItemFactory.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/MergedHeaderItemFactory.kt @@ -38,6 +38,7 @@ import org.matrix.android.sdk.api.query.QueryStringValue import org.matrix.android.sdk.api.session.events.model.EventType import org.matrix.android.sdk.api.session.events.model.content.EncryptionEventContent import org.matrix.android.sdk.api.session.events.model.toModel +import org.matrix.android.sdk.api.session.getRoom import org.matrix.android.sdk.api.session.room.model.PowerLevelsContent import org.matrix.android.sdk.api.session.room.model.create.RoomCreateContent import org.matrix.android.sdk.api.session.room.powerlevels.PowerLevelsHelper diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/MessageItemFactory.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/MessageItemFactory.kt index 04e087d25d..186b34dc29 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/MessageItemFactory.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/MessageItemFactory.kt @@ -436,7 +436,7 @@ class MessageItemFactory @Inject constructor( val otherUserId = if (informationData.sentByMe) messageContent.toUserId else informationData.senderId val otherUserName = if (informationData.sentByMe) { - session.getRoomMember(messageContent.toUserId, roomId)?.displayName + session.roomService().getRoomMember(messageContent.toUserId, roomId)?.displayName } else { informationData.memberName } diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/TimelineFactory.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/TimelineFactory.kt index 3ec1366131..bd2a3e7ebe 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/TimelineFactory.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/TimelineFactory.kt @@ -22,6 +22,7 @@ import im.vector.app.features.home.room.detail.timeline.merged.MergedTimelines import kotlinx.coroutines.CoroutineScope import org.matrix.android.sdk.api.session.Session import org.matrix.android.sdk.api.session.events.model.EventType +import org.matrix.android.sdk.api.session.getRoom import org.matrix.android.sdk.api.session.room.Room import org.matrix.android.sdk.api.session.room.timeline.Timeline import javax.inject.Inject diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/VerificationItemFactory.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/VerificationItemFactory.kt index fb8f8fce9d..dfba50d209 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/VerificationItemFactory.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/VerificationItemFactory.kt @@ -32,6 +32,7 @@ import org.matrix.android.sdk.api.session.crypto.verification.safeValueOf import org.matrix.android.sdk.api.session.events.model.EventType import org.matrix.android.sdk.api.session.events.model.RelationType import org.matrix.android.sdk.api.session.events.model.toModel +import org.matrix.android.sdk.api.session.getRoom import org.matrix.android.sdk.api.session.room.model.message.MessageRelationContent import org.matrix.android.sdk.api.session.room.model.message.MessageVerificationCancelContent import javax.inject.Inject diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/helper/LocationPinProvider.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/helper/LocationPinProvider.kt index 7262284c95..8ef910c931 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/helper/LocationPinProvider.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/helper/LocationPinProvider.kt @@ -29,6 +29,7 @@ import im.vector.app.core.di.ActiveSessionHolder import im.vector.app.core.glide.GlideApp import im.vector.app.core.utils.DimensionConverter import im.vector.app.features.home.AvatarRenderer +import org.matrix.android.sdk.api.session.getUser import org.matrix.android.sdk.api.util.toMatrixItem import timber.log.Timber import javax.inject.Inject diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/reactions/ViewReactionsViewModel.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/reactions/ViewReactionsViewModel.kt index 29b8c207df..5f4befd035 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/reactions/ViewReactionsViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/reactions/ViewReactionsViewModel.kt @@ -33,6 +33,7 @@ import im.vector.app.core.platform.VectorViewModel import im.vector.app.features.home.room.detail.timeline.action.TimelineEventFragmentArgs import kotlinx.coroutines.flow.map import org.matrix.android.sdk.api.session.Session +import org.matrix.android.sdk.api.session.getRoom import org.matrix.android.sdk.flow.flow import org.matrix.android.sdk.flow.unwrap diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/render/EventTextRenderer.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/render/EventTextRenderer.kt index d50a6fb297..83cffc4279 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/render/EventTextRenderer.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/render/EventTextRenderer.kt @@ -62,7 +62,7 @@ class EventTextRenderer @AssistedInject constructor(@Assisted private val roomId * ========================================================================================== */ private fun addNotifyEveryoneSpans(text: Spannable, roomId: String) { - val room: RoomSummary? = sessionHolder.getSafeActiveSession()?.getRoomSummary(roomId) + val room: RoomSummary? = sessionHolder.getSafeActiveSession()?.roomService()?.getRoomSummary(roomId) val matrixItem = MatrixItem.EveryoneInRoomItem( id = roomId, avatarUrl = room?.avatarUrl, diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/upgrade/MigrateRoomViewModel.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/upgrade/MigrateRoomViewModel.kt index 5a535e5696..6643ae4ac6 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/upgrade/MigrateRoomViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/upgrade/MigrateRoomViewModel.kt @@ -29,6 +29,8 @@ import im.vector.app.core.platform.VectorViewModel import im.vector.app.features.session.coroutineScope import kotlinx.coroutines.launch import org.matrix.android.sdk.api.session.Session +import org.matrix.android.sdk.api.session.getRoom +import org.matrix.android.sdk.api.session.getRoomSummary class MigrateRoomViewModel @AssistedInject constructor( @Assisted initialState: MigrateRoomViewState, diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/upgrade/UpgradeRoomViewModelTask.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/upgrade/UpgradeRoomViewModelTask.kt index 8859aaeacf..7e7a3cb7cd 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/upgrade/UpgradeRoomViewModelTask.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/upgrade/UpgradeRoomViewModelTask.kt @@ -20,6 +20,7 @@ import im.vector.app.core.platform.ViewModelTask import im.vector.app.core.resources.StringProvider import org.matrix.android.sdk.api.extensions.tryOrNull import org.matrix.android.sdk.api.session.Session +import org.matrix.android.sdk.api.session.getRoom import timber.log.Timber import javax.inject.Inject diff --git a/vector/src/main/java/im/vector/app/features/home/room/list/RoomListSectionBuilderGroup.kt b/vector/src/main/java/im/vector/app/features/home/room/list/RoomListSectionBuilderGroup.kt index bd43a83f2c..0a31987ae5 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/list/RoomListSectionBuilderGroup.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/list/RoomListSectionBuilderGroup.kt @@ -70,11 +70,11 @@ class RoomListSectionBuilderGroup( }, { qpm -> val name = stringProvider.getString(R.string.bottom_action_rooms) - val updatableFilterLivePageResult = session.getFilteredPagedRoomSummariesLive(qpm) + val updatableFilterLivePageResult = session.roomService().getFilteredPagedRoomSummariesLive(qpm) onUpdatable(updatableFilterLivePageResult) val itemCountFlow = updatableFilterLivePageResult.livePagedList.asFlow() - .flatMapLatest { session.getRoomCountLive(updatableFilterLivePageResult.queryParams).asFlow() } + .flatMapLatest { session.roomService().getRoomCountLive(updatableFilterLivePageResult.queryParams).asFlow() } .distinctUntilChanged() sections.add( @@ -252,7 +252,7 @@ class RoomListSectionBuilderGroup( query: (RoomSummaryQueryParams.Builder) -> Unit) { withQueryParams(query) { roomQueryParams -> val name = stringProvider.getString(nameRes) - session.getFilteredPagedRoomSummariesLive(roomQueryParams) + session.roomService().getFilteredPagedRoomSummariesLive(roomQueryParams) .also { activeSpaceUpdaters.add(it) }.livePagedList @@ -262,7 +262,7 @@ class RoomListSectionBuilderGroup( .onEach { sections.find { it.sectionName == name } ?.notificationCount - ?.postValue(session.getNotificationCountForRooms(roomQueryParams)) + ?.postValue(session.roomService().getNotificationCountForRooms(roomQueryParams)) } .flowOn(Dispatchers.Default) .launchIn(coroutineScope) @@ -272,7 +272,7 @@ class RoomListSectionBuilderGroup( sectionName = name, livePages = livePagedList, notifyOfLocalEcho = notifyOfLocalEcho, - itemCount = session.getRoomCountLive(roomQueryParams).asFlow() + itemCount = session.roomService().getRoomCountLive(roomQueryParams).asFlow() ) ) } diff --git a/vector/src/main/java/im/vector/app/features/home/room/list/RoomListSectionBuilderSpace.kt b/vector/src/main/java/im/vector/app/features/home/room/list/RoomListSectionBuilderSpace.kt index d405bc5b6f..59137ec490 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/list/RoomListSectionBuilderSpace.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/list/RoomListSectionBuilderSpace.kt @@ -47,6 +47,7 @@ import org.matrix.android.sdk.api.query.ActiveSpaceFilter import org.matrix.android.sdk.api.query.RoomCategoryFilter import org.matrix.android.sdk.api.query.RoomTagQueryFilter import org.matrix.android.sdk.api.session.Session +import org.matrix.android.sdk.api.session.getRoomSummary import org.matrix.android.sdk.api.session.room.RoomSummaryQueryParams import org.matrix.android.sdk.api.session.room.UpdatableLivePageResult import org.matrix.android.sdk.api.session.room.model.Membership @@ -324,11 +325,11 @@ class RoomListSectionBuilderSpace( }, { qpm -> val name = stringProvider.getString(R.string.bottom_action_rooms) - val updatableFilterLivePageResult = session.getFilteredPagedRoomSummariesLive(qpm) + val updatableFilterLivePageResult = session.roomService().getFilteredPagedRoomSummariesLive(qpm) onUpdatable(updatableFilterLivePageResult) val itemCountFlow = updatableFilterLivePageResult.livePagedList.asFlow() - .flatMapLatest { session.getRoomCountLive(updatableFilterLivePageResult.queryParams).asFlow() } + .flatMapLatest { session.roomService().getRoomCountLive(updatableFilterLivePageResult.queryParams).asFlow() } .distinctUntilChanged() sections.add( @@ -354,13 +355,13 @@ class RoomListSectionBuilderSpace( val liveQueryParams = MutableStateFlow(updatedQueryParams) val itemCountFlow = liveQueryParams .flatMapLatest { - session.getRoomCountLive(it).asFlow() + session.roomService().getRoomCountLive(it).asFlow() } .flowOn(Dispatchers.Main) .distinctUntilChanged() val name = stringProvider.getString(nameRes) - val filteredPagedRoomSummariesLive = session.getFilteredPagedRoomSummariesLive( + val filteredPagedRoomSummariesLive = session.roomService().getFilteredPagedRoomSummariesLive( roomQueryParams.process(spaceFilterStrategy, appStateHandler.safeActiveSpaceId()), pagedListConfig ) @@ -407,7 +408,7 @@ class RoomListSectionBuilderSpace( if (countRoomAsNotif) { RoomAggregateNotificationCount(it.size, it.size) } else { - session.getNotificationCountForRooms( + session.roomService().getNotificationCountForRooms( roomQueryParams.process(spaceFilterStrategy, appStateHandler.safeActiveSpaceId()) ) } diff --git a/vector/src/main/java/im/vector/app/features/home/room/list/RoomListViewModel.kt b/vector/src/main/java/im/vector/app/features/home/room/list/RoomListViewModel.kt index 70974bc1f6..9fb13084d1 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/list/RoomListViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/list/RoomListViewModel.kt @@ -42,6 +42,7 @@ import kotlinx.coroutines.launch import org.matrix.android.sdk.api.extensions.orFalse import org.matrix.android.sdk.api.query.QueryStringValue import org.matrix.android.sdk.api.session.Session +import org.matrix.android.sdk.api.session.getRoom 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.model.tag.RoomTag @@ -233,7 +234,7 @@ class RoomListViewModel @AssistedInject constructor( viewModelScope.launch { try { - session.leaveRoom(roomId) + session.roomService().leaveRoom(roomId) // We do not update the rejectingRoomsIds here, because, the room is not rejected yet regarding the sync data. // Instead, we wait for the room to be rejected // Known bug: if the user is invited again (after rejecting the first invitation), the loading will be displayed instead of the buttons. @@ -265,7 +266,7 @@ class RoomListViewModel @AssistedInject constructor( viewModelScope.launch { try { - session.joinRoom(action.roomId, null, action.viaServers ?: emptyList()) + session.roomService().joinRoom(action.roomId, null, action.viaServers ?: emptyList()) suggestedRoomJoiningState.postValue(suggestedRoomJoiningState.value.orEmpty().toMutableMap().apply { this[action.roomId] = Success(Unit) @@ -319,7 +320,7 @@ class RoomListViewModel @AssistedInject constructor( private fun handleLeaveRoom(action: RoomListAction.LeaveRoom) { _viewEvents.post(RoomListViewEvents.Loading(null)) viewModelScope.launch { - val value = runCatching { session.leaveRoom(action.roomId) } + val value = runCatching { session.roomService().leaveRoom(action.roomId) } .fold({ RoomListViewEvents.Done }, { RoomListViewEvents.Failure(it) }) _viewEvents.post(value) } diff --git a/vector/src/main/java/im/vector/app/features/home/room/threads/list/viewmodel/ThreadListController.kt b/vector/src/main/java/im/vector/app/features/home/room/threads/list/viewmodel/ThreadListController.kt index 54c44e178f..6b3f0dc6b8 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/threads/list/viewmodel/ThreadListController.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/threads/list/viewmodel/ThreadListController.kt @@ -49,7 +49,7 @@ class ThreadListController @Inject constructor( } override fun buildModels() = - when (session.getHomeServerCapabilities().canUseThreading) { + when (session.homeServerCapabilitiesService().getHomeServerCapabilities().canUseThreading) { true -> buildThreadSummaries() false -> buildThreadList() } diff --git a/vector/src/main/java/im/vector/app/features/home/room/threads/list/viewmodel/ThreadListViewModel.kt b/vector/src/main/java/im/vector/app/features/home/room/threads/list/viewmodel/ThreadListViewModel.kt index 8840131f38..a022ca19f3 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/threads/list/viewmodel/ThreadListViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/threads/list/viewmodel/ThreadListViewModel.kt @@ -33,6 +33,7 @@ import kotlinx.coroutines.flow.flowOn import kotlinx.coroutines.flow.map import kotlinx.coroutines.launch import org.matrix.android.sdk.api.session.Session +import org.matrix.android.sdk.api.session.getRoom import org.matrix.android.sdk.api.session.threads.ThreadTimelineEvent import org.matrix.android.sdk.flow.flow @@ -68,7 +69,7 @@ class ThreadListViewModel @AssistedInject constructor(@Assisted val initialState * capabilities */ private fun fetchAndObserveThreads() { - when (session.getHomeServerCapabilities().canUseThreading) { + when (session.homeServerCapabilitiesService().getHomeServerCapabilities().canUseThreading) { true -> { fetchThreadList() observeThreadSummaries() @@ -125,7 +126,7 @@ class ThreadListViewModel @AssistedInject constructor(@Assisted val initialState } } - fun canHomeserverUseThreading() = session.getHomeServerCapabilities().canUseThreading + fun canHomeserverUseThreading() = session.homeServerCapabilitiesService().getHomeServerCapabilities().canUseThreading fun applyFiltering(shouldFilterThreads: Boolean) { analyticsTracker.capture(Interaction.Name.MobileThreadListFilterItem.toAnalyticsInteraction()) diff --git a/vector/src/main/java/im/vector/app/features/homeserver/HomeServerCapabilitiesViewModel.kt b/vector/src/main/java/im/vector/app/features/homeserver/HomeServerCapabilitiesViewModel.kt index 9223485eff..1e4fccefd5 100644 --- a/vector/src/main/java/im/vector/app/features/homeserver/HomeServerCapabilitiesViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/homeserver/HomeServerCapabilitiesViewModel.kt @@ -53,7 +53,7 @@ class HomeServerCapabilitiesViewModel @AssistedInject constructor( override fun initialState(viewModelContext: ViewModelContext): HomeServerCapabilitiesViewState { val session = EntryPoints.get(viewModelContext.app(), SingletonEntryPoint::class.java).activeSessionHolder().getSafeActiveSession() return HomeServerCapabilitiesViewState( - capabilities = session?.getHomeServerCapabilities() ?: HomeServerCapabilities() + capabilities = session?.homeServerCapabilitiesService()?.getHomeServerCapabilities() ?: HomeServerCapabilities() ) } } diff --git a/vector/src/main/java/im/vector/app/features/html/PillsPostProcessor.kt b/vector/src/main/java/im/vector/app/features/html/PillsPostProcessor.kt index 506f5e773c..2d63d69c35 100644 --- a/vector/src/main/java/im/vector/app/features/html/PillsPostProcessor.kt +++ b/vector/src/main/java/im/vector/app/features/html/PillsPostProcessor.kt @@ -26,6 +26,8 @@ import im.vector.app.core.di.ActiveSessionHolder import im.vector.app.core.glide.GlideApp import im.vector.app.features.home.AvatarRenderer import io.noties.markwon.core.spans.LinkSpan +import org.matrix.android.sdk.api.session.getRoomSummary +import org.matrix.android.sdk.api.session.getUser import org.matrix.android.sdk.api.session.permalinks.PermalinkData import org.matrix.android.sdk.api.session.permalinks.PermalinkParser import org.matrix.android.sdk.api.session.room.model.RoomSummary @@ -100,7 +102,7 @@ class PillsPostProcessor @AssistedInject constructor(@Assisted private val roomI if (roomId == null) { sessionHolder.getSafeActiveSession()?.getUser(userId)?.toMatrixItem() } else { - sessionHolder.getSafeActiveSession()?.getRoomMember(userId, roomId)?.toMatrixItem() + sessionHolder.getSafeActiveSession()?.roomService()?.getRoomMember(userId, roomId)?.toMatrixItem() } private fun PermalinkData.RoomLink.toMatrixItem(): MatrixItem? = @@ -116,7 +118,7 @@ class PillsPostProcessor @AssistedInject constructor(@Assisted private val roomI } private fun PermalinkData.GroupLink.toMatrixItem(): MatrixItem? { - val group = sessionHolder.getSafeActiveSession()?.getGroupSummary(groupId) + val group = sessionHolder.getSafeActiveSession()?.groupService()?.getGroupSummary(groupId) return MatrixItem.GroupItem(groupId, group?.displayName, group?.avatarUrl) } } diff --git a/vector/src/main/java/im/vector/app/features/invite/InviteUsersToRoomViewModel.kt b/vector/src/main/java/im/vector/app/features/invite/InviteUsersToRoomViewModel.kt index 42f08c334e..a7745c1681 100644 --- a/vector/src/main/java/im/vector/app/features/invite/InviteUsersToRoomViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/invite/InviteUsersToRoomViewModel.kt @@ -31,6 +31,7 @@ import kotlinx.coroutines.flow.catch import kotlinx.coroutines.flow.map import kotlinx.coroutines.launch import org.matrix.android.sdk.api.session.Session +import org.matrix.android.sdk.api.session.getRoom class InviteUsersToRoomViewModel @AssistedInject constructor( @Assisted initialState: InviteUsersToRoomViewState, diff --git a/vector/src/main/java/im/vector/app/features/invite/InvitesAcceptor.kt b/vector/src/main/java/im/vector/app/features/invite/InvitesAcceptor.kt index a482998f77..bdc9ee2d1a 100644 --- a/vector/src/main/java/im/vector/app/features/invite/InvitesAcceptor.kt +++ b/vector/src/main/java/im/vector/app/features/invite/InvitesAcceptor.kt @@ -34,6 +34,7 @@ import kotlinx.coroutines.sync.withPermit import org.matrix.android.sdk.api.extensions.orFalse import org.matrix.android.sdk.api.failure.Failure import org.matrix.android.sdk.api.session.Session +import org.matrix.android.sdk.api.session.getRoom import org.matrix.android.sdk.api.session.room.members.ChangeMembershipState import org.matrix.android.sdk.api.session.room.model.Membership import org.matrix.android.sdk.api.session.room.roomSummaryQueryParams @@ -111,11 +112,11 @@ class InvitesAcceptor @Inject constructor( rejectInviteSafely(roomId) return } - val roomMembershipChanged = getChangeMemberships(roomId) + val roomMembershipChanged = roomService().getChangeMemberships(roomId) if (roomMembershipChanged != ChangeMembershipState.Joined && !roomMembershipChanged.isInProgress()) { try { Timber.v("Try auto join room: $roomId") - joinRoom(roomId) + roomService().joinRoom(roomId) } catch (failure: Throwable) { Timber.v("Failed auto join room: $roomId") // if we got 404 on invites, the inviting user have left or the hs is off. @@ -134,7 +135,7 @@ class InvitesAcceptor @Inject constructor( private suspend fun Session.rejectInviteSafely(roomId: String) { try { - leaveRoom(roomId) + roomService().leaveRoom(roomId) shouldRejectRoomIds.remove(roomId) } catch (failure: Throwable) { Timber.v("Fail rejecting invite for room: $roomId") diff --git a/vector/src/main/java/im/vector/app/features/link/LinkHandlerActivity.kt b/vector/src/main/java/im/vector/app/features/link/LinkHandlerActivity.kt index 2cb41784b7..5b44f69821 100644 --- a/vector/src/main/java/im/vector/app/features/link/LinkHandlerActivity.kt +++ b/vector/src/main/java/im/vector/app/features/link/LinkHandlerActivity.kt @@ -133,7 +133,7 @@ class LinkHandlerActivity : VectorBaseActivity() { } else { lifecycleScope.launch { try { - session.signOut(true) + session.signOutService().signOut(true) Timber.d("## displayAlreadyLoginPopup(): logout succeeded") sessionHolder.clearActiveSession() startLoginActivity(uri) diff --git a/vector/src/main/java/im/vector/app/features/location/LocationSharingService.kt b/vector/src/main/java/im/vector/app/features/location/LocationSharingService.kt index 2126cdac04..84b4d2e9b3 100644 --- a/vector/src/main/java/im/vector/app/features/location/LocationSharingService.kt +++ b/vector/src/main/java/im/vector/app/features/location/LocationSharingService.kt @@ -31,6 +31,7 @@ import kotlinx.parcelize.Parcelize import org.matrix.android.sdk.api.session.Session 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.getRoom import org.matrix.android.sdk.api.session.room.model.livelocation.BeaconInfo import org.matrix.android.sdk.api.session.room.model.livelocation.LiveLocationBeaconContent import timber.log.Timber diff --git a/vector/src/main/java/im/vector/app/features/location/LocationSharingViewModel.kt b/vector/src/main/java/im/vector/app/features/location/LocationSharingViewModel.kt index e67d5d0abb..34cb68973c 100644 --- a/vector/src/main/java/im/vector/app/features/location/LocationSharingViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/location/LocationSharingViewModel.kt @@ -36,6 +36,8 @@ import kotlinx.coroutines.flow.sample import kotlinx.coroutines.launch import org.matrix.android.sdk.api.extensions.orFalse import org.matrix.android.sdk.api.session.Session +import org.matrix.android.sdk.api.session.getRoom +import org.matrix.android.sdk.api.session.getUser import org.matrix.android.sdk.api.util.toMatrixItem /** diff --git a/vector/src/main/java/im/vector/app/features/login2/created/AccountCreatedViewModel.kt b/vector/src/main/java/im/vector/app/features/login2/created/AccountCreatedViewModel.kt index 568cdab119..ac4edba7fb 100644 --- a/vector/src/main/java/im/vector/app/features/login2/created/AccountCreatedViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/login2/created/AccountCreatedViewModel.kt @@ -81,7 +81,7 @@ class AccountCreatedViewModel @AssistedInject constructor( private fun handleSetAvatar(action: AccountCreatedAction.SetAvatar) { setState { copy(isLoading = true) } viewModelScope.launch { - val result = runCatching { session.updateAvatar(session.myUserId, action.avatarUri, action.filename) } + val result = runCatching { session.profileService().updateAvatar(session.myUserId, action.avatarUri, action.filename) } .onFailure { _viewEvents.post(AccountCreatedViewEvents.Failure(it)) } setState { copy( @@ -95,7 +95,7 @@ class AccountCreatedViewModel @AssistedInject constructor( private fun handleSetDisplayName(action: AccountCreatedAction.SetDisplayName) { setState { copy(isLoading = true) } viewModelScope.launch { - val result = runCatching { session.setDisplayName(session.myUserId, action.displayName) } + val result = runCatching { session.profileService().setDisplayName(session.myUserId, action.displayName) } .onFailure { _viewEvents.post(AccountCreatedViewEvents.Failure(it)) } setState { copy( diff --git a/vector/src/main/java/im/vector/app/features/matrixto/MatrixToBottomSheetViewModel.kt b/vector/src/main/java/im/vector/app/features/matrixto/MatrixToBottomSheetViewModel.kt index 6d0e380bc9..b6db5f487d 100644 --- a/vector/src/main/java/im/vector/app/features/matrixto/MatrixToBottomSheetViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/matrixto/MatrixToBottomSheetViewModel.kt @@ -36,6 +36,7 @@ import kotlinx.coroutines.launch 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.getRoom import org.matrix.android.sdk.api.session.permalinks.PermalinkData import org.matrix.android.sdk.api.session.room.model.Membership import org.matrix.android.sdk.api.session.room.peeking.PeekResult @@ -110,7 +111,7 @@ class MatrixToBottomSheetViewModel @AssistedInject constructor( // could this room be already known val knownRoom = if (permalinkData.isRoomAlias) { tryOrNull { - session.getRoomIdByAlias(permalinkData.roomIdOrAlias, false) + session.roomService().getRoomIdByAlias(permalinkData.roomIdOrAlias, false) } ?.getOrNull() ?.roomId?.let { @@ -195,7 +196,7 @@ class MatrixToBottomSheetViewModel @AssistedInject constructor( private fun checkForKnownMembers(someMembers: List) { viewModelScope.launch(Dispatchers.Default) { val knownMembers = someMembers.filter { - session.getExistingDirectRoomWithUser(it.id) != null + session.roomService().getExistingDirectRoomWithUser(it.id) != null } // put one with avatar first, and take 5 val finalRes = (knownMembers.filter { it.avatarUrl != null } + knownMembers.filter { it.avatarUrl == null }) @@ -234,7 +235,7 @@ class MatrixToBottomSheetViewModel @AssistedInject constructor( } private suspend fun resolveUser(userId: String): User { - return tryOrNull { session.resolveUser(userId) } + return tryOrNull { session.userService().resolveUser(userId) } // Create raw user in case the user is not searchable ?: User(userId, null, null) } @@ -244,7 +245,7 @@ class MatrixToBottomSheetViewModel @AssistedInject constructor( * main thing is trying to see if it's a space or a room */ private suspend fun resolveRoom(roomIdOrAlias: String): PeekResult { - return session.peekRoom(roomIdOrAlias) + return session.roomService().peekRoom(roomIdOrAlias) } override fun handle(action: MatrixToAction) { @@ -297,7 +298,7 @@ class MatrixToBottomSheetViewModel @AssistedInject constructor( } viewModelScope.launch { try { - session.joinRoom( + session.roomService().joinRoom( roomIdOrAlias = action.roomIdOrAlias, reason = null, viaServers = action.viaServers?.take(3) ?: emptyList() @@ -316,7 +317,7 @@ class MatrixToBottomSheetViewModel @AssistedInject constructor( private suspend fun getRoomIdFromRoomIdOrAlias(roomIdOrAlias: String): String { return if (MatrixPatterns.isRoomAlias(roomIdOrAlias)) { - session.getRoomIdByAlias(roomIdOrAlias, true).get().roomId + session.roomService().getRoomIdByAlias(roomIdOrAlias, true).get().roomId } else roomIdOrAlias } diff --git a/vector/src/main/java/im/vector/app/features/media/VectorAttachmentViewerActivity.kt b/vector/src/main/java/im/vector/app/features/media/VectorAttachmentViewerActivity.kt index d8c2b83f9b..a9755138de 100644 --- a/vector/src/main/java/im/vector/app/features/media/VectorAttachmentViewerActivity.kt +++ b/vector/src/main/java/im/vector/app/features/media/VectorAttachmentViewerActivity.kt @@ -53,6 +53,7 @@ import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.launch import kotlinx.coroutines.withContext import kotlinx.parcelize.Parcelize +import org.matrix.android.sdk.api.session.getRoom import timber.log.Timber import javax.inject.Inject diff --git a/vector/src/main/java/im/vector/app/features/navigation/DefaultNavigator.kt b/vector/src/main/java/im/vector/app/features/navigation/DefaultNavigator.kt index 086a40636c..076b7be3ad 100644 --- a/vector/src/main/java/im/vector/app/features/navigation/DefaultNavigator.kt +++ b/vector/src/main/java/im/vector/app/features/navigation/DefaultNavigator.kt @@ -101,6 +101,8 @@ import im.vector.app.features.widgets.WidgetActivity import im.vector.app.features.widgets.WidgetArgsBuilder import im.vector.app.space import org.matrix.android.sdk.api.session.crypto.verification.IncomingSasVerificationTransaction +import org.matrix.android.sdk.api.session.getRoom +import org.matrix.android.sdk.api.session.getRoomSummary import org.matrix.android.sdk.api.session.permalinks.PermalinkData import org.matrix.android.sdk.api.session.room.model.roomdirectory.PublicRoom import org.matrix.android.sdk.api.session.terms.TermsService diff --git a/vector/src/main/java/im/vector/app/features/notifications/NotifiableEventResolver.kt b/vector/src/main/java/im/vector/app/features/notifications/NotifiableEventResolver.kt index 855774e512..43eab0c1f2 100644 --- a/vector/src/main/java/im/vector/app/features/notifications/NotifiableEventResolver.kt +++ b/vector/src/main/java/im/vector/app/features/notifications/NotifiableEventResolver.kt @@ -34,6 +34,9 @@ import org.matrix.android.sdk.api.session.events.model.isEdition import org.matrix.android.sdk.api.session.events.model.isImageMessage import org.matrix.android.sdk.api.session.events.model.supportsNotification import org.matrix.android.sdk.api.session.events.model.toModel +import org.matrix.android.sdk.api.session.getRoom +import org.matrix.android.sdk.api.session.getRoomSummary +import org.matrix.android.sdk.api.session.getUser 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.message.MessageWithAttachmentContent @@ -100,7 +103,7 @@ class NotifiableEventResolver @Inject constructor( // Ignore message edition if (event.isEdition()) return null - val actions = session.getActions(event) + val actions = session.pushRuleService().getActions(event) val notificationAction = actions.toNotificationAction() return if (notificationAction.shouldNotify) { @@ -233,7 +236,7 @@ class NotifiableEventResolver @Inject constructor( private fun resolveStateRoomEvent(event: Event, session: Session, canBeReplaced: Boolean, isNoisy: Boolean): NotifiableEvent? { val content = event.content?.toModel() ?: return null val roomId = event.roomId ?: return null - val dName = event.senderId?.let { session.getRoomMember(it, roomId)?.displayName } + val dName = event.senderId?.let { session.roomService().getRoomMember(it, roomId)?.displayName } if (Membership.INVITE == content.membership) { val roomSummary = session.getRoomSummary(roomId) val body = noticeEventFormatter.format(event, dName, isDm = roomSummary?.isDirect.orFalse()) diff --git a/vector/src/main/java/im/vector/app/features/notifications/NotificationBroadcastReceiver.kt b/vector/src/main/java/im/vector/app/features/notifications/NotificationBroadcastReceiver.kt index 505f4cc4a0..3d5bd7930c 100644 --- a/vector/src/main/java/im/vector/app/features/notifications/NotificationBroadcastReceiver.kt +++ b/vector/src/main/java/im/vector/app/features/notifications/NotificationBroadcastReceiver.kt @@ -29,6 +29,7 @@ import im.vector.app.features.session.coroutineScope import kotlinx.coroutines.launch import org.matrix.android.sdk.api.extensions.tryOrNull import org.matrix.android.sdk.api.session.Session +import org.matrix.android.sdk.api.session.getRoom import org.matrix.android.sdk.api.session.room.Room import org.matrix.android.sdk.api.session.room.read.ReadService import timber.log.Timber @@ -83,7 +84,7 @@ class NotificationBroadcastReceiver : BroadcastReceiver() { if (room != null) { session.coroutineScope.launch { tryOrNull { - session.joinRoom(room.roomId) + session.roomService().joinRoom(room.roomId) analyticsTracker.capture(room.roomSummary().toAnalyticsJoinedRoom()) } } @@ -94,7 +95,7 @@ class NotificationBroadcastReceiver : BroadcastReceiver() { private fun handleRejectRoom(roomId: String) { activeSessionHolder.getSafeActiveSession()?.let { session -> session.coroutineScope.launch { - tryOrNull { session.leaveRoom(roomId) } + tryOrNull { session.roomService().leaveRoom(roomId) } } } } @@ -137,7 +138,7 @@ class NotificationBroadcastReceiver : BroadcastReceiver() { editedEventId = null, noisy = false, timestamp = System.currentTimeMillis(), - senderName = session.getRoomMember(session.myUserId, room.roomId)?.displayName + senderName = session.roomService().getRoomMember(session.myUserId, room.roomId)?.displayName ?: context?.getString(R.string.notification_sender_me), senderId = session.myUserId, body = message, diff --git a/vector/src/main/java/im/vector/app/features/notifications/NotificationDrawerManager.kt b/vector/src/main/java/im/vector/app/features/notifications/NotificationDrawerManager.kt index fa56e3b8ed..62cac7507f 100644 --- a/vector/src/main/java/im/vector/app/features/notifications/NotificationDrawerManager.kt +++ b/vector/src/main/java/im/vector/app/features/notifications/NotificationDrawerManager.kt @@ -27,6 +27,7 @@ import im.vector.app.features.displayname.getBestName import im.vector.app.features.settings.VectorPreferences import org.matrix.android.sdk.api.session.Session import org.matrix.android.sdk.api.session.content.ContentUrlResolver +import org.matrix.android.sdk.api.session.getUser import org.matrix.android.sdk.api.util.toMatrixItem import timber.log.Timber import javax.inject.Inject diff --git a/vector/src/main/java/im/vector/app/features/notifications/NotificationEventPersistence.kt b/vector/src/main/java/im/vector/app/features/notifications/NotificationEventPersistence.kt index a4a7570fec..5a716ff173 100644 --- a/vector/src/main/java/im/vector/app/features/notifications/NotificationEventPersistence.kt +++ b/vector/src/main/java/im/vector/app/features/notifications/NotificationEventPersistence.kt @@ -34,7 +34,7 @@ class NotificationEventPersistence @Inject constructor(private val context: Cont val file = File(context.applicationContext.cacheDir, ROOMS_NOTIFICATIONS_FILE_NAME) if (file.exists()) { file.inputStream().use { - val events: ArrayList? = currentSession?.loadSecureSecret(it, KEY_ALIAS_SECRET_STORAGE) + val events: ArrayList? = currentSession?.secureStorageService()?.loadSecureSecret(it, KEY_ALIAS_SECRET_STORAGE) if (events != null) { return factory(events) } @@ -55,7 +55,7 @@ class NotificationEventPersistence @Inject constructor(private val context: Cont val file = File(context.applicationContext.cacheDir, ROOMS_NOTIFICATIONS_FILE_NAME) if (!file.exists()) file.createNewFile() FileOutputStream(file).use { - currentSession.securelyStoreObject(queuedEvents.rawEvents(), KEY_ALIAS_SECRET_STORAGE, it) + currentSession.secureStorageService().securelyStoreObject(queuedEvents.rawEvents(), KEY_ALIAS_SECRET_STORAGE, it) } } catch (e: Throwable) { Timber.e(e, "## Failed to save cached notification info") diff --git a/vector/src/main/java/im/vector/app/features/notifications/OutdatedEventDetector.kt b/vector/src/main/java/im/vector/app/features/notifications/OutdatedEventDetector.kt index c6ef616afe..5a9a950a02 100644 --- a/vector/src/main/java/im/vector/app/features/notifications/OutdatedEventDetector.kt +++ b/vector/src/main/java/im/vector/app/features/notifications/OutdatedEventDetector.kt @@ -16,6 +16,7 @@ package im.vector.app.features.notifications import im.vector.app.ActiveSessionDataSource +import org.matrix.android.sdk.api.session.getRoom import javax.inject.Inject class OutdatedEventDetector @Inject constructor( diff --git a/vector/src/main/java/im/vector/app/features/notifications/PushRuleTriggerListener.kt b/vector/src/main/java/im/vector/app/features/notifications/PushRuleTriggerListener.kt index cd44ae461a..58f895bf0c 100644 --- a/vector/src/main/java/im/vector/app/features/notifications/PushRuleTriggerListener.kt +++ b/vector/src/main/java/im/vector/app/features/notifications/PushRuleTriggerListener.kt @@ -71,12 +71,12 @@ class PushRuleTriggerListener @Inject constructor( stop() } this.session = session - session.addPushRuleListener(this) + session.pushRuleService().addPushRuleListener(this) } fun stop() { scope.coroutineContext.cancelChildren(CancellationException("PushRuleTriggerListener stopping")) - session?.removePushRuleListener(this) + session?.pushRuleService()?.removePushRuleListener(this) session = null notificationDrawerManager.clearAllEvents() } diff --git a/vector/src/main/java/im/vector/app/features/onboarding/OnboardingViewModel.kt b/vector/src/main/java/im/vector/app/features/onboarding/OnboardingViewModel.kt index 2b286e6d93..82835849c0 100644 --- a/vector/src/main/java/im/vector/app/features/onboarding/OnboardingViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/onboarding/OnboardingViewModel.kt @@ -562,7 +562,7 @@ class OnboardingViewModel @AssistedInject constructor( private suspend fun createPersonalizationState(session: Session, state: OnboardingViewState): PersonalizationState { return when { vectorFeatures.isOnboardingPersonalizeEnabled() -> { - val homeServerCapabilities = session.getHomeServerCapabilities() + val homeServerCapabilities = session.homeServerCapabilitiesService().getHomeServerCapabilities() val capabilityOverrides = vectorOverrides.forceHomeserverCapabilities?.firstOrNull() state.personalizationState.copy( supportsChangingDisplayName = capabilityOverrides?.canChangeDisplayName ?: homeServerCapabilities.canChangeDisplayName, @@ -705,7 +705,7 @@ class OnboardingViewModel @AssistedInject constructor( viewModelScope.launch { val activeSession = activeSessionHolder.getActiveSession() try { - activeSession.setDisplayName(activeSession.myUserId, displayName) + activeSession.profileService().setDisplayName(activeSession.myUserId, displayName) setState { copy( isLoading = false, @@ -760,7 +760,7 @@ class OnboardingViewModel @AssistedInject constructor( viewModelScope.launch { val activeSession = activeSessionHolder.getActiveSession() try { - activeSession.updateAvatar( + activeSession.profileService().updateAvatar( activeSession.myUserId, pictureUri, uriFilenameResolver.getFilenameFromUri(pictureUri) ?: UUID.randomUUID().toString() diff --git a/vector/src/main/java/im/vector/app/features/permalink/PermalinkHandler.kt b/vector/src/main/java/im/vector/app/features/permalink/PermalinkHandler.kt index f840e9ea6f..cc2d712bb2 100644 --- a/vector/src/main/java/im/vector/app/features/permalink/PermalinkHandler.kt +++ b/vector/src/main/java/im/vector/app/features/permalink/PermalinkHandler.kt @@ -32,6 +32,8 @@ import kotlinx.coroutines.withContext import org.matrix.android.sdk.api.extensions.orFalse import org.matrix.android.sdk.api.extensions.tryOrNull import org.matrix.android.sdk.api.session.events.model.getRootThreadEventId +import org.matrix.android.sdk.api.session.getRoom +import org.matrix.android.sdk.api.session.getRoomSummary import org.matrix.android.sdk.api.session.permalinks.PermalinkData import org.matrix.android.sdk.api.session.permalinks.PermalinkParser import org.matrix.android.sdk.api.session.permalinks.PermalinkService @@ -145,7 +147,7 @@ class PermalinkHandler @Inject constructor(private val activeSessionHolder: Acti private suspend fun PermalinkData.RoomLink.getRoomId(): String? { val session = activeSessionHolder.getSafeActiveSession() return if (isRoomAlias && session != null) { - val roomIdByAlias = session.getRoomIdByAlias(roomIdOrAlias, true) + val roomIdByAlias = session.roomService().getRoomIdByAlias(roomIdOrAlias, true) roomIdByAlias.getOrNull()?.roomId } else { roomIdOrAlias diff --git a/vector/src/main/java/im/vector/app/features/poll/create/CreatePollViewModel.kt b/vector/src/main/java/im/vector/app/features/poll/create/CreatePollViewModel.kt index 835f6d670e..1840aa261b 100644 --- a/vector/src/main/java/im/vector/app/features/poll/create/CreatePollViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/poll/create/CreatePollViewModel.kt @@ -25,6 +25,7 @@ import im.vector.app.core.di.hiltMavericksViewModelFactory import im.vector.app.core.platform.VectorViewModel import im.vector.app.features.poll.PollMode import org.matrix.android.sdk.api.session.Session +import org.matrix.android.sdk.api.session.getRoom import org.matrix.android.sdk.api.session.room.model.message.MessagePollContent import org.matrix.android.sdk.api.session.room.model.message.PollType import org.matrix.android.sdk.api.session.room.timeline.getLastMessageContent diff --git a/vector/src/main/java/im/vector/app/features/room/RequireActiveMembershipViewModel.kt b/vector/src/main/java/im/vector/app/features/room/RequireActiveMembershipViewModel.kt index 329618045f..9d6172bcea 100644 --- a/vector/src/main/java/im/vector/app/features/room/RequireActiveMembershipViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/room/RequireActiveMembershipViewModel.kt @@ -36,6 +36,7 @@ import kotlinx.coroutines.flow.onEach import org.matrix.android.sdk.api.query.QueryStringValue import org.matrix.android.sdk.api.session.Session import org.matrix.android.sdk.api.session.events.model.EventType +import org.matrix.android.sdk.api.session.getRoom 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.RoomSummary diff --git a/vector/src/main/java/im/vector/app/features/roomdirectory/RoomDirectoryViewModel.kt b/vector/src/main/java/im/vector/app/features/roomdirectory/RoomDirectoryViewModel.kt index 710d4d5b5f..2cebc96dac 100644 --- a/vector/src/main/java/im/vector/app/features/roomdirectory/RoomDirectoryViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/roomdirectory/RoomDirectoryViewModel.kt @@ -165,7 +165,7 @@ class RoomDirectoryViewModel @AssistedInject constructor( currentJob = viewModelScope.launch { val data = try { - session.getPublicRooms(roomDirectoryData.homeServer, + session.roomDirectoryService().getPublicRooms(roomDirectoryData.homeServer, PublicRoomsParams( limit = PUBLIC_ROOMS_LIMIT, filter = PublicRoomsFilter(searchTerm = filter), @@ -225,7 +225,7 @@ class RoomDirectoryViewModel @AssistedInject constructor( val viaServers = listOfNotNull(state.roomDirectoryData.homeServer) viewModelScope.launch { try { - session.joinRoom(action.publicRoom.roomId, viaServers = viaServers) + session.roomService().joinRoom(action.publicRoom.roomId, viaServers = viaServers) analyticsTracker.capture(action.publicRoom.toAnalyticsJoinedRoom()) // We do not update the joiningRoomsIds here, because, the room is not joined yet regarding the sync data. // Instead, we wait for the room to be joined diff --git a/vector/src/main/java/im/vector/app/features/roomdirectory/createroom/CreateRoomViewModel.kt b/vector/src/main/java/im/vector/app/features/roomdirectory/createroom/CreateRoomViewModel.kt index 7d65c44a57..caf17e09d6 100644 --- a/vector/src/main/java/im/vector/app/features/roomdirectory/createroom/CreateRoomViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/roomdirectory/createroom/CreateRoomViewModel.kt @@ -40,6 +40,7 @@ import org.matrix.android.sdk.api.extensions.orFalse import org.matrix.android.sdk.api.extensions.tryOrNull import org.matrix.android.sdk.api.raw.RawService import org.matrix.android.sdk.api.session.Session +import org.matrix.android.sdk.api.session.getRoomSummary import org.matrix.android.sdk.api.session.homeserver.HomeServerCapabilities import org.matrix.android.sdk.api.session.room.alias.RoomAliasError import org.matrix.android.sdk.api.session.room.failure.CreateRoomFailure @@ -74,7 +75,8 @@ class CreateRoomViewModel @AssistedInject constructor( val parentSpaceId = initialState.parentSpaceId ?: appStateHandler.safeActiveSpaceId() - val restrictedSupport = session.getHomeServerCapabilities().isFeatureSupported(HomeServerCapabilities.ROOM_CAP_RESTRICTED) + val restrictedSupport = session.homeServerCapabilitiesService().getHomeServerCapabilities() + .isFeatureSupported(HomeServerCapabilities.ROOM_CAP_RESTRICTED) val createRestricted = restrictedSupport == HomeServerCapabilities.RoomCapabilitySupport.SUPPORTED val defaultJoinRules = if (parentSpaceId != null && createRestricted) { @@ -265,7 +267,7 @@ class CreateRoomViewModel @AssistedInject constructor( RoomJoinRules.RESTRICTED -> { state.parentSpaceId?.let { featurePreset = RestrictedRoomPreset( - session.getHomeServerCapabilities(), + session.homeServerCapabilitiesService().getHomeServerCapabilities(), listOf(RoomJoinRulesAllowEntry.restrictedToRoom(state.parentSpaceId)) ) } @@ -297,7 +299,7 @@ class CreateRoomViewModel @AssistedInject constructor( // TODO: Should this be non-cancellable? viewModelScope.launch { - runCatching { session.createRoom(createRoomParams) }.fold( + runCatching { session.roomService().createRoom(createRoomParams) }.fold( { roomId -> analyticsTracker.capture(CreatedRoom(isDM = createRoomParams.isDirect.orFalse())) if (state.parentSpaceId != null) { diff --git a/vector/src/main/java/im/vector/app/features/roomdirectory/picker/RoomDirectoryPickerViewModel.kt b/vector/src/main/java/im/vector/app/features/roomdirectory/picker/RoomDirectoryPickerViewModel.kt index 51af9a8286..48b6997bd4 100644 --- a/vector/src/main/java/im/vector/app/features/roomdirectory/picker/RoomDirectoryPickerViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/roomdirectory/picker/RoomDirectoryPickerViewModel.kt @@ -152,7 +152,7 @@ class RoomDirectoryPickerViewModel @AssistedInject constructor( copy(addServerAsync = Loading()) } try { - session.getPublicRooms( + session.roomDirectoryService().getPublicRooms( server = enteredServer, publicRoomsParams = PublicRoomsParams(limit = 1) ) diff --git a/vector/src/main/java/im/vector/app/features/roomdirectory/roompreview/RoomPreviewViewModel.kt b/vector/src/main/java/im/vector/app/features/roomdirectory/roompreview/RoomPreviewViewModel.kt index 8eefd7659d..88bfc32de9 100644 --- a/vector/src/main/java/im/vector/app/features/roomdirectory/roompreview/RoomPreviewViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/roomdirectory/roompreview/RoomPreviewViewModel.kt @@ -72,6 +72,7 @@ class RoomPreviewViewModel @AssistedInject constructor( // we might want to check if the mail is bound to this account? // if it is the invite val threePids = session + .profileService() .getThreePids() .filterIsInstance() @@ -107,7 +108,7 @@ class RoomPreviewViewModel @AssistedInject constructor( } viewModelScope.launch(Dispatchers.IO) { val peekResult = tryOrNull { - session.peekRoom(initialState.roomAlias ?: initialState.roomId) + session.roomService().peekRoom(initialState.roomAlias ?: initialState.roomId) } when (peekResult) { @@ -226,7 +227,7 @@ class RoomPreviewViewModel @AssistedInject constructor( state.fromEmailInvite?.privateKey ?: "" ) - session.joinRoom(state.roomId, reason = null, thirdPartySigned) + session.roomService().joinRoom(state.roomId, reason = null, thirdPartySigned) } catch (failure: Throwable) { setState { copy( @@ -246,7 +247,7 @@ class RoomPreviewViewModel @AssistedInject constructor( } viewModelScope.launch { try { - session.joinRoom(state.roomId, viaServers = state.homeServers) + session.roomService().joinRoom(state.roomId, viaServers = state.homeServers) analyticsTracker.capture(JoinedRoom( // Always false in this case (?) isDM = false, diff --git a/vector/src/main/java/im/vector/app/features/roommemberprofile/RoomMemberProfileViewModel.kt b/vector/src/main/java/im/vector/app/features/roommemberprofile/RoomMemberProfileViewModel.kt index 4bcf9ef55d..f440043d6e 100644 --- a/vector/src/main/java/im/vector/app/features/roommemberprofile/RoomMemberProfileViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/roommemberprofile/RoomMemberProfileViewModel.kt @@ -48,6 +48,7 @@ import org.matrix.android.sdk.api.session.accountdata.UserAccountDataTypes 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.toModel +import org.matrix.android.sdk.api.session.getRoom 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.Membership @@ -327,7 +328,8 @@ class RoomMemberProfileViewModel @AssistedInject constructor( private suspend fun fetchProfileInfo() { val result = runCatchingToAsync { - session.getProfile(initialState.userId) + session.profileService() + .getProfile(initialState.userId) .let { User.fromJson(initialState.userId, it) } .toMatrixItem() } @@ -386,9 +388,9 @@ class RoomMemberProfileViewModel @AssistedInject constructor( viewModelScope.launch { val event = try { if (isIgnored) { - session.unIgnoreUserIds(listOf(state.userId)) + session.userService().unIgnoreUserIds(listOf(state.userId)) } else { - session.ignoreUserIds(listOf(state.userId)) + session.userService().ignoreUserIds(listOf(state.userId)) } RoomMemberProfileViewEvents.OnIgnoreActionSuccess } catch (failure: Throwable) { diff --git a/vector/src/main/java/im/vector/app/features/roommemberprofile/devices/DeviceListBottomSheetViewModel.kt b/vector/src/main/java/im/vector/app/features/roommemberprofile/devices/DeviceListBottomSheetViewModel.kt index 5c64232a5a..19040a1fde 100644 --- a/vector/src/main/java/im/vector/app/features/roommemberprofile/devices/DeviceListBottomSheetViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/roommemberprofile/devices/DeviceListBottomSheetViewModel.kt @@ -33,6 +33,7 @@ import org.matrix.android.sdk.api.session.Session import org.matrix.android.sdk.api.session.crypto.crosssigning.MXCrossSigningInfo import org.matrix.android.sdk.api.session.crypto.model.CryptoDeviceInfo import org.matrix.android.sdk.api.session.crypto.verification.VerificationMethod +import org.matrix.android.sdk.api.session.getUser import org.matrix.android.sdk.api.util.MatrixItem import org.matrix.android.sdk.api.util.toMatrixItem import org.matrix.android.sdk.flow.flow diff --git a/vector/src/main/java/im/vector/app/features/roomprofile/RoomProfileViewModel.kt b/vector/src/main/java/im/vector/app/features/roomprofile/RoomProfileViewModel.kt index 7c6623b087..8453cc95cd 100644 --- a/vector/src/main/java/im/vector/app/features/roomprofile/RoomProfileViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/roomprofile/RoomProfileViewModel.kt @@ -39,6 +39,7 @@ import org.matrix.android.sdk.api.query.QueryStringValue import org.matrix.android.sdk.api.session.Session 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.getRoom import org.matrix.android.sdk.api.session.room.members.roomMemberQueryParams import org.matrix.android.sdk.api.session.room.model.Membership import org.matrix.android.sdk.api.session.room.model.create.RoomCreateContent @@ -188,7 +189,7 @@ class RoomProfileViewModel @AssistedInject constructor( _viewEvents.post(RoomProfileViewEvents.Loading(stringProvider.getString(R.string.room_profile_leaving_room))) viewModelScope.launch { try { - session.leaveRoom(room.roomId) + session.roomService().leaveRoom(room.roomId) analyticsTracker.capture(Interaction( index = null, interactionType = null, diff --git a/vector/src/main/java/im/vector/app/features/roomprofile/alias/RoomAliasViewModel.kt b/vector/src/main/java/im/vector/app/features/roomprofile/alias/RoomAliasViewModel.kt index adffbcbd06..550af98df2 100644 --- a/vector/src/main/java/im/vector/app/features/roomprofile/alias/RoomAliasViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/roomprofile/alias/RoomAliasViewModel.kt @@ -36,6 +36,7 @@ import org.matrix.android.sdk.api.query.QueryStringValue import org.matrix.android.sdk.api.session.Session 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.getRoom 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.flow.flow @@ -72,7 +73,7 @@ class RoomAliasViewModel @AssistedInject constructor(@Assisted initialState: Roo } viewModelScope.launch { runCatching { - session.getRoomDirectoryVisibility(room.roomId) + session.roomDirectoryService().getRoomDirectoryVisibility(room.roomId) }.fold( { setState { @@ -205,7 +206,7 @@ class RoomAliasViewModel @AssistedInject constructor(@Assisted initialState: Roo postLoading(true) viewModelScope.launch { runCatching { - session.setRoomDirectoryVisibility(room.roomId, action.roomDirectoryVisibility) + session.roomDirectoryService().setRoomDirectoryVisibility(room.roomId, action.roomDirectoryVisibility) }.fold( { setState { @@ -354,7 +355,7 @@ class RoomAliasViewModel @AssistedInject constructor(@Assisted initialState: Roo private fun handleRemoveLocalAlias(action: RoomAliasAction.RemoveLocalAlias) { postLoading(true) viewModelScope.launch { - runCatching { session.deleteRoomAlias(action.alias) } + runCatching { session.roomService().deleteRoomAlias(action.alias) } .onFailure { setState { copy(isLoading = false) diff --git a/vector/src/main/java/im/vector/app/features/roomprofile/banned/RoomBannedMemberListViewModel.kt b/vector/src/main/java/im/vector/app/features/roomprofile/banned/RoomBannedMemberListViewModel.kt index ec249c75ba..3262d61650 100644 --- a/vector/src/main/java/im/vector/app/features/roomprofile/banned/RoomBannedMemberListViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/roomprofile/banned/RoomBannedMemberListViewModel.kt @@ -32,6 +32,7 @@ import org.matrix.android.sdk.api.query.QueryStringValue import org.matrix.android.sdk.api.session.Session 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.getRoom import org.matrix.android.sdk.api.session.room.members.roomMemberQueryParams import org.matrix.android.sdk.api.session.room.model.Membership import org.matrix.android.sdk.api.session.room.model.RoomMemberContent diff --git a/vector/src/main/java/im/vector/app/features/roomprofile/members/RoomMemberListViewModel.kt b/vector/src/main/java/im/vector/app/features/roomprofile/members/RoomMemberListViewModel.kt index 7a9dcb7178..f7e06fe444 100644 --- a/vector/src/main/java/im/vector/app/features/roomprofile/members/RoomMemberListViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/roomprofile/members/RoomMemberListViewModel.kt @@ -39,6 +39,7 @@ import org.matrix.android.sdk.api.session.Session import org.matrix.android.sdk.api.session.crypto.model.RoomEncryptionTrustLevel 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.getRoom import org.matrix.android.sdk.api.session.room.members.roomMemberQueryParams import org.matrix.android.sdk.api.session.room.model.Membership import org.matrix.android.sdk.api.session.room.model.PowerLevelsContent diff --git a/vector/src/main/java/im/vector/app/features/roomprofile/notifications/RoomNotificationSettingsViewModel.kt b/vector/src/main/java/im/vector/app/features/roomprofile/notifications/RoomNotificationSettingsViewModel.kt index 4108167409..bef7a7872f 100644 --- a/vector/src/main/java/im/vector/app/features/roomprofile/notifications/RoomNotificationSettingsViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/roomprofile/notifications/RoomNotificationSettingsViewModel.kt @@ -26,6 +26,7 @@ import im.vector.app.core.di.hiltMavericksViewModelFactory import im.vector.app.core.platform.VectorViewModel import kotlinx.coroutines.launch import org.matrix.android.sdk.api.session.Session +import org.matrix.android.sdk.api.session.getRoom import org.matrix.android.sdk.flow.flow import org.matrix.android.sdk.flow.unwrap diff --git a/vector/src/main/java/im/vector/app/features/roomprofile/permissions/RoomPermissionsViewModel.kt b/vector/src/main/java/im/vector/app/features/roomprofile/permissions/RoomPermissionsViewModel.kt index eff4f811fc..e132e89d31 100644 --- a/vector/src/main/java/im/vector/app/features/roomprofile/permissions/RoomPermissionsViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/roomprofile/permissions/RoomPermissionsViewModel.kt @@ -31,6 +31,7 @@ import kotlinx.coroutines.launch import org.matrix.android.sdk.api.session.Session 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.getRoom 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.flow.flow diff --git a/vector/src/main/java/im/vector/app/features/roomprofile/settings/RoomSettingsViewModel.kt b/vector/src/main/java/im/vector/app/features/roomprofile/settings/RoomSettingsViewModel.kt index 8ad5bcdce6..1041354fd5 100644 --- a/vector/src/main/java/im/vector/app/features/roomprofile/settings/RoomSettingsViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/roomprofile/settings/RoomSettingsViewModel.kt @@ -35,6 +35,7 @@ import org.matrix.android.sdk.api.query.QueryStringValue import org.matrix.android.sdk.api.session.Session 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.getRoom import org.matrix.android.sdk.api.session.homeserver.HomeServerCapabilities import org.matrix.android.sdk.api.session.room.model.RoomAvatarContent import org.matrix.android.sdk.api.session.room.model.RoomGuestAccessContent @@ -67,7 +68,7 @@ class RoomSettingsViewModel @AssistedInject constructor(@Assisted initialState: observeRoomAvatar() observeState() - val homeServerCapabilities = session.getHomeServerCapabilities() + val homeServerCapabilities = session.homeServerCapabilitiesService().getHomeServerCapabilities() val canUseRestricted = homeServerCapabilities .isFeatureSupported(HomeServerCapabilities.ROOM_CAP_RESTRICTED, room.getRoomVersion()) diff --git a/vector/src/main/java/im/vector/app/features/roomprofile/settings/joinrule/advanced/RoomJoinRuleChooseRestrictedViewModel.kt b/vector/src/main/java/im/vector/app/features/roomprofile/settings/joinrule/advanced/RoomJoinRuleChooseRestrictedViewModel.kt index f1897761b2..1707439f01 100644 --- a/vector/src/main/java/im/vector/app/features/roomprofile/settings/joinrule/advanced/RoomJoinRuleChooseRestrictedViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/roomprofile/settings/joinrule/advanced/RoomJoinRuleChooseRestrictedViewModel.kt @@ -40,6 +40,8 @@ import org.matrix.android.sdk.api.query.QueryStringValue import org.matrix.android.sdk.api.session.Session 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.getRoom +import org.matrix.android.sdk.api.session.getRoomSummary import org.matrix.android.sdk.api.session.homeserver.HomeServerCapabilities import org.matrix.android.sdk.api.session.room.model.Membership import org.matrix.android.sdk.api.session.room.model.RoomJoinRules @@ -97,7 +99,7 @@ class RoomJoinRuleChooseRestrictedViewModel @AssistedInject constructor( } } - val homeServerCapabilities = session.getHomeServerCapabilities() + val homeServerCapabilities = session.homeServerCapabilitiesService().getHomeServerCapabilities() var safeRule: RoomJoinRules = joinRulesContent?.joinRules ?: RoomJoinRules.INVITE // server is not really checking that, just to be sure let's check val restrictedSupportedByThisVersion = homeServerCapabilities @@ -355,7 +357,7 @@ class RoomJoinRuleChooseRestrictedViewModel @AssistedInject constructor( viewModelScope.launch { if (vectorPreferences.developerMode()) { // in developer mode we let you choose any room or space to restrict to - val filteredCandidates = session.getRoomSummaries( + val filteredCandidates = session.roomService().getRoomSummaries( roomSummaryQueryParams { excludeType = null displayName = QueryStringValue.Contains(action.filter, QueryStringValue.Case.INSENSITIVE) diff --git a/vector/src/main/java/im/vector/app/features/roomprofile/uploads/RoomUploadsViewModel.kt b/vector/src/main/java/im/vector/app/features/roomprofile/uploads/RoomUploadsViewModel.kt index c9aaca4373..0fbcab9327 100644 --- a/vector/src/main/java/im/vector/app/features/roomprofile/uploads/RoomUploadsViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/roomprofile/uploads/RoomUploadsViewModel.kt @@ -28,6 +28,7 @@ import im.vector.app.core.di.hiltMavericksViewModelFactory import im.vector.app.core.platform.VectorViewModel import kotlinx.coroutines.launch import org.matrix.android.sdk.api.session.Session +import org.matrix.android.sdk.api.session.getRoom 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 diff --git a/vector/src/main/java/im/vector/app/features/settings/SecretsSynchronisationInfo.kt b/vector/src/main/java/im/vector/app/features/settings/SecretsSynchronisationInfo.kt index e21366db02..d667a4f589 100644 --- a/vector/src/main/java/im/vector/app/features/settings/SecretsSynchronisationInfo.kt +++ b/vector/src/main/java/im/vector/app/features/settings/SecretsSynchronisationInfo.kt @@ -45,7 +45,7 @@ fun Session.liveSecretSynchronisationInfo(): Flow { sessionFlow.liveCrossSigningPrivateKeys() ) { _, crossSigningInfo, pInfo -> // first check if 4S is already setup - val is4SSetup = sharedSecretStorageService.isRecoverySetup() + val is4SSetup = sharedSecretStorageService().isRecoverySetup() val isCrossSigningEnabled = crossSigningInfo.getOrNull() != null val isCrossSigningTrusted = crossSigningInfo.getOrNull()?.isTrusted() == true val allPrivateKeysKnown = pInfo.getOrNull()?.allKnown().orFalse() @@ -63,7 +63,7 @@ fun Session.liveSecretSynchronisationInfo(): Flow { allPrivateKeysKnown = allPrivateKeysKnown, megolmBackupAvailable = megolmBackupAvailable, megolmSecretKnown = megolmKeyKnown, - isMegolmKeyIn4S = sharedSecretStorageService.isMegolmKeyInBackup() + isMegolmKeyIn4S = sharedSecretStorageService().isMegolmKeyInBackup() ) } .distinctUntilChanged() diff --git a/vector/src/main/java/im/vector/app/features/settings/VectorSettingsGeneralFragment.kt b/vector/src/main/java/im/vector/app/features/settings/VectorSettingsGeneralFragment.kt index 7060bd67fd..678356b05b 100644 --- a/vector/src/main/java/im/vector/app/features/settings/VectorSettingsGeneralFragment.kt +++ b/vector/src/main/java/im/vector/app/features/settings/VectorSettingsGeneralFragment.kt @@ -64,6 +64,7 @@ import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.launch import kotlinx.coroutines.withContext import org.matrix.android.sdk.api.failure.isInvalidPassword +import org.matrix.android.sdk.api.session.getUser import org.matrix.android.sdk.api.session.integrationmanager.IntegrationManagerConfig import org.matrix.android.sdk.api.session.integrationmanager.IntegrationManagerService import org.matrix.android.sdk.flow.flow @@ -177,7 +178,7 @@ class VectorSettingsGeneralFragment @Inject constructor( // Password // Hide the preference if password can not be updated - if (session.getHomeServerCapabilities().canChangePassword) { + if (session.homeServerCapabilitiesService().getHomeServerCapabilities().canChangePassword) { mPasswordPreference.onPreferenceClickListener = Preference.OnPreferenceClickListener { onPasswordUpdateClick() false @@ -332,7 +333,7 @@ class VectorSettingsGeneralFragment @Inject constructor( lifecycleScope.launch { val result = runCatching { - session.updateAvatar(session.myUserId, uri, getFilenameFromUri(context, uri) ?: UUID.randomUUID().toString()) + session.profileService().updateAvatar(session.myUserId, uri, getFilenameFromUri(context, uri) ?: UUID.randomUUID().toString()) } if (!isAdded) return@launch @@ -444,7 +445,7 @@ class VectorSettingsGeneralFragment @Inject constructor( showPasswordLoadingView(true) lifecycleScope.launch { val result = runCatching { - session.changePassword(oldPwd, newPwd) + session.accountService().changePassword(oldPwd, newPwd) } if (!isAdded) { return@launch @@ -476,7 +477,7 @@ class VectorSettingsGeneralFragment @Inject constructor( displayLoadingView() lifecycleScope.launch { - val result = runCatching { session.setDisplayName(session.myUserId, value) } + val result = runCatching { session.profileService().setDisplayName(session.myUserId, value) } if (!isAdded) return@launch result.fold( onSuccess = { diff --git a/vector/src/main/java/im/vector/app/features/settings/VectorSettingsLabsFragment.kt b/vector/src/main/java/im/vector/app/features/settings/VectorSettingsLabsFragment.kt index c46a64ad31..e1e155865a 100644 --- a/vector/src/main/java/im/vector/app/features/settings/VectorSettingsLabsFragment.kt +++ b/vector/src/main/java/im/vector/app/features/settings/VectorSettingsLabsFragment.kt @@ -64,7 +64,7 @@ class VectorSettingsLabsFragment @Inject constructor( */ private fun onThreadsPreferenceClickedInterceptor(vectorSwitchPreference: VectorSwitchPreference) { val userEnabledThreads = vectorPreferences.areThreadMessagesEnabled() - if (!session.getHomeServerCapabilities().canUseThreading && userEnabledThreads) { + if (!session.homeServerCapabilitiesService().getHomeServerCapabilities().canUseThreading && userEnabledThreads) { activity?.let { MaterialAlertDialogBuilder(it) .setTitle(R.string.threads_labs_enable_notice_title) diff --git a/vector/src/main/java/im/vector/app/features/settings/VectorSettingsPreferencesFragment.kt b/vector/src/main/java/im/vector/app/features/settings/VectorSettingsPreferencesFragment.kt index 155234a172..af9ac52d1e 100644 --- a/vector/src/main/java/im/vector/app/features/settings/VectorSettingsPreferencesFragment.kt +++ b/vector/src/main/java/im/vector/app/features/settings/VectorSettingsPreferencesFragment.kt @@ -86,7 +86,7 @@ class VectorSettingsPreferencesFragment @Inject constructor( pref.setOnPreferenceChangeListener { _, newValue -> val presenceOfflineModeEnabled = newValue as? Boolean ?: false lifecycleScope.launch { - session.setMyPresence(if (presenceOfflineModeEnabled) PresenceEnum.OFFLINE else PresenceEnum.ONLINE) + session.presenceService().setMyPresence(if (presenceOfflineModeEnabled) PresenceEnum.OFFLINE else PresenceEnum.ONLINE) } true } diff --git a/vector/src/main/java/im/vector/app/features/settings/account/deactivation/DeactivateAccountViewModel.kt b/vector/src/main/java/im/vector/app/features/settings/account/deactivation/DeactivateAccountViewModel.kt index 7057f4dce4..ec52fd58b9 100644 --- a/vector/src/main/java/im/vector/app/features/settings/account/deactivation/DeactivateAccountViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/settings/account/deactivation/DeactivateAccountViewModel.kt @@ -66,7 +66,8 @@ class DeactivateAccountViewModel @AssistedInject constructor(@Assisted private v } } is DeactivateAccountAction.PasswordAuthDone -> { - val decryptedPass = session.loadSecureSecret(action.password.fromBase64().inputStream(), ReAuthActivity.DEFAULT_RESULT_KEYSTORE_ALIAS) + val decryptedPass = session.secureStorageService() + .loadSecureSecret(action.password.fromBase64().inputStream(), ReAuthActivity.DEFAULT_RESULT_KEYSTORE_ALIAS) uiaContinuation?.resume( UserPasswordAuth( session = pendingAuth?.session, @@ -89,7 +90,7 @@ class DeactivateAccountViewModel @AssistedInject constructor(@Assisted private v viewModelScope.launch { val event = try { - session.deactivateAccount( + session.accountService().deactivateAccount( action.eraseAllData, object : UserInteractiveAuthInterceptor { override fun performStage(flowResponse: RegistrationFlowResponse, errCode: String?, promise: Continuation) { diff --git a/vector/src/main/java/im/vector/app/features/settings/crosssigning/CrossSigningSettingsViewModel.kt b/vector/src/main/java/im/vector/app/features/settings/crosssigning/CrossSigningSettingsViewModel.kt index 0d4c39a230..94d6b8ff93 100644 --- a/vector/src/main/java/im/vector/app/features/settings/crosssigning/CrossSigningSettingsViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/settings/crosssigning/CrossSigningSettingsViewModel.kt @@ -129,7 +129,8 @@ class CrossSigningSettingsViewModel @AssistedInject constructor( } } is CrossSigningSettingsAction.PasswordAuthDone -> { - val decryptedPass = session.loadSecureSecret(action.password.fromBase64().inputStream(), ReAuthActivity.DEFAULT_RESULT_KEYSTORE_ALIAS) + val decryptedPass = session.secureStorageService() + .loadSecureSecret(action.password.fromBase64().inputStream(), ReAuthActivity.DEFAULT_RESULT_KEYSTORE_ALIAS) uiaContinuation?.resume( UserPasswordAuth( session = pendingAuth?.session, diff --git a/vector/src/main/java/im/vector/app/features/settings/devices/DeviceVerificationInfoBottomSheetViewModel.kt b/vector/src/main/java/im/vector/app/features/settings/devices/DeviceVerificationInfoBottomSheetViewModel.kt index 2573a2f395..b24b8475a5 100644 --- a/vector/src/main/java/im/vector/app/features/settings/devices/DeviceVerificationInfoBottomSheetViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/settings/devices/DeviceVerificationInfoBottomSheetViewModel.kt @@ -48,7 +48,7 @@ class DeviceVerificationInfoBottomSheetViewModel @AssistedInject constructor(@As copy( hasAccountCrossSigning = session.cryptoService().crossSigningService().isCrossSigningInitialized(), accountCrossSigningIsTrusted = session.cryptoService().crossSigningService().isCrossSigningVerified(), - isRecoverySetup = session.sharedSecretStorageService.isRecoverySetup() + isRecoverySetup = session.sharedSecretStorageService().isRecoverySetup() ) } session.flow().liveCrossSigningInfo(session.myUserId) diff --git a/vector/src/main/java/im/vector/app/features/settings/devices/DevicesViewModel.kt b/vector/src/main/java/im/vector/app/features/settings/devices/DevicesViewModel.kt index 46a2ba03b1..4558c4bfb4 100644 --- a/vector/src/main/java/im/vector/app/features/settings/devices/DevicesViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/settings/devices/DevicesViewModel.kt @@ -219,7 +219,8 @@ class DevicesViewModel @AssistedInject constructor( Unit } is DevicesAction.PasswordAuthDone -> { - val decryptedPass = session.loadSecureSecret(action.password.fromBase64().inputStream(), ReAuthActivity.DEFAULT_RESULT_KEYSTORE_ALIAS) + val decryptedPass = session.secureStorageService() + .loadSecureSecret(action.password.fromBase64().inputStream(), ReAuthActivity.DEFAULT_RESULT_KEYSTORE_ALIAS) uiaContinuation?.resume( UserPasswordAuth( session = pendingAuth?.session, diff --git a/vector/src/main/java/im/vector/app/features/settings/homeserver/HomeserverSettingsViewModel.kt b/vector/src/main/java/im/vector/app/features/settings/homeserver/HomeserverSettingsViewModel.kt index fab563b49e..9e237f818b 100644 --- a/vector/src/main/java/im/vector/app/features/settings/homeserver/HomeserverSettingsViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/settings/homeserver/HomeserverSettingsViewModel.kt @@ -47,7 +47,7 @@ class HomeserverSettingsViewModel @AssistedInject constructor( copy( homeserverUrl = session.sessionParams.homeServerUrl, homeserverClientServerApiUrl = session.sessionParams.homeServerUrlBase, - homeServerCapabilities = session.getHomeServerCapabilities() + homeServerCapabilities = session.homeServerCapabilitiesService().getHomeServerCapabilities() ) } fetchHomeserverVersion() @@ -57,12 +57,12 @@ class HomeserverSettingsViewModel @AssistedInject constructor( private fun refreshHomeServerCapabilities() { viewModelScope.launch { runCatching { - session.refreshHomeServerCapabilities() + session.homeServerCapabilitiesService().refreshHomeServerCapabilities() } setState { copy( - homeServerCapabilities = session.getHomeServerCapabilities() + homeServerCapabilities = session.homeServerCapabilitiesService().getHomeServerCapabilities() ) } } diff --git a/vector/src/main/java/im/vector/app/features/settings/ignored/IgnoredUsersViewModel.kt b/vector/src/main/java/im/vector/app/features/settings/ignored/IgnoredUsersViewModel.kt index 14f7cd9230..df76d68c17 100644 --- a/vector/src/main/java/im/vector/app/features/settings/ignored/IgnoredUsersViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/settings/ignored/IgnoredUsersViewModel.kt @@ -63,7 +63,7 @@ class IgnoredUsersViewModel @AssistedInject constructor( setState { copy(isLoading = true) } viewModelScope.launch { val viewEvent = try { - session.unIgnoreUserIds(listOf(action.userId)) + session.userService().unIgnoreUserIds(listOf(action.userId)) IgnoredUsersViewEvents.Success } catch (throwable: Throwable) { IgnoredUsersViewEvents.Failure(throwable) diff --git a/vector/src/main/java/im/vector/app/features/settings/notifications/VectorSettingsAdvancedNotificationPreferenceFragment.kt b/vector/src/main/java/im/vector/app/features/settings/notifications/VectorSettingsAdvancedNotificationPreferenceFragment.kt index bbc92fbe77..a11bc9b0cf 100644 --- a/vector/src/main/java/im/vector/app/features/settings/notifications/VectorSettingsAdvancedNotificationPreferenceFragment.kt +++ b/vector/src/main/java/im/vector/app/features/settings/notifications/VectorSettingsAdvancedNotificationPreferenceFragment.kt @@ -38,7 +38,7 @@ class VectorSettingsAdvancedNotificationPreferenceFragment @Inject constructor() for (preferenceKey in prefKeyToPushRuleId.keys) { val preference = findPreference(preferenceKey) if (preference is PushRulePreference) { - val ruleAndKind: PushRuleAndKind? = session.getPushRules().findDefaultRule(prefKeyToPushRuleId[preferenceKey]) + val ruleAndKind: PushRuleAndKind? = session.pushRuleService().getPushRules().findDefaultRule(prefKeyToPushRuleId[preferenceKey]) if (ruleAndKind == null) { // The rule is not defined, hide the preference @@ -57,7 +57,7 @@ class VectorSettingsAdvancedNotificationPreferenceFragment @Inject constructor() lifecycleScope.launch { val result = runCatching { - session.updatePushRuleActions(ruleAndKind.kind, + session.pushRuleService().updatePushRuleActions(ruleAndKind.kind, ruleAndKind.pushRule.ruleId, enabled, newActions) diff --git a/vector/src/main/java/im/vector/app/features/settings/notifications/VectorSettingsKeywordAndMentionsNotificationPreferenceFragment.kt b/vector/src/main/java/im/vector/app/features/settings/notifications/VectorSettingsKeywordAndMentionsNotificationPreferenceFragment.kt index 3117fd4b55..fcad0820cc 100644 --- a/vector/src/main/java/im/vector/app/features/settings/notifications/VectorSettingsKeywordAndMentionsNotificationPreferenceFragment.kt +++ b/vector/src/main/java/im/vector/app/features/settings/notifications/VectorSettingsKeywordAndMentionsNotificationPreferenceFragment.kt @@ -50,7 +50,7 @@ class VectorSettingsKeywordAndMentionsNotificationPreferenceFragment : override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - session.getKeywords().observe(viewLifecycleOwner, this::updateWithKeywords) + session.pushRuleService().getKeywords().observe(viewLifecycleOwner, this::updateWithKeywords) } override fun bindPref() { @@ -61,7 +61,7 @@ class VectorSettingsKeywordAndMentionsNotificationPreferenceFragment : val yourKeywordsCategory = findPreference("SETTINGS_YOUR_KEYWORDS")!! yourKeywordsCategory.isIconSpaceReserved = false - val keywordRules = session.getPushRules().content?.filter { !it.ruleId.startsWith(".") }.orEmpty() + val keywordRules = session.pushRuleService().getPushRules().content?.filter { !it.ruleId.startsWith(".") }.orEmpty() val enableKeywords = keywordRules.isEmpty() || keywordRules.any(PushRule::enabled) val editKeywordPreference = findPreference("SETTINGS_KEYWORD_EDIT")!! @@ -119,7 +119,7 @@ class VectorSettingsKeywordAndMentionsNotificationPreferenceFragment : val results = keywords.map { runCatching { withContext(Dispatchers.Default) { - session.updatePushRuleActions(RuleKind.CONTENT, + session.pushRuleService().updatePushRuleActions(RuleKind.CONTENT, it, enabled, newActions) @@ -151,7 +151,7 @@ class VectorSettingsKeywordAndMentionsNotificationPreferenceFragment : displayLoadingView() lifecycleScope.launch { val result = runCatching { - session.addPushRule(RuleKind.CONTENT, newRule) + session.pushRuleService().addPushRule(RuleKind.CONTENT, newRule) } hideLoadingView() if (!isAdded) { @@ -167,7 +167,7 @@ class VectorSettingsKeywordAndMentionsNotificationPreferenceFragment : displayLoadingView() lifecycleScope.launch { val result = runCatching { - session.removePushRule(RuleKind.CONTENT, keyword) + session.pushRuleService().removePushRule(RuleKind.CONTENT, keyword) } hideLoadingView() if (!isAdded) { diff --git a/vector/src/main/java/im/vector/app/features/settings/notifications/VectorSettingsNotificationPreferenceFragment.kt b/vector/src/main/java/im/vector/app/features/settings/notifications/VectorSettingsNotificationPreferenceFragment.kt index 05a7cfecd8..d9cd5b3461 100644 --- a/vector/src/main/java/im/vector/app/features/settings/notifications/VectorSettingsNotificationPreferenceFragment.kt +++ b/vector/src/main/java/im/vector/app/features/settings/notifications/VectorSettingsNotificationPreferenceFragment.kt @@ -81,7 +81,7 @@ class VectorSettingsNotificationPreferenceFragment @Inject constructor( override fun bindPref() { findPreference(VectorPreferences.SETTINGS_ENABLE_ALL_NOTIF_PREFERENCE_KEY)!!.let { pref -> - val pushRuleService = session + val pushRuleService = session.pushRuleService() val mRuleMaster = pushRuleService.getPushRules().getAllRules() .find { it.ruleId == RuleIds.RULE_ID_DISABLE_ALL } @@ -104,7 +104,7 @@ class VectorSettingsNotificationPreferenceFragment @Inject constructor( } else { FcmHelper.getFcmToken(requireContext())?.let { pushManager.unregisterPusher(it) - session.refreshPushers() + session.pushersService().refreshPushers() } } } @@ -318,7 +318,7 @@ class VectorSettingsNotificationPreferenceFragment @Inject constructor( override fun onResume() { super.onResume() - activeSessionHolder.getSafeActiveSession()?.refreshPushers() + activeSessionHolder.getSafeActiveSession()?.pushersService()?.refreshPushers() interactionListener?.requestedKeyToHighlight()?.let { key -> interactionListener?.requestHighlightPreferenceKeyOnResume(null) @@ -365,7 +365,7 @@ class VectorSettingsNotificationPreferenceFragment @Inject constructor( } private fun updateEnabledForAccount(preference: Preference?) { - val pushRuleService = session + val pushRuleService = session.pushRuleService() val switchPref = preference as SwitchPreference pushRuleService.getPushRules().getAllRules() .find { it.ruleId == RuleIds.RULE_ID_DISABLE_ALL } @@ -414,15 +414,15 @@ private fun SwitchPreference.setTransactionalSwitchChangeListener(scope: Corouti * @see ThreePid.Email */ private fun Session.getEmailsWithPushInformation(): List> { - val emailPushers = getPushers().filter { it.kind == Pusher.KIND_EMAIL } - return getThreePids() + val emailPushers = pushersService().getPushers().filter { it.kind == Pusher.KIND_EMAIL } + return profileService().getThreePids() .filterIsInstance() .map { it to emailPushers.any { pusher -> pusher.pushKey == it.email } } } private fun Session.getEmailsWithPushInformationLive(): LiveData>> { - val emailThreePids = getThreePidsLive(refreshData = true).map { it.filterIsInstance() } - val emailPushers = getPushersLive().map { it.filter { pusher -> pusher.kind == Pusher.KIND_EMAIL } } + val emailThreePids = profileService().getThreePidsLive(refreshData = true).map { it.filterIsInstance() } + val emailPushers = pushersService().getPushersLive().map { it.filter { pusher -> pusher.kind == Pusher.KIND_EMAIL } } return combineLatest(emailThreePids, emailPushers) { emailThreePidsResult, emailPushersResult -> emailThreePidsResult.map { it to emailPushersResult.any { pusher -> pusher.pushKey == it.email } } }.distinctUntilChanged() diff --git a/vector/src/main/java/im/vector/app/features/settings/notifications/VectorSettingsPushRuleNotificationPreferenceFragment.kt b/vector/src/main/java/im/vector/app/features/settings/notifications/VectorSettingsPushRuleNotificationPreferenceFragment.kt index 5b78387013..1381dd79ae 100644 --- a/vector/src/main/java/im/vector/app/features/settings/notifications/VectorSettingsPushRuleNotificationPreferenceFragment.kt +++ b/vector/src/main/java/im/vector/app/features/settings/notifications/VectorSettingsPushRuleNotificationPreferenceFragment.kt @@ -33,7 +33,7 @@ abstract class VectorSettingsPushRuleNotificationPreferenceFragment : for (preferenceKey in prefKeyToPushRuleId.keys) { val preference = findPreference(preferenceKey)!! preference.isIconSpaceReserved = false - val ruleAndKind: PushRuleAndKind? = session.getPushRules().findDefaultRule(prefKeyToPushRuleId[preferenceKey]) + val ruleAndKind: PushRuleAndKind? = session.pushRuleService().getPushRules().findDefaultRule(prefKeyToPushRuleId[preferenceKey]) if (ruleAndKind == null) { // The rule is not defined, hide the preference preference.isVisible = false @@ -58,7 +58,7 @@ abstract class VectorSettingsPushRuleNotificationPreferenceFragment : lifecycleScope.launch { val result = runCatching { - session.updatePushRuleActions(kind, + session.pushRuleService().updatePushRuleActions(kind, ruleId, enabled, newActions) diff --git a/vector/src/main/java/im/vector/app/features/settings/push/PushGatewaysViewModel.kt b/vector/src/main/java/im/vector/app/features/settings/push/PushGatewaysViewModel.kt index 4d95447f2d..14b7a53b65 100644 --- a/vector/src/main/java/im/vector/app/features/settings/push/PushGatewaysViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/settings/push/PushGatewaysViewModel.kt @@ -49,7 +49,7 @@ class PushGatewaysViewModel @AssistedInject constructor(@Assisted initialState: init { observePushers() // Force a refresh - session.refreshPushers() + session.pushersService().refreshPushers() } private fun observePushers() { @@ -70,7 +70,7 @@ class PushGatewaysViewModel @AssistedInject constructor(@Assisted initialState: private fun removePusher(pusher: Pusher) { viewModelScope.launch { kotlin.runCatching { - session.removePusher(pusher) + session.pushersService().removePusher(pusher) }.onFailure { _viewEvents.post(PushGatewayViewEvents.RemovePusherFailed(it)) } @@ -78,6 +78,6 @@ class PushGatewaysViewModel @AssistedInject constructor(@Assisted initialState: } private fun handleRefresh() { - session.refreshPushers() + session.pushersService().refreshPushers() } } diff --git a/vector/src/main/java/im/vector/app/features/settings/push/PushRulesViewModel.kt b/vector/src/main/java/im/vector/app/features/settings/push/PushRulesViewModel.kt index 549085ee32..deda34115e 100644 --- a/vector/src/main/java/im/vector/app/features/settings/push/PushRulesViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/settings/push/PushRulesViewModel.kt @@ -36,7 +36,7 @@ class PushRulesViewModel(initialState: PushRulesViewState) : override fun initialState(viewModelContext: ViewModelContext): PushRulesViewState? { val session = EntryPoints.get(viewModelContext.app(), SingletonEntryPoint::class.java).activeSessionHolder().getActiveSession() - val rules = session.getPushRules().getAllRules() + val rules = session.pushRuleService().getPushRules().getAllRules() return PushRulesViewState(rules) } } diff --git a/vector/src/main/java/im/vector/app/features/settings/threepids/ThreePidsSettingsViewModel.kt b/vector/src/main/java/im/vector/app/features/settings/threepids/ThreePidsSettingsViewModel.kt index 0af0a8baa5..587337d210 100644 --- a/vector/src/main/java/im/vector/app/features/settings/threepids/ThreePidsSettingsViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/settings/threepids/ThreePidsSettingsViewModel.kt @@ -133,7 +133,8 @@ class ThreePidsSettingsViewModel @AssistedInject constructor( } } is ThreePidsSettingsAction.PasswordAuthDone -> { - val decryptedPass = session.loadSecureSecret(action.password.fromBase64().inputStream(), ReAuthActivity.DEFAULT_RESULT_KEYSTORE_ALIAS) + val decryptedPass = session.secureStorageService() + .loadSecureSecret(action.password.fromBase64().inputStream(), ReAuthActivity.DEFAULT_RESULT_KEYSTORE_ALIAS) uiaContinuation?.resume( UserPasswordAuth( session = pendingAuth?.session, @@ -175,7 +176,7 @@ class ThreePidsSettingsViewModel @AssistedInject constructor( viewModelScope.launch { // First submit the code try { - session.submitSmsCode(action.threePid, action.code) + session.profileService().submitSmsCode(action.threePid, action.code) } catch (failure: Throwable) { isLoading(false) setState { @@ -190,7 +191,7 @@ class ThreePidsSettingsViewModel @AssistedInject constructor( // then finalize pendingThreePid = action.threePid - loadingSuspendable { session.finalizeAddingThreePid(action.threePid, uiaInterceptor) } + loadingSuspendable { session.profileService().finalizeAddingThreePid(action.threePid, uiaInterceptor) } } } @@ -218,7 +219,7 @@ class ThreePidsSettingsViewModel @AssistedInject constructor( } else { viewModelScope.launch { loadingSuspendable { - session.addThreePid(action.threePid) + session.profileService().addThreePid(action.threePid) // Also reset the state setState { copy( @@ -235,14 +236,14 @@ class ThreePidsSettingsViewModel @AssistedInject constructor( isLoading(true) pendingThreePid = action.threePid viewModelScope.launch { - loadingSuspendable { session.finalizeAddingThreePid(action.threePid, uiaInterceptor) } + loadingSuspendable { session.profileService().finalizeAddingThreePid(action.threePid, uiaInterceptor) } } } private fun handleCancelThreePid(action: ThreePidsSettingsAction.CancelThreePid) { isLoading(true) viewModelScope.launch { - loadingSuspendable { session.cancelAddingThreePid(action.threePid) } + loadingSuspendable { session.profileService().cancelAddingThreePid(action.threePid) } } } @@ -258,7 +259,7 @@ class ThreePidsSettingsViewModel @AssistedInject constructor( private fun handleDeleteThreePid(action: ThreePidsSettingsAction.DeleteThreePid) { isLoading(true) viewModelScope.launch { - loadingSuspendable { session.deleteThreePid(action.threePid) } + loadingSuspendable { session.profileService().deleteThreePid(action.threePid) } } } } diff --git a/vector/src/main/java/im/vector/app/features/settings/troubleshoot/TestAccountSettings.kt b/vector/src/main/java/im/vector/app/features/settings/troubleshoot/TestAccountSettings.kt index 99a02cd5be..b6e78fa580 100644 --- a/vector/src/main/java/im/vector/app/features/settings/troubleshoot/TestAccountSettings.kt +++ b/vector/src/main/java/im/vector/app/features/settings/troubleshoot/TestAccountSettings.kt @@ -38,7 +38,7 @@ class TestAccountSettings @Inject constructor(private val stringProvider: String override fun perform(activityResultLauncher: ActivityResultLauncher) { val session = activeSessionHolder.getSafeActiveSession() ?: return - val defaultRule = session.getPushRules().getAllRules() + val defaultRule = session.pushRuleService().getPushRules().getAllRules() .find { it.ruleId == RuleIds.RULE_ID_DISABLE_ALL } if (defaultRule != null) { @@ -54,7 +54,7 @@ class TestAccountSettings @Inject constructor(private val stringProvider: String session.coroutineScope.launch { tryOrNull { - session.updatePushRuleEnableStatus(RuleKind.OVERRIDE, defaultRule, !defaultRule.enabled) + session.pushRuleService().updatePushRuleEnableStatus(RuleKind.OVERRIDE, defaultRule, !defaultRule.enabled) } withContext(Dispatchers.Main) { manager?.retry(activityResultLauncher) diff --git a/vector/src/main/java/im/vector/app/features/settings/troubleshoot/TestPushRulesSettings.kt b/vector/src/main/java/im/vector/app/features/settings/troubleshoot/TestPushRulesSettings.kt index 54e63916c6..69e3021738 100644 --- a/vector/src/main/java/im/vector/app/features/settings/troubleshoot/TestPushRulesSettings.kt +++ b/vector/src/main/java/im/vector/app/features/settings/troubleshoot/TestPushRulesSettings.kt @@ -37,7 +37,7 @@ class TestPushRulesSettings @Inject constructor(private val activeSessionHolder: override fun perform(activityResultLauncher: ActivityResultLauncher) { val session = activeSessionHolder.getSafeActiveSession() ?: return - val pushRules = session.getPushRules().getAllRules() + val pushRules = session.pushRuleService().getPushRules().getAllRules() var oneOrMoreRuleIsOff = false var oneOrMoreRuleAreSilent = false testedRules.forEach { ruleId -> diff --git a/vector/src/main/java/im/vector/app/features/share/IncomingShareFragment.kt b/vector/src/main/java/im/vector/app/features/share/IncomingShareFragment.kt index 9dc433e96f..199536b62b 100644 --- a/vector/src/main/java/im/vector/app/features/share/IncomingShareFragment.kt +++ b/vector/src/main/java/im/vector/app/features/share/IncomingShareFragment.kt @@ -41,6 +41,7 @@ import im.vector.app.features.attachments.AttachmentsHelper import im.vector.app.features.attachments.preview.AttachmentsPreviewActivity import im.vector.app.features.attachments.preview.AttachmentsPreviewArgs import org.matrix.android.sdk.api.session.content.ContentAttachmentData +import org.matrix.android.sdk.api.session.getRoomSummary import org.matrix.android.sdk.api.session.room.model.RoomSummary import javax.inject.Inject diff --git a/vector/src/main/java/im/vector/app/features/share/IncomingShareViewModel.kt b/vector/src/main/java/im/vector/app/features/share/IncomingShareViewModel.kt index 1d72f224c4..2be4c99fba 100644 --- a/vector/src/main/java/im/vector/app/features/share/IncomingShareViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/share/IncomingShareViewModel.kt @@ -34,6 +34,7 @@ import kotlinx.coroutines.flow.sample import org.matrix.android.sdk.api.query.QueryStringValue import org.matrix.android.sdk.api.session.Session import org.matrix.android.sdk.api.session.content.ContentAttachmentData +import org.matrix.android.sdk.api.session.getRoom import org.matrix.android.sdk.api.session.room.model.Membership import org.matrix.android.sdk.api.session.room.roomSummaryQueryParams import org.matrix.android.sdk.flow.flow diff --git a/vector/src/main/java/im/vector/app/features/signout/soft/SoftLogoutViewModel.kt b/vector/src/main/java/im/vector/app/features/signout/soft/SoftLogoutViewModel.kt index 00422d8872..5f31e6b508 100644 --- a/vector/src/main/java/im/vector/app/features/signout/soft/SoftLogoutViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/signout/soft/SoftLogoutViewModel.kt @@ -37,6 +37,7 @@ import kotlinx.coroutines.launch import org.matrix.android.sdk.api.auth.AuthenticationService import org.matrix.android.sdk.api.auth.data.LoginFlowTypes import org.matrix.android.sdk.api.session.Session +import org.matrix.android.sdk.api.session.getUser import timber.log.Timber /** @@ -169,7 +170,7 @@ class SoftLogoutViewModel @AssistedInject constructor( } viewModelScope.launch { try { - session.updateCredentials(action.credentials) + session.signOutService().updateCredentials(action.credentials) onSessionRestored() } catch (failure: Throwable) { _viewEvents.post(SoftLogoutViewEvents.Failure(failure)) @@ -192,7 +193,7 @@ class SoftLogoutViewModel @AssistedInject constructor( } viewModelScope.launch { try { - session.signInAgain(action.password) + session.signOutService().signInAgain(action.password) onSessionRestored() } catch (failure: Throwable) { setState { diff --git a/vector/src/main/java/im/vector/app/features/spaces/SpaceListViewModel.kt b/vector/src/main/java/im/vector/app/features/spaces/SpaceListViewModel.kt index a239e939ea..73e8e5e6a6 100644 --- a/vector/src/main/java/im/vector/app/features/spaces/SpaceListViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/spaces/SpaceListViewModel.kt @@ -50,6 +50,7 @@ import org.matrix.android.sdk.api.query.QueryStringValue import org.matrix.android.sdk.api.session.Session import org.matrix.android.sdk.api.session.events.model.toContent import org.matrix.android.sdk.api.session.events.model.toModel +import org.matrix.android.sdk.api.session.getRoom import org.matrix.android.sdk.api.session.group.groupSummaryQueryParams import org.matrix.android.sdk.api.session.room.RoomSortOrder import org.matrix.android.sdk.api.session.room.accountdata.RoomAccountDataTypes @@ -82,7 +83,7 @@ class SpaceListViewModel @AssistedInject constructor(@Assisted initialState: Spa init { - session.getUserLive(session.myUserId) + session.userService().getUserLive(session.myUserId) .asFlow() .setOnEach { copy( @@ -100,14 +101,14 @@ class SpaceListViewModel @AssistedInject constructor(@Assisted initialState: Spa ) } - session.getGroupSummariesLive(groupSummaryQueryParams {}) + session.groupService().getGroupSummariesLive(groupSummaryQueryParams {}) .asFlow() .setOnEach { copy(legacyGroups = it) } // XXX there should be a way to refactor this and share it - session.getPagedRoomSummariesLive( + session.roomService().getPagedRoomSummariesLive( roomSummaryQueryParams { this.memberships = listOf(Membership.JOIN) this.activeSpaceFilter = ActiveSpaceFilter.ActiveSpace(null).takeIf { @@ -120,11 +121,11 @@ class SpaceListViewModel @AssistedInject constructor(@Assisted initialState: Spa val inviteCount = if (autoAcceptInvites.hideInvites) { 0 } else { - session.getRoomSummaries( + session.roomService().getRoomSummaries( roomSummaryQueryParams { this.memberships = listOf(Membership.INVITE) } ).size } - val totalCount = session.getNotificationCountForRooms( + val totalCount = session.roomService().getNotificationCountForRooms( roomSummaryQueryParams { this.memberships = listOf(Membership.JOIN) this.activeSpaceFilter = ActiveSpaceFilter.ActiveSpace(null).takeIf { diff --git a/vector/src/main/java/im/vector/app/features/spaces/SpaceMenuViewModel.kt b/vector/src/main/java/im/vector/app/features/spaces/SpaceMenuViewModel.kt index cf3d01681b..4e1489ef9b 100644 --- a/vector/src/main/java/im/vector/app/features/spaces/SpaceMenuViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/spaces/SpaceMenuViewModel.kt @@ -38,6 +38,8 @@ import org.matrix.android.sdk.api.query.ActiveSpaceFilter import org.matrix.android.sdk.api.query.RoomCategoryFilter import org.matrix.android.sdk.api.session.Session import org.matrix.android.sdk.api.session.events.model.EventType +import org.matrix.android.sdk.api.session.getRoom +import org.matrix.android.sdk.api.session.getRoomSummary 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.Role @@ -136,7 +138,7 @@ class SpaceMenuViewModel @AssistedInject constructor( } else if (state.leaveMode == SpaceMenuState.LeaveMode.LEAVE_ALL) { // need to find all child rooms that i have joined - session.getRoomSummaries( + session.roomService().getRoomSummaries( roomSummaryQueryParams { excludeType = null activeSpaceFilter = ActiveSpaceFilter.ActiveSpace(initialState.spaceId) diff --git a/vector/src/main/java/im/vector/app/features/spaces/create/CreateSpaceViewModel.kt b/vector/src/main/java/im/vector/app/features/spaces/create/CreateSpaceViewModel.kt index 330467d161..46da2f5826 100644 --- a/vector/src/main/java/im/vector/app/features/spaces/create/CreateSpaceViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/spaces/create/CreateSpaceViewModel.kt @@ -315,7 +315,7 @@ class CreateSpaceViewModel @AssistedInject constructor( } viewModelScope.launch { try { - when (val result = session.checkAliasAvailability(aliasLocalPart)) { + when (val result = session.roomDirectoryService().checkAliasAvailability(aliasLocalPart)) { AliasAvailabilityResult.Available -> { setState { copy( diff --git a/vector/src/main/java/im/vector/app/features/spaces/create/CreateSpaceViewModelTask.kt b/vector/src/main/java/im/vector/app/features/spaces/create/CreateSpaceViewModelTask.kt index d9c18db01d..c7777649bd 100644 --- a/vector/src/main/java/im/vector/app/features/spaces/create/CreateSpaceViewModelTask.kt +++ b/vector/src/main/java/im/vector/app/features/spaces/create/CreateSpaceViewModelTask.kt @@ -113,7 +113,7 @@ class CreateSpaceViewModelTask @Inject constructor( try { val roomId = try { if (params.isPublic) { - session.createRoom( + session.roomService().createRoom( CreateRoomParams().apply { this.name = roomName this.preset = CreateRoomPreset.PRESET_PUBLIC_CHAT @@ -121,13 +121,14 @@ class CreateSpaceViewModelTask @Inject constructor( ) } else { val homeServerCapabilities = session + .homeServerCapabilitiesService() .getHomeServerCapabilities() val restrictedSupport = homeServerCapabilities .isFeatureSupported(HomeServerCapabilities.ROOM_CAP_RESTRICTED) val createRestricted = restrictedSupport == HomeServerCapabilities.RoomCapabilitySupport.SUPPORTED if (createRestricted) { - session.createRoom(CreateRoomParams().apply { + session.roomService().createRoom(CreateRoomParams().apply { this.name = roomName this.featurePreset = RestrictedRoomPreset( homeServerCapabilities, @@ -140,7 +141,7 @@ class CreateSpaceViewModelTask @Inject constructor( } }) } else { - session.createRoom(CreateRoomParams().apply { + session.roomService().createRoom(CreateRoomParams().apply { this.name = roomName visibility = RoomDirectoryVisibility.PRIVATE this.preset = CreateRoomPreset.PRESET_PRIVATE_CHAT diff --git a/vector/src/main/java/im/vector/app/features/spaces/explore/SpaceDirectoryViewModel.kt b/vector/src/main/java/im/vector/app/features/spaces/explore/SpaceDirectoryViewModel.kt index b980b7a457..fe43ad7997 100644 --- a/vector/src/main/java/im/vector/app/features/spaces/explore/SpaceDirectoryViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/spaces/explore/SpaceDirectoryViewModel.kt @@ -35,6 +35,8 @@ import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.launch import org.matrix.android.sdk.api.session.Session import org.matrix.android.sdk.api.session.events.model.EventType +import org.matrix.android.sdk.api.session.getRoom +import org.matrix.android.sdk.api.session.getRoomSummary import org.matrix.android.sdk.api.session.room.model.Membership import org.matrix.android.sdk.api.session.room.model.RoomJoinRules import org.matrix.android.sdk.api.session.room.model.RoomSummary @@ -409,7 +411,7 @@ class SpaceDirectoryViewModel @AssistedInject constructor( if (isSpace) { session.spaceService().joinSpace(childId, null, spaceChildInfo.viaServers) } else { - session.joinRoom(childId, null, spaceChildInfo.viaServers) + session.roomService().joinRoom(childId, null, spaceChildInfo.viaServers) } } catch (failure: Throwable) { Timber.e(failure, "## Space: Failed to join room or subspace") diff --git a/vector/src/main/java/im/vector/app/features/spaces/invite/SpaceInviteBottomSheetViewModel.kt b/vector/src/main/java/im/vector/app/features/spaces/invite/SpaceInviteBottomSheetViewModel.kt index b03d21e6bd..93bf51368b 100644 --- a/vector/src/main/java/im/vector/app/features/spaces/invite/SpaceInviteBottomSheetViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/spaces/invite/SpaceInviteBottomSheetViewModel.kt @@ -33,6 +33,8 @@ import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch import org.matrix.android.sdk.api.extensions.tryOrNull import org.matrix.android.sdk.api.session.Session +import org.matrix.android.sdk.api.session.getRoomSummary +import org.matrix.android.sdk.api.session.getUser 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.peeking.PeekResult @@ -46,7 +48,7 @@ class SpaceInviteBottomSheetViewModel @AssistedInject constructor( init { session.getRoomSummary(initialState.spaceId)?.let { roomSummary -> val knownMembers = roomSummary.otherMemberIds.filter { - session.getExistingDirectRoomWithUser(it) != null + session.roomService().getExistingDirectRoomWithUser(it) != null }.mapNotNull { session.getUser(it) } // put one with avatar first, and take 5 val peopleYouKnow = (knownMembers.filter { it.avatarUrl != null } + knownMembers.filter { it.avatarUrl == null }) @@ -70,7 +72,7 @@ class SpaceInviteBottomSheetViewModel @AssistedInject constructor( */ private fun getLatestRoomSummary(roomSummary: RoomSummary) { viewModelScope.launch(Dispatchers.IO) { - val peekResult = tryOrNull { session.peekRoom(roomSummary.roomId) } as? PeekResult.Success ?: return@launch + val peekResult = tryOrNull { session.roomService().peekRoom(roomSummary.roomId) } as? PeekResult.Success ?: return@launch setState { copy( summary = Success( diff --git a/vector/src/main/java/im/vector/app/features/spaces/leave/SpaceLeaveAdvancedViewModel.kt b/vector/src/main/java/im/vector/app/features/spaces/leave/SpaceLeaveAdvancedViewModel.kt index fc241e711c..3f5a27f696 100644 --- a/vector/src/main/java/im/vector/app/features/spaces/leave/SpaceLeaveAdvancedViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/spaces/leave/SpaceLeaveAdvancedViewModel.kt @@ -36,6 +36,8 @@ import okhttp3.internal.toImmutableList import org.matrix.android.sdk.api.query.ActiveSpaceFilter import org.matrix.android.sdk.api.query.RoomCategoryFilter import org.matrix.android.sdk.api.session.Session +import org.matrix.android.sdk.api.session.getRoom +import org.matrix.android.sdk.api.session.getRoomSummary import org.matrix.android.sdk.api.session.room.model.Membership import org.matrix.android.sdk.api.session.room.roomSummaryQueryParams import org.matrix.android.sdk.flow.flow @@ -72,7 +74,7 @@ class SpaceLeaveAdvancedViewModel @AssistedInject constructor( try { state.selectedRooms.forEach { try { - session.leaveRoom(it) + session.roomService().leaveRoom(it) } catch (failure: Throwable) { // silently ignore? Timber.e(failure, "Fail to leave sub rooms/spaces") @@ -110,7 +112,7 @@ class SpaceLeaveAdvancedViewModel @AssistedInject constructor( } viewModelScope.launch { - val children = session.getRoomSummaries( + val children = session.roomService().getRoomSummaries( roomSummaryQueryParams { includeType = null memberships = listOf(Membership.JOIN) diff --git a/vector/src/main/java/im/vector/app/features/spaces/manage/SpaceAddRoomsViewModel.kt b/vector/src/main/java/im/vector/app/features/spaces/manage/SpaceAddRoomsViewModel.kt index 318f701985..0be0fb0464 100644 --- a/vector/src/main/java/im/vector/app/features/spaces/manage/SpaceAddRoomsViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/spaces/manage/SpaceAddRoomsViewModel.kt @@ -39,6 +39,7 @@ import org.matrix.android.sdk.api.query.ActiveSpaceFilter import org.matrix.android.sdk.api.query.QueryStringValue import org.matrix.android.sdk.api.query.RoomCategoryFilter import org.matrix.android.sdk.api.session.Session +import org.matrix.android.sdk.api.session.getRoomSummary import org.matrix.android.sdk.api.session.room.RoomSortOrder import org.matrix.android.sdk.api.session.room.UpdatableLivePageResult import org.matrix.android.sdk.api.session.room.model.Membership @@ -63,8 +64,10 @@ class SpaceAddRoomsViewModel @AssistedInject constructor( companion object : MavericksViewModelFactory by hiltMavericksViewModelFactory() + private val roomService = session.roomService() + val spaceUpdatableLivePageResult: UpdatableLivePageResult by lazy { - session.getFilteredPagedRoomSummariesLive( + roomService.getFilteredPagedRoomSummariesLive( roomSummaryQueryParams { this.memberships = listOf(Membership.JOIN) this.excludeType = null @@ -84,12 +87,12 @@ class SpaceAddRoomsViewModel @AssistedInject constructor( val spaceCountFlow: Flow by lazy { spaceUpdatableLivePageResult.livePagedList.asFlow() - .flatMapLatest { session.getRoomCountLive(spaceUpdatableLivePageResult.queryParams).asFlow() } + .flatMapLatest { roomService.getRoomCountLive(spaceUpdatableLivePageResult.queryParams).asFlow() } .distinctUntilChanged() } val roomUpdatableLivePageResult: UpdatableLivePageResult by lazy { - session.getFilteredPagedRoomSummariesLive( + roomService.getFilteredPagedRoomSummariesLive( roomSummaryQueryParams { this.memberships = listOf(Membership.JOIN) this.excludeType = listOf(RoomType.SPACE) @@ -110,12 +113,12 @@ class SpaceAddRoomsViewModel @AssistedInject constructor( val roomCountFlow: Flow by lazy { roomUpdatableLivePageResult.livePagedList.asFlow() - .flatMapLatest { session.getRoomCountLive(roomUpdatableLivePageResult.queryParams).asFlow() } + .flatMapLatest { roomService.getRoomCountLive(roomUpdatableLivePageResult.queryParams).asFlow() } .distinctUntilChanged() } val dmUpdatableLivePageResult: UpdatableLivePageResult by lazy { - session.getFilteredPagedRoomSummariesLive( + roomService.getFilteredPagedRoomSummariesLive( roomSummaryQueryParams { this.memberships = listOf(Membership.JOIN) this.excludeType = listOf(RoomType.SPACE) @@ -136,7 +139,7 @@ class SpaceAddRoomsViewModel @AssistedInject constructor( val dmCountFlow: Flow by lazy { dmUpdatableLivePageResult.livePagedList.asFlow() - .flatMapLatest { session.getRoomCountLive(dmUpdatableLivePageResult.queryParams).asFlow() } + .flatMapLatest { roomService.getRoomCountLive(dmUpdatableLivePageResult.queryParams).asFlow() } .distinctUntilChanged() } diff --git a/vector/src/main/java/im/vector/app/features/spaces/manage/SpaceManageRoomsViewModel.kt b/vector/src/main/java/im/vector/app/features/spaces/manage/SpaceManageRoomsViewModel.kt index a1dd26a936..6896b85924 100644 --- a/vector/src/main/java/im/vector/app/features/spaces/manage/SpaceManageRoomsViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/spaces/manage/SpaceManageRoomsViewModel.kt @@ -33,6 +33,7 @@ import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch import org.matrix.android.sdk.api.extensions.tryOrNull import org.matrix.android.sdk.api.session.Session +import org.matrix.android.sdk.api.session.getRoomSummary class SpaceManageRoomsViewModel @AssistedInject constructor( @Assisted val initialState: SpaceManageRoomViewState, diff --git a/vector/src/main/java/im/vector/app/features/spaces/people/SpacePeopleViewModel.kt b/vector/src/main/java/im/vector/app/features/spaces/people/SpacePeopleViewModel.kt index 4fee675351..988f2214c9 100644 --- a/vector/src/main/java/im/vector/app/features/spaces/people/SpacePeopleViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/spaces/people/SpacePeopleViewModel.kt @@ -65,7 +65,7 @@ class SpacePeopleViewModel @AssistedInject constructor( private fun handleChatWith(action: SpacePeopleViewAction.ChatWith) { val otherUserId = action.member.userId if (otherUserId == session.myUserId) return - val existingRoomId = session.getExistingDirectRoomWithUser(otherUserId) + val existingRoomId = session.roomService().getExistingDirectRoomWithUser(otherUserId) if (existingRoomId != null) { // just open it _viewEvents.post(SpacePeopleViewEvents.OpenRoom(existingRoomId)) @@ -86,7 +86,7 @@ class SpacePeopleViewModel @AssistedInject constructor( } try { - val roomId = session.createRoom(roomParams) + val roomId = session.roomService().createRoom(roomParams) analyticsTracker.capture(CreatedRoom(isDM = roomParams.isDirect.orFalse())) _viewEvents.post(SpacePeopleViewEvents.OpenRoom(roomId)) setState { copy(createAndInviteState = Success(roomId)) } diff --git a/vector/src/main/java/im/vector/app/features/spaces/preview/SpacePreviewViewModel.kt b/vector/src/main/java/im/vector/app/features/spaces/preview/SpacePreviewViewModel.kt index f7471bc7aa..888f4a65b5 100644 --- a/vector/src/main/java/im/vector/app/features/spaces/preview/SpacePreviewViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/spaces/preview/SpacePreviewViewModel.kt @@ -31,6 +31,7 @@ import im.vector.app.core.platform.VectorViewModel import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch import org.matrix.android.sdk.api.session.Session +import org.matrix.android.sdk.api.session.getRoomSummary import org.matrix.android.sdk.api.session.room.model.RoomType import org.matrix.android.sdk.api.session.room.peeking.PeekResult import org.matrix.android.sdk.api.session.space.JoinSpaceResult diff --git a/vector/src/main/java/im/vector/app/features/spaces/share/ShareSpaceViewModel.kt b/vector/src/main/java/im/vector/app/features/spaces/share/ShareSpaceViewModel.kt index c624f1ed46..43d69e6fef 100644 --- a/vector/src/main/java/im/vector/app/features/spaces/share/ShareSpaceViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/spaces/share/ShareSpaceViewModel.kt @@ -30,6 +30,8 @@ import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.onEach import org.matrix.android.sdk.api.extensions.orFalse import org.matrix.android.sdk.api.session.Session +import org.matrix.android.sdk.api.session.getRoom +import org.matrix.android.sdk.api.session.getRoomSummary import org.matrix.android.sdk.api.session.room.powerlevels.PowerLevelsHelper class ShareSpaceViewModel @AssistedInject constructor( diff --git a/vector/src/main/java/im/vector/app/features/terms/ReviewTermsViewModel.kt b/vector/src/main/java/im/vector/app/features/terms/ReviewTermsViewModel.kt index 8fe1f598f6..3a9b772630 100644 --- a/vector/src/main/java/im/vector/app/features/terms/ReviewTermsViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/terms/ReviewTermsViewModel.kt @@ -84,7 +84,7 @@ class ReviewTermsViewModel @AssistedInject constructor( viewModelScope.launch { try { - session.agreeToTerms( + session.termsService().agreeToTerms( termsArgs.type, termsArgs.baseURL, agreedUrls, @@ -109,7 +109,7 @@ class ReviewTermsViewModel @AssistedInject constructor( viewModelScope.launch { try { - val data = session.getTerms(termsArgs.type, termsArgs.baseURL) + val data = session.termsService().getTerms(termsArgs.type, termsArgs.baseURL) val terms = data.serverResponse.getLocalizedTerms(action.preferredLanguageCode).map { Term(it.localizedUrl ?: "", it.localizedName ?: "", diff --git a/vector/src/main/java/im/vector/app/features/usercode/UserCodeSharedViewModel.kt b/vector/src/main/java/im/vector/app/features/usercode/UserCodeSharedViewModel.kt index da894a42be..02955cf2b3 100644 --- a/vector/src/main/java/im/vector/app/features/usercode/UserCodeSharedViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/usercode/UserCodeSharedViewModel.kt @@ -31,6 +31,7 @@ import kotlinx.coroutines.launch import org.matrix.android.sdk.api.extensions.tryOrNull import org.matrix.android.sdk.api.raw.RawService import org.matrix.android.sdk.api.session.Session +import org.matrix.android.sdk.api.session.getUser import org.matrix.android.sdk.api.session.permalinks.PermalinkData import org.matrix.android.sdk.api.session.permalinks.PermalinkParser import org.matrix.android.sdk.api.session.user.model.User @@ -115,7 +116,7 @@ class UserCodeSharedViewModel @AssistedInject constructor( _viewEvents.post(UserCodeShareViewEvents.ToastMessage(stringProvider.getString(R.string.not_implemented))) } is PermalinkData.UserLink -> { - val user = tryOrNull { session.resolveUser(linkedId.userId) } + val user = tryOrNull { session.userService().resolveUser(linkedId.userId) } // Create raw Uxid in case the user is not searchable ?: User(linkedId.userId, null, null) diff --git a/vector/src/main/java/im/vector/app/features/userdirectory/UserListViewModel.kt b/vector/src/main/java/im/vector/app/features/userdirectory/UserListViewModel.kt index 783fddf8ad..291153ef2b 100644 --- a/vector/src/main/java/im/vector/app/features/userdirectory/UserListViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/userdirectory/UserListViewModel.kt @@ -191,7 +191,7 @@ class UserListViewModel @AssistedInject constructor( knownUsersSearch .sample(300) .flatMapLatest { search -> - session.getPagedUsersLive(search, state.excludedUserIds).asFlow() + session.userService().getPagedUsersLive(search, state.excludedUserIds).asFlow() } .execute { copy(knownUsers = it) @@ -212,7 +212,7 @@ class UserListViewModel @AssistedInject constructor( ThreePidUser(email = search, user = null) } else { try { - val user = tryOrNull { session.getProfileAsUser(foundThreePid.matrixId) } ?: User(foundThreePid.matrixId) + val user = tryOrNull { session.profileService().getProfileAsUser(foundThreePid.matrixId) } ?: User(foundThreePid.matrixId) ThreePidUser( email = search, user = user @@ -232,10 +232,11 @@ class UserListViewModel @AssistedInject constructor( emptyList() } else { val searchResult = session + .userService() .searchUsersDirectory(search, 50, state.excludedUserIds.orEmpty()) .sortedBy { it.toMatrixItem().firstLetterOfDisplayName() } val userProfile = if (MatrixPatterns.isUserId(search)) { - val user = tryOrNull { session.getProfileAsUser(search) } + val user = tryOrNull { session.profileService().getProfileAsUser(search) } User( userId = search, displayName = user?.displayName, diff --git a/vector/src/main/java/im/vector/app/features/widgets/WidgetPostAPIHandler.kt b/vector/src/main/java/im/vector/app/features/widgets/WidgetPostAPIHandler.kt index 51e7e6fcb7..e616f8f73f 100644 --- a/vector/src/main/java/im/vector/app/features/widgets/WidgetPostAPIHandler.kt +++ b/vector/src/main/java/im/vector/app/features/widgets/WidgetPostAPIHandler.kt @@ -33,6 +33,7 @@ import org.matrix.android.sdk.api.session.events.model.Event 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.toModel +import org.matrix.android.sdk.api.session.getRoom import org.matrix.android.sdk.api.session.room.model.Membership import org.matrix.android.sdk.api.session.room.model.PowerLevelsContent import org.matrix.android.sdk.api.session.room.powerlevels.PowerLevelsHelper diff --git a/vector/src/main/java/im/vector/app/features/widgets/WidgetViewModel.kt b/vector/src/main/java/im/vector/app/features/widgets/WidgetViewModel.kt index 2ba35573f0..c7b1429304 100644 --- a/vector/src/main/java/im/vector/app/features/widgets/WidgetViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/widgets/WidgetViewModel.kt @@ -37,6 +37,7 @@ import org.matrix.android.sdk.api.session.Session import org.matrix.android.sdk.api.session.events.model.Content 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.getRoom import org.matrix.android.sdk.api.session.integrationmanager.IntegrationManagerService import org.matrix.android.sdk.api.session.room.model.PowerLevelsContent import org.matrix.android.sdk.api.session.room.powerlevels.PowerLevelsHelper diff --git a/vector/src/main/java/im/vector/app/features/workers/signout/ServerBackupStatusViewModel.kt b/vector/src/main/java/im/vector/app/features/workers/signout/ServerBackupStatusViewModel.kt index 8fb5b27376..1c55145e16 100644 --- a/vector/src/main/java/im/vector/app/features/workers/signout/ServerBackupStatusViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/workers/signout/ServerBackupStatusViewModel.kt @@ -87,7 +87,7 @@ class ServerBackupStatusViewModel @AssistedInject constructor(@Assisted initialS val liveCrossSigningPrivateKeys = session.flow().liveCrossSigningPrivateKeys() combine(liveUserAccountData, liveCrossSigningInfo, keyBackupFlow, liveCrossSigningPrivateKeys) { _, crossSigningInfo, keyBackupState, pInfo -> // first check if 4S is already setup - if (session.sharedSecretStorageService.isRecoverySetup()) { + if (session.sharedSecretStorageService().isRecoverySetup()) { // 4S is already setup sp we should not display anything return@combine when (keyBackupState) { KeysBackupState.BackingUp -> BannerState.BackingUp diff --git a/vector/src/main/java/im/vector/app/features/workers/signout/SignoutCheckViewModel.kt b/vector/src/main/java/im/vector/app/features/workers/signout/SignoutCheckViewModel.kt index fbc0b8fcff..79df62d7fb 100644 --- a/vector/src/main/java/im/vector/app/features/workers/signout/SignoutCheckViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/workers/signout/SignoutCheckViewModel.kt @@ -74,7 +74,7 @@ class SignoutCheckViewModel @AssistedInject constructor( session.cryptoService().keysBackupService().addListener(this) session.cryptoService().keysBackupService().checkAndStartKeysBackup() - val quad4SIsSetup = session.sharedSecretStorageService.isRecoverySetup() + val quad4SIsSetup = session.sharedSecretStorageService().isRecoverySetup() val allKeysKnown = session.cryptoService().crossSigningService().allPrivateKeysKnown() val backupState = session.cryptoService().keysBackupService().state setState { @@ -88,7 +88,7 @@ class SignoutCheckViewModel @AssistedInject constructor( session.flow().liveUserAccountData(setOf(MASTER_KEY_SSSS_NAME, USER_SIGNING_KEY_SSSS_NAME, SELF_SIGNING_KEY_SSSS_NAME)) .map { - session.sharedSecretStorageService.isRecoverySetup() + session.sharedSecretStorageService().isRecoverySetup() } .distinctUntilChanged() .execute { diff --git a/vector/src/test/java/im/vector/app/test/fakes/FakeSession.kt b/vector/src/test/java/im/vector/app/test/fakes/FakeSession.kt index 1fff67e982..5f02879e65 100644 --- a/vector/src/test/java/im/vector/app/test/fakes/FakeSession.kt +++ b/vector/src/test/java/im/vector/app/test/fakes/FakeSession.kt @@ -16,7 +16,6 @@ package im.vector.app.test.fakes -import android.net.Uri import im.vector.app.core.extensions.configureAndStart import im.vector.app.core.extensions.startSyncing import im.vector.app.core.extensions.vectorStore @@ -27,6 +26,8 @@ import io.mockk.coJustRun import io.mockk.mockk import io.mockk.mockkStatic import org.matrix.android.sdk.api.session.Session +import org.matrix.android.sdk.api.session.homeserver.HomeServerCapabilitiesService +import org.matrix.android.sdk.api.session.profile.ProfileService class FakeSession( val fakeCryptoService: FakeCryptoService = FakeCryptoService(), @@ -41,12 +42,12 @@ class FakeSession( override val myUserId: String = "@fake:server.fake" - override fun cryptoService() = fakeCryptoService - override val sharedSecretStorageService = fakeSharedSecretStorageService override val coroutineDispatchers = testCoroutineDispatchers - override suspend fun setDisplayName(userId: String, newDisplayName: String) = fakeProfileService.setDisplayName(userId, newDisplayName) - override suspend fun updateAvatar(userId: String, newAvatarUri: Uri, fileName: String) = fakeProfileService.updateAvatar(userId, newAvatarUri, fileName) - override fun getHomeServerCapabilities() = fakeHomeServerCapabilitiesService.getHomeServerCapabilities() + + override fun cryptoService() = fakeCryptoService + override fun profileService(): ProfileService = fakeProfileService + override fun homeServerCapabilitiesService(): HomeServerCapabilitiesService = fakeHomeServerCapabilitiesService + override fun sharedSecretStorageService() = fakeSharedSecretStorageService fun givenVectorStore(vectorSessionStore: VectorSessionStore) { coEvery {