mirror of
https://github.com/Novaloop-AG/element-x-android.git
synced 2026-11-02 20:38:40 +00:00
Merge develop into the PreviewParam rename
The 174 commits develop gained since this branch was cut touch preview data in three ways, and each is resolved so the flipped konsist rule still holds across the merged tree. Two screens the branch had renamed were deleted upstream by "Remove the account provider search screen and homeserver resolver": the changeaccountprovider and searchaccountprovider packages. Their deletion wins, so ChangeAccountProviderStatePreviewParam, SearchAccountProviderStatePreviewParam and the two views that used them go with them rather than coming back under the new name. Two preview classes develop added still carried the old suffix and are renamed here, along with the `@PreviewParameter` reference in each view: GlobalSearchStateProvider -> GlobalSearchStatePreviewParam and SendFailureDialogStateProvider -> SendFailureDialogStatePreviewParam. Everything else merged textually. No production class extending PreviewParameterProvider is left with a `Provider` name, and no reference to any of the 194 renamed names survives outside the CHANGES.md entry that records a past pull request title.
This commit is contained in:
@@ -7,7 +7,6 @@
|
|||||||
"PR-Dependencies",
|
"PR-Dependencies",
|
||||||
],
|
],
|
||||||
"ignoreDeps": [
|
"ignoreDeps": [
|
||||||
"string:app_name",
|
|
||||||
"gradle",
|
"gradle",
|
||||||
],
|
],
|
||||||
"minimumReleaseAge": "7 days",
|
"minimumReleaseAge": "7 days",
|
||||||
|
|||||||
@@ -31,9 +31,6 @@ __pycache__/
|
|||||||
# Local configuration file (sdk path, etc)
|
# Local configuration file (sdk path, etc)
|
||||||
local.properties
|
local.properties
|
||||||
|
|
||||||
# Proguard folder generated by Eclipse
|
|
||||||
proguard/
|
|
||||||
|
|
||||||
# Log Files
|
# Log Files
|
||||||
*.log
|
*.log
|
||||||
|
|
||||||
|
|||||||
Generated
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
<component name="CopyrightManager">
|
<component name="CopyrightManager">
|
||||||
<copyright>
|
<copyright>
|
||||||
<option name="notice" value="© &#36;today.year Element Creations Ltd. Element Creations Ltd, Element Software SARL, Element Software Inc., and Element Software GmbH (the "Element Group") only make this file available under a proprietary license model. Without a proprietary license with us, you cannot use this file. The terms of the proprietary license agreement between you and any member of the Element Group shall always apply to your use of this file. Unauthorised use, copying, distribution, or modification of this file, via any medium, is strictly prohibited. For details about the licensing terms, you must either visit our website or contact a member of our sales team." />
|
<option name="notice" value="© &#36;today.year Element Creations Ltd. SPDX-License-Identifier: LicenseRef-Element-Commercial SPDX-License-Identifier: LicenseRef-Element-Proprietary" />
|
||||||
<option name="myName" value="Element Enterprise" />
|
<option name="myName" value="Element Enterprise" />
|
||||||
</copyright>
|
</copyright>
|
||||||
</component>
|
</component>
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
appId: ${MAESTRO_APP_ID}
|
|
||||||
---
|
|
||||||
- tapOn:
|
|
||||||
id: "login-change_server"
|
|
||||||
- takeScreenshot: build/maestro/200-ChangeServer
|
|
||||||
- tapOn: "matrix.org"
|
|
||||||
- tapOn:
|
|
||||||
id: "login-change_server"
|
|
||||||
- tapOn: "Other"
|
|
||||||
- tapOn:
|
|
||||||
id: "change_server-server"
|
|
||||||
- inputText: "element"
|
|
||||||
- hideKeyboard
|
|
||||||
- extendedWaitUntil:
|
|
||||||
visible: "element.io"
|
|
||||||
timeout: 10000
|
|
||||||
- tapOn: "element.io"
|
|
||||||
# Revert to matrix.org
|
|
||||||
- tapOn:
|
|
||||||
id: "login-change_server"
|
|
||||||
- tapOn: "matrix.org"
|
|
||||||
@@ -3,8 +3,7 @@ appId: ${MAESTRO_APP_ID}
|
|||||||
- tapOn: "Sign in manually"
|
- tapOn: "Sign in manually"
|
||||||
- runFlow: ../assertions/assertLoginDisplayed.yaml
|
- runFlow: ../assertions/assertLoginDisplayed.yaml
|
||||||
- takeScreenshot: build/maestro/100-SignIn
|
- takeScreenshot: build/maestro/100-SignIn
|
||||||
- runFlow: changeServer.yaml
|
# The account provider field defaults to matrix.org, so continue straight to the MAS login.
|
||||||
- runFlow: ../assertions/assertLoginDisplayed.yaml
|
|
||||||
- tapOn:
|
- tapOn:
|
||||||
id: "login-continue"
|
id: "login-continue"
|
||||||
## MAS page
|
## MAS page
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
appId: ${MAESTRO_APP_ID}
|
appId: ${MAESTRO_APP_ID}
|
||||||
---
|
---
|
||||||
- extendedWaitUntil:
|
- extendedWaitUntil:
|
||||||
visible: "Change account provider"
|
visible: "Enter your account provider"
|
||||||
timeout: 10000
|
timeout: 10000
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ PRs must meet these rules.
|
|||||||
- Use `@PreviewsDayNight` for consistency.
|
- Use `@PreviewsDayNight` for consistency.
|
||||||
- Use `PreviewParameterProvider` (e.g., `FooStatePreviewParam`) to provide states.
|
- Use `PreviewParameterProvider` (e.g., `FooStatePreviewParam`) to provide states.
|
||||||
- Wrap previews in `ElementPreview { ... }`.
|
- Wrap previews in `ElementPreview { ... }`.
|
||||||
|
- When writing tests, never try to record the screenshots, the CI will do it.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|||||||
+83
@@ -1,3 +1,86 @@
|
|||||||
|
Changes in Element X v26.08.2
|
||||||
|
=============================
|
||||||
|
|
||||||
|
<!-- Release notes generated using configuration in .github/release.yml at v26.08.2 -->
|
||||||
|
|
||||||
|
**Note: this release in an internal release, it will not be pushed to the stores.**
|
||||||
|
|
||||||
|
## What's Changed
|
||||||
|
### ✨ Features
|
||||||
|
* Remove the legacy web-based account creation for matrix.org by @jmartinesp in https://github.com/element-hq/element-x-android/pull/7412
|
||||||
|
### 🙌 Improvements
|
||||||
|
* Move the custom tile server URL config to the Element wellknown content by @jmartinesp in https://github.com/element-hq/element-x-android/pull/7416
|
||||||
|
* Explain a rate limiting push gateway in the notification troubleshooter by @hayaksi1 in https://github.com/element-hq/element-x-android/pull/7448
|
||||||
|
* Move the `:libraries:wellknown` logic into `enterprise` modules by @jmartinesp in https://github.com/element-hq/element-x-android/pull/7429
|
||||||
|
* Refresh the room members when a mention is started by @hayaksi1 in https://github.com/element-hq/element-x-android/pull/7438
|
||||||
|
* Close the invite screen once the invite has been declined by @hayaksi1 in https://github.com/element-hq/element-x-android/pull/7440
|
||||||
|
* Use Profiles sliding sync extension check for own profile subscription by @ganfra in https://github.com/element-hq/element-x-android/pull/7403
|
||||||
|
* Simplify choosing the account provider during sign in, with autocomplete of previously used ones by @jennaharris7 in https://github.com/element-hq/element-x-android/pull/7394
|
||||||
|
### 🐛 Bugfixes
|
||||||
|
* Fix wrong TextComposer placeholder displayed when in a thread. by @bmarty in https://github.com/element-hq/element-x-android/pull/7413
|
||||||
|
* Fix bug reports failing to send after the app has crashed by @hayaksi1 in https://github.com/element-hq/element-x-android/pull/7395
|
||||||
|
* Fix outgoing session verification stuck with incomplete recovery setup by @hardcore-sushi in https://github.com/element-hq/element-x-android/pull/7433
|
||||||
|
* Keep transparency when an image is shared into the app with an imprecise mime type by @hayaksi1 in https://github.com/element-hq/element-x-android/pull/7452
|
||||||
|
* Don't restart the sync service if the client is shutting down by @jmartinesp in https://github.com/element-hq/element-x-android/pull/7472
|
||||||
|
* Normalize the applicationName used in user agent by @bmarty in https://github.com/element-hq/element-x-android/pull/7477
|
||||||
|
* Keep playing a voice message when another app plays a short sound by @hayaksi1 in https://github.com/element-hq/element-x-android/pull/7454
|
||||||
|
* Keep the send button when the composer is emptied while editing a message by @hayaksi1 in https://github.com/element-hq/element-x-android/pull/7456
|
||||||
|
* Do not open the room again when the app is resumed from the recents list by @hayaksi1 in https://github.com/element-hq/element-x-android/pull/7436
|
||||||
|
* Stop waiting for a room alias that the remote server never resolves by @hayaksi1 in https://github.com/element-hq/element-x-android/pull/7446
|
||||||
|
### 🧱 Build
|
||||||
|
* build-rust-sdk: print the command we run by @richvdh in https://github.com/element-hq/element-x-android/pull/7407
|
||||||
|
* Remove license check on Pro modules. by @bmarty in https://github.com/element-hq/element-x-android/pull/7418
|
||||||
|
* Improve build time config and update the Firebase configuration by @bmarty in https://github.com/element-hq/element-x-android/pull/7473
|
||||||
|
* Make the PUSHER_APP_ID configurable at build time. by @bmarty in https://github.com/element-hq/element-x-android/pull/7478
|
||||||
|
### 📄 Documentation
|
||||||
|
* Add KDoc to all the interfaces of the api modules by @bmarty in https://github.com/element-hq/element-x-android/pull/7426
|
||||||
|
### 🚧 In development 🚧
|
||||||
|
* [LinkNewDevice] Ensure the notice screen is also protected by the timeout. by @bmarty in https://github.com/element-hq/element-x-android/pull/7428
|
||||||
|
### Dependency upgrades
|
||||||
|
* Update kotlin to v2.3.11 by @renovate[bot] in https://github.com/element-hq/element-x-android/pull/7396
|
||||||
|
* Update plugin sonarqube to v7.4.0.8496 by @renovate[bot] in https://github.com/element-hq/element-x-android/pull/7415
|
||||||
|
* Update metro to v1.4.1 by @renovate[bot] in https://github.com/element-hq/element-x-android/pull/7421
|
||||||
|
* Update roborazzi to v1.71.0 by @renovate[bot] in https://github.com/element-hq/element-x-android/pull/7423
|
||||||
|
* Update dependency io.sentry:sentry-android to v8.52.0 by @renovate[bot] in https://github.com/element-hq/element-x-android/pull/7414
|
||||||
|
* Update dependency org.matrix.rustcomponents:sdk-android to v26.08.13 by @renovate[bot] in https://github.com/element-hq/element-x-android/pull/7420
|
||||||
|
* Update dependency io.github.sergio-sastre.ComposablePreviewScanner:android to v0.9.2 by @renovate[bot] in https://github.com/element-hq/element-x-android/pull/7431
|
||||||
|
* Update dependency org.maplibre.compose:maplibre-compose to v0.14.0 by @renovate[bot] in https://github.com/element-hq/element-x-android/pull/7432
|
||||||
|
* Update dependency org.matrix.rustcomponents:sdk-android to v26.08.17 by @renovate[bot] in https://github.com/element-hq/element-x-android/pull/7460
|
||||||
|
* Update dependency org.matrix.rustcomponents:sdk-android to v26.08.19 by @renovate[bot] in https://github.com/element-hq/element-x-android/pull/7479
|
||||||
|
* Update media3 to v1.11.0 by @renovate[bot] in https://github.com/element-hq/element-x-android/pull/7427
|
||||||
|
* Update dependency androidx.compose:compose-bom to v2026.08.00 by @renovate[bot] in https://github.com/element-hq/element-x-android/pull/7483
|
||||||
|
### 💼 Element Pro
|
||||||
|
* Add hooks to allow providing additional feature flags in EX pro by @richvdh in https://github.com/element-hq/element-x-android/pull/7419
|
||||||
|
* Use the right base URL for the ESS config/well known endpoints by @jmartinesp in https://github.com/element-hq/element-x-android/pull/7469
|
||||||
|
### Others
|
||||||
|
* Do not display pinned events that the client cannot render by @hayaksi1 in https://github.com/element-hq/element-x-android/pull/7379
|
||||||
|
* Hide the forward action on live location shares by @hayaksi1 in https://github.com/element-hq/element-x-android/pull/7343
|
||||||
|
* Do not fail the screenshot recording job when there is nothing to commit by @hayaksi1 in https://github.com/element-hq/element-x-android/pull/7355
|
||||||
|
* Show the account a UnifiedPush registration belongs to in the distributor by @hayaksi1 in https://github.com/element-hq/element-x-android/pull/7345
|
||||||
|
* Stop repeating messages that are already shown in a room notification by @hayaksi1 in https://github.com/element-hq/element-x-android/pull/7370
|
||||||
|
* Turn a matrix: URI in a message into a pill by @hayaksi1 in https://github.com/element-hq/element-x-android/pull/7354
|
||||||
|
* Send a message with Enter on a physical keyboard, Shift+Enter for a new line by @hayaksi1 in https://github.com/element-hq/element-x-android/pull/7353
|
||||||
|
* Do not group timeline messages sent more than five minutes apart by @hayaksi1 in https://github.com/element-hq/element-x-android/pull/7349
|
||||||
|
* Linkify URLs whose host is a bracketed IPv6 address by @hayaksi1 in https://github.com/element-hq/element-x-android/pull/7347
|
||||||
|
* Add missing tests for `RustTemporaryMatrixClient` by @jmartinesp in https://github.com/element-hq/element-x-android/pull/7417
|
||||||
|
* Revert "Keep manually revealed media visible when re-entering a room" by @bmarty in https://github.com/element-hq/element-x-android/pull/7424
|
||||||
|
* Fix outdated documentation. by @bmarty in https://github.com/element-hq/element-x-android/pull/7430
|
||||||
|
* Sync strings - New language supported: Arabic by @bmarty in https://github.com/element-hq/element-x-android/pull/7461
|
||||||
|
* Keep the focused login field visible above the keyboard by @hayaksi1 in https://github.com/element-hq/element-x-android/pull/7455
|
||||||
|
* Relax image compression so photos and screenshots keep more detail by @hayaksi1 in https://github.com/element-hq/element-x-android/pull/7451
|
||||||
|
* Open the user profile of a user id that contains a slash by @hayaksi1 in https://github.com/element-hq/element-x-android/pull/7445
|
||||||
|
* Remove the F-Droid dex patching step from the release script by @hayaksi1 in https://github.com/element-hq/element-x-android/pull/7442
|
||||||
|
* Convert markdown to HTML when a caption is edited by @hayaksi1 in https://github.com/element-hq/element-x-android/pull/7441
|
||||||
|
* Exclude carriage returns from the login and password fields by @hayaksi1 in https://github.com/element-hq/element-x-android/pull/7439
|
||||||
|
* Show an error when the room to leave cannot be found by @hayaksi1 in https://github.com/element-hq/element-x-android/pull/7437
|
||||||
|
* Give the room name in the timeline top bar a 48dp tap target by @hayaksi1 in https://github.com/element-hq/element-x-android/pull/7450
|
||||||
|
* Model the fake voice recorder on a cancellable recording job by @hayaksi1 in https://github.com/element-hq/element-x-android/pull/7466
|
||||||
|
|
||||||
|
## New Contributors
|
||||||
|
* @hardcore-sushi made their first contribution in https://github.com/element-hq/element-x-android/pull/7433
|
||||||
|
|
||||||
|
**Full Changelog**: https://github.com/element-hq/element-x-android/compare/v26.08.1...v26.08.2
|
||||||
|
|
||||||
Changes in Element X v26.08.1
|
Changes in Element X v26.08.1
|
||||||
=============================
|
=============================
|
||||||
|
|
||||||
|
|||||||
+28
-17
@@ -127,24 +127,11 @@ android {
|
|||||||
optimization {
|
optimization {
|
||||||
enable = true
|
enable = true
|
||||||
keepRules {
|
keepRules {
|
||||||
files.add(File(projectDir, "common-proguard-rules.pro"))
|
// Equivalent of adding `getDefaultProguardFile("proguard-android-optimize.txt")` (this is the default value).
|
||||||
files.add(getDefaultProguardFile("proguard-android-optimize.txt"))
|
includeDefault = true
|
||||||
|
|
||||||
// Depending on whether the app flavor is enterprise or not we want to use different proguard rules.
|
|
||||||
val flavorProguardFile = if (isEnterpriseBuild) {
|
|
||||||
// Custom rules for enterprise builds
|
|
||||||
File(projectDir, "enterprise-proguard-rules.pro")
|
|
||||||
} else {
|
|
||||||
// These default rules prevent the OSS app from being obfuscated
|
|
||||||
File(projectDir, "default-proguard-rules.pro")
|
|
||||||
}
|
|
||||||
|
|
||||||
if (flavorProguardFile.exists()) {
|
|
||||||
files.add(flavorProguardFile)
|
|
||||||
} else {
|
|
||||||
logger.warn("Proguard file ${flavorProguardFile.absolutePath} does not exist")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
// Our custom keep rules are registered as `keepRules` source folders in the `androidComponents` block below,
|
||||||
|
// as the former `keepRules.files` DSL is deprecated since AGP 9.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -229,6 +216,30 @@ androidComponents {
|
|||||||
)
|
)
|
||||||
|
|
||||||
onVariants { variant ->
|
onVariants { variant ->
|
||||||
|
// Register the R8 keep rules source folders for optimized build types (release, nightly).
|
||||||
|
// Replaces the deprecated `optimization.keepRules.files` DSL (AGP 9+).
|
||||||
|
if (variant.buildType != "debug") {
|
||||||
|
variant.sources.keepRules?.let { keepRules ->
|
||||||
|
// Common rules, always applied.
|
||||||
|
keepRules.addStaticSourceDirectory("proguard/common")
|
||||||
|
|
||||||
|
// Depending on whether the app flavor is enterprise or not we want to use different proguard rules.
|
||||||
|
val flavorProguardDir = if (isEnterpriseBuild) {
|
||||||
|
// Custom rules for enterprise builds
|
||||||
|
"../enterprise/proguard"
|
||||||
|
} else {
|
||||||
|
// Custom fules for FOSS builds
|
||||||
|
"proguard/foss"
|
||||||
|
}
|
||||||
|
|
||||||
|
if (File(projectDir, flavorProguardDir).exists()) {
|
||||||
|
keepRules.addStaticSourceDirectory(flavorProguardDir)
|
||||||
|
} else {
|
||||||
|
logger.warn("Proguard folder ${File(projectDir, flavorProguardDir).absolutePath} does not exist")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Assigns a different version code for each output APK
|
// Assigns a different version code for each output APK
|
||||||
// other than the universal APK.
|
// other than the universal APK.
|
||||||
variant.outputs.forEach { output ->
|
variant.outputs.forEach { output ->
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ import dev.zacsweers.metro.ContributesTo
|
|||||||
import dev.zacsweers.metro.Provides
|
import dev.zacsweers.metro.Provides
|
||||||
import dev.zacsweers.metro.SingleIn
|
import dev.zacsweers.metro.SingleIn
|
||||||
import io.element.android.appconfig.ApplicationConfig
|
import io.element.android.appconfig.ApplicationConfig
|
||||||
import io.element.android.features.enterprise.api.EnterpriseService
|
import io.element.android.features.enterprise.api.IsEnterpriseBuild
|
||||||
import io.element.android.libraries.androidutils.system.getVersionCodeFromManifest
|
import io.element.android.libraries.androidutils.system.getVersionCodeFromManifest
|
||||||
import io.element.android.libraries.core.coroutine.CoroutineDispatchers
|
import io.element.android.libraries.core.coroutine.CoroutineDispatchers
|
||||||
import io.element.android.libraries.core.meta.BuildMeta
|
import io.element.android.libraries.core.meta.BuildMeta
|
||||||
@@ -74,17 +74,18 @@ object AppModule {
|
|||||||
fun providesBuildMeta(
|
fun providesBuildMeta(
|
||||||
@ApplicationContext context: Context,
|
@ApplicationContext context: Context,
|
||||||
buildType: BuildType,
|
buildType: BuildType,
|
||||||
enterpriseService: EnterpriseService,
|
isEnterpriseBuild: IsEnterpriseBuild,
|
||||||
): BuildMeta {
|
): BuildMeta {
|
||||||
val applicationName = ApplicationConfig.APPLICATION_NAME.takeIf { it.isNotEmpty() } ?: context.getString(R.string.app_name)
|
val applicationName = ApplicationConfig.APPLICATION_NAME.takeIf { it.isNotEmpty() } ?: context.getString(R.string.app_name)
|
||||||
|
val isEnterprise = isEnterpriseBuild()
|
||||||
return BuildMeta(
|
return BuildMeta(
|
||||||
isDebuggable = BuildConfig.DEBUG,
|
isDebuggable = BuildConfig.DEBUG,
|
||||||
buildType = buildType,
|
buildType = buildType,
|
||||||
applicationName = applicationName,
|
applicationName = applicationName,
|
||||||
productionApplicationName = if (enterpriseService.isEnterpriseBuild) applicationName else ApplicationConfig.PRODUCTION_APPLICATION_NAME,
|
productionApplicationName = if (isEnterprise) applicationName else ApplicationConfig.PRODUCTION_APPLICATION_NAME,
|
||||||
desktopApplicationName = if (enterpriseService.isEnterpriseBuild) applicationName else ApplicationConfig.DESKTOP_APPLICATION_NAME,
|
desktopApplicationName = if (isEnterprise) applicationName else ApplicationConfig.DESKTOP_APPLICATION_NAME,
|
||||||
applicationId = BuildConfig.APPLICATION_ID,
|
applicationId = BuildConfig.APPLICATION_ID,
|
||||||
isEnterpriseBuild = enterpriseService.isEnterpriseBuild,
|
isEnterpriseBuild = isEnterprise,
|
||||||
// TODO EAx Config.LOW_PRIVACY_LOG_ENABLE,
|
// TODO EAx Config.LOW_PRIVACY_LOG_ENABLE,
|
||||||
lowPrivacyLoggingEnabled = false,
|
lowPrivacyLoggingEnabled = false,
|
||||||
versionName = BuildConfig.VERSION_NAME,
|
versionName = BuildConfig.VERSION_NAME,
|
||||||
|
|||||||
@@ -1,16 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2025 Element Creations Ltd.
|
|
||||||
* Copyright 2023-2025 New Vector Ltd.
|
|
||||||
*
|
|
||||||
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial.
|
|
||||||
* Please see LICENSE files in the repository root for full details.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package io.element.android.appconfig
|
|
||||||
|
|
||||||
object PushConfig {
|
|
||||||
/**
|
|
||||||
* Note: pusher_app_id cannot exceed 64 chars.
|
|
||||||
*/
|
|
||||||
const val PUSHER_APP_ID: String = "im.vector.app.android"
|
|
||||||
}
|
|
||||||
@@ -61,17 +61,23 @@ dependencies {
|
|||||||
testCommonDependencies(libs)
|
testCommonDependencies(libs)
|
||||||
testImplementation(projects.features.login.test)
|
testImplementation(projects.features.login.test)
|
||||||
testImplementation(projects.features.share.test)
|
testImplementation(projects.features.share.test)
|
||||||
|
testImplementation(projects.libraries.accountselect.test)
|
||||||
testImplementation(projects.libraries.featureflag.test)
|
testImplementation(projects.libraries.featureflag.test)
|
||||||
testImplementation(projects.libraries.matrix.test)
|
testImplementation(projects.libraries.matrix.test)
|
||||||
|
testImplementation(projects.libraries.matrixmedia.test)
|
||||||
testImplementation(projects.libraries.oauth.test)
|
testImplementation(projects.libraries.oauth.test)
|
||||||
testImplementation(projects.libraries.permissions.test)
|
testImplementation(projects.libraries.permissions.test)
|
||||||
testImplementation(projects.libraries.preferences.test)
|
testImplementation(projects.libraries.preferences.test)
|
||||||
testImplementation(projects.libraries.push.test)
|
testImplementation(projects.libraries.push.test)
|
||||||
testImplementation(projects.libraries.pushproviders.test)
|
testImplementation(projects.libraries.pushproviders.test)
|
||||||
|
testImplementation(projects.libraries.sessionStorage.test)
|
||||||
|
testImplementation(projects.features.announcement.test)
|
||||||
testImplementation(projects.features.forward.test)
|
testImplementation(projects.features.forward.test)
|
||||||
testImplementation(projects.features.messages.test)
|
testImplementation(projects.features.messages.test)
|
||||||
testImplementation(projects.features.networkmonitor.test)
|
testImplementation(projects.features.networkmonitor.test)
|
||||||
|
testImplementation(projects.features.preferences.test)
|
||||||
testImplementation(projects.features.rageshake.test)
|
testImplementation(projects.features.rageshake.test)
|
||||||
|
testImplementation(projects.features.signedout.test)
|
||||||
testImplementation(projects.services.apperror.test)
|
testImplementation(projects.services.apperror.test)
|
||||||
testImplementation(projects.services.appnavstate.test)
|
testImplementation(projects.services.appnavstate.test)
|
||||||
testImplementation(projects.services.analytics.test)
|
testImplementation(projects.services.analytics.test)
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ import io.element.android.compound.colors.SemanticColorsLightDark
|
|||||||
import io.element.android.features.createroom.api.CreateRoomEntryPoint
|
import io.element.android.features.createroom.api.CreateRoomEntryPoint
|
||||||
import io.element.android.features.enterprise.api.EnterpriseService
|
import io.element.android.features.enterprise.api.EnterpriseService
|
||||||
import io.element.android.features.enterprise.api.SessionEnterpriseService
|
import io.element.android.features.enterprise.api.SessionEnterpriseService
|
||||||
import io.element.android.features.enterprise.api.remoteconfig.RemoteEnterpriseConfigProvider
|
import io.element.android.features.enterprise.api.remoteconfig.CustomMapTilerConfigProvider
|
||||||
import io.element.android.features.ftue.api.FtueEntryPoint
|
import io.element.android.features.ftue.api.FtueEntryPoint
|
||||||
import io.element.android.features.ftue.api.state.FtueService
|
import io.element.android.features.ftue.api.state.FtueService
|
||||||
import io.element.android.features.ftue.api.state.FtueState
|
import io.element.android.features.ftue.api.state.FtueState
|
||||||
@@ -157,7 +157,7 @@ class LoggedInFlowNode(
|
|||||||
private val analyticsRoomListStateWatcher: AnalyticsRoomListStateWatcher,
|
private val analyticsRoomListStateWatcher: AnalyticsRoomListStateWatcher,
|
||||||
private val createRoomEntryPoint: CreateRoomEntryPoint,
|
private val createRoomEntryPoint: CreateRoomEntryPoint,
|
||||||
private val activeLiveLocationShareManager: ActiveLiveLocationShareManager,
|
private val activeLiveLocationShareManager: ActiveLiveLocationShareManager,
|
||||||
private val remoteEnterpriseConfigProvider: RemoteEnterpriseConfigProvider,
|
private val customMapTilerConfigProvider: CustomMapTilerConfigProvider,
|
||||||
) : BaseFlowNode<LoggedInFlowNode.NavTarget>(
|
) : BaseFlowNode<LoggedInFlowNode.NavTarget>(
|
||||||
backstack = BackStack(
|
backstack = BackStack(
|
||||||
initialElement = NavTarget.Placeholder,
|
initialElement = NavTarget.Placeholder,
|
||||||
@@ -335,11 +335,11 @@ class LoggedInFlowNode(
|
|||||||
}
|
}
|
||||||
NavTarget.Home -> {
|
NavTarget.Home -> {
|
||||||
val callback = object : HomeEntryPoint.Callback {
|
val callback = object : HomeEntryPoint.Callback {
|
||||||
override fun navigateToRoom(roomId: RoomId, joinedRoom: JoinedRoom?) {
|
override fun navigateToRoom(roomId: RoomId, eventId: EventId?, joinedRoom: JoinedRoom?) {
|
||||||
lifecycleScope.launch {
|
lifecycleScope.launch {
|
||||||
attachRoom(
|
attachRoom(
|
||||||
roomIdOrAlias = roomId.toRoomIdOrAlias(),
|
roomIdOrAlias = roomId.toRoomIdOrAlias(),
|
||||||
initialElement = RoomNavigationTarget.Root(joinedRoom = joinedRoom),
|
initialElement = RoomNavigationTarget.Root(joinedRoom = joinedRoom, eventId = eventId),
|
||||||
clearBackstack = false,
|
clearBackstack = false,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -685,7 +685,7 @@ class LoggedInFlowNode(
|
|||||||
|
|
||||||
val currentMapTilerConfig = LocalMapTilerConfig.current
|
val currentMapTilerConfig = LocalMapTilerConfig.current
|
||||||
val updatedMapTilerConfig by produceState(currentMapTilerConfig) {
|
val updatedMapTilerConfig by produceState(currentMapTilerConfig) {
|
||||||
value = remoteEnterpriseConfigProvider.get(matrixClient.sessionId).dataOrNull()?.mapTilerConfig ?: currentMapTilerConfig
|
value = customMapTilerConfigProvider.get().getOrNull() ?: currentMapTilerConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
ElementThemeApp(
|
ElementThemeApp(
|
||||||
|
|||||||
@@ -32,7 +32,6 @@ import dev.zacsweers.metro.Assisted
|
|||||||
import dev.zacsweers.metro.AssistedInject
|
import dev.zacsweers.metro.AssistedInject
|
||||||
import im.vector.app.features.analytics.plan.JoinedRoom
|
import im.vector.app.features.analytics.plan.JoinedRoom
|
||||||
import io.element.android.annotations.ContributesNode
|
import io.element.android.annotations.ContributesNode
|
||||||
import io.element.android.appnav.di.MatrixSessionCache
|
|
||||||
import io.element.android.appnav.intent.IntentResolver
|
import io.element.android.appnav.intent.IntentResolver
|
||||||
import io.element.android.appnav.intent.ResolvedIntent
|
import io.element.android.appnav.intent.ResolvedIntent
|
||||||
import io.element.android.appnav.room.RoomFlowNode
|
import io.element.android.appnav.room.RoomFlowNode
|
||||||
@@ -40,6 +39,7 @@ import io.element.android.appnav.room.RoomNavigationTarget
|
|||||||
import io.element.android.appnav.root.RootNavStateFlowFactory
|
import io.element.android.appnav.root.RootNavStateFlowFactory
|
||||||
import io.element.android.appnav.root.RootPresenter
|
import io.element.android.appnav.root.RootPresenter
|
||||||
import io.element.android.appnav.root.RootView
|
import io.element.android.appnav.root.RootView
|
||||||
|
import io.element.android.appnav.session.MatrixSessionCache
|
||||||
import io.element.android.features.announcement.api.AnnouncementService
|
import io.element.android.features.announcement.api.AnnouncementService
|
||||||
import io.element.android.features.login.api.LoginParams
|
import io.element.android.features.login.api.LoginParams
|
||||||
import io.element.android.features.login.api.accesscontrol.AccountProviderAccessControl
|
import io.element.android.features.login.api.accesscontrol.AccountProviderAccessControl
|
||||||
@@ -109,6 +109,13 @@ class RootFlowNode(
|
|||||||
buildContext = buildContext,
|
buildContext = buildContext,
|
||||||
plugins = plugins
|
plugins = plugins
|
||||||
) {
|
) {
|
||||||
|
/**
|
||||||
|
* Login params coming from a launch or new [Intent], waiting to be consumed by the not logged in flow.
|
||||||
|
* Kept here so that the root nav target can be computed from both the logged in state and the pending
|
||||||
|
* login params, whatever the order in which the intent and the first nav state emission are processed.
|
||||||
|
*/
|
||||||
|
private var pendingLoginParams: LoginParams? = null
|
||||||
|
|
||||||
override fun onBuilt() {
|
override fun onBuilt() {
|
||||||
analyticsColdStartWatcher.start()
|
analyticsColdStartWatcher.start()
|
||||||
appCoroutineScope.launch {
|
appCoroutineScope.launch {
|
||||||
@@ -152,7 +159,7 @@ class RootFlowNode(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
LoggedInState.NotLoggedIn -> {
|
LoggedInState.NotLoggedIn -> {
|
||||||
switchToNotLoggedInFlow(null)
|
switchToNotLoggedInFlow(pendingLoginParams)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -194,15 +201,18 @@ class RootFlowNode(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun switchToLoggedInFlow(sessionId: SessionId, navId: Int) {
|
private fun switchToLoggedInFlow(sessionId: SessionId, navId: Int) {
|
||||||
|
pendingLoginParams = null
|
||||||
backstack.safeRoot(NavTarget.LoggedInFlow(sessionId, navId))
|
backstack.safeRoot(NavTarget.LoggedInFlow(sessionId, navId))
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun switchToNotLoggedInFlow(params: LoginParams?) {
|
private fun switchToNotLoggedInFlow(params: LoginParams?) {
|
||||||
|
Timber.d("switchToNotLoggedInFlow, hasLoginParams=${params != null}")
|
||||||
matrixSessionCache.removeAll()
|
matrixSessionCache.removeAll()
|
||||||
backstack.safeRoot(NavTarget.NotLoggedInFlow(params))
|
backstack.safeRoot(NavTarget.NotLoggedInFlow(params))
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun switchToSignedOutFlow(sessionId: SessionId) {
|
private fun switchToSignedOutFlow(sessionId: SessionId) {
|
||||||
|
pendingLoginParams = null
|
||||||
backstack.safeRoot(NavTarget.SignedOutFlow(sessionId))
|
backstack.safeRoot(NavTarget.SignedOutFlow(sessionId))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -319,6 +329,7 @@ class RootFlowNode(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onDone() {
|
override fun onDone() {
|
||||||
|
pendingLoginParams = null
|
||||||
backstack.pop()
|
backstack.pop()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -418,6 +429,7 @@ class RootFlowNode(
|
|||||||
Timber.w("Login link ignored, multi account is disabled")
|
Timber.w("Login link ignored, multi account is disabled")
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
pendingLoginParams = params
|
||||||
switchToNotLoggedInFlow(params)
|
switchToNotLoggedInFlow(params)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -76,6 +76,7 @@ class IntentResolver(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun Intent.canBeIgnored(): Boolean {
|
private fun Intent.canBeIgnored(): Boolean {
|
||||||
|
if (flags and Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY != 0) return true
|
||||||
return action == Intent.ACTION_MAIN &&
|
return action == Intent.ACTION_MAIN &&
|
||||||
categories?.contains(Intent.CATEGORY_LAUNCHER) == true
|
categories?.contains(Intent.CATEGORY_LAUNCHER) == true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ package io.element.android.appnav.root
|
|||||||
import com.bumble.appyx.core.state.MutableSavedStateMap
|
import com.bumble.appyx.core.state.MutableSavedStateMap
|
||||||
import com.bumble.appyx.core.state.SavedStateMap
|
import com.bumble.appyx.core.state.SavedStateMap
|
||||||
import dev.zacsweers.metro.Inject
|
import dev.zacsweers.metro.Inject
|
||||||
import io.element.android.appnav.di.MatrixSessionCache
|
import io.element.android.appnav.session.MatrixSessionCache
|
||||||
import io.element.android.features.preferences.api.CacheService
|
import io.element.android.features.preferences.api.CacheService
|
||||||
import io.element.android.libraries.matrix.ui.media.ImageLoaderHolder
|
import io.element.android.libraries.matrix.ui.media.ImageLoaderHolder
|
||||||
import io.element.android.libraries.preferences.api.store.SessionPreferencesStoreFactory
|
import io.element.android.libraries.preferences.api.store.SessionPreferencesStoreFactory
|
||||||
|
|||||||
+2
-2
@@ -6,7 +6,7 @@
|
|||||||
* Please see LICENSE files in the repository root for full details.
|
* Please see LICENSE files in the repository root for full details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package io.element.android.appnav.di
|
package io.element.android.appnav.session
|
||||||
|
|
||||||
import androidx.annotation.VisibleForTesting
|
import androidx.annotation.VisibleForTesting
|
||||||
import com.bumble.appyx.core.state.MutableSavedStateMap
|
import com.bumble.appyx.core.state.MutableSavedStateMap
|
||||||
@@ -115,7 +115,7 @@ class MatrixSessionCache(
|
|||||||
|
|
||||||
private fun onNewMatrixClient(matrixClient: MatrixClient) {
|
private fun onNewMatrixClient(matrixClient: MatrixClient) {
|
||||||
val syncOrchestrator = syncOrchestratorFactory.create(
|
val syncOrchestrator = syncOrchestratorFactory.create(
|
||||||
syncService = matrixClient.syncService,
|
matrixClient = matrixClient,
|
||||||
sessionCoroutineScope = matrixClient.sessionCoroutineScope,
|
sessionCoroutineScope = matrixClient.sessionCoroutineScope,
|
||||||
)
|
)
|
||||||
sessionIdsToMatrixSession[matrixClient.sessionId] = InMemoryMatrixSession(
|
sessionIdsToMatrixSession[matrixClient.sessionId] = InMemoryMatrixSession(
|
||||||
+12
-5
@@ -6,7 +6,7 @@
|
|||||||
* Please see LICENSE files in the repository root for full details.
|
* Please see LICENSE files in the repository root for full details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package io.element.android.appnav.di
|
package io.element.android.appnav.session
|
||||||
|
|
||||||
import androidx.annotation.VisibleForTesting
|
import androidx.annotation.VisibleForTesting
|
||||||
import dev.zacsweers.metro.Assisted
|
import dev.zacsweers.metro.Assisted
|
||||||
@@ -16,7 +16,7 @@ import io.element.android.features.networkmonitor.api.NetworkMonitor
|
|||||||
import io.element.android.features.networkmonitor.api.NetworkStatus
|
import io.element.android.features.networkmonitor.api.NetworkStatus
|
||||||
import io.element.android.libraries.core.coroutine.CoroutineDispatchers
|
import io.element.android.libraries.core.coroutine.CoroutineDispatchers
|
||||||
import io.element.android.libraries.core.coroutine.childScope
|
import io.element.android.libraries.core.coroutine.childScope
|
||||||
import io.element.android.libraries.matrix.api.sync.SyncService
|
import io.element.android.libraries.matrix.api.MatrixClient
|
||||||
import io.element.android.libraries.matrix.api.sync.SyncState
|
import io.element.android.libraries.matrix.api.sync.SyncState
|
||||||
import io.element.android.services.analytics.api.AnalyticsService
|
import io.element.android.services.analytics.api.AnalyticsService
|
||||||
import io.element.android.services.analytics.api.recordTransaction
|
import io.element.android.services.analytics.api.recordTransaction
|
||||||
@@ -37,7 +37,7 @@ import kotlin.time.Duration.Companion.seconds
|
|||||||
|
|
||||||
@AssistedInject
|
@AssistedInject
|
||||||
class SyncOrchestrator(
|
class SyncOrchestrator(
|
||||||
@Assisted private val syncService: SyncService,
|
@Assisted private val matrixClient: MatrixClient,
|
||||||
@Assisted sessionCoroutineScope: CoroutineScope,
|
@Assisted sessionCoroutineScope: CoroutineScope,
|
||||||
private val appForegroundStateService: AppForegroundStateService,
|
private val appForegroundStateService: AppForegroundStateService,
|
||||||
private val networkMonitor: NetworkMonitor,
|
private val networkMonitor: NetworkMonitor,
|
||||||
@@ -47,13 +47,15 @@ class SyncOrchestrator(
|
|||||||
@AssistedFactory
|
@AssistedFactory
|
||||||
interface Factory {
|
interface Factory {
|
||||||
fun create(
|
fun create(
|
||||||
syncService: SyncService,
|
matrixClient: MatrixClient,
|
||||||
sessionCoroutineScope: CoroutineScope,
|
sessionCoroutineScope: CoroutineScope,
|
||||||
): SyncOrchestrator
|
): SyncOrchestrator
|
||||||
}
|
}
|
||||||
|
|
||||||
private val tag = "SyncOrchestrator"
|
private val tag = "SyncOrchestrator"
|
||||||
|
|
||||||
|
private val syncService = matrixClient.syncService
|
||||||
|
|
||||||
private val coroutineScope = sessionCoroutineScope.childScope(dispatchers.io, tag)
|
private val coroutineScope = sessionCoroutineScope.childScope(dispatchers.io, tag)
|
||||||
|
|
||||||
private val started = AtomicBoolean(false)
|
private val started = AtomicBoolean(false)
|
||||||
@@ -94,7 +96,7 @@ class SyncOrchestrator(
|
|||||||
appForegroundStateService.isInCall,
|
appForegroundStateService.isInCall,
|
||||||
appForegroundStateService.isSyncingNotificationEvent,
|
appForegroundStateService.isSyncingNotificationEvent,
|
||||||
appForegroundStateService.hasRingingCall,
|
appForegroundStateService.hasRingingCall,
|
||||||
appForegroundStateService.isSharingLiveLocation
|
appForegroundStateService.isSharingLiveLocation,
|
||||||
)
|
)
|
||||||
val isAppActiveFlow = combine(isAppActiveFlows) { actives -> actives.any { it } }
|
val isAppActiveFlow = combine(isAppActiveFlows) { actives -> actives.any { it } }
|
||||||
combine(
|
combine(
|
||||||
@@ -103,6 +105,11 @@ class SyncOrchestrator(
|
|||||||
networkMonitor.connectivity,
|
networkMonitor.connectivity,
|
||||||
isAppActiveFlow,
|
isAppActiveFlow,
|
||||||
) { syncState, networkState, isAppActive ->
|
) { syncState, networkState, isAppActive ->
|
||||||
|
if (matrixClient.isShuttingDown) {
|
||||||
|
Timber.tag(tag).d("Matrix client is shutting down, no need to start the sync service again")
|
||||||
|
return@combine SyncStateAction.NoOp
|
||||||
|
}
|
||||||
|
|
||||||
val isNetworkAvailable = networkState == NetworkStatus.Connected
|
val isNetworkAvailable = networkState == NetworkStatus.Connected
|
||||||
|
|
||||||
Timber.tag(tag).d("isAppActive=$isAppActive, isNetworkAvailable=$isNetworkAvailable")
|
Timber.tag(tag).d("isAppActive=$isAppActive, isNetworkAvailable=$isNetworkAvailable")
|
||||||
@@ -0,0 +1,189 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2026 Element Creations Ltd.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial.
|
||||||
|
* Please see LICENSE files in the repository root for full details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
@file:OptIn(ExperimentalCoroutinesApi::class)
|
||||||
|
|
||||||
|
package io.element.android.appnav
|
||||||
|
|
||||||
|
import android.content.Intent
|
||||||
|
import android.net.Uri
|
||||||
|
import androidx.arch.core.executor.testing.InstantTaskExecutorRule
|
||||||
|
import com.bumble.appyx.core.modality.AncestryInfo
|
||||||
|
import com.bumble.appyx.core.modality.BuildContext
|
||||||
|
import com.bumble.appyx.core.node.node
|
||||||
|
import com.bumble.appyx.navmodel.backstack.activeElement
|
||||||
|
import com.bumble.appyx.testing.junit4.util.MainDispatcherRule
|
||||||
|
import com.bumble.appyx.testing.unit.common.helper.parentNodeTestHelper
|
||||||
|
import com.bumble.appyx.utils.customisations.NodeCustomisationDirectoryImpl
|
||||||
|
import com.google.common.truth.Truth.assertThat
|
||||||
|
import io.element.android.appnav.intent.IntentResolver
|
||||||
|
import io.element.android.appnav.root.RootNavStateFlowFactory
|
||||||
|
import io.element.android.appnav.root.RootPresenter
|
||||||
|
import io.element.android.appnav.session.FakeSyncOrchestratorFactory
|
||||||
|
import io.element.android.appnav.session.MatrixSessionCache
|
||||||
|
import io.element.android.features.login.api.LoginEntryPoint
|
||||||
|
import io.element.android.features.login.api.LoginParams
|
||||||
|
import io.element.android.features.login.test.FakeLoginEntryPoint
|
||||||
|
import io.element.android.features.login.test.FakeLoginIntentResolver
|
||||||
|
import io.element.android.features.login.test.accesscontrol.FakeAccountProviderAccessControl
|
||||||
|
import io.element.android.features.preferences.test.FakeCacheService
|
||||||
|
import io.element.android.features.rageshake.test.FakeBugReportEntryPoint
|
||||||
|
import io.element.android.features.rageshake.test.logs.FakeAnnouncementService
|
||||||
|
import io.element.android.features.share.test.FakeShareIntentHandler
|
||||||
|
import io.element.android.features.signedout.test.FakeSignedOutEntryPoint
|
||||||
|
import io.element.android.libraries.accountselect.test.FakeAccountSelectEntryPoint
|
||||||
|
import io.element.android.libraries.architecture.AssistedNodeFactory
|
||||||
|
import io.element.android.libraries.featureflag.test.FakeFeatureFlagService
|
||||||
|
import io.element.android.libraries.matrix.test.FakeSdkMetadata
|
||||||
|
import io.element.android.libraries.matrix.test.auth.FakeMatrixAuthenticationService
|
||||||
|
import io.element.android.libraries.matrix.test.permalink.FakePermalinkParser
|
||||||
|
import io.element.android.libraries.matrix.ui.media.test.FakeImageLoaderHolder
|
||||||
|
import io.element.android.libraries.oauth.test.FakeOAuthActionFlow
|
||||||
|
import io.element.android.libraries.oauth.test.FakeOAuthIntentResolver
|
||||||
|
import io.element.android.libraries.preferences.test.FakeSessionPreferencesStoreFactory
|
||||||
|
import io.element.android.libraries.sessionstorage.api.SessionStore
|
||||||
|
import io.element.android.libraries.sessionstorage.test.InMemorySessionStore
|
||||||
|
import io.element.android.services.analytics.test.FakeAnalyticsService
|
||||||
|
import io.element.android.services.analytics.test.watchers.FakeAnalyticsColdStartWatcher
|
||||||
|
import io.element.android.services.apperror.test.FakeAppErrorStateService
|
||||||
|
import io.element.android.tests.testutils.node.FakeNodeFactoriesBindings
|
||||||
|
import io.element.android.tests.testutils.node.FakeParentNode
|
||||||
|
import io.element.android.tests.testutils.presenter.NotUsedPresenter
|
||||||
|
import io.element.android.tests.testutils.robolectric.RobolectricTest
|
||||||
|
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||||
|
import kotlinx.coroutines.test.TestScope
|
||||||
|
import kotlinx.coroutines.test.runCurrent
|
||||||
|
import kotlinx.coroutines.test.runTest
|
||||||
|
import org.junit.Rule
|
||||||
|
import org.junit.Test
|
||||||
|
|
||||||
|
private const val A_LOGIN_LINK = "https://mobile.element.io/element/?account_provider=example.com&login_hint=mxid:@alice:example.com"
|
||||||
|
|
||||||
|
private val A_LOGIN_PARAMS = LoginParams(
|
||||||
|
accountProvider = "example.com",
|
||||||
|
loginHint = "mxid:@alice:example.com",
|
||||||
|
)
|
||||||
|
|
||||||
|
private val A_LOGIN_ENTRY_POINT_PARAMS = LoginEntryPoint.Params(
|
||||||
|
accountProvider = A_LOGIN_PARAMS.accountProvider,
|
||||||
|
loginHint = A_LOGIN_PARAMS.loginHint,
|
||||||
|
)
|
||||||
|
|
||||||
|
class RootFlowNodeTest : RobolectricTest() {
|
||||||
|
@get:Rule
|
||||||
|
val instantTaskExecutorRule = InstantTaskExecutorRule()
|
||||||
|
|
||||||
|
@get:Rule
|
||||||
|
val mainDispatcherRule = MainDispatcherRule()
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `given no session, when a login link is handled before the nav state is observed, then the login params are kept`() = runTest {
|
||||||
|
var loginEntryPointParams: LoginEntryPoint.Params? = null
|
||||||
|
val rootFlowNode = createRootFlowNode(
|
||||||
|
loginEntryPoint = FakeLoginEntryPoint { buildContext, params ->
|
||||||
|
loginEntryPointParams = params
|
||||||
|
node(buildContext) {}
|
||||||
|
},
|
||||||
|
)
|
||||||
|
rootFlowNode.parentNodeTestHelper()
|
||||||
|
// The intent is handled first, this is what happens when the deep link cold starts the app.
|
||||||
|
rootFlowNode.handleIntent(aLoginIntent())
|
||||||
|
assertThat(rootFlowNode.backstack.activeElement).isEqualTo(RootFlowNode.NavTarget.NotLoggedInFlow(A_LOGIN_PARAMS))
|
||||||
|
// Then the first nav state emission lands, it must not override the login params.
|
||||||
|
runCurrent()
|
||||||
|
assertThat(rootFlowNode.backstack.activeElement).isEqualTo(RootFlowNode.NavTarget.NotLoggedInFlow(A_LOGIN_PARAMS))
|
||||||
|
assertThat(loginEntryPointParams).isEqualTo(A_LOGIN_ENTRY_POINT_PARAMS)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `given no session, when a login link is handled after the nav state is observed, then the login params are applied`() = runTest {
|
||||||
|
var loginEntryPointParams: LoginEntryPoint.Params? = null
|
||||||
|
val rootFlowNode = createRootFlowNode(
|
||||||
|
loginEntryPoint = FakeLoginEntryPoint { buildContext, params ->
|
||||||
|
loginEntryPointParams = params
|
||||||
|
node(buildContext) {}
|
||||||
|
},
|
||||||
|
)
|
||||||
|
rootFlowNode.parentNodeTestHelper()
|
||||||
|
// The nav state is observed first, this is what happens when the app is already running.
|
||||||
|
runCurrent()
|
||||||
|
assertThat(rootFlowNode.backstack.activeElement).isEqualTo(RootFlowNode.NavTarget.NotLoggedInFlow(null))
|
||||||
|
rootFlowNode.handleIntent(aLoginIntent())
|
||||||
|
runCurrent()
|
||||||
|
assertThat(rootFlowNode.backstack.activeElement).isEqualTo(RootFlowNode.NavTarget.NotLoggedInFlow(A_LOGIN_PARAMS))
|
||||||
|
assertThat(loginEntryPointParams).isEqualTo(A_LOGIN_ENTRY_POINT_PARAMS)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun aLoginIntent() = Intent(Intent.ACTION_VIEW, Uri.parse(A_LOGIN_LINK))
|
||||||
|
|
||||||
|
private fun TestScope.createRootFlowNode(
|
||||||
|
loginEntryPoint: LoginEntryPoint,
|
||||||
|
sessionStore: SessionStore = InMemorySessionStore(),
|
||||||
|
): RootFlowNode {
|
||||||
|
val matrixSessionCache = MatrixSessionCache(
|
||||||
|
authenticationService = FakeMatrixAuthenticationService(),
|
||||||
|
syncOrchestratorFactory = FakeSyncOrchestratorFactory(),
|
||||||
|
analyticsService = FakeAnalyticsService(),
|
||||||
|
)
|
||||||
|
val parentNode = FakeParentNode(
|
||||||
|
graph = FakeNodeFactoriesBindings(
|
||||||
|
mapOf(
|
||||||
|
NotLoggedInFlowNode::class to AssistedNodeFactory { buildContext, plugins ->
|
||||||
|
NotLoggedInFlowNode(
|
||||||
|
buildContext = buildContext,
|
||||||
|
plugins = plugins,
|
||||||
|
loginEntryPoint = loginEntryPoint,
|
||||||
|
imageLoaderHolder = FakeImageLoaderHolder(),
|
||||||
|
analyticsColdStartWatcher = FakeAnalyticsColdStartWatcher(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
return RootFlowNode(
|
||||||
|
buildContext = BuildContext(
|
||||||
|
ancestryInfo = AncestryInfo.Child(anchor = parentNode),
|
||||||
|
savedStateMap = null,
|
||||||
|
customisations = NodeCustomisationDirectoryImpl(),
|
||||||
|
),
|
||||||
|
plugins = emptyList(),
|
||||||
|
sessionStore = sessionStore,
|
||||||
|
accountProviderAccessControl = FakeAccountProviderAccessControl { true },
|
||||||
|
navStateFlowFactory = RootNavStateFlowFactory(
|
||||||
|
sessionStore = sessionStore,
|
||||||
|
cacheService = FakeCacheService(),
|
||||||
|
matrixSessionCache = matrixSessionCache,
|
||||||
|
imageLoaderHolder = FakeImageLoaderHolder(),
|
||||||
|
sessionPreferencesStoreFactory = FakeSessionPreferencesStoreFactory(),
|
||||||
|
),
|
||||||
|
matrixSessionCache = matrixSessionCache,
|
||||||
|
presenter = RootPresenter(
|
||||||
|
crashDetectionPresenter = NotUsedPresenter(),
|
||||||
|
rageshakeDetectionPresenter = NotUsedPresenter(),
|
||||||
|
appErrorStateService = FakeAppErrorStateService(),
|
||||||
|
analyticsService = FakeAnalyticsService(),
|
||||||
|
sdkMetadata = FakeSdkMetadata("sha"),
|
||||||
|
),
|
||||||
|
bugReportEntryPoint = FakeBugReportEntryPoint(),
|
||||||
|
signedOutEntryPoint = FakeSignedOutEntryPoint(),
|
||||||
|
accountSelectEntryPoint = FakeAccountSelectEntryPoint(),
|
||||||
|
intentResolver = IntentResolver(
|
||||||
|
deeplinkParser = { null },
|
||||||
|
loginIntentResolver = FakeLoginIntentResolver { A_LOGIN_PARAMS },
|
||||||
|
oAuthIntentResolver = FakeOAuthIntentResolver { null },
|
||||||
|
permalinkParser = FakePermalinkParser(),
|
||||||
|
shareIntentHandler = FakeShareIntentHandler(),
|
||||||
|
),
|
||||||
|
oAuthActionFlow = FakeOAuthActionFlow(),
|
||||||
|
featureFlagService = FakeFeatureFlagService(),
|
||||||
|
announcementService = FakeAnnouncementService(),
|
||||||
|
analyticsService = FakeAnalyticsService(),
|
||||||
|
analyticsColdStartWatcher = FakeAnalyticsColdStartWatcher(),
|
||||||
|
appCoroutineScope = backgroundScope,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,10 +8,11 @@
|
|||||||
|
|
||||||
package io.element.android.appnav
|
package io.element.android.appnav
|
||||||
|
|
||||||
import io.element.android.appnav.di.SyncOrchestrator
|
import io.element.android.appnav.session.SyncOrchestrator
|
||||||
import io.element.android.features.networkmonitor.api.NetworkStatus
|
import io.element.android.features.networkmonitor.api.NetworkStatus
|
||||||
import io.element.android.features.networkmonitor.test.FakeNetworkMonitor
|
import io.element.android.features.networkmonitor.test.FakeNetworkMonitor
|
||||||
import io.element.android.libraries.matrix.api.sync.SyncState
|
import io.element.android.libraries.matrix.api.sync.SyncState
|
||||||
|
import io.element.android.libraries.matrix.test.FakeMatrixClient
|
||||||
import io.element.android.libraries.matrix.test.sync.FakeSyncService
|
import io.element.android.libraries.matrix.test.sync.FakeSyncService
|
||||||
import io.element.android.services.analytics.test.FakeAnalyticsService
|
import io.element.android.services.analytics.test.FakeAnalyticsService
|
||||||
import io.element.android.services.appnavstate.test.FakeAppForegroundStateService
|
import io.element.android.services.appnavstate.test.FakeAppForegroundStateService
|
||||||
@@ -40,7 +41,7 @@ class SyncOrchestratorTest {
|
|||||||
}
|
}
|
||||||
val networkMonitor = FakeNetworkMonitor(initialStatus = NetworkStatus.Disconnected)
|
val networkMonitor = FakeNetworkMonitor(initialStatus = NetworkStatus.Disconnected)
|
||||||
val syncOrchestrator = createSyncOrchestrator(
|
val syncOrchestrator = createSyncOrchestrator(
|
||||||
syncService = syncService,
|
matrixClient = FakeMatrixClient(syncService = syncService),
|
||||||
networkMonitor = networkMonitor,
|
networkMonitor = networkMonitor,
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -60,7 +61,7 @@ class SyncOrchestratorTest {
|
|||||||
}
|
}
|
||||||
val networkMonitor = FakeNetworkMonitor(initialStatus = NetworkStatus.Connected)
|
val networkMonitor = FakeNetworkMonitor(initialStatus = NetworkStatus.Connected)
|
||||||
val syncOrchestrator = createSyncOrchestrator(
|
val syncOrchestrator = createSyncOrchestrator(
|
||||||
syncService = syncService,
|
matrixClient = FakeMatrixClient(syncService = syncService),
|
||||||
networkMonitor = networkMonitor,
|
networkMonitor = networkMonitor,
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -85,7 +86,7 @@ class SyncOrchestratorTest {
|
|||||||
val networkMonitor = FakeNetworkMonitor(initialStatus = NetworkStatus.Connected)
|
val networkMonitor = FakeNetworkMonitor(initialStatus = NetworkStatus.Connected)
|
||||||
val appForegroundStateService = FakeAppForegroundStateService(initialForegroundValue = true)
|
val appForegroundStateService = FakeAppForegroundStateService(initialForegroundValue = true)
|
||||||
val syncOrchestrator = createSyncOrchestrator(
|
val syncOrchestrator = createSyncOrchestrator(
|
||||||
syncService = syncService,
|
matrixClient = FakeMatrixClient(syncService = syncService),
|
||||||
networkMonitor = networkMonitor,
|
networkMonitor = networkMonitor,
|
||||||
appForegroundStateService = appForegroundStateService,
|
appForegroundStateService = appForegroundStateService,
|
||||||
)
|
)
|
||||||
@@ -117,7 +118,7 @@ class SyncOrchestratorTest {
|
|||||||
val networkMonitor = FakeNetworkMonitor(initialStatus = NetworkStatus.Connected)
|
val networkMonitor = FakeNetworkMonitor(initialStatus = NetworkStatus.Connected)
|
||||||
val appForegroundStateService = FakeAppForegroundStateService(initialForegroundValue = true)
|
val appForegroundStateService = FakeAppForegroundStateService(initialForegroundValue = true)
|
||||||
val syncOrchestrator = createSyncOrchestrator(
|
val syncOrchestrator = createSyncOrchestrator(
|
||||||
syncService = syncService,
|
matrixClient = FakeMatrixClient(syncService = syncService),
|
||||||
networkMonitor = networkMonitor,
|
networkMonitor = networkMonitor,
|
||||||
appForegroundStateService = appForegroundStateService,
|
appForegroundStateService = appForegroundStateService,
|
||||||
)
|
)
|
||||||
@@ -165,7 +166,7 @@ class SyncOrchestratorTest {
|
|||||||
initialIsSyncingNotificationEventValue = false,
|
initialIsSyncingNotificationEventValue = false,
|
||||||
)
|
)
|
||||||
val syncOrchestrator = createSyncOrchestrator(
|
val syncOrchestrator = createSyncOrchestrator(
|
||||||
syncService = syncService,
|
matrixClient = FakeMatrixClient(syncService = syncService),
|
||||||
networkMonitor = networkMonitor,
|
networkMonitor = networkMonitor,
|
||||||
appForegroundStateService = appForegroundStateService,
|
appForegroundStateService = appForegroundStateService,
|
||||||
)
|
)
|
||||||
@@ -208,7 +209,7 @@ class SyncOrchestratorTest {
|
|||||||
initialIsSyncingNotificationEventValue = false,
|
initialIsSyncingNotificationEventValue = false,
|
||||||
)
|
)
|
||||||
val syncOrchestrator = createSyncOrchestrator(
|
val syncOrchestrator = createSyncOrchestrator(
|
||||||
syncService = syncService,
|
matrixClient = FakeMatrixClient(syncService = syncService),
|
||||||
networkMonitor = networkMonitor,
|
networkMonitor = networkMonitor,
|
||||||
appForegroundStateService = appForegroundStateService,
|
appForegroundStateService = appForegroundStateService,
|
||||||
)
|
)
|
||||||
@@ -252,7 +253,7 @@ class SyncOrchestratorTest {
|
|||||||
initialHasRingingCall = false,
|
initialHasRingingCall = false,
|
||||||
)
|
)
|
||||||
val syncOrchestrator = createSyncOrchestrator(
|
val syncOrchestrator = createSyncOrchestrator(
|
||||||
syncService = syncService,
|
matrixClient = FakeMatrixClient(syncService = syncService),
|
||||||
networkMonitor = networkMonitor,
|
networkMonitor = networkMonitor,
|
||||||
appForegroundStateService = appForegroundStateService,
|
appForegroundStateService = appForegroundStateService,
|
||||||
)
|
)
|
||||||
@@ -296,7 +297,7 @@ class SyncOrchestratorTest {
|
|||||||
initialIsInCallValue = true,
|
initialIsInCallValue = true,
|
||||||
)
|
)
|
||||||
val syncOrchestrator = createSyncOrchestrator(
|
val syncOrchestrator = createSyncOrchestrator(
|
||||||
syncService = syncService,
|
matrixClient = FakeMatrixClient(syncService = syncService),
|
||||||
networkMonitor = networkMonitor,
|
networkMonitor = networkMonitor,
|
||||||
appForegroundStateService = appForegroundStateService,
|
appForegroundStateService = appForegroundStateService,
|
||||||
)
|
)
|
||||||
@@ -339,7 +340,7 @@ class SyncOrchestratorTest {
|
|||||||
initialIsInCallValue = false,
|
initialIsInCallValue = false,
|
||||||
)
|
)
|
||||||
val syncOrchestrator = createSyncOrchestrator(
|
val syncOrchestrator = createSyncOrchestrator(
|
||||||
syncService = syncService,
|
matrixClient = FakeMatrixClient(syncService = syncService),
|
||||||
networkMonitor = networkMonitor,
|
networkMonitor = networkMonitor,
|
||||||
appForegroundStateService = appForegroundStateService,
|
appForegroundStateService = appForegroundStateService,
|
||||||
)
|
)
|
||||||
@@ -369,7 +370,7 @@ class SyncOrchestratorTest {
|
|||||||
}
|
}
|
||||||
val networkMonitor = FakeNetworkMonitor(initialStatus = NetworkStatus.Disconnected)
|
val networkMonitor = FakeNetworkMonitor(initialStatus = NetworkStatus.Disconnected)
|
||||||
val syncOrchestrator = createSyncOrchestrator(
|
val syncOrchestrator = createSyncOrchestrator(
|
||||||
syncService = syncService,
|
matrixClient = FakeMatrixClient(syncService = syncService),
|
||||||
networkMonitor = networkMonitor,
|
networkMonitor = networkMonitor,
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -381,12 +382,44 @@ class SyncOrchestratorTest {
|
|||||||
startSyncRecorder.assertions().isNeverCalled()
|
startSyncRecorder.assertions().isNeverCalled()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `when the client is shutting down, the orchestrator does nothing`() = runTest {
|
||||||
|
val networkMonitor = FakeNetworkMonitor(initialStatus = NetworkStatus.Disconnected)
|
||||||
|
val appForegroundStateService = FakeAppForegroundStateService(
|
||||||
|
initialForegroundValue = false,
|
||||||
|
initialIsSyncingNotificationEventValue = false,
|
||||||
|
initialIsInCallValue = false,
|
||||||
|
)
|
||||||
|
|
||||||
|
val startSyncRecorder = lambdaRecorder<Result<Unit>> { Result.success(Unit) }
|
||||||
|
val syncService = FakeSyncService(initialSyncState = SyncState.Idle).apply {
|
||||||
|
startSyncLambda = startSyncRecorder
|
||||||
|
}
|
||||||
|
val syncOrchestrator = createSyncOrchestrator(
|
||||||
|
matrixClient = FakeMatrixClient(syncService = syncService, isShuttingDownResult = { true }),
|
||||||
|
networkMonitor = networkMonitor,
|
||||||
|
appForegroundStateService = appForegroundStateService,
|
||||||
|
)
|
||||||
|
|
||||||
|
// We start observing
|
||||||
|
syncOrchestrator.observeStates()
|
||||||
|
|
||||||
|
// These should still not trigger a sync, sync the client is shutting down
|
||||||
|
networkMonitor.givenNetworkBlocked(false)
|
||||||
|
appForegroundStateService.updateIsInCallState(true)
|
||||||
|
appForegroundStateService.isInForeground.value = true
|
||||||
|
|
||||||
|
advanceTimeBy(10.seconds)
|
||||||
|
|
||||||
|
startSyncRecorder.assertions().isNeverCalled()
|
||||||
|
}
|
||||||
|
|
||||||
private fun TestScope.createSyncOrchestrator(
|
private fun TestScope.createSyncOrchestrator(
|
||||||
syncService: FakeSyncService = FakeSyncService(),
|
matrixClient: FakeMatrixClient = FakeMatrixClient(),
|
||||||
networkMonitor: FakeNetworkMonitor = FakeNetworkMonitor(),
|
networkMonitor: FakeNetworkMonitor = FakeNetworkMonitor(),
|
||||||
appForegroundStateService: FakeAppForegroundStateService = FakeAppForegroundStateService(),
|
appForegroundStateService: FakeAppForegroundStateService = FakeAppForegroundStateService(),
|
||||||
) = SyncOrchestrator(
|
) = SyncOrchestrator(
|
||||||
syncService = syncService,
|
matrixClient = matrixClient,
|
||||||
sessionCoroutineScope = backgroundScope,
|
sessionCoroutineScope = backgroundScope,
|
||||||
networkMonitor = networkMonitor,
|
networkMonitor = networkMonitor,
|
||||||
appForegroundStateService = appForegroundStateService,
|
appForegroundStateService = appForegroundStateService,
|
||||||
|
|||||||
@@ -45,6 +45,24 @@ class IntentResolverTest : RobolectricTest() {
|
|||||||
assertThat(result).isNull()
|
assertThat(result).isNull()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `resolve intent replayed from the history should return null`() {
|
||||||
|
val sut = createIntentResolver(
|
||||||
|
deeplinkParserResult = DeeplinkData.Room(
|
||||||
|
sessionId = A_SESSION_ID,
|
||||||
|
roomId = A_ROOM_ID,
|
||||||
|
threadId = null,
|
||||||
|
eventId = null,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
val intent = Intent(RuntimeEnvironment.getApplication(), Activity::class.java).apply {
|
||||||
|
action = Intent.ACTION_VIEW
|
||||||
|
addFlags(Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY)
|
||||||
|
}
|
||||||
|
val result = sut.resolve(intent)
|
||||||
|
assertThat(result).isNull()
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `test resolve navigation intent root`() {
|
fun `test resolve navigation intent root`() {
|
||||||
val sut = createIntentResolver(
|
val sut = createIntentResolver(
|
||||||
|
|||||||
+19
@@ -0,0 +1,19 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2026 Element Creations Ltd.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial.
|
||||||
|
* Please see LICENSE files in the repository root for full details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package io.element.android.appnav.session
|
||||||
|
|
||||||
|
import io.element.android.libraries.matrix.api.MatrixClient
|
||||||
|
import io.element.android.tests.testutils.lambda.lambdaError
|
||||||
|
import kotlinx.coroutines.CoroutineScope
|
||||||
|
|
||||||
|
class FakeSyncOrchestratorFactory : SyncOrchestrator.Factory {
|
||||||
|
override fun create(
|
||||||
|
matrixClient: MatrixClient,
|
||||||
|
sessionCoroutineScope: CoroutineScope,
|
||||||
|
): SyncOrchestrator = lambdaError()
|
||||||
|
}
|
||||||
+4
-4
@@ -6,12 +6,12 @@
|
|||||||
* Please see LICENSE files in the repository root for full details.
|
* Please see LICENSE files in the repository root for full details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package io.element.android.appnav.di
|
package io.element.android.appnav.session
|
||||||
|
|
||||||
import com.bumble.appyx.core.state.MutableSavedStateMapImpl
|
import com.bumble.appyx.core.state.MutableSavedStateMapImpl
|
||||||
import com.google.common.truth.Truth.assertThat
|
import com.google.common.truth.Truth.assertThat
|
||||||
import io.element.android.features.networkmonitor.test.FakeNetworkMonitor
|
import io.element.android.features.networkmonitor.test.FakeNetworkMonitor
|
||||||
import io.element.android.libraries.matrix.api.sync.SyncService
|
import io.element.android.libraries.matrix.api.MatrixClient
|
||||||
import io.element.android.libraries.matrix.test.A_SESSION_ID
|
import io.element.android.libraries.matrix.test.A_SESSION_ID
|
||||||
import io.element.android.libraries.matrix.test.FakeMatrixClient
|
import io.element.android.libraries.matrix.test.FakeMatrixClient
|
||||||
import io.element.android.libraries.matrix.test.auth.FakeMatrixAuthenticationService
|
import io.element.android.libraries.matrix.test.auth.FakeMatrixAuthenticationService
|
||||||
@@ -138,11 +138,11 @@ class MatrixSessionCacheTest {
|
|||||||
|
|
||||||
return object : SyncOrchestrator.Factory {
|
return object : SyncOrchestrator.Factory {
|
||||||
override fun create(
|
override fun create(
|
||||||
syncService: SyncService,
|
matrixClient: MatrixClient,
|
||||||
sessionCoroutineScope: CoroutineScope,
|
sessionCoroutineScope: CoroutineScope,
|
||||||
): SyncOrchestrator {
|
): SyncOrchestrator {
|
||||||
return SyncOrchestrator(
|
return SyncOrchestrator(
|
||||||
syncService = syncService,
|
matrixClient = matrixClient,
|
||||||
sessionCoroutineScope = sessionCoroutineScope,
|
sessionCoroutineScope = sessionCoroutineScope,
|
||||||
appForegroundStateService = FakeAppForegroundStateService(),
|
appForegroundStateService = FakeAppForegroundStateService(),
|
||||||
networkMonitor = FakeNetworkMonitor(),
|
networkMonitor = FakeNetworkMonitor(),
|
||||||
+1
-1
@@ -98,7 +98,7 @@ allprojects {
|
|||||||
// This is disabled by default, but the CI will enforce this.
|
// This is disabled by default, but the CI will enforce this.
|
||||||
// You can override by passing `-PallWarningsAsErrors=true` in the command line
|
// You can override by passing `-PallWarningsAsErrors=true` in the command line
|
||||||
// Or add a line with "allWarningsAsErrors=true" in your ~/.gradle/gradle.properties file
|
// Or add a line with "allWarningsAsErrors=true" in your ~/.gradle/gradle.properties file
|
||||||
allWarningsAsErrors = project.properties["allWarningsAsErrors"] == "true"
|
allWarningsAsErrors = findProperty("allWarningsAsErrors") == "true"
|
||||||
|
|
||||||
// Uncomment to suppress Compose Kotlin compiler compatibility warning
|
// Uncomment to suppress Compose Kotlin compiler compatibility warning
|
||||||
// freeCompilerArgs.addAll(listOf("-P", "plugin:androidx.compose.compiler.plugins.kotlin:suppressKotlinVersionCompatibilityCheck=true"))
|
// freeCompilerArgs.addAll(listOf("-P", "plugin:androidx.compose.compiler.plugins.kotlin:suppressKotlinVersionCompatibilityCheck=true"))
|
||||||
|
|||||||
+1
-1
Submodule enterprise updated: f5f910856c...ae0001a17d
@@ -0,0 +1,2 @@
|
|||||||
|
Main changes in this version: bug fixes and improvements.
|
||||||
|
Full changelog: https://github.com/element-hq/element-x-android/releases
|
||||||
+2
@@ -11,7 +11,9 @@ package io.element.android.features.call.impl.pip
|
|||||||
import io.element.android.features.call.impl.utils.PipController
|
import io.element.android.features.call.impl.utils.PipController
|
||||||
|
|
||||||
sealed interface PictureInPictureEvent {
|
sealed interface PictureInPictureEvent {
|
||||||
|
data object OnCallStarted : PictureInPictureEvent
|
||||||
data class SetPipController(val pipController: PipController) : PictureInPictureEvent
|
data class SetPipController(val pipController: PipController) : PictureInPictureEvent
|
||||||
data object EnterPictureInPicture : PictureInPictureEvent
|
data object EnterPictureInPicture : PictureInPictureEvent
|
||||||
data class OnPictureInPictureModeChanged(val isInPip: Boolean) : PictureInPictureEvent
|
data class OnPictureInPictureModeChanged(val isInPip: Boolean) : PictureInPictureEvent
|
||||||
|
data class SetPipOrientation(val orientation: Int?) : PictureInPictureEvent
|
||||||
}
|
}
|
||||||
|
|||||||
+7
@@ -38,6 +38,9 @@ class PictureInPicturePresenter(
|
|||||||
|
|
||||||
fun handleEvent(event: PictureInPictureEvent) {
|
fun handleEvent(event: PictureInPictureEvent) {
|
||||||
when (event) {
|
when (event) {
|
||||||
|
is PictureInPictureEvent.OnCallStarted -> {
|
||||||
|
pipController?.setupPipCallbacks()
|
||||||
|
}
|
||||||
is PictureInPictureEvent.SetPipController -> {
|
is PictureInPictureEvent.SetPipController -> {
|
||||||
pipController = event.pipController
|
pipController = event.pipController
|
||||||
}
|
}
|
||||||
@@ -55,6 +58,10 @@ class PictureInPicturePresenter(
|
|||||||
pipController?.exitPip()
|
pipController?.exitPip()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
is PictureInPictureEvent.SetPipOrientation -> {
|
||||||
|
Timber.tag(loggerTag.value).d("onOrientationChange: ${event.orientation}")
|
||||||
|
pipView?.setPipOrientation(event.orientation)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
@@ -9,6 +9,7 @@
|
|||||||
package io.element.android.features.call.impl.pip
|
package io.element.android.features.call.impl.pip
|
||||||
|
|
||||||
interface PipView {
|
interface PipView {
|
||||||
|
fun setPipOrientation(orientation: Int?)
|
||||||
fun setPipParams()
|
fun setPipParams()
|
||||||
fun enterPipMode(): Boolean
|
fun enterPipMode(): Boolean
|
||||||
fun hangUp()
|
fun hangUp()
|
||||||
|
|||||||
+7
-1
@@ -118,6 +118,7 @@ internal fun CallScreenView(
|
|||||||
if (webViewAudioManager?.isInCallMode?.get() == false) {
|
if (webViewAudioManager?.isInCallMode?.get() == false) {
|
||||||
Timber.d("URL $url is loaded, starting in-call audio mode")
|
Timber.d("URL $url is loaded, starting in-call audio mode")
|
||||||
webViewAudioManager?.onCallStarted()
|
webViewAudioManager?.onCallStarted()
|
||||||
|
pipState.eventSink(PictureInPictureEvent.OnCallStarted)
|
||||||
} else {
|
} else {
|
||||||
Timber.d("Can't start in-call audio mode since the app is already in it.")
|
Timber.d("Can't start in-call audio mode since the app is already in it.")
|
||||||
}
|
}
|
||||||
@@ -130,7 +131,12 @@ internal fun CallScreenView(
|
|||||||
onInvalidAudioDeviceAdded = { invalidAudioDeviceReason = it },
|
onInvalidAudioDeviceAdded = { invalidAudioDeviceReason = it },
|
||||||
)
|
)
|
||||||
state.eventSink(CallScreenEvent.SetupMessageChannels(interceptor))
|
state.eventSink(CallScreenEvent.SetupMessageChannels(interceptor))
|
||||||
val pipController = WebViewPipController(webView)
|
val pipController = WebViewPipController(
|
||||||
|
webView = webView,
|
||||||
|
updatePipOrientation = { orientation ->
|
||||||
|
pipState.eventSink(PictureInPictureEvent.SetPipOrientation(orientation))
|
||||||
|
}
|
||||||
|
)
|
||||||
pipState.eventSink(PictureInPictureEvent.SetPipController(pipController))
|
pipState.eventSink(PictureInPictureEvent.SetPipController(pipController))
|
||||||
},
|
},
|
||||||
onDestroyWebView = {
|
onDestroyWebView = {
|
||||||
|
|||||||
+13
-3
@@ -11,9 +11,9 @@ package io.element.android.features.call.impl.ui
|
|||||||
import android.Manifest
|
import android.Manifest
|
||||||
import android.app.PictureInPictureParams
|
import android.app.PictureInPictureParams
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
|
import android.content.res.Configuration
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.util.Rational
|
|
||||||
import android.view.WindowManager
|
import android.view.WindowManager
|
||||||
import android.webkit.PermissionRequest
|
import android.webkit.PermissionRequest
|
||||||
import androidx.activity.compose.setContent
|
import androidx.activity.compose.setContent
|
||||||
@@ -49,6 +49,7 @@ import io.element.android.features.call.impl.pip.PipView
|
|||||||
import io.element.android.features.call.impl.services.CallForegroundService
|
import io.element.android.features.call.impl.services.CallForegroundService
|
||||||
import io.element.android.features.enterprise.api.EnterpriseService
|
import io.element.android.features.enterprise.api.EnterpriseService
|
||||||
import io.element.android.libraries.androidutils.browser.ConsoleMessageLogger
|
import io.element.android.libraries.androidutils.browser.ConsoleMessageLogger
|
||||||
|
import io.element.android.libraries.androidutils.media.setAspectRatioFromOrientation
|
||||||
import io.element.android.libraries.architecture.Presenter
|
import io.element.android.libraries.architecture.Presenter
|
||||||
import io.element.android.libraries.architecture.bindings
|
import io.element.android.libraries.architecture.bindings
|
||||||
import io.element.android.libraries.audio.api.AudioFocus
|
import io.element.android.libraries.audio.api.AudioFocus
|
||||||
@@ -86,6 +87,8 @@ class ElementCallActivity :
|
|||||||
|
|
||||||
private var eventSink: ((CallScreenEvent) -> Unit)? = null
|
private var eventSink: ((CallScreenEvent) -> Unit)? = null
|
||||||
|
|
||||||
|
private var currentPipOrientation: Int? = null
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
|
|
||||||
@@ -199,6 +202,7 @@ class ElementCallActivity :
|
|||||||
}
|
}
|
||||||
DisposableEffect(Unit) {
|
DisposableEffect(Unit) {
|
||||||
val onPictureInPictureModeChangedListener = Consumer { _: PictureInPictureModeChangedInfo ->
|
val onPictureInPictureModeChangedListener = Consumer { _: PictureInPictureModeChangedInfo ->
|
||||||
|
setPipParams()
|
||||||
pipEventSink(PictureInPictureEvent.OnPictureInPictureModeChanged(isInPictureInPictureMode))
|
pipEventSink(PictureInPictureEvent.OnPictureInPictureModeChanged(isInPictureInPictureMode))
|
||||||
if (!isInPictureInPictureMode && !lifecycle.currentState.isAtLeast(Lifecycle.State.STARTED)) {
|
if (!isInPictureInPictureMode && !lifecycle.currentState.isAtLeast(Lifecycle.State.STARTED)) {
|
||||||
Timber.tag(loggerTag.value).d("Exiting PiP mode: Hangup the call")
|
Timber.tag(loggerTag.value).d("Exiting PiP mode: Hangup the call")
|
||||||
@@ -296,11 +300,17 @@ class ElementCallActivity :
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun setPipOrientation(orientation: Int?) {
|
||||||
|
currentPipOrientation = orientation
|
||||||
|
setPictureInPictureParams(getPictureInPictureParams())
|
||||||
|
}
|
||||||
|
|
||||||
@RequiresApi(Build.VERSION_CODES.O)
|
@RequiresApi(Build.VERSION_CODES.O)
|
||||||
private fun getPictureInPictureParams(): PictureInPictureParams {
|
private fun getPictureInPictureParams(): PictureInPictureParams {
|
||||||
|
// Portrait for calls seems more appropriate as a fallback value
|
||||||
|
val orientation = currentPipOrientation ?: Configuration.ORIENTATION_PORTRAIT
|
||||||
return PictureInPictureParams.Builder()
|
return PictureInPictureParams.Builder()
|
||||||
// Portrait for calls seems more appropriate
|
.setAspectRatioFromOrientation(orientation)
|
||||||
.setAspectRatio(Rational(3, 5))
|
|
||||||
.apply {
|
.apply {
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
||||||
setAutoEnterEnabled(true)
|
setAutoEnterEnabled(true)
|
||||||
|
|||||||
+1
@@ -9,6 +9,7 @@
|
|||||||
package io.element.android.features.call.impl.utils
|
package io.element.android.features.call.impl.utils
|
||||||
|
|
||||||
interface PipController {
|
interface PipController {
|
||||||
|
fun setupPipCallbacks()
|
||||||
suspend fun canEnterPip(): Boolean
|
suspend fun canEnterPip(): Boolean
|
||||||
fun enterPip()
|
fun enterPip()
|
||||||
fun exitPip()
|
fun exitPip()
|
||||||
|
|||||||
+1
-1
@@ -250,7 +250,7 @@ class WebViewAudioManager(
|
|||||||
|
|
||||||
hasRegisteredCallbacks = true
|
hasRegisteredCallbacks = true
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
)
|
)
|
||||||
Timber.d("Setting androidNativeBridge javascript interface in webview")
|
Timber.d("Setting androidNativeBridge javascript interface in webview")
|
||||||
webView.addJavascriptInterface(webViewAudioDeviceSelectedCallback, "androidNativeBridge")
|
webView.addJavascriptInterface(webViewAudioDeviceSelectedCallback, "androidNativeBridge")
|
||||||
|
|||||||
+30
@@ -8,7 +8,10 @@
|
|||||||
|
|
||||||
package io.element.android.features.call.impl.utils
|
package io.element.android.features.call.impl.utils
|
||||||
|
|
||||||
|
import android.content.res.Configuration
|
||||||
|
import android.webkit.JavascriptInterface
|
||||||
import android.webkit.WebView
|
import android.webkit.WebView
|
||||||
|
import timber.log.Timber
|
||||||
import kotlin.coroutines.resume
|
import kotlin.coroutines.resume
|
||||||
import kotlin.coroutines.suspendCoroutine
|
import kotlin.coroutines.suspendCoroutine
|
||||||
|
|
||||||
@@ -18,7 +21,18 @@ import kotlin.coroutines.suspendCoroutine
|
|||||||
*/
|
*/
|
||||||
class WebViewPipController(
|
class WebViewPipController(
|
||||||
private val webView: WebView,
|
private val webView: WebView,
|
||||||
|
updatePipOrientation: (orientation: Int?) -> Unit,
|
||||||
) : PipController {
|
) : PipController {
|
||||||
|
init {
|
||||||
|
// Register the JavaScript interface ahead of time to ensure it's available when the WebView content is loaded and tries to call it
|
||||||
|
webView.addJavascriptInterface(PipBridge(updatePipOrientation), "androidPipBridge")
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun setupPipCallbacks() {
|
||||||
|
Timber.d("Adding callback in controls.onPipMediaOrientationUpdate")
|
||||||
|
webView.evaluateJavascript("controls.onPipMediaOrientationUpdate = (orientation) => { androidPipBridge.setPipOrientation(orientation); };", null)
|
||||||
|
}
|
||||||
|
|
||||||
override suspend fun canEnterPip(): Boolean {
|
override suspend fun canEnterPip(): Boolean {
|
||||||
return suspendCoroutine { continuation ->
|
return suspendCoroutine { continuation ->
|
||||||
webView.evaluateJavascript("controls.canEnterPip()") { result ->
|
webView.evaluateJavascript("controls.canEnterPip()") { result ->
|
||||||
@@ -36,3 +50,19 @@ class WebViewPipController(
|
|||||||
webView.evaluateJavascript("controls.disablePip()", null)
|
webView.evaluateJavascript("controls.disablePip()", null)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private class PipBridge(
|
||||||
|
private val onOrientationChange: (orientation: Int?) -> Unit,
|
||||||
|
) {
|
||||||
|
@JavascriptInterface
|
||||||
|
fun setPipOrientation(orientation: String?) {
|
||||||
|
Timber.d("Picture-in-picture orientation changed in webview, orientation: $orientation")
|
||||||
|
// This callback is used to update the picture-in-picture orientation in the WebView when it changes
|
||||||
|
val orientation = when (orientation) {
|
||||||
|
"portrait" -> Configuration.ORIENTATION_PORTRAIT
|
||||||
|
"landscape" -> Configuration.ORIENTATION_LANDSCAPE
|
||||||
|
else -> return
|
||||||
|
}
|
||||||
|
onOrientationChange(orientation)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
+3
@@ -12,10 +12,13 @@ import io.element.android.features.call.impl.utils.PipController
|
|||||||
import io.element.android.tests.testutils.lambda.lambdaError
|
import io.element.android.tests.testutils.lambda.lambdaError
|
||||||
|
|
||||||
class FakePipController(
|
class FakePipController(
|
||||||
|
private val setupPipCallbacksResult: () -> Unit = { lambdaError() },
|
||||||
private val canEnterPipResult: () -> Boolean = { lambdaError() },
|
private val canEnterPipResult: () -> Boolean = { lambdaError() },
|
||||||
private val enterPipResult: () -> Unit = { lambdaError() },
|
private val enterPipResult: () -> Unit = { lambdaError() },
|
||||||
private val exitPipResult: () -> Unit = { lambdaError() },
|
private val exitPipResult: () -> Unit = { lambdaError() },
|
||||||
) : PipController {
|
) : PipController {
|
||||||
|
override fun setupPipCallbacks() = setupPipCallbacksResult()
|
||||||
|
|
||||||
override suspend fun canEnterPip(): Boolean = canEnterPipResult()
|
override suspend fun canEnterPip(): Boolean = canEnterPipResult()
|
||||||
|
|
||||||
override fun enterPip() = enterPipResult()
|
override fun enterPip() = enterPipResult()
|
||||||
|
|||||||
+3
-1
@@ -13,9 +13,11 @@ import io.element.android.tests.testutils.lambda.lambdaError
|
|||||||
class FakePipView(
|
class FakePipView(
|
||||||
private val setPipParamsResult: () -> Unit = { lambdaError() },
|
private val setPipParamsResult: () -> Unit = { lambdaError() },
|
||||||
private val enterPipModeResult: () -> Boolean = { lambdaError() },
|
private val enterPipModeResult: () -> Boolean = { lambdaError() },
|
||||||
private val handUpResult: () -> Unit = { lambdaError() }
|
private val handUpResult: () -> Unit = { lambdaError() },
|
||||||
|
private val onOrientationChangeResult: (orientation: Int?) -> Unit = { lambdaError() },
|
||||||
) : PipView {
|
) : PipView {
|
||||||
override fun setPipParams() = setPipParamsResult()
|
override fun setPipParams() = setPipParamsResult()
|
||||||
override fun enterPipMode(): Boolean = enterPipModeResult()
|
override fun enterPipMode(): Boolean = enterPipModeResult()
|
||||||
override fun hangUp() = handUpResult()
|
override fun hangUp() = handUpResult()
|
||||||
|
override fun setPipOrientation(orientation: Int?) = onOrientationChangeResult(orientation)
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -299,10 +299,10 @@ private fun Content(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ensure that the string does not contain any new line characters, which can happen when pasting values.
|
* Ensure that the string does not contain any line separator, which can happen when pasting values.
|
||||||
*/
|
*/
|
||||||
private fun String.sanitize(): String {
|
private fun String.sanitize(): String {
|
||||||
return replace("\n", "")
|
return filterNot { it == '\n' || it == '\r' }
|
||||||
}
|
}
|
||||||
|
|
||||||
@PreviewsDayNight
|
@PreviewsDayNight
|
||||||
|
|||||||
+18
@@ -0,0 +1,18 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2026 Element Creations Ltd.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial.
|
||||||
|
* Please see LICENSE files in the repository root for full details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package io.element.android.features.enterprise.api
|
||||||
|
|
||||||
|
import io.element.android.libraries.matrix.api.MatrixClientBuilder
|
||||||
|
import io.element.android.libraries.matrix.api.core.SessionId
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A hook that can be used to customize the [MatrixClientBuilder] for enterprise features.
|
||||||
|
*/
|
||||||
|
fun interface ClientBuilderEnterpriseHook {
|
||||||
|
suspend operator fun invoke(clientBuilder: MatrixClientBuilder, sessionId: SessionId): MatrixClientBuilder
|
||||||
|
}
|
||||||
+17
@@ -0,0 +1,17 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2026 Element Creations Ltd.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial.
|
||||||
|
* Please see LICENSE files in the repository root for full details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package io.element.android.features.enterprise.api
|
||||||
|
|
||||||
|
import io.element.android.libraries.matrix.api.MatrixClient
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A hook that can be used to customize the [MatrixClient] for enterprise features.
|
||||||
|
*/
|
||||||
|
fun interface ClientEnterpriseHook {
|
||||||
|
suspend operator fun invoke(client: MatrixClient)
|
||||||
|
}
|
||||||
+15
-24
@@ -10,9 +10,8 @@ package io.element.android.features.enterprise.api
|
|||||||
|
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
import io.element.android.compound.colors.SemanticColorsLightDark
|
import io.element.android.compound.colors.SemanticColorsLightDark
|
||||||
import io.element.android.libraries.matrix.api.UrlContentFetcher
|
import io.element.android.libraries.matrix.api.ClientUrlContentFetcher
|
||||||
import io.element.android.libraries.matrix.api.core.SessionId
|
import io.element.android.libraries.matrix.api.core.SessionId
|
||||||
import io.element.android.libraries.wellknown.api.ElementWellKnown
|
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -21,9 +20,6 @@ import kotlinx.coroutines.flow.Flow
|
|||||||
* On a standard build this reports permissive defaults, so callers do not need to branch on the build type themselves.
|
* On a standard build this reports permissive defaults, so callers do not need to branch on the build type themselves.
|
||||||
*/
|
*/
|
||||||
interface EnterpriseService {
|
interface EnterpriseService {
|
||||||
/** Whether this build is an enterprise one; `false` for the public app. */
|
|
||||||
val isEnterpriseBuild: Boolean
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether the given session belongs to an enterprise deployment, which can be true even on a standard build.
|
* Whether the given session belongs to an enterprise deployment, which can be true even on a standard build.
|
||||||
*
|
*
|
||||||
@@ -35,23 +31,31 @@ interface EnterpriseService {
|
|||||||
* Rewrites the authentication server URL when the deployment requires a different one from the one advertised.
|
* Rewrites the authentication server URL when the deployment requires a different one from the one advertised.
|
||||||
*
|
*
|
||||||
* @param url the URL to rewrite.
|
* @param url the URL to rewrite.
|
||||||
* @param homeserver the homeserver the URL belongs to.
|
|
||||||
* @param urlContentFetcher used to read the deployment configuration; a client that is not authenticated yet also works.
|
* @param urlContentFetcher used to read the deployment configuration; a client that is not authenticated yet also works.
|
||||||
*/
|
*/
|
||||||
suspend fun tweakMasUrl(url: String, homeserver: String, urlContentFetcher: UrlContentFetcher): String
|
suspend fun tweakMasUrl(url: String, urlContentFetcher: ClientUrlContentFetcher): String
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The homeservers the user is allowed to sign in to; an empty list, or one containing [ANY_ACCOUNT_PROVIDER], means no restriction.
|
* Returns the list of homeservers the user is allowed to sign in to.
|
||||||
|
*
|
||||||
|
* If the list is empty or contains the special value [ANY_ACCOUNT_PROVIDER], the user is allowed to sign in to any homeserver.
|
||||||
*/
|
*/
|
||||||
fun defaultHomeserverList(): List<String>
|
fun homeserverAllowList(): List<String>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether the user is allowed to sign in to a given homeserver, according to [defaultHomeserverList].
|
* Whether the user is allowed to sign in to a given homeserver, according to [homeserverAllowList].
|
||||||
*
|
*
|
||||||
* @param homeserverUrl the server the user is trying to use.
|
* @param homeserverUrl the server the user is trying to use.
|
||||||
*/
|
*/
|
||||||
suspend fun isAllowedToConnectToHomeserver(homeserverUrl: String): Boolean
|
suspend fun isAllowedToConnectToHomeserver(homeserverUrl: String): Boolean
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether the given homeserver enforces the use of Element Pro or a derived app.
|
||||||
|
*
|
||||||
|
* @param serverName the homeserver to check.
|
||||||
|
*/
|
||||||
|
suspend fun isElementProEnforced(serverName: String): Boolean
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Override the brand color.
|
* Override the brand color.
|
||||||
* @param sessionId the session to override the brand color for, or null to set the brand color to use when there is no session.
|
* @param sessionId the session to override the brand color for, or null to set the brand color to use when there is no session.
|
||||||
@@ -94,26 +98,13 @@ interface EnterpriseService {
|
|||||||
*/
|
*/
|
||||||
fun getNoisyNotificationChannelId(sessionId: SessionId): String?
|
fun getNoisyNotificationChannelId(sessionId: SessionId): String?
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the overridden Element Well-Known data if it has been set, or null if not set.
|
|
||||||
*/
|
|
||||||
fun overriddenElementWellKnown(): ElementWellKnown?
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the Element Server Suite (ESS) config endpoint URL for the given domain.
|
|
||||||
* Returns `null` when this build does not read its configuration from an ESS deployment.
|
|
||||||
*
|
|
||||||
* @param domain the server whose configuration endpoint is requested.
|
|
||||||
*/
|
|
||||||
fun essConfigEndpointUrl(domain: String): String?
|
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
const val ANY_ACCOUNT_PROVIDER = "*"
|
const val ANY_ACCOUNT_PROVIDER = "*"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun EnterpriseService.canConnectToAnyHomeserver(): Boolean {
|
fun EnterpriseService.canConnectToAnyHomeserver(): Boolean {
|
||||||
return defaultHomeserverList().let {
|
return homeserverAllowList().let {
|
||||||
it.isEmpty() || it.contains(EnterpriseService.ANY_ACCOUNT_PROVIDER)
|
it.isEmpty() || it.contains(EnterpriseService.ANY_ACCOUNT_PROVIDER)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+18
@@ -0,0 +1,18 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2026 Element Creations Ltd.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial.
|
||||||
|
* Please see LICENSE files in the repository root for full details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package io.element.android.features.enterprise.api
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A use case to check if this build of the app is an enterprise build.
|
||||||
|
*/
|
||||||
|
fun interface IsEnterpriseBuild {
|
||||||
|
/**
|
||||||
|
* Returns `true` if this build of the app is an enterprise build, `false` otherwise.
|
||||||
|
*/
|
||||||
|
operator fun invoke(): Boolean
|
||||||
|
}
|
||||||
+3
-3
@@ -14,6 +14,9 @@ package io.element.android.features.enterprise.api
|
|||||||
* [init] must have run before the other members return meaningful answers.
|
* [init] must have run before the other members return meaningful answers.
|
||||||
*/
|
*/
|
||||||
interface SessionEnterpriseService {
|
interface SessionEnterpriseService {
|
||||||
|
/** Loads the deployment configuration of this session; to be called once when the session starts. */
|
||||||
|
suspend fun init()
|
||||||
|
|
||||||
/** Whether Element Call may be used on this session, which a deployment can turn off. */
|
/** Whether Element Call may be used on this session, which a deployment can turn off. */
|
||||||
suspend fun isElementCallAvailable(): Boolean
|
suspend fun isElementCallAvailable(): Boolean
|
||||||
|
|
||||||
@@ -26,7 +29,4 @@ interface SessionEnterpriseService {
|
|||||||
|
|
||||||
/** Whether the homeserver forbids creating encrypted rooms, in which case the app must not offer the option. */
|
/** Whether the homeserver forbids creating encrypted rooms, in which case the app must not offer the option. */
|
||||||
suspend fun isEncryptionDisabledByHomeserver(): Boolean
|
suspend fun isEncryptionDisabledByHomeserver(): Boolean
|
||||||
|
|
||||||
/** Loads the deployment configuration of this session; to be called once when the session starts. */
|
|
||||||
suspend fun init()
|
|
||||||
}
|
}
|
||||||
|
|||||||
+15
@@ -0,0 +1,15 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2026 Element Creations Ltd.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial.
|
||||||
|
* Please see LICENSE files in the repository root for full details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package io.element.android.features.enterprise.api.remoteconfig
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A provider of a runtime-fetched MapTiler configuration, which can be used to override the default MapTiler configuration.
|
||||||
|
*/
|
||||||
|
fun interface CustomMapTilerConfigProvider {
|
||||||
|
suspend fun get(): Result<MapTilerConfig?>
|
||||||
|
}
|
||||||
+4
-15
@@ -1,29 +1,18 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2025 Element Creations Ltd.
|
* Copyright (c) 2026 Element Creations Ltd.
|
||||||
* Copyright 2023-2025 New Vector Ltd.
|
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial.
|
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial.
|
||||||
* Please see LICENSE files in the repository root for full details.
|
* Please see LICENSE files in the repository root for full details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package io.element.android.libraries.wellknown.api
|
package io.element.android.features.enterprise.api.remoteconfig
|
||||||
|
|
||||||
data class ElementWellKnown(
|
import androidx.compose.runtime.Immutable
|
||||||
val registrationHelperUrl: String?,
|
|
||||||
val enforceElementPro: Boolean?,
|
|
||||||
val rageshakeUrl: String?,
|
|
||||||
val brandColor: String?,
|
|
||||||
val notificationSound: String?,
|
|
||||||
val identityProviderAppScheme: String?,
|
|
||||||
val customRecoveryPassphrase: CustomRecoveryPassphrase?,
|
|
||||||
val contentScannerUrl: String?,
|
|
||||||
val forceDisableE2EE: Boolean?,
|
|
||||||
val mapTilerConfig: MapTilerConfig?,
|
|
||||||
)
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A `MapTiler` configuration received from the server. This configuration is used to display maps in the app.
|
* A `MapTiler` configuration received from the server. This configuration is used to display maps in the app.
|
||||||
*/
|
*/
|
||||||
|
@Immutable
|
||||||
data class MapTilerConfig(
|
data class MapTilerConfig(
|
||||||
/** The API key to use with MapTiler. This is always not null, but can be empty/blank. */
|
/** The API key to use with MapTiler. This is always not null, but can be empty/blank. */
|
||||||
val apiKey: String,
|
val apiKey: String,
|
||||||
-17
@@ -1,17 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2026 Element Creations Ltd.
|
|
||||||
*
|
|
||||||
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial.
|
|
||||||
* Please see LICENSE files in the repository root for full details.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package io.element.android.features.enterprise.api.remoteconfig
|
|
||||||
|
|
||||||
import io.element.android.libraries.wellknown.api.ElementWellKnown
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Typealias for the well-known configuration used for enterprise features.
|
|
||||||
*
|
|
||||||
* This will allow for easier refactoring in the future when we'll want to move as much of its logic as possible to this module.
|
|
||||||
*/
|
|
||||||
typealias RemoteEnterpriseConfig = ElementWellKnown
|
|
||||||
-35
@@ -1,35 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2026 Element Creations Ltd.
|
|
||||||
*
|
|
||||||
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial.
|
|
||||||
* Please see LICENSE files in the repository root for full details.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package io.element.android.features.enterprise.api.remoteconfig
|
|
||||||
|
|
||||||
import io.element.android.libraries.matrix.api.UrlContentFetcher
|
|
||||||
import io.element.android.libraries.matrix.api.core.SessionId
|
|
||||||
import io.element.android.libraries.wellknown.api.WellknownRetrieverResult
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Wrapper to fetch the remote enterprise configuration for a given [SessionId], either from a local cache or from a remote source.
|
|
||||||
*/
|
|
||||||
interface RemoteEnterpriseConfigProvider {
|
|
||||||
/**
|
|
||||||
* Returns the configuration of a session, served from the cache when possible.
|
|
||||||
* A stale entry is reported as outdated while a refresh runs in the background, so this rarely waits on the network.
|
|
||||||
*
|
|
||||||
* @param sessionId the session whose configuration is requested.
|
|
||||||
*/
|
|
||||||
suspend fun get(sessionId: SessionId): WellknownRetrieverResult<RemoteEnterpriseConfig>
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a provider, which needs a fetcher because the configuration is read over HTTP.
|
|
||||||
*/
|
|
||||||
interface Factory {
|
|
||||||
/**
|
|
||||||
* @param urlContentFetcher used to perform the request; a client that is not authenticated yet also works.
|
|
||||||
*/
|
|
||||||
fun create(urlContentFetcher: UrlContentFetcher): RemoteEnterpriseConfigProvider
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+9
-10
@@ -1,45 +1,44 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2025 Element Creations Ltd.
|
* Copyright (c) 2026 Element Creations Ltd.
|
||||||
* Copyright 2025 New Vector Ltd.
|
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial.
|
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial.
|
||||||
* Please see LICENSE files in the repository root for full details.
|
* Please see LICENSE files in the repository root for full details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package io.element.android.libraries.wellknown.api
|
package io.element.android.features.enterprise.api.remoteconfig
|
||||||
|
|
||||||
sealed interface WellknownRetrieverResult<out T> {
|
sealed interface RemoteEnterpriseConfigResult<out T> {
|
||||||
/**
|
/**
|
||||||
* Well-known data has been successfully retrieved.
|
* Well-known data has been successfully retrieved.
|
||||||
*/
|
*/
|
||||||
data class Success<out T>(val data: T) : WellknownRetrieverResult<T>
|
data class Success<out T>(val data: T) : RemoteEnterpriseConfigResult<T>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Well-known data has been retrieved from the local cache but is outdated and a manual refresh has been launched.
|
* Well-known data has been retrieved from the local cache but is outdated and a manual refresh has been launched.
|
||||||
*/
|
*/
|
||||||
data class Outdated<out T>(val data: T) : WellknownRetrieverResult<T>
|
data class Outdated<out T>(val data: T) : RemoteEnterpriseConfigResult<T>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Well-known data is not found (file does not exist server side, we got a 404).
|
* Well-known data is not found (file does not exist server side, we got a 404).
|
||||||
*/
|
*/
|
||||||
data object NotFound : WellknownRetrieverResult<Nothing>
|
data object NotFound : RemoteEnterpriseConfigResult<Nothing>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Any other error.
|
* Any other error.
|
||||||
*/
|
*/
|
||||||
data class Error(val exception: Exception) : WellknownRetrieverResult<Nothing>
|
data class Error(val exception: Exception) : RemoteEnterpriseConfigResult<Nothing>
|
||||||
|
|
||||||
fun dataOrNull(): T? = when (this) {
|
fun dataOrNull(): T? = when (this) {
|
||||||
is Success<T> -> data
|
is Success<T> -> data
|
||||||
is Outdated<T> -> data
|
is Outdated<T> -> data
|
||||||
is Error -> null
|
is Error -> null
|
||||||
NotFound -> null
|
is NotFound -> null
|
||||||
}
|
}
|
||||||
|
|
||||||
fun upToDateDataOrNull(): T? = when (this) {
|
fun upToDateDataOrNull(): T? = when (this) {
|
||||||
is Success<T> -> data
|
is Success<T> -> data
|
||||||
is Outdated<T> -> null
|
is Outdated<T> -> null
|
||||||
is Error -> null
|
is Error -> null
|
||||||
NotFound -> null
|
is NotFound -> null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+25
@@ -0,0 +1,25 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2026 Element Creations Ltd.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial.
|
||||||
|
* Please see LICENSE files in the repository root for full details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package io.element.android.features.enterprise.impl
|
||||||
|
|
||||||
|
import dev.zacsweers.metro.AppScope
|
||||||
|
import dev.zacsweers.metro.ContributesBinding
|
||||||
|
import io.element.android.features.enterprise.api.ClientBuilderEnterpriseHook
|
||||||
|
import io.element.android.libraries.matrix.api.MatrixClientBuilder
|
||||||
|
import io.element.android.libraries.matrix.api.core.SessionId
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default implementation of [ClientBuilderEnterpriseHook] that does nothing for FOSS.
|
||||||
|
*/
|
||||||
|
@ContributesBinding(AppScope::class)
|
||||||
|
class DefaultClientBuilderEnterpriseHook : ClientBuilderEnterpriseHook {
|
||||||
|
override suspend fun invoke(clientBuilder: MatrixClientBuilder, sessionId: SessionId): MatrixClientBuilder {
|
||||||
|
// No modification
|
||||||
|
return clientBuilder
|
||||||
|
}
|
||||||
|
}
|
||||||
+23
@@ -0,0 +1,23 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2026 Element Creations Ltd.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial.
|
||||||
|
* Please see LICENSE files in the repository root for full details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package io.element.android.features.enterprise.impl
|
||||||
|
|
||||||
|
import dev.zacsweers.metro.AppScope
|
||||||
|
import dev.zacsweers.metro.ContributesBinding
|
||||||
|
import io.element.android.features.enterprise.api.ClientEnterpriseHook
|
||||||
|
import io.element.android.libraries.matrix.api.MatrixClient
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default implementation of [ClientEnterpriseHook] that does nothing for FOSS.
|
||||||
|
*/
|
||||||
|
@ContributesBinding(AppScope::class)
|
||||||
|
class DefaultClientEnterpriseHook : ClientEnterpriseHook {
|
||||||
|
override suspend fun invoke(client: MatrixClient) {
|
||||||
|
// No-op
|
||||||
|
}
|
||||||
|
}
|
||||||
+4
-10
@@ -14,20 +14,18 @@ import dev.zacsweers.metro.ContributesBinding
|
|||||||
import io.element.android.compound.colors.SemanticColorsLightDark
|
import io.element.android.compound.colors.SemanticColorsLightDark
|
||||||
import io.element.android.features.enterprise.api.BugReportUrl
|
import io.element.android.features.enterprise.api.BugReportUrl
|
||||||
import io.element.android.features.enterprise.api.EnterpriseService
|
import io.element.android.features.enterprise.api.EnterpriseService
|
||||||
import io.element.android.libraries.matrix.api.UrlContentFetcher
|
import io.element.android.libraries.matrix.api.ClientUrlContentFetcher
|
||||||
import io.element.android.libraries.matrix.api.core.SessionId
|
import io.element.android.libraries.matrix.api.core.SessionId
|
||||||
import io.element.android.libraries.wellknown.api.ElementWellKnown
|
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
import kotlinx.coroutines.flow.flowOf
|
import kotlinx.coroutines.flow.flowOf
|
||||||
|
|
||||||
@ContributesBinding(AppScope::class)
|
@ContributesBinding(AppScope::class)
|
||||||
class DefaultEnterpriseService : EnterpriseService {
|
class DefaultEnterpriseService : EnterpriseService {
|
||||||
override val isEnterpriseBuild = false
|
|
||||||
|
|
||||||
override suspend fun isEnterpriseUser(sessionId: SessionId) = false
|
override suspend fun isEnterpriseUser(sessionId: SessionId) = false
|
||||||
override suspend fun tweakMasUrl(url: String, homeserver: String, urlContentFetcher: UrlContentFetcher) = url
|
override suspend fun tweakMasUrl(url: String, urlContentFetcher: ClientUrlContentFetcher) = url
|
||||||
override fun defaultHomeserverList(): List<String> = emptyList()
|
override fun homeserverAllowList(): List<String> = emptyList()
|
||||||
override suspend fun isAllowedToConnectToHomeserver(homeserverUrl: String) = true
|
override suspend fun isAllowedToConnectToHomeserver(homeserverUrl: String) = true
|
||||||
|
override suspend fun isElementProEnforced(serverName: String): Boolean = false
|
||||||
|
|
||||||
override suspend fun overrideBrandColor(sessionId: SessionId?, brandColor: String?) = Unit
|
override suspend fun overrideBrandColor(sessionId: SessionId?, brandColor: String?) = Unit
|
||||||
|
|
||||||
@@ -47,8 +45,4 @@ class DefaultEnterpriseService : EnterpriseService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun getNoisyNotificationChannelId(sessionId: SessionId): String? = null
|
override fun getNoisyNotificationChannelId(sessionId: SessionId): String? = null
|
||||||
|
|
||||||
override fun overriddenElementWellKnown(): ElementWellKnown? = null
|
|
||||||
|
|
||||||
override fun essConfigEndpointUrl(domain: String): String? = null
|
|
||||||
}
|
}
|
||||||
|
|||||||
+17
@@ -0,0 +1,17 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2026 Element Creations Ltd.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial.
|
||||||
|
* Please see LICENSE files in the repository root for full details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package io.element.android.features.enterprise.impl
|
||||||
|
|
||||||
|
import dev.zacsweers.metro.AppScope
|
||||||
|
import dev.zacsweers.metro.ContributesBinding
|
||||||
|
import io.element.android.features.enterprise.api.IsEnterpriseBuild
|
||||||
|
|
||||||
|
@ContributesBinding(AppScope::class)
|
||||||
|
class DefaultIsEnterpriseBuild : IsEnterpriseBuild {
|
||||||
|
override fun invoke(): Boolean = false
|
||||||
|
}
|
||||||
+18
@@ -0,0 +1,18 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2026 Element Creations Ltd.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial.
|
||||||
|
* Please see LICENSE files in the repository root for full details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package io.element.android.features.enterprise.impl.remoteconfig
|
||||||
|
|
||||||
|
import dev.zacsweers.metro.ContributesBinding
|
||||||
|
import io.element.android.features.enterprise.api.remoteconfig.CustomMapTilerConfigProvider
|
||||||
|
import io.element.android.features.enterprise.api.remoteconfig.MapTilerConfig
|
||||||
|
import io.element.android.libraries.di.SessionScope
|
||||||
|
|
||||||
|
@ContributesBinding(SessionScope::class)
|
||||||
|
class DefaultCustomMapTilerConfigProvider : CustomMapTilerConfigProvider {
|
||||||
|
override suspend fun get(): Result<MapTilerConfig?> = Result.success(null)
|
||||||
|
}
|
||||||
-30
@@ -1,30 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2026 Element Creations Ltd.
|
|
||||||
*
|
|
||||||
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial.
|
|
||||||
* Please see LICENSE files in the repository root for full details.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package io.element.android.features.enterprise.impl.remoteconfig
|
|
||||||
|
|
||||||
import dev.zacsweers.metro.AppScope
|
|
||||||
import dev.zacsweers.metro.ContributesBinding
|
|
||||||
import io.element.android.features.enterprise.api.remoteconfig.RemoteEnterpriseConfig
|
|
||||||
import io.element.android.features.enterprise.api.remoteconfig.RemoteEnterpriseConfigProvider
|
|
||||||
import io.element.android.libraries.matrix.api.UrlContentFetcher
|
|
||||||
import io.element.android.libraries.matrix.api.core.SessionId
|
|
||||||
import io.element.android.libraries.wellknown.api.WellknownRetrieverResult
|
|
||||||
|
|
||||||
@ContributesBinding(AppScope::class)
|
|
||||||
class DefaultRemoteEnterpriseConfigProvider : RemoteEnterpriseConfigProvider {
|
|
||||||
override suspend fun get(sessionId: SessionId): WellknownRetrieverResult<RemoteEnterpriseConfig> {
|
|
||||||
return WellknownRetrieverResult.NotFound
|
|
||||||
}
|
|
||||||
|
|
||||||
@ContributesBinding(AppScope::class)
|
|
||||||
class Factory : RemoteEnterpriseConfigProvider.Factory {
|
|
||||||
override fun create(urlContentFetcher: UrlContentFetcher): RemoteEnterpriseConfigProvider {
|
|
||||||
return DefaultRemoteEnterpriseConfigProvider()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-29
@@ -1,29 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2026 Element Creations Ltd.
|
|
||||||
*
|
|
||||||
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial.
|
|
||||||
* Please see LICENSE files in the repository root for full details.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package io.element.android.features.enterprise.impl.scanner
|
|
||||||
|
|
||||||
import dev.zacsweers.metro.AppScope
|
|
||||||
import dev.zacsweers.metro.ContributesBinding
|
|
||||||
import io.element.android.libraries.matrix.api.UrlContentFetcher
|
|
||||||
import io.element.android.libraries.matrix.api.core.SessionId
|
|
||||||
import io.element.android.libraries.matrix.api.scanner.ContentScannerUrlProvider
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Default FOSS implementation of [ContentScannerUrlProvider] that returns `null` for the content scanner URL.
|
|
||||||
*/
|
|
||||||
@ContributesBinding(AppScope::class)
|
|
||||||
class DefaultContentScannerUrlProvider : ContentScannerUrlProvider {
|
|
||||||
override suspend fun getContentScannerUrl(sessionId: SessionId): Result<String?> = Result.success(null)
|
|
||||||
|
|
||||||
@ContributesBinding(AppScope::class)
|
|
||||||
class Factory : ContentScannerUrlProvider.Factory {
|
|
||||||
override fun create(urlContentFetcher: UrlContentFetcher): ContentScannerUrlProvider {
|
|
||||||
return DefaultContentScannerUrlProvider()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+2
-8
@@ -19,15 +19,9 @@ import org.junit.Test
|
|||||||
|
|
||||||
class DefaultEnterpriseServiceTest {
|
class DefaultEnterpriseServiceTest {
|
||||||
@Test
|
@Test
|
||||||
fun `isEnterpriseBuild is false`() {
|
fun homeserverWhitelist() {
|
||||||
val defaultEnterpriseService = DefaultEnterpriseService()
|
val defaultEnterpriseService = DefaultEnterpriseService()
|
||||||
assertThat(defaultEnterpriseService.isEnterpriseBuild).isFalse()
|
assertThat(defaultEnterpriseService.homeserverAllowList()).isEmpty()
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `defaultHomeserverList should return empty list`() {
|
|
||||||
val defaultEnterpriseService = DefaultEnterpriseService()
|
|
||||||
assertThat(defaultEnterpriseService.defaultHomeserverList()).isEmpty()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
+10
-17
@@ -12,9 +12,8 @@ import androidx.compose.ui.graphics.Color
|
|||||||
import io.element.android.compound.colors.SemanticColorsLightDark
|
import io.element.android.compound.colors.SemanticColorsLightDark
|
||||||
import io.element.android.features.enterprise.api.BugReportUrl
|
import io.element.android.features.enterprise.api.BugReportUrl
|
||||||
import io.element.android.features.enterprise.api.EnterpriseService
|
import io.element.android.features.enterprise.api.EnterpriseService
|
||||||
import io.element.android.libraries.matrix.api.UrlContentFetcher
|
import io.element.android.libraries.matrix.api.ClientUrlContentFetcher
|
||||||
import io.element.android.libraries.matrix.api.core.SessionId
|
import io.element.android.libraries.matrix.api.core.SessionId
|
||||||
import io.element.android.libraries.wellknown.api.ElementWellKnown
|
|
||||||
import io.element.android.tests.testutils.lambda.lambdaError
|
import io.element.android.tests.testutils.lambda.lambdaError
|
||||||
import io.element.android.tests.testutils.simulateLongTask
|
import io.element.android.tests.testutils.simulateLongTask
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
@@ -22,7 +21,6 @@ import kotlinx.coroutines.flow.MutableStateFlow
|
|||||||
import kotlinx.coroutines.flow.asStateFlow
|
import kotlinx.coroutines.flow.asStateFlow
|
||||||
|
|
||||||
class FakeEnterpriseService(
|
class FakeEnterpriseService(
|
||||||
override val isEnterpriseBuild: Boolean = false,
|
|
||||||
private val isEnterpriseUserResult: (SessionId) -> Boolean = { lambdaError() },
|
private val isEnterpriseUserResult: (SessionId) -> Boolean = { lambdaError() },
|
||||||
private val defaultHomeserverListResult: () -> List<String> = { emptyList() },
|
private val defaultHomeserverListResult: () -> List<String> = { emptyList() },
|
||||||
private val isAllowedToConnectToHomeserverResult: (String) -> Boolean = { lambdaError() },
|
private val isAllowedToConnectToHomeserverResult: (String) -> Boolean = { lambdaError() },
|
||||||
@@ -32,9 +30,8 @@ class FakeEnterpriseService(
|
|||||||
private val firebasePushGatewayResult: () -> String? = { lambdaError() },
|
private val firebasePushGatewayResult: () -> String? = { lambdaError() },
|
||||||
private val unifiedPushDefaultPushGatewayResult: () -> String? = { lambdaError() },
|
private val unifiedPushDefaultPushGatewayResult: () -> String? = { lambdaError() },
|
||||||
private val getNoisyNotificationChannelIdResult: (SessionId?) -> String? = { lambdaError() },
|
private val getNoisyNotificationChannelIdResult: (SessionId?) -> String? = { lambdaError() },
|
||||||
private val tweakMasUrlResult: (String, String, UrlContentFetcher) -> String = { _, _, _ -> lambdaError() },
|
private val tweakMasUrlResult: (String, ClientUrlContentFetcher) -> String = { _, _ -> lambdaError() },
|
||||||
private val overrideWellKnownResult: () -> ElementWellKnown? = { lambdaError() },
|
private val isElementProEnforcedResult: (String) -> Boolean = { lambdaError() },
|
||||||
private val essConfigEndpointUrlResult: (String) -> String = { lambdaError() },
|
|
||||||
) : EnterpriseService {
|
) : EnterpriseService {
|
||||||
private val brandColorState = MutableStateFlow(initialBrandColor)
|
private val brandColorState = MutableStateFlow(initialBrandColor)
|
||||||
private val semanticColorsState = MutableStateFlow(initialSemanticColors)
|
private val semanticColorsState = MutableStateFlow(initialSemanticColors)
|
||||||
@@ -43,11 +40,11 @@ class FakeEnterpriseService(
|
|||||||
isEnterpriseUserResult(sessionId)
|
isEnterpriseUserResult(sessionId)
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun tweakMasUrl(url: String, homeserver: String, urlContentFetcher: UrlContentFetcher): String = simulateLongTask {
|
override suspend fun tweakMasUrl(url: String, urlContentFetcher: ClientUrlContentFetcher): String = simulateLongTask {
|
||||||
tweakMasUrlResult(url, homeserver, urlContentFetcher)
|
tweakMasUrlResult(url, urlContentFetcher)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun defaultHomeserverList(): List<String> {
|
override fun homeserverAllowList(): List<String> {
|
||||||
return defaultHomeserverListResult()
|
return defaultHomeserverListResult()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -55,6 +52,10 @@ class FakeEnterpriseService(
|
|||||||
isAllowedToConnectToHomeserverResult(homeserverUrl)
|
isAllowedToConnectToHomeserverResult(homeserverUrl)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override suspend fun isElementProEnforced(serverName: String): Boolean = simulateLongTask {
|
||||||
|
isElementProEnforcedResult(serverName)
|
||||||
|
}
|
||||||
|
|
||||||
override suspend fun overrideBrandColor(sessionId: SessionId?, brandColor: String?) = simulateLongTask {
|
override suspend fun overrideBrandColor(sessionId: SessionId?, brandColor: String?) = simulateLongTask {
|
||||||
overrideBrandColorResult(sessionId, brandColor)
|
overrideBrandColorResult(sessionId, brandColor)
|
||||||
}
|
}
|
||||||
@@ -83,12 +84,4 @@ class FakeEnterpriseService(
|
|||||||
override fun getNoisyNotificationChannelId(sessionId: SessionId): String? {
|
override fun getNoisyNotificationChannelId(sessionId: SessionId): String? {
|
||||||
return getNoisyNotificationChannelIdResult(sessionId)
|
return getNoisyNotificationChannelIdResult(sessionId)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun overriddenElementWellKnown(): ElementWellKnown? {
|
|
||||||
return overrideWellKnownResult()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun essConfigEndpointUrl(domain: String): String {
|
|
||||||
return essConfigEndpointUrlResult(domain)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
-21
@@ -1,21 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2026 Element Creations Ltd.
|
|
||||||
*
|
|
||||||
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial.
|
|
||||||
* Please see LICENSE files in the repository root for full details.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package io.element.android.features.enterprise.test.remoteconfig
|
|
||||||
|
|
||||||
import io.element.android.features.enterprise.api.remoteconfig.RemoteEnterpriseConfig
|
|
||||||
import io.element.android.features.enterprise.api.remoteconfig.RemoteEnterpriseConfigProvider
|
|
||||||
import io.element.android.libraries.matrix.api.core.SessionId
|
|
||||||
import io.element.android.libraries.wellknown.api.WellknownRetrieverResult
|
|
||||||
|
|
||||||
class FakeRemoteEnterpriseConfigProvider(
|
|
||||||
private val getResult: (SessionId) -> WellknownRetrieverResult<RemoteEnterpriseConfig> = { WellknownRetrieverResult.NotFound }
|
|
||||||
) : RemoteEnterpriseConfigProvider {
|
|
||||||
override suspend fun get(sessionId: SessionId): WellknownRetrieverResult<RemoteEnterpriseConfig> {
|
|
||||||
return getResult(sessionId)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-17
@@ -1,17 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2026 Element Creations Ltd.
|
|
||||||
*
|
|
||||||
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial.
|
|
||||||
* Please see LICENSE files in the repository root for full details.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package io.element.android.features.enterprise.test.remoteconfig
|
|
||||||
|
|
||||||
import io.element.android.features.enterprise.api.remoteconfig.RemoteEnterpriseConfigProvider
|
|
||||||
import io.element.android.libraries.matrix.api.UrlContentFetcher
|
|
||||||
|
|
||||||
class FakeRemoteEnterpriseConfigProviderFactory(
|
|
||||||
private val remoteEnterpriseConfigProvider: RemoteEnterpriseConfigProvider = FakeRemoteEnterpriseConfigProvider(),
|
|
||||||
) : RemoteEnterpriseConfigProvider.Factory {
|
|
||||||
override fun create(urlContentFetcher: UrlContentFetcher): RemoteEnterpriseConfigProvider = remoteEnterpriseConfigProvider
|
|
||||||
}
|
|
||||||
+22
@@ -0,0 +1,22 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2026 Element Creations Ltd.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial.
|
||||||
|
* Please see LICENSE files in the repository root for full details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package io.element.android.features.enterprise.test.remoteconfig
|
||||||
|
|
||||||
|
import io.element.android.features.enterprise.api.remoteconfig.MapTilerConfig
|
||||||
|
|
||||||
|
fun aMapTilerConfig(
|
||||||
|
apiKey: String = "test_api_key",
|
||||||
|
baseUrl: String? = null,
|
||||||
|
lightStyleId: String? = null,
|
||||||
|
darkStyleId: String? = null,
|
||||||
|
) = MapTilerConfig(
|
||||||
|
apiKey = apiKey,
|
||||||
|
baseUrl = baseUrl,
|
||||||
|
lightStyleId = lightStyleId,
|
||||||
|
darkStyleId = darkStyleId,
|
||||||
|
)
|
||||||
+2
-1
@@ -12,6 +12,7 @@ import com.bumble.appyx.core.modality.BuildContext
|
|||||||
import com.bumble.appyx.core.node.Node
|
import com.bumble.appyx.core.node.Node
|
||||||
import com.bumble.appyx.core.plugin.Plugin
|
import com.bumble.appyx.core.plugin.Plugin
|
||||||
import io.element.android.libraries.architecture.FeatureEntryPoint
|
import io.element.android.libraries.architecture.FeatureEntryPoint
|
||||||
|
import io.element.android.libraries.matrix.api.core.EventId
|
||||||
import io.element.android.libraries.matrix.api.core.RoomId
|
import io.element.android.libraries.matrix.api.core.RoomId
|
||||||
import io.element.android.libraries.matrix.api.room.JoinedRoom
|
import io.element.android.libraries.matrix.api.room.JoinedRoom
|
||||||
|
|
||||||
@@ -23,7 +24,7 @@ interface HomeEntryPoint : FeatureEntryPoint {
|
|||||||
): Node
|
): Node
|
||||||
|
|
||||||
interface Callback : Plugin {
|
interface Callback : Plugin {
|
||||||
fun navigateToRoom(roomId: RoomId, joinedRoom: JoinedRoom?)
|
fun navigateToRoom(roomId: RoomId, eventId: EventId?, joinedRoom: JoinedRoom?)
|
||||||
fun navigateToCreateRoom()
|
fun navigateToCreateRoom()
|
||||||
fun navigateToCreateSpace()
|
fun navigateToCreateSpace()
|
||||||
fun navigateToSettings()
|
fun navigateToSettings()
|
||||||
|
|||||||
+10
-3
@@ -56,6 +56,7 @@ import io.element.android.libraries.designsystem.utils.DelayedVisibility
|
|||||||
import io.element.android.libraries.di.SessionScope
|
import io.element.android.libraries.di.SessionScope
|
||||||
import io.element.android.libraries.di.annotations.SessionCoroutineScope
|
import io.element.android.libraries.di.annotations.SessionCoroutineScope
|
||||||
import io.element.android.libraries.matrix.api.MatrixClient
|
import io.element.android.libraries.matrix.api.MatrixClient
|
||||||
|
import io.element.android.libraries.matrix.api.core.EventId
|
||||||
import io.element.android.libraries.matrix.api.core.RoomId
|
import io.element.android.libraries.matrix.api.core.RoomId
|
||||||
import io.element.android.services.analytics.api.AnalyticsService
|
import io.element.android.services.analytics.api.AnalyticsService
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
@@ -183,6 +184,7 @@ class HomeFlowNode(
|
|||||||
|
|
||||||
fun navigateToRoom(
|
fun navigateToRoom(
|
||||||
roomId: RoomId,
|
roomId: RoomId,
|
||||||
|
eventId: EventId?,
|
||||||
) {
|
) {
|
||||||
if (!loadingJoinedRoomJob.value.isUninitialized()) {
|
if (!loadingJoinedRoomJob.value.isUninitialized()) {
|
||||||
Timber.w("Already loading a room, ignoring navigateToRoom for $roomId")
|
Timber.w("Already loading a room, ignoring navigateToRoom for $roomId")
|
||||||
@@ -195,7 +197,7 @@ class HomeFlowNode(
|
|||||||
}.fold(
|
}.fold(
|
||||||
onSuccess = { joinedRoom ->
|
onSuccess = { joinedRoom ->
|
||||||
if (isActive) {
|
if (isActive) {
|
||||||
callback.navigateToRoom(roomId, joinedRoom)
|
callback.navigateToRoom(roomId = roomId, eventId = eventId, joinedRoom = joinedRoom)
|
||||||
loadingJoinedRoomJob.value = AsyncData.Success(coroutineContext.job)
|
loadingJoinedRoomJob.value = AsyncData.Success(coroutineContext.job)
|
||||||
// Wait a bit before resetting the state to avoid allowing to open several rooms
|
// Wait a bit before resetting the state to avoid allowing to open several rooms
|
||||||
delay(200.milliseconds)
|
delay(200.milliseconds)
|
||||||
@@ -205,7 +207,7 @@ class HomeFlowNode(
|
|||||||
onFailure = {
|
onFailure = {
|
||||||
// If the operation wasn't cancelled, navigate without the room, using the room id
|
// If the operation wasn't cancelled, navigate without the room, using the room id
|
||||||
if (it !is CancellationException) {
|
if (it !is CancellationException) {
|
||||||
callback.navigateToRoom(roomId, null)
|
callback.navigateToRoom(roomId = roomId, eventId = null, joinedRoom = null)
|
||||||
}
|
}
|
||||||
loadingJoinedRoomJob.value = AsyncData.Failure(error = it, prevData = coroutineContext.job)
|
loadingJoinedRoomJob.value = AsyncData.Failure(error = it, prevData = coroutineContext.job)
|
||||||
// Wait a bit before resetting the state to avoid allowing to open several rooms
|
// Wait a bit before resetting the state to avoid allowing to open several rooms
|
||||||
@@ -233,7 +235,7 @@ class HomeFlowNode(
|
|||||||
acceptDeclineInviteView = {
|
acceptDeclineInviteView = {
|
||||||
acceptDeclineInviteView.Render(
|
acceptDeclineInviteView.Render(
|
||||||
state = state.roomListState.acceptDeclineInviteState,
|
state = state.roomListState.acceptDeclineInviteState,
|
||||||
onAcceptInviteSuccess = ::navigateToRoom,
|
onAcceptInviteSuccess = { navigateToRoom(roomId = it, eventId = null) },
|
||||||
onDeclineInviteSuccess = { },
|
onDeclineInviteSuccess = { },
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
)
|
)
|
||||||
@@ -269,6 +271,11 @@ class HomeFlowNode(
|
|||||||
parentNode = this,
|
parentNode = this,
|
||||||
buildContext = buildContext,
|
buildContext = buildContext,
|
||||||
inviteData = navTarget.inviteData,
|
inviteData = navTarget.inviteData,
|
||||||
|
callback = object : DeclineInviteAndBlockEntryPoint.Callback {
|
||||||
|
override fun onDeclineSuccess() {
|
||||||
|
backstack.pop()
|
||||||
|
}
|
||||||
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
is NavTarget.SelectNewOwnersWhenLeavingRoom -> {
|
is NavTarget.SelectNewOwnersWhenLeavingRoom -> {
|
||||||
|
|||||||
+41
-16
@@ -55,6 +55,8 @@ import io.element.android.features.home.impl.roomlist.RoomListContextMenu
|
|||||||
import io.element.android.features.home.impl.roomlist.RoomListDeclineInviteMenu
|
import io.element.android.features.home.impl.roomlist.RoomListDeclineInviteMenu
|
||||||
import io.element.android.features.home.impl.roomlist.RoomListEvent
|
import io.element.android.features.home.impl.roomlist.RoomListEvent
|
||||||
import io.element.android.features.home.impl.roomlist.RoomListState
|
import io.element.android.features.home.impl.roomlist.RoomListState
|
||||||
|
import io.element.android.features.home.impl.search.GlobalSearchEvent
|
||||||
|
import io.element.android.features.home.impl.search.GlobalSearchView
|
||||||
import io.element.android.features.home.impl.search.RoomListSearchView
|
import io.element.android.features.home.impl.search.RoomListSearchView
|
||||||
import io.element.android.features.home.impl.spacefilters.SpaceFiltersEvent
|
import io.element.android.features.home.impl.spacefilters.SpaceFiltersEvent
|
||||||
import io.element.android.features.home.impl.spacefilters.SpaceFiltersState
|
import io.element.android.features.home.impl.spacefilters.SpaceFiltersState
|
||||||
@@ -73,6 +75,7 @@ import io.element.android.libraries.designsystem.utils.lazyColumnContentPadding
|
|||||||
import io.element.android.libraries.designsystem.utils.scaffoldScrollableContentInsets
|
import io.element.android.libraries.designsystem.utils.scaffoldScrollableContentInsets
|
||||||
import io.element.android.libraries.designsystem.utils.snackbar.SnackbarHost
|
import io.element.android.libraries.designsystem.utils.snackbar.SnackbarHost
|
||||||
import io.element.android.libraries.designsystem.utils.snackbar.rememberSnackbarHostState
|
import io.element.android.libraries.designsystem.utils.snackbar.rememberSnackbarHostState
|
||||||
|
import io.element.android.libraries.matrix.api.core.EventId
|
||||||
import io.element.android.libraries.matrix.api.core.RoomId
|
import io.element.android.libraries.matrix.api.core.RoomId
|
||||||
import io.element.android.libraries.ui.strings.CommonStrings
|
import io.element.android.libraries.ui.strings.CommonStrings
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
@@ -80,7 +83,7 @@ import kotlinx.coroutines.launch
|
|||||||
@Composable
|
@Composable
|
||||||
fun HomeView(
|
fun HomeView(
|
||||||
homeState: HomeState,
|
homeState: HomeState,
|
||||||
onRoomClick: (RoomId) -> Unit,
|
onRoomClick: (RoomId, EventId?) -> Unit,
|
||||||
onSettingsClick: () -> Unit,
|
onSettingsClick: () -> Unit,
|
||||||
onSetUpRecoveryClick: () -> Unit,
|
onSetUpRecoveryClick: () -> Unit,
|
||||||
onConfirmRecoveryKeyClick: () -> Unit,
|
onConfirmRecoveryKeyClick: () -> Unit,
|
||||||
@@ -122,22 +125,34 @@ fun HomeView(
|
|||||||
state = homeState,
|
state = homeState,
|
||||||
onSetUpRecoveryClick = onSetUpRecoveryClick,
|
onSetUpRecoveryClick = onSetUpRecoveryClick,
|
||||||
onConfirmRecoveryKeyClick = onConfirmRecoveryKeyClick,
|
onConfirmRecoveryKeyClick = onConfirmRecoveryKeyClick,
|
||||||
onRoomClick = { if (firstThrottler.canHandle()) onRoomClick(it) },
|
onRoomClick = { roomId -> if (firstThrottler.canHandle()) onRoomClick(roomId, null) },
|
||||||
onOpenSettings = { if (firstThrottler.canHandle()) onSettingsClick() },
|
onOpenSettings = { if (firstThrottler.canHandle()) onSettingsClick() },
|
||||||
onStartChatClick = { if (firstThrottler.canHandle()) onStartChatClick() },
|
onStartChatClick = { if (firstThrottler.canHandle()) onStartChatClick() },
|
||||||
onCreateSpaceClick = { if (firstThrottler.canHandle()) onCreateSpaceClick() },
|
onCreateSpaceClick = { if (firstThrottler.canHandle()) onCreateSpaceClick() },
|
||||||
onMenuActionClick = onMenuActionClick,
|
onMenuActionClick = onMenuActionClick,
|
||||||
)
|
)
|
||||||
// This overlaid view will only be visible when state.displaySearchResults is true
|
|
||||||
RoomListSearchView(
|
if (state.globalSearchState.isEnabled) {
|
||||||
state = state.searchState,
|
GlobalSearchView(
|
||||||
eventSink = state.eventSink,
|
state = state.globalSearchState,
|
||||||
hideInvitesAvatars = state.hideInvitesAvatars,
|
onSelectSearchResult = { roomId, eventId -> if (firstThrottler.canHandle()) onRoomClick(roomId, eventId) },
|
||||||
onRoomClick = { if (firstThrottler.canHandle()) onRoomClick(it) },
|
modifier = Modifier
|
||||||
modifier = Modifier
|
.fillMaxSize()
|
||||||
.fillMaxSize()
|
.background(ElementTheme.colors.bgCanvasDefault),
|
||||||
.background(ElementTheme.colors.bgCanvasDefault)
|
)
|
||||||
)
|
} else {
|
||||||
|
// This overlaid view will only be visible when state.displaySearchResults is true
|
||||||
|
RoomListSearchView(
|
||||||
|
state = state.searchState,
|
||||||
|
eventSink = state.eventSink,
|
||||||
|
hideInvitesAvatars = state.hideInvitesAvatars,
|
||||||
|
onRoomClick = { roomId -> if (firstThrottler.canHandle()) onRoomClick(roomId, null) },
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxSize()
|
||||||
|
.background(ElementTheme.colors.bgCanvasDefault)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
acceptDeclineInviteView()
|
acceptDeclineInviteView()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -186,8 +201,18 @@ private fun HomeScaffold(
|
|||||||
selectedNavigationItem = state.currentHomeNavigationBarItem,
|
selectedNavigationItem = state.currentHomeNavigationBarItem,
|
||||||
currentUserAndNeighbors = state.currentUserAndNeighbors,
|
currentUserAndNeighbors = state.currentUserAndNeighbors,
|
||||||
showAvatarIndicator = state.showAvatarIndicator,
|
showAvatarIndicator = state.showAvatarIndicator,
|
||||||
areSearchResultsDisplayed = roomListState.searchState.isSearchActive,
|
areSearchResultsDisplayed = if (roomListState.globalSearchState.isEnabled) {
|
||||||
onToggleSearch = { roomListState.eventSink(RoomListEvent.ToggleSearchResults) },
|
roomListState.globalSearchState.isSearchActive
|
||||||
|
} else {
|
||||||
|
roomListState.searchState.isSearchActive
|
||||||
|
},
|
||||||
|
onToggleSearch = {
|
||||||
|
if (roomListState.globalSearchState.isEnabled) {
|
||||||
|
roomListState.globalSearchState.eventSink(GlobalSearchEvent.ToggleSearchVisibility)
|
||||||
|
} else {
|
||||||
|
roomListState.eventSink(RoomListEvent.ToggleSearchResults)
|
||||||
|
}
|
||||||
|
},
|
||||||
onMenuActionClick = onMenuActionClick,
|
onMenuActionClick = onMenuActionClick,
|
||||||
onOpenSettings = onOpenSettings,
|
onOpenSettings = onOpenSettings,
|
||||||
onAccountSwitch = {
|
onAccountSwitch = {
|
||||||
@@ -349,7 +374,7 @@ internal fun RoomListRoomSummary.contentType() = displayType.ordinal
|
|||||||
internal fun HomeViewPreview(@PreviewParameter(HomeStatePreviewParam::class) state: HomeState) = ElementPreview {
|
internal fun HomeViewPreview(@PreviewParameter(HomeStatePreviewParam::class) state: HomeState) = ElementPreview {
|
||||||
HomeView(
|
HomeView(
|
||||||
homeState = state,
|
homeState = state,
|
||||||
onRoomClick = {},
|
onRoomClick = { _, _ -> },
|
||||||
onSettingsClick = {},
|
onSettingsClick = {},
|
||||||
onSetUpRecoveryClick = {},
|
onSetUpRecoveryClick = {},
|
||||||
onConfirmRecoveryKeyClick = {},
|
onConfirmRecoveryKeyClick = {},
|
||||||
@@ -369,7 +394,7 @@ internal fun HomeViewPreview(@PreviewParameter(HomeStatePreviewParam::class) sta
|
|||||||
internal fun HomeViewA11yPreview() = ElementPreview {
|
internal fun HomeViewA11yPreview() = ElementPreview {
|
||||||
HomeView(
|
HomeView(
|
||||||
homeState = aHomeState(),
|
homeState = aHomeState(),
|
||||||
onRoomClick = {},
|
onRoomClick = { _, _ -> },
|
||||||
onSettingsClick = {},
|
onSettingsClick = {},
|
||||||
onSetUpRecoveryClick = {},
|
onSetUpRecoveryClick = {},
|
||||||
onConfirmRecoveryKeyClick = {},
|
onConfirmRecoveryKeyClick = {},
|
||||||
|
|||||||
+5
@@ -15,6 +15,8 @@ import io.element.android.features.home.impl.filters.RoomListFiltersPresenter
|
|||||||
import io.element.android.features.home.impl.filters.RoomListFiltersState
|
import io.element.android.features.home.impl.filters.RoomListFiltersState
|
||||||
import io.element.android.features.home.impl.roomlist.RoomListPresenter
|
import io.element.android.features.home.impl.roomlist.RoomListPresenter
|
||||||
import io.element.android.features.home.impl.roomlist.RoomListState
|
import io.element.android.features.home.impl.roomlist.RoomListState
|
||||||
|
import io.element.android.features.home.impl.search.GlobalSearchPresenter
|
||||||
|
import io.element.android.features.home.impl.search.GlobalSearchState
|
||||||
import io.element.android.features.home.impl.search.RoomListSearchPresenter
|
import io.element.android.features.home.impl.search.RoomListSearchPresenter
|
||||||
import io.element.android.features.home.impl.search.RoomListSearchState
|
import io.element.android.features.home.impl.search.RoomListSearchState
|
||||||
import io.element.android.features.home.impl.spacefilters.SpaceFiltersPresenter
|
import io.element.android.features.home.impl.spacefilters.SpaceFiltersPresenter
|
||||||
@@ -36,4 +38,7 @@ interface RoomListModule {
|
|||||||
|
|
||||||
@Binds
|
@Binds
|
||||||
fun bindSpaceFiltersPresenter(presenter: SpaceFiltersPresenter): Presenter<SpaceFiltersState>
|
fun bindSpaceFiltersPresenter(presenter: SpaceFiltersPresenter): Presenter<SpaceFiltersState>
|
||||||
|
|
||||||
|
@Binds
|
||||||
|
fun bindGlobalSearchPresenter(presenter: GlobalSearchPresenter): Presenter<GlobalSearchState>
|
||||||
}
|
}
|
||||||
|
|||||||
+4
@@ -30,6 +30,7 @@ import io.element.android.features.announcement.api.AnnouncementService
|
|||||||
import io.element.android.features.home.impl.datasource.RoomListDataSource
|
import io.element.android.features.home.impl.datasource.RoomListDataSource
|
||||||
import io.element.android.features.home.impl.filters.RoomListFiltersState
|
import io.element.android.features.home.impl.filters.RoomListFiltersState
|
||||||
import io.element.android.features.home.impl.filters.into
|
import io.element.android.features.home.impl.filters.into
|
||||||
|
import io.element.android.features.home.impl.search.GlobalSearchState
|
||||||
import io.element.android.features.home.impl.search.RoomListSearchEvent
|
import io.element.android.features.home.impl.search.RoomListSearchEvent
|
||||||
import io.element.android.features.home.impl.search.RoomListSearchState
|
import io.element.android.features.home.impl.search.RoomListSearchState
|
||||||
import io.element.android.features.home.impl.spacefilters.SpaceFiltersState
|
import io.element.android.features.home.impl.spacefilters.SpaceFiltersState
|
||||||
@@ -85,6 +86,7 @@ class RoomListPresenter(
|
|||||||
private val announcementService: AnnouncementService,
|
private val announcementService: AnnouncementService,
|
||||||
private val coldStartWatcher: AnalyticsColdStartWatcher,
|
private val coldStartWatcher: AnalyticsColdStartWatcher,
|
||||||
private val spaceFiltersPresenter: Presenter<SpaceFiltersState>,
|
private val spaceFiltersPresenter: Presenter<SpaceFiltersState>,
|
||||||
|
private val globalSearchPresenter: Presenter<GlobalSearchState>,
|
||||||
private val featureFlagService: FeatureFlagService,
|
private val featureFlagService: FeatureFlagService,
|
||||||
) : Presenter<RoomListState> {
|
) : Presenter<RoomListState> {
|
||||||
private val encryptionService = client.encryptionService
|
private val encryptionService = client.encryptionService
|
||||||
@@ -97,6 +99,7 @@ class RoomListPresenter(
|
|||||||
val searchState = searchPresenter.present()
|
val searchState = searchPresenter.present()
|
||||||
val spaceFiltersState = spaceFiltersPresenter.present()
|
val spaceFiltersState = spaceFiltersPresenter.present()
|
||||||
val acceptDeclineInviteState = acceptDeclineInvitePresenter.present()
|
val acceptDeclineInviteState = acceptDeclineInvitePresenter.present()
|
||||||
|
val globalSearchState = globalSearchPresenter.present()
|
||||||
|
|
||||||
LaunchedEffect(Unit) {
|
LaunchedEffect(Unit) {
|
||||||
roomListDataSource.launchIn(this)
|
roomListDataSource.launchIn(this)
|
||||||
@@ -177,6 +180,7 @@ class RoomListPresenter(
|
|||||||
leaveRoomState = leaveRoomState,
|
leaveRoomState = leaveRoomState,
|
||||||
filtersState = filtersState,
|
filtersState = filtersState,
|
||||||
searchState = searchState,
|
searchState = searchState,
|
||||||
|
globalSearchState = globalSearchState,
|
||||||
spaceFiltersState = spaceFiltersState,
|
spaceFiltersState = spaceFiltersState,
|
||||||
contentState = contentState,
|
contentState = contentState,
|
||||||
acceptDeclineInviteState = acceptDeclineInviteState,
|
acceptDeclineInviteState = acceptDeclineInviteState,
|
||||||
|
|||||||
+2
@@ -11,6 +11,7 @@ package io.element.android.features.home.impl.roomlist
|
|||||||
import androidx.compose.runtime.Immutable
|
import androidx.compose.runtime.Immutable
|
||||||
import io.element.android.features.home.impl.filters.RoomListFiltersState
|
import io.element.android.features.home.impl.filters.RoomListFiltersState
|
||||||
import io.element.android.features.home.impl.model.RoomListRoomSummary
|
import io.element.android.features.home.impl.model.RoomListRoomSummary
|
||||||
|
import io.element.android.features.home.impl.search.GlobalSearchState
|
||||||
import io.element.android.features.home.impl.search.RoomListSearchState
|
import io.element.android.features.home.impl.search.RoomListSearchState
|
||||||
import io.element.android.features.home.impl.spacefilters.SpaceFiltersState
|
import io.element.android.features.home.impl.spacefilters.SpaceFiltersState
|
||||||
import io.element.android.features.invite.api.acceptdecline.AcceptDeclineInviteState
|
import io.element.android.features.invite.api.acceptdecline.AcceptDeclineInviteState
|
||||||
@@ -27,6 +28,7 @@ data class RoomListState(
|
|||||||
val leaveRoomState: LeaveRoomState,
|
val leaveRoomState: LeaveRoomState,
|
||||||
val filtersState: RoomListFiltersState,
|
val filtersState: RoomListFiltersState,
|
||||||
val searchState: RoomListSearchState,
|
val searchState: RoomListSearchState,
|
||||||
|
val globalSearchState: GlobalSearchState,
|
||||||
val spaceFiltersState: SpaceFiltersState,
|
val spaceFiltersState: SpaceFiltersState,
|
||||||
val contentState: RoomListContentState,
|
val contentState: RoomListContentState,
|
||||||
val acceptDeclineInviteState: AcceptDeclineInviteState,
|
val acceptDeclineInviteState: AcceptDeclineInviteState,
|
||||||
|
|||||||
+8
-1
@@ -16,7 +16,9 @@ import io.element.android.features.home.impl.model.RoomListRoomSummary
|
|||||||
import io.element.android.features.home.impl.model.RoomSummaryDisplayType
|
import io.element.android.features.home.impl.model.RoomSummaryDisplayType
|
||||||
import io.element.android.features.home.impl.model.aRoomListRoomSummary
|
import io.element.android.features.home.impl.model.aRoomListRoomSummary
|
||||||
import io.element.android.features.home.impl.model.anInviteSender
|
import io.element.android.features.home.impl.model.anInviteSender
|
||||||
|
import io.element.android.features.home.impl.search.GlobalSearchState
|
||||||
import io.element.android.features.home.impl.search.RoomListSearchState
|
import io.element.android.features.home.impl.search.RoomListSearchState
|
||||||
|
import io.element.android.features.home.impl.search.aGlobalSearchState
|
||||||
import io.element.android.features.home.impl.search.aRoomListSearchState
|
import io.element.android.features.home.impl.search.aRoomListSearchState
|
||||||
import io.element.android.features.home.impl.spacefilters.SpaceFiltersState
|
import io.element.android.features.home.impl.spacefilters.SpaceFiltersState
|
||||||
import io.element.android.features.home.impl.spacefilters.anUnselectedSpaceFiltersState
|
import io.element.android.features.home.impl.spacefilters.anUnselectedSpaceFiltersState
|
||||||
@@ -41,7 +43,10 @@ open class RoomListStatePreviewParam : PreviewParameterProvider<RoomListState> {
|
|||||||
aRoomListState(contentState = aRoomsContentState(securityBannerState = SecurityBannerState.RecoveryKeyConfirmation)),
|
aRoomListState(contentState = aRoomsContentState(securityBannerState = SecurityBannerState.RecoveryKeyConfirmation)),
|
||||||
aRoomListState(contentState = anEmptyContentState()),
|
aRoomListState(contentState = anEmptyContentState()),
|
||||||
aRoomListState(contentState = aSkeletonContentState()),
|
aRoomListState(contentState = aSkeletonContentState()),
|
||||||
aRoomListState(searchState = aRoomListSearchState(isSearchActive = true, query = "Test")),
|
aRoomListState(
|
||||||
|
searchState = aRoomListSearchState(isSearchActive = true, query = "Test"),
|
||||||
|
globalSearchState = aGlobalSearchState(isEnabled = false),
|
||||||
|
),
|
||||||
aRoomListState(contentState = aRoomsContentState(securityBannerState = SecurityBannerState.SetUpRecovery)),
|
aRoomListState(contentState = aRoomsContentState(securityBannerState = SecurityBannerState.SetUpRecovery)),
|
||||||
aRoomListState(contentState = aRoomsContentState(batteryOptimizationState = aBatteryOptimizationState(shouldDisplayBanner = true))),
|
aRoomListState(contentState = aRoomsContentState(batteryOptimizationState = aBatteryOptimizationState(shouldDisplayBanner = true))),
|
||||||
aRoomListState(contentState = anEmptyContentState(securityBannerState = SecurityBannerState.RecoveryKeyConfirmation)),
|
aRoomListState(contentState = anEmptyContentState(securityBannerState = SecurityBannerState.RecoveryKeyConfirmation)),
|
||||||
@@ -53,6 +58,7 @@ internal fun aRoomListState(
|
|||||||
declineInviteMenu: RoomListState.DeclineInviteMenu = RoomListState.DeclineInviteMenu.Hidden,
|
declineInviteMenu: RoomListState.DeclineInviteMenu = RoomListState.DeclineInviteMenu.Hidden,
|
||||||
leaveRoomState: LeaveRoomState = aLeaveRoomState(),
|
leaveRoomState: LeaveRoomState = aLeaveRoomState(),
|
||||||
searchState: RoomListSearchState = aRoomListSearchState(),
|
searchState: RoomListSearchState = aRoomListSearchState(),
|
||||||
|
globalSearchState: GlobalSearchState = aGlobalSearchState(),
|
||||||
filtersState: RoomListFiltersState = aRoomListFiltersState(),
|
filtersState: RoomListFiltersState = aRoomListFiltersState(),
|
||||||
spaceFiltersState: SpaceFiltersState = anUnselectedSpaceFiltersState(),
|
spaceFiltersState: SpaceFiltersState = anUnselectedSpaceFiltersState(),
|
||||||
contentState: RoomListContentState = aRoomsContentState(),
|
contentState: RoomListContentState = aRoomsContentState(),
|
||||||
@@ -66,6 +72,7 @@ internal fun aRoomListState(
|
|||||||
leaveRoomState = leaveRoomState,
|
leaveRoomState = leaveRoomState,
|
||||||
filtersState = filtersState,
|
filtersState = filtersState,
|
||||||
searchState = searchState,
|
searchState = searchState,
|
||||||
|
globalSearchState = globalSearchState,
|
||||||
spaceFiltersState = spaceFiltersState,
|
spaceFiltersState = spaceFiltersState,
|
||||||
contentState = contentState,
|
contentState = contentState,
|
||||||
acceptDeclineInviteState = acceptDeclineInviteState,
|
acceptDeclineInviteState = acceptDeclineInviteState,
|
||||||
|
|||||||
+18
@@ -0,0 +1,18 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2026 Element Creations Ltd.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial.
|
||||||
|
* Please see LICENSE files in the repository root for full details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package io.element.android.features.home.impl.search
|
||||||
|
|
||||||
|
import androidx.compose.runtime.Immutable
|
||||||
|
|
||||||
|
@Immutable
|
||||||
|
sealed interface GlobalSearchEvent {
|
||||||
|
object ClearQuery : GlobalSearchEvent
|
||||||
|
object ToggleSearchVisibility : GlobalSearchEvent
|
||||||
|
data class UpdateVisibleRange(val range: IntRange) : GlobalSearchEvent
|
||||||
|
data class UpdateTarget(val target: GlobalSearchTarget) : GlobalSearchEvent
|
||||||
|
}
|
||||||
+301
@@ -0,0 +1,301 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2026 Element Creations Ltd.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial.
|
||||||
|
* Please see LICENSE files in the repository root for full details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package io.element.android.features.home.impl.search
|
||||||
|
|
||||||
|
import androidx.compose.foundation.text.input.clearText
|
||||||
|
import androidx.compose.foundation.text.input.rememberTextFieldState
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.compose.runtime.mutableStateOf
|
||||||
|
import androidx.compose.runtime.produceState
|
||||||
|
import androidx.compose.runtime.remember
|
||||||
|
import androidx.compose.runtime.rememberCoroutineScope
|
||||||
|
import androidx.compose.runtime.setValue
|
||||||
|
import dev.zacsweers.metro.Inject
|
||||||
|
import io.element.android.libraries.androidutils.filesize.FileSizeFormatter
|
||||||
|
import io.element.android.libraries.architecture.AsyncData
|
||||||
|
import io.element.android.libraries.architecture.Presenter
|
||||||
|
import io.element.android.libraries.core.coroutine.CoroutineDispatchers
|
||||||
|
import io.element.android.libraries.dateformatter.api.DateFormatter
|
||||||
|
import io.element.android.libraries.dateformatter.api.DateFormatterMode
|
||||||
|
import io.element.android.libraries.eventformatter.api.RoomLatestEventFormatter
|
||||||
|
import io.element.android.libraries.featureflag.api.FeatureFlagService
|
||||||
|
import io.element.android.libraries.featureflag.api.FeatureFlags
|
||||||
|
import io.element.android.libraries.matrix.api.MatrixClient
|
||||||
|
import io.element.android.libraries.matrix.api.permalink.PermalinkParser
|
||||||
|
import io.element.android.libraries.matrix.api.room.RoomInfo
|
||||||
|
import io.element.android.libraries.matrix.api.roomlist.LatestEventValue
|
||||||
|
import io.element.android.libraries.matrix.api.search.MessageSearch
|
||||||
|
import io.element.android.libraries.matrix.api.search.MessageSearchPaginationState
|
||||||
|
import io.element.android.libraries.matrix.api.search.MessageSearchResult
|
||||||
|
import io.element.android.libraries.matrix.api.search.MessageSearchService
|
||||||
|
import io.element.android.libraries.matrix.api.timeline.item.event.AudioMessageType
|
||||||
|
import io.element.android.libraries.matrix.api.timeline.item.event.FileMessageType
|
||||||
|
import io.element.android.libraries.matrix.api.timeline.item.event.ImageMessageType
|
||||||
|
import io.element.android.libraries.matrix.api.timeline.item.event.MessageContent
|
||||||
|
import io.element.android.libraries.matrix.api.timeline.item.event.MessageTypeWithAttachment
|
||||||
|
import io.element.android.libraries.matrix.api.timeline.item.event.StickerMessageType
|
||||||
|
import io.element.android.libraries.matrix.api.timeline.item.event.VideoMessageType
|
||||||
|
import io.element.android.libraries.matrix.api.timeline.item.event.VoiceMessageType
|
||||||
|
import io.element.android.libraries.matrix.api.timeline.item.event.isMediaContent
|
||||||
|
import io.element.android.libraries.matrix.ui.components.AttachmentThumbnailType
|
||||||
|
import io.element.android.libraries.matrix.ui.messages.toPlainText
|
||||||
|
import kotlinx.collections.immutable.persistentListOf
|
||||||
|
import kotlinx.collections.immutable.toImmutableList
|
||||||
|
import kotlinx.coroutines.async
|
||||||
|
import kotlinx.coroutines.awaitAll
|
||||||
|
import kotlinx.coroutines.delay
|
||||||
|
import kotlinx.coroutines.flow.collectLatest
|
||||||
|
import kotlinx.coroutines.flow.combine
|
||||||
|
import kotlinx.coroutines.flow.first
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
import timber.log.Timber
|
||||||
|
import kotlin.jvm.optionals.getOrElse
|
||||||
|
import kotlin.time.Duration.Companion.milliseconds
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
class GlobalSearchPresenter(
|
||||||
|
private val roomListSearchDataSourceFactory: RoomListSearchDataSource.Factory,
|
||||||
|
private val messageSearchService: MessageSearchService,
|
||||||
|
private val featureFlagService: FeatureFlagService,
|
||||||
|
private val latestEventFormatter: RoomLatestEventFormatter,
|
||||||
|
private val dateFormatter: DateFormatter,
|
||||||
|
private val fileSizeFormatter: FileSizeFormatter,
|
||||||
|
private val permalinkParser: PermalinkParser,
|
||||||
|
private val coroutineDispatchers: CoroutineDispatchers,
|
||||||
|
private val matrixClient: MatrixClient,
|
||||||
|
) : Presenter<GlobalSearchState> {
|
||||||
|
@Composable
|
||||||
|
override fun present(): GlobalSearchState {
|
||||||
|
val coroutineScope = rememberCoroutineScope()
|
||||||
|
val isEnabled by produceState(false) {
|
||||||
|
featureFlagService.isFeatureEnabledFlow(FeatureFlags.MessageSearch).collectLatest { value = it }
|
||||||
|
}
|
||||||
|
val roomListSearchDataSource = remember { roomListSearchDataSourceFactory.create(coroutineScope = coroutineScope) }
|
||||||
|
val queryState = rememberTextFieldState()
|
||||||
|
var isSearchActive by remember { mutableStateOf(false) }
|
||||||
|
var searchResults: AsyncData<GlobalSearchResults> by remember { mutableStateOf(AsyncData.Uninitialized) }
|
||||||
|
var currentTarget: GlobalSearchTarget by remember { mutableStateOf(GlobalSearchTarget.ROOMS) }
|
||||||
|
val currentMessageSearch: MessageSearch = remember { messageSearchService.createMessageSearch(scope = coroutineScope) }
|
||||||
|
|
||||||
|
LaunchedEffect(queryState.text) {
|
||||||
|
// Add a delay to avoid performing too many searches in a short period of time, which can be expensive
|
||||||
|
delay(200.milliseconds)
|
||||||
|
|
||||||
|
searchResults = if (queryState.text.isNotEmpty()) {
|
||||||
|
AsyncData.Loading(prevData = searchResults.dataOrNull())
|
||||||
|
} else {
|
||||||
|
AsyncData.Uninitialized
|
||||||
|
}
|
||||||
|
|
||||||
|
launch { roomListSearchDataSource.setSearchQuery(queryState.text.toString()) }
|
||||||
|
launch {
|
||||||
|
currentMessageSearch.setQuery(queryState.text.toString())
|
||||||
|
.onFailure { Timber.e(it, "Could not set query for message search") }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
LaunchedEffect(currentTarget) {
|
||||||
|
if (queryState.text.isNotEmpty()) {
|
||||||
|
searchResults = AsyncData.Loading()
|
||||||
|
}
|
||||||
|
|
||||||
|
when (currentTarget) {
|
||||||
|
GlobalSearchTarget.ROOMS -> {
|
||||||
|
roomListSearchDataSource.roomSummaries.collectLatest { results ->
|
||||||
|
Timber.d("Room list search found ${results.size} items")
|
||||||
|
// The room list data source always returns some values, even if the query is empty,
|
||||||
|
// so we only want to update the search results if the query is not empty
|
||||||
|
searchResults = if (queryState.text.isNotEmpty()) {
|
||||||
|
AsyncData.Success(GlobalSearchResults.RoomListResults(results = results))
|
||||||
|
} else {
|
||||||
|
AsyncData.Uninitialized
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
GlobalSearchTarget.MESSAGES -> {
|
||||||
|
Timber.d("Message search found ${currentMessageSearch.results.value.size} items")
|
||||||
|
combine(
|
||||||
|
currentMessageSearch.results,
|
||||||
|
currentMessageSearch.paginationState,
|
||||||
|
) { results, paginationState ->
|
||||||
|
Pair(results, paginationState)
|
||||||
|
}.collectLatest { (results, paginationState) ->
|
||||||
|
Timber.d("Message search found ${results.size} items, pagination state: $paginationState")
|
||||||
|
|
||||||
|
// Try processing the results in parallel to speed up the processing time, since we have to wait until we get the room info for each
|
||||||
|
// result, which can be slow if we have a lot of results. The original order is kept by using `awaitAll()`.
|
||||||
|
val mappedResults = results.map { result ->
|
||||||
|
async(coroutineDispatchers.computation) {
|
||||||
|
val roomInfo = matrixClient.getRoomInfoFlow(result.roomId).first().getOrElse { return@async null }
|
||||||
|
val formattedTimestamp = dateFormatter.format(
|
||||||
|
timestamp = result.timestamp,
|
||||||
|
mode = DateFormatterMode.TimeOrDate,
|
||||||
|
useRelative = true
|
||||||
|
)
|
||||||
|
|
||||||
|
if (!result.content.isMediaContent()) {
|
||||||
|
mapMessageContent(result, roomInfo, formattedTimestamp)
|
||||||
|
} else {
|
||||||
|
mapMediaContent(result, roomInfo, formattedTimestamp)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.awaitAll()
|
||||||
|
.mapNotNull { it }
|
||||||
|
|
||||||
|
searchResults = when {
|
||||||
|
queryState.text.isEmpty() -> AsyncData.Uninitialized
|
||||||
|
mappedResults.isNotEmpty() -> {
|
||||||
|
AsyncData.Success(GlobalSearchResults.MessageSearchResults(results = mappedResults.toImmutableList()))
|
||||||
|
}
|
||||||
|
paginationState is MessageSearchPaginationState.Idle && paginationState.endReached -> {
|
||||||
|
AsyncData.Success(GlobalSearchResults.MessageSearchResults(results = persistentListOf()))
|
||||||
|
}
|
||||||
|
paginationState is MessageSearchPaginationState.Loading -> {
|
||||||
|
AsyncData.Loading(prevData = searchResults.dataOrNull())
|
||||||
|
}
|
||||||
|
else -> {
|
||||||
|
AsyncData.Uninitialized
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun handleEvent(event: GlobalSearchEvent) {
|
||||||
|
when (event) {
|
||||||
|
GlobalSearchEvent.ClearQuery -> {
|
||||||
|
queryState.clearText()
|
||||||
|
}
|
||||||
|
GlobalSearchEvent.ToggleSearchVisibility -> {
|
||||||
|
isSearchActive = !isSearchActive
|
||||||
|
queryState.clearText()
|
||||||
|
}
|
||||||
|
is GlobalSearchEvent.UpdateVisibleRange -> {
|
||||||
|
when (currentTarget) {
|
||||||
|
GlobalSearchTarget.ROOMS -> coroutineScope.launch {
|
||||||
|
// TODO Maybe this is not needed? We're not displaying the latest event or timestamp info so maybe we dont need to subscribe
|
||||||
|
// to the room info for each room in the search results.
|
||||||
|
roomListSearchDataSource.updateVisibleRange(event.range)
|
||||||
|
}
|
||||||
|
GlobalSearchTarget.MESSAGES -> coroutineScope.launch {
|
||||||
|
val currentCount = (searchResults.dataOrNull() as? GlobalSearchResults.MessageSearchResults)?.results?.size ?: 0
|
||||||
|
val currentPaginationState = currentMessageSearch.paginationState.value
|
||||||
|
val canPaginate = currentPaginationState is MessageSearchPaginationState.Idle && !currentPaginationState.endReached
|
||||||
|
if (event.range.last >= currentCount - 10 && canPaginate) {
|
||||||
|
currentMessageSearch.paginate()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
is GlobalSearchEvent.UpdateTarget -> currentTarget = event.target
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return GlobalSearchState(
|
||||||
|
isEnabled = isEnabled,
|
||||||
|
isSearchActive = isSearchActive,
|
||||||
|
queryState = queryState,
|
||||||
|
currentTarget = currentTarget,
|
||||||
|
results = searchResults,
|
||||||
|
eventSink = ::handleEvent,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun mapMessageContent(
|
||||||
|
result: MessageSearchResult,
|
||||||
|
roomInfo: RoomInfo,
|
||||||
|
formattedTimestamp: String,
|
||||||
|
): MessageSearchResultItem.Message? {
|
||||||
|
val body = latestEventFormatter.format(
|
||||||
|
latestEvent = LatestEventValue.Remote(
|
||||||
|
timestamp = result.timestamp,
|
||||||
|
content = result.content,
|
||||||
|
senderId = result.senderId,
|
||||||
|
senderProfile = result.senderProfile,
|
||||||
|
isOwn = matrixClient.isMe(result.senderId),
|
||||||
|
),
|
||||||
|
isDmRoom = false,
|
||||||
|
)
|
||||||
|
return MessageSearchResultItem.Message(
|
||||||
|
messageSearchResult = result,
|
||||||
|
body = body?.toString() ?: "",
|
||||||
|
formattedTimestamp = formattedTimestamp,
|
||||||
|
roomInfo = roomInfo,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun mapMediaContent(
|
||||||
|
result: MessageSearchResult,
|
||||||
|
roomInfo: RoomInfo,
|
||||||
|
formattedTimestamp: String,
|
||||||
|
): MessageSearchResultItem.Media? {
|
||||||
|
val messageType = when (val content = result.content) {
|
||||||
|
is MessageContent if content.type is MessageTypeWithAttachment -> content.type as MessageTypeWithAttachment
|
||||||
|
else -> return null
|
||||||
|
}
|
||||||
|
|
||||||
|
val caption = messageType.toPlainText(permalinkParser, default = messageType.caption ?: messageType.filename)
|
||||||
|
|
||||||
|
val thumbnailType = when (messageType) {
|
||||||
|
is ImageMessageType -> AttachmentThumbnailType.Image
|
||||||
|
is VideoMessageType -> AttachmentThumbnailType.Video
|
||||||
|
is AudioMessageType -> AttachmentThumbnailType.Audio
|
||||||
|
is VoiceMessageType -> AttachmentThumbnailType.Voice
|
||||||
|
is FileMessageType -> AttachmentThumbnailType.File
|
||||||
|
is StickerMessageType -> AttachmentThumbnailType.Image
|
||||||
|
}
|
||||||
|
val thumbnailSource = when (messageType) {
|
||||||
|
is ImageMessageType -> messageType.info?.thumbnailSource ?: messageType.source
|
||||||
|
is VideoMessageType -> messageType.info?.thumbnailSource
|
||||||
|
is AudioMessageType -> null
|
||||||
|
is VoiceMessageType -> null
|
||||||
|
is FileMessageType -> null
|
||||||
|
is StickerMessageType -> messageType.info?.thumbnailSource ?: messageType.source
|
||||||
|
}
|
||||||
|
val blurhash = when (messageType) {
|
||||||
|
is ImageMessageType -> messageType.info?.blurhash
|
||||||
|
is VideoMessageType -> messageType.info?.blurhash
|
||||||
|
is AudioMessageType -> null
|
||||||
|
is VoiceMessageType -> null
|
||||||
|
is FileMessageType -> null
|
||||||
|
is StickerMessageType -> messageType.info?.blurhash
|
||||||
|
}
|
||||||
|
|
||||||
|
val extension = messageType.filename.split(".").takeIf { it.size > 1 }?.lastOrNull()?.uppercase()
|
||||||
|
val formattedSize = when (messageType) {
|
||||||
|
is ImageMessageType -> messageType.info?.size
|
||||||
|
is VideoMessageType -> messageType.info?.size
|
||||||
|
is AudioMessageType -> messageType.info?.size
|
||||||
|
is VoiceMessageType -> messageType.info?.size
|
||||||
|
is FileMessageType -> messageType.info?.size
|
||||||
|
is StickerMessageType -> messageType.info?.size
|
||||||
|
}
|
||||||
|
?.let(fileSizeFormatter::format)
|
||||||
|
|
||||||
|
val mediaContent = MediaSearchResultContent(
|
||||||
|
filename = messageType.filename,
|
||||||
|
extension = extension,
|
||||||
|
caption = caption,
|
||||||
|
formattedSize = formattedSize,
|
||||||
|
thumbnailSource = thumbnailSource,
|
||||||
|
thumbnailType = thumbnailType,
|
||||||
|
blurhash = blurhash
|
||||||
|
)
|
||||||
|
|
||||||
|
return MessageSearchResultItem.Media(
|
||||||
|
messageSearchResult = result,
|
||||||
|
mediaContent = mediaContent,
|
||||||
|
formattedTimestamp = formattedTimestamp,
|
||||||
|
roomInfo = roomInfo,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
+92
@@ -0,0 +1,92 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2026 Element Creations Ltd.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial.
|
||||||
|
* Please see LICENSE files in the repository root for full details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package io.element.android.features.home.impl.search
|
||||||
|
|
||||||
|
import androidx.compose.foundation.text.input.TextFieldState
|
||||||
|
import androidx.compose.runtime.Immutable
|
||||||
|
import io.element.android.features.home.impl.model.RoomListRoomSummary
|
||||||
|
import io.element.android.libraries.architecture.AsyncData
|
||||||
|
import io.element.android.libraries.matrix.api.core.EventId
|
||||||
|
import io.element.android.libraries.matrix.api.core.RoomId
|
||||||
|
import io.element.android.libraries.matrix.api.core.UserId
|
||||||
|
import io.element.android.libraries.matrix.api.media.MediaSource
|
||||||
|
import io.element.android.libraries.matrix.api.room.RoomInfo
|
||||||
|
import io.element.android.libraries.matrix.api.search.MessageSearchResult
|
||||||
|
import io.element.android.libraries.matrix.api.timeline.item.event.getDisambiguatedDisplayName
|
||||||
|
import io.element.android.libraries.matrix.ui.components.AttachmentThumbnailType
|
||||||
|
import kotlinx.collections.immutable.ImmutableList
|
||||||
|
|
||||||
|
@Immutable
|
||||||
|
data class GlobalSearchState(
|
||||||
|
val isEnabled: Boolean,
|
||||||
|
val isSearchActive: Boolean,
|
||||||
|
val queryState: TextFieldState,
|
||||||
|
val currentTarget: GlobalSearchTarget,
|
||||||
|
val results: AsyncData<GlobalSearchResults>,
|
||||||
|
val eventSink: (GlobalSearchEvent) -> Unit
|
||||||
|
)
|
||||||
|
|
||||||
|
@Immutable
|
||||||
|
enum class GlobalSearchTarget {
|
||||||
|
ROOMS,
|
||||||
|
MESSAGES,
|
||||||
|
}
|
||||||
|
|
||||||
|
@Immutable
|
||||||
|
sealed interface GlobalSearchResults {
|
||||||
|
data class RoomListResults(val results: ImmutableList<RoomListRoomSummary>) : GlobalSearchResults
|
||||||
|
data class MessageSearchResults(val results: ImmutableList<MessageSearchResultItem>) : GlobalSearchResults
|
||||||
|
|
||||||
|
fun isEmpty(): Boolean = when (this) {
|
||||||
|
is RoomListResults -> results.isEmpty()
|
||||||
|
is MessageSearchResults -> results.isEmpty()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sealed interface MessageSearchResultItem {
|
||||||
|
val roomId: RoomId
|
||||||
|
val eventId: EventId
|
||||||
|
val senderId: UserId
|
||||||
|
val senderName: String
|
||||||
|
val roomInfo: RoomInfo
|
||||||
|
val formattedTimestamp: String
|
||||||
|
|
||||||
|
data class Message(
|
||||||
|
val messageSearchResult: MessageSearchResult,
|
||||||
|
val body: String,
|
||||||
|
override val roomInfo: RoomInfo,
|
||||||
|
override val formattedTimestamp: String,
|
||||||
|
) : MessageSearchResultItem {
|
||||||
|
override val roomId: RoomId = messageSearchResult.roomId
|
||||||
|
override val eventId: EventId = messageSearchResult.eventId
|
||||||
|
override val senderId: UserId = messageSearchResult.senderId
|
||||||
|
override val senderName: String = messageSearchResult.senderProfile.getDisambiguatedDisplayName(senderId)
|
||||||
|
}
|
||||||
|
|
||||||
|
data class Media(
|
||||||
|
val messageSearchResult: MessageSearchResult,
|
||||||
|
val mediaContent: MediaSearchResultContent,
|
||||||
|
override val roomInfo: RoomInfo,
|
||||||
|
override val formattedTimestamp: String,
|
||||||
|
) : MessageSearchResultItem {
|
||||||
|
override val roomId: RoomId = messageSearchResult.roomId
|
||||||
|
override val eventId: EventId = messageSearchResult.eventId
|
||||||
|
override val senderId: UserId = messageSearchResult.senderId
|
||||||
|
override val senderName: String = messageSearchResult.senderProfile.getDisambiguatedDisplayName(senderId)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
data class MediaSearchResultContent(
|
||||||
|
val filename: String,
|
||||||
|
val extension: String?,
|
||||||
|
val caption: String?,
|
||||||
|
val formattedSize: String?,
|
||||||
|
val thumbnailSource: MediaSource?,
|
||||||
|
val thumbnailType: AttachmentThumbnailType,
|
||||||
|
val blurhash: String?,
|
||||||
|
)
|
||||||
+249
@@ -0,0 +1,249 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2026 Element Creations Ltd.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial.
|
||||||
|
* Please see LICENSE files in the repository root for full details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package io.element.android.features.home.impl.search
|
||||||
|
|
||||||
|
import androidx.compose.foundation.text.input.TextFieldState
|
||||||
|
import androidx.compose.ui.tooling.preview.PreviewParameterProvider
|
||||||
|
import io.element.android.features.home.impl.roomlist.aRoomListRoomSummaryList
|
||||||
|
import io.element.android.libraries.architecture.AsyncData
|
||||||
|
import io.element.android.libraries.matrix.api.core.EventId
|
||||||
|
import io.element.android.libraries.matrix.api.core.RoomAlias
|
||||||
|
import io.element.android.libraries.matrix.api.core.RoomId
|
||||||
|
import io.element.android.libraries.matrix.api.core.UserId
|
||||||
|
import io.element.android.libraries.matrix.api.media.MediaSource
|
||||||
|
import io.element.android.libraries.matrix.api.room.CallIntentConsensus
|
||||||
|
import io.element.android.libraries.matrix.api.room.CurrentUserMembership
|
||||||
|
import io.element.android.libraries.matrix.api.room.RoomInfo
|
||||||
|
import io.element.android.libraries.matrix.api.room.RoomMember
|
||||||
|
import io.element.android.libraries.matrix.api.room.RoomNotificationMode
|
||||||
|
import io.element.android.libraries.matrix.api.room.history.RoomHistoryVisibility
|
||||||
|
import io.element.android.libraries.matrix.api.room.join.JoinRule
|
||||||
|
import io.element.android.libraries.matrix.api.room.powerlevels.RoomPowerLevels
|
||||||
|
import io.element.android.libraries.matrix.api.room.powerlevels.RoomPowerLevelsValues
|
||||||
|
import io.element.android.libraries.matrix.api.room.tombstone.SuccessorRoom
|
||||||
|
import io.element.android.libraries.matrix.api.search.MessageSearchResult
|
||||||
|
import io.element.android.libraries.matrix.api.timeline.item.EventThreadInfo
|
||||||
|
import io.element.android.libraries.matrix.api.timeline.item.event.InReplyTo
|
||||||
|
import io.element.android.libraries.matrix.api.timeline.item.event.MessageContent
|
||||||
|
import io.element.android.libraries.matrix.api.timeline.item.event.MessageType
|
||||||
|
import io.element.android.libraries.matrix.api.timeline.item.event.ProfileDetails
|
||||||
|
import io.element.android.libraries.matrix.api.timeline.item.event.TextMessageType
|
||||||
|
import io.element.android.libraries.matrix.api.user.MatrixUser
|
||||||
|
import io.element.android.libraries.matrix.ui.components.AttachmentThumbnailType
|
||||||
|
import io.element.android.libraries.matrix.ui.messages.reply.aProfileDetailsReady
|
||||||
|
import kotlinx.collections.immutable.persistentListOf
|
||||||
|
import kotlinx.collections.immutable.persistentMapOf
|
||||||
|
import kotlinx.collections.immutable.toImmutableList
|
||||||
|
import kotlinx.collections.immutable.toPersistentList
|
||||||
|
|
||||||
|
class GlobalSearchStatePreviewParam : PreviewParameterProvider<GlobalSearchState> {
|
||||||
|
override val values: Sequence<GlobalSearchState>
|
||||||
|
get() = sequenceOf(
|
||||||
|
// Not enabled, no preview
|
||||||
|
aGlobalSearchState(isEnabled = false),
|
||||||
|
aGlobalSearchState(isSearchActive = true, queryState = TextFieldState("Query")),
|
||||||
|
aGlobalSearchState(
|
||||||
|
isSearchActive = true,
|
||||||
|
currentTarget = GlobalSearchTarget.ROOMS,
|
||||||
|
queryState = TextFieldState("Query"),
|
||||||
|
results = AsyncData.Loading(),
|
||||||
|
),
|
||||||
|
aGlobalSearchState(
|
||||||
|
isSearchActive = true,
|
||||||
|
currentTarget = GlobalSearchTarget.ROOMS,
|
||||||
|
queryState = TextFieldState("Query"),
|
||||||
|
results = AsyncData.Success(
|
||||||
|
GlobalSearchResults.RoomListResults(
|
||||||
|
results = aRoomListRoomSummaryList().mapIndexed { index, summary ->
|
||||||
|
summary.copy(name = "Room with Query #${index + 1}")
|
||||||
|
}.toPersistentList()
|
||||||
|
)
|
||||||
|
),
|
||||||
|
),
|
||||||
|
aGlobalSearchState(
|
||||||
|
isSearchActive = true,
|
||||||
|
currentTarget = GlobalSearchTarget.MESSAGES,
|
||||||
|
queryState = TextFieldState("Query"),
|
||||||
|
results = AsyncData.Success(GlobalSearchResults.MessageSearchResults(persistentListOf(
|
||||||
|
MessageSearchResultItem.Message(
|
||||||
|
messageSearchResult = aMessageSearchResult(eventId = EventId("\$eventId1:server.org")),
|
||||||
|
body = "A message with Query",
|
||||||
|
roomInfo = aRoomInfo(),
|
||||||
|
formattedTimestamp = "12:00",
|
||||||
|
),
|
||||||
|
MessageSearchResultItem.Media(
|
||||||
|
messageSearchResult = aMessageSearchResult(eventId = EventId("\$eventId2:server.org")),
|
||||||
|
mediaContent = MediaSearchResultContent(
|
||||||
|
filename = "file.png",
|
||||||
|
extension = "PNG",
|
||||||
|
caption = "A caption containing Query",
|
||||||
|
formattedSize = "1 MB",
|
||||||
|
thumbnailSource = MediaSource("https://example.com/thumbnail.png"),
|
||||||
|
thumbnailType = AttachmentThumbnailType.Image,
|
||||||
|
blurhash = null,
|
||||||
|
),
|
||||||
|
roomInfo = aRoomInfo(),
|
||||||
|
formattedTimestamp = "12:00",
|
||||||
|
),
|
||||||
|
))),
|
||||||
|
),
|
||||||
|
aGlobalSearchState(
|
||||||
|
isSearchActive = true,
|
||||||
|
currentTarget = GlobalSearchTarget.MESSAGES,
|
||||||
|
queryState = TextFieldState("Query"),
|
||||||
|
results = AsyncData.Success(GlobalSearchResults.MessageSearchResults(persistentListOf())),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun aRoomInfo(
|
||||||
|
id: RoomId = RoomId("!roomId:server.org"),
|
||||||
|
name: String? = "A room",
|
||||||
|
rawName: String? = "A room raw name",
|
||||||
|
topic: String? = "A room topic",
|
||||||
|
avatarUrl: String? = "https://example.com/avatar.png",
|
||||||
|
isPublic: Boolean = true,
|
||||||
|
isDirect: Boolean = false,
|
||||||
|
isEncrypted: Boolean = false,
|
||||||
|
joinRule: JoinRule? = JoinRule.Public,
|
||||||
|
isSpace: Boolean = false,
|
||||||
|
successorRoom: SuccessorRoom? = null,
|
||||||
|
isFavorite: Boolean = false,
|
||||||
|
canonicalAlias: RoomAlias? = null,
|
||||||
|
alternativeAliases: List<RoomAlias> = emptyList(),
|
||||||
|
currentUserMembership: CurrentUserMembership = CurrentUserMembership.JOINED,
|
||||||
|
inviter: RoomMember? = null,
|
||||||
|
activeMembersCount: Long = 2,
|
||||||
|
invitedMembersCount: Long = 1,
|
||||||
|
joinedMembersCount: Long = 1,
|
||||||
|
highlightCount: Long = 0,
|
||||||
|
notificationCount: Long = 0,
|
||||||
|
userDefinedNotificationMode: RoomNotificationMode? = null,
|
||||||
|
hasRoomCall: Boolean = false,
|
||||||
|
roomPowerLevels: RoomPowerLevels? = RoomPowerLevels(
|
||||||
|
values = RoomPowerLevelsValues(
|
||||||
|
ban = 0,
|
||||||
|
invite = 0,
|
||||||
|
kick = 0,
|
||||||
|
eventsDefault = 0,
|
||||||
|
stateDefault = 0,
|
||||||
|
redactEvents = 0,
|
||||||
|
roomName = 0,
|
||||||
|
roomAvatar = 0,
|
||||||
|
roomTopic = 0,
|
||||||
|
spaceChild = 0,
|
||||||
|
beacon = 0,
|
||||||
|
beaconInfo = 0
|
||||||
|
),
|
||||||
|
users = persistentMapOf(),
|
||||||
|
),
|
||||||
|
activeRoomCallParticipants: List<UserId> = emptyList(),
|
||||||
|
heroes: List<MatrixUser> = emptyList(),
|
||||||
|
pinnedEventIds: List<EventId> = emptyList(),
|
||||||
|
roomCreators: List<UserId> = emptyList(),
|
||||||
|
isMarkedUnread: Boolean = false,
|
||||||
|
numUnreadMessages: Long = 0,
|
||||||
|
numUnreadNotifications: Long = 0,
|
||||||
|
numUnreadMentions: Long = 0,
|
||||||
|
historyVisibility: RoomHistoryVisibility = RoomHistoryVisibility.Joined,
|
||||||
|
roomVersion: String? = "11",
|
||||||
|
privilegedCreatorRole: Boolean = false,
|
||||||
|
isLowPriority: Boolean = false,
|
||||||
|
activeCallIntentConsensus: CallIntentConsensus = CallIntentConsensus.None,
|
||||||
|
isDm: Boolean = false,
|
||||||
|
fullyReadEventId: EventId? = null,
|
||||||
|
) = RoomInfo(
|
||||||
|
id = id,
|
||||||
|
name = name,
|
||||||
|
rawName = rawName,
|
||||||
|
topic = topic,
|
||||||
|
avatarUrl = avatarUrl,
|
||||||
|
isPublic = isPublic,
|
||||||
|
isDirect = isDirect,
|
||||||
|
isEncrypted = isEncrypted,
|
||||||
|
joinRule = joinRule,
|
||||||
|
isSpace = isSpace,
|
||||||
|
successorRoom = successorRoom,
|
||||||
|
isFavorite = isFavorite,
|
||||||
|
canonicalAlias = canonicalAlias,
|
||||||
|
alternativeAliases = alternativeAliases.toImmutableList(),
|
||||||
|
currentUserMembership = currentUserMembership,
|
||||||
|
inviter = inviter,
|
||||||
|
activeMembersCount = activeMembersCount,
|
||||||
|
invitedMembersCount = invitedMembersCount,
|
||||||
|
joinedMembersCount = joinedMembersCount,
|
||||||
|
highlightCount = highlightCount,
|
||||||
|
notificationCount = notificationCount,
|
||||||
|
userDefinedNotificationMode = userDefinedNotificationMode,
|
||||||
|
hasRoomCall = hasRoomCall,
|
||||||
|
roomPowerLevels = roomPowerLevels,
|
||||||
|
activeRoomCallParticipants = activeRoomCallParticipants.toImmutableList(),
|
||||||
|
heroes = heroes.toImmutableList(),
|
||||||
|
pinnedEventIds = pinnedEventIds.toImmutableList(),
|
||||||
|
creators = roomCreators.toImmutableList(),
|
||||||
|
isMarkedUnread = isMarkedUnread,
|
||||||
|
numUnreadMessages = numUnreadMessages,
|
||||||
|
numUnreadNotifications = numUnreadNotifications,
|
||||||
|
numUnreadMentions = numUnreadMentions,
|
||||||
|
historyVisibility = historyVisibility,
|
||||||
|
roomVersion = roomVersion,
|
||||||
|
privilegedCreatorRole = privilegedCreatorRole,
|
||||||
|
isLowPriority = isLowPriority,
|
||||||
|
activeCallIntentConsensus = activeCallIntentConsensus,
|
||||||
|
isDm = isDm,
|
||||||
|
fullyReadEventId = fullyReadEventId,
|
||||||
|
)
|
||||||
|
|
||||||
|
fun aMessageContent(
|
||||||
|
body: String = "body",
|
||||||
|
inReplyTo: InReplyTo? = null,
|
||||||
|
isEdited: Boolean = false,
|
||||||
|
threadInfo: EventThreadInfo? = null,
|
||||||
|
messageType: MessageType = TextMessageType(
|
||||||
|
body = body,
|
||||||
|
formatted = null
|
||||||
|
)
|
||||||
|
) = MessageContent(
|
||||||
|
body = body,
|
||||||
|
inReplyTo = inReplyTo,
|
||||||
|
isEdited = isEdited,
|
||||||
|
threadInfo = threadInfo,
|
||||||
|
type = messageType
|
||||||
|
)
|
||||||
|
|
||||||
|
internal fun aMessageSearchResult(
|
||||||
|
roomId: RoomId = RoomId("!roomId:server.org"),
|
||||||
|
eventId: EventId = EventId("\$eventId:server.org"),
|
||||||
|
senderId: UserId = UserId("@user:server.org"),
|
||||||
|
senderProfile: ProfileDetails = aProfileDetailsReady(),
|
||||||
|
content: MessageContent = aMessageContent(),
|
||||||
|
timestamp: Long = 0L,
|
||||||
|
) = MessageSearchResult(
|
||||||
|
roomId = roomId,
|
||||||
|
eventId = eventId,
|
||||||
|
senderId = senderId,
|
||||||
|
senderProfile = senderProfile,
|
||||||
|
content = content,
|
||||||
|
timestamp = timestamp,
|
||||||
|
)
|
||||||
|
|
||||||
|
internal fun aGlobalSearchState(
|
||||||
|
isEnabled: Boolean = true,
|
||||||
|
isSearchActive: Boolean = false,
|
||||||
|
queryState: TextFieldState = TextFieldState(),
|
||||||
|
currentTarget: GlobalSearchTarget = GlobalSearchTarget.ROOMS,
|
||||||
|
results: AsyncData<GlobalSearchResults> = AsyncData.Uninitialized,
|
||||||
|
eventSink: (GlobalSearchEvent) -> Unit = {},
|
||||||
|
) = GlobalSearchState(
|
||||||
|
isEnabled = isEnabled,
|
||||||
|
isSearchActive = isSearchActive,
|
||||||
|
queryState = queryState,
|
||||||
|
currentTarget = currentTarget,
|
||||||
|
results = results,
|
||||||
|
eventSink = eventSink
|
||||||
|
)
|
||||||
+564
@@ -0,0 +1,564 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2026 Element Creations Ltd.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial.
|
||||||
|
* Please see LICENSE files in the repository root for full details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package io.element.android.features.home.impl.search
|
||||||
|
|
||||||
|
import androidx.activity.compose.BackHandler
|
||||||
|
import androidx.compose.animation.AnimatedVisibility
|
||||||
|
import androidx.compose.animation.fadeIn
|
||||||
|
import androidx.compose.animation.fadeOut
|
||||||
|
import androidx.compose.foundation.background
|
||||||
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
|
import androidx.compose.foundation.layout.Column
|
||||||
|
import androidx.compose.foundation.layout.Row
|
||||||
|
import androidx.compose.foundation.layout.Spacer
|
||||||
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
|
import androidx.compose.foundation.layout.padding
|
||||||
|
import androidx.compose.foundation.layout.size
|
||||||
|
import androidx.compose.foundation.layout.width
|
||||||
|
import androidx.compose.foundation.lazy.LazyColumn
|
||||||
|
import androidx.compose.foundation.lazy.LazyListScope
|
||||||
|
import androidx.compose.foundation.lazy.itemsIndexed
|
||||||
|
import androidx.compose.foundation.lazy.rememberLazyListState
|
||||||
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||||
|
import androidx.compose.foundation.text.input.TextFieldLineLimits
|
||||||
|
import androidx.compose.material3.MaterialTheme
|
||||||
|
import androidx.compose.material3.SingleChoiceSegmentedButtonRow
|
||||||
|
import androidx.compose.material3.TextFieldDefaults
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
|
import androidx.compose.runtime.remember
|
||||||
|
import androidx.compose.ui.Alignment
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.draw.clip
|
||||||
|
import androidx.compose.ui.draw.drawBehind
|
||||||
|
import androidx.compose.ui.focus.FocusRequester
|
||||||
|
import androidx.compose.ui.focus.focusRequester
|
||||||
|
import androidx.compose.ui.geometry.Offset
|
||||||
|
import androidx.compose.ui.graphics.Color
|
||||||
|
import androidx.compose.ui.res.stringResource
|
||||||
|
import androidx.compose.ui.semantics.contentDescription
|
||||||
|
import androidx.compose.ui.semantics.semantics
|
||||||
|
import androidx.compose.ui.text.style.TextOverflow
|
||||||
|
import androidx.compose.ui.tooling.preview.PreviewParameter
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
|
import io.element.android.compound.theme.ElementTheme
|
||||||
|
import io.element.android.compound.tokens.generated.CompoundIcons
|
||||||
|
import io.element.android.features.home.impl.R
|
||||||
|
import io.element.android.features.home.impl.model.RoomListRoomSummary
|
||||||
|
import io.element.android.libraries.designsystem.atomic.molecules.IconTitleSubtitleMolecule
|
||||||
|
import io.element.android.libraries.designsystem.components.BigIcon
|
||||||
|
import io.element.android.libraries.designsystem.components.avatar.Avatar
|
||||||
|
import io.element.android.libraries.designsystem.components.avatar.AvatarData
|
||||||
|
import io.element.android.libraries.designsystem.components.avatar.AvatarSize
|
||||||
|
import io.element.android.libraries.designsystem.components.avatar.AvatarType
|
||||||
|
import io.element.android.libraries.designsystem.components.button.BackButton
|
||||||
|
import io.element.android.libraries.designsystem.modifiers.niceClickable
|
||||||
|
import io.element.android.libraries.designsystem.preview.ElementPreview
|
||||||
|
import io.element.android.libraries.designsystem.preview.PreviewsDayNight
|
||||||
|
import io.element.android.libraries.designsystem.text.roundToPx
|
||||||
|
import io.element.android.libraries.designsystem.theme.components.FilledTextField
|
||||||
|
import io.element.android.libraries.designsystem.theme.components.Icon
|
||||||
|
import io.element.android.libraries.designsystem.theme.components.IconButton
|
||||||
|
import io.element.android.libraries.designsystem.theme.components.LinearProgressIndicator
|
||||||
|
import io.element.android.libraries.designsystem.theme.components.Scaffold
|
||||||
|
import io.element.android.libraries.designsystem.theme.components.SegmentedButton
|
||||||
|
import io.element.android.libraries.designsystem.theme.components.Text
|
||||||
|
import io.element.android.libraries.designsystem.theme.components.TopAppBar
|
||||||
|
import io.element.android.libraries.designsystem.utils.OnVisibleRangeChangeEffect
|
||||||
|
import io.element.android.libraries.designsystem.utils.lazyColumnContentPadding
|
||||||
|
import io.element.android.libraries.designsystem.utils.scaffoldScrollableContentInsets
|
||||||
|
import io.element.android.libraries.matrix.api.core.EventId
|
||||||
|
import io.element.android.libraries.matrix.api.core.RoomId
|
||||||
|
import io.element.android.libraries.matrix.ui.components.AttachmentThumbnail
|
||||||
|
import io.element.android.libraries.matrix.ui.components.AttachmentThumbnailInfo
|
||||||
|
import io.element.android.libraries.matrix.ui.model.getAvatarData
|
||||||
|
import io.element.android.libraries.ui.strings.CommonStrings
|
||||||
|
import kotlinx.collections.immutable.ImmutableList
|
||||||
|
import kotlinx.collections.immutable.toImmutableList
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun GlobalSearchView(
|
||||||
|
state: GlobalSearchState,
|
||||||
|
onSelectSearchResult: (RoomId, EventId?) -> Unit,
|
||||||
|
modifier: Modifier = Modifier,
|
||||||
|
) {
|
||||||
|
BackHandler(enabled = state.isSearchActive) {
|
||||||
|
state.eventSink(GlobalSearchEvent.ToggleSearchVisibility)
|
||||||
|
}
|
||||||
|
|
||||||
|
AnimatedVisibility(
|
||||||
|
visible = state.isSearchActive,
|
||||||
|
enter = fadeIn(),
|
||||||
|
exit = fadeOut(),
|
||||||
|
) {
|
||||||
|
Column(modifier = modifier) {
|
||||||
|
GlobalSearchContent(
|
||||||
|
state = state,
|
||||||
|
onBackButtonClick = {
|
||||||
|
state.eventSink(GlobalSearchEvent.ToggleSearchVisibility)
|
||||||
|
},
|
||||||
|
onSelectSearchResult = onSelectSearchResult,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
private fun GlobalSearchContent(
|
||||||
|
state: GlobalSearchState,
|
||||||
|
onBackButtonClick: () -> Unit,
|
||||||
|
onSelectSearchResult: (RoomId, EventId?) -> Unit,
|
||||||
|
) {
|
||||||
|
val borderColor = MaterialTheme.colorScheme.tertiary
|
||||||
|
val strokeWidth = 1.dp
|
||||||
|
|
||||||
|
val drawBottomLineModifier = Modifier.drawBehind {
|
||||||
|
drawLine(
|
||||||
|
color = borderColor,
|
||||||
|
start = Offset(0f, size.height),
|
||||||
|
end = Offset(size.width, size.height),
|
||||||
|
strokeWidth = strokeWidth.value
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
Scaffold(
|
||||||
|
topBar = {
|
||||||
|
TopAppBar(
|
||||||
|
navigationIcon = { BackButton(onClick = onBackButtonClick) },
|
||||||
|
title = {
|
||||||
|
// The stateSaver will keep the selection state when returning to this UI
|
||||||
|
val focusRequester = remember { FocusRequester() }
|
||||||
|
val searchLabel = stringResource(CommonStrings.action_search)
|
||||||
|
FilledTextField(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.focusRequester(focusRequester)
|
||||||
|
.semantics { contentDescription = searchLabel },
|
||||||
|
state = state.queryState,
|
||||||
|
lineLimits = TextFieldLineLimits.SingleLine,
|
||||||
|
colors = TextFieldDefaults.colors(
|
||||||
|
focusedContainerColor = Color.Transparent,
|
||||||
|
unfocusedContainerColor = Color.Transparent,
|
||||||
|
disabledContainerColor = Color.Transparent,
|
||||||
|
focusedIndicatorColor = Color.Transparent,
|
||||||
|
unfocusedIndicatorColor = Color.Transparent,
|
||||||
|
disabledIndicatorColor = Color.Transparent,
|
||||||
|
errorIndicatorColor = Color.Transparent,
|
||||||
|
),
|
||||||
|
trailingIcon = if (state.queryState.text.isNotEmpty()) {
|
||||||
|
@Composable {
|
||||||
|
IconButton(onClick = { state.eventSink(GlobalSearchEvent.ClearQuery) }) {
|
||||||
|
Icon(
|
||||||
|
imageVector = CompoundIcons.Close(),
|
||||||
|
contentDescription = stringResource(CommonStrings.a11y_clear_search_field)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
null
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
LaunchedEffect(Unit) {
|
||||||
|
if (!focusRequester.restoreFocusedChild()) {
|
||||||
|
focusRequester.requestFocus()
|
||||||
|
}
|
||||||
|
focusRequester.saveFocusedChild()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
},
|
||||||
|
contentWindowInsets = scaffoldScrollableContentInsets,
|
||||||
|
) { padding ->
|
||||||
|
Column(
|
||||||
|
modifier = Modifier.padding(padding),
|
||||||
|
) {
|
||||||
|
SingleChoiceSegmentedButtonRow(
|
||||||
|
modifier = drawBottomLineModifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.padding(start = 16.dp, end = 16.dp, top = 8.dp, bottom = 8.dp)
|
||||||
|
) {
|
||||||
|
SegmentedButton(
|
||||||
|
index = 0,
|
||||||
|
count = 2,
|
||||||
|
selected = state.currentTarget == GlobalSearchTarget.ROOMS,
|
||||||
|
onClick = { state.eventSink(GlobalSearchEvent.UpdateTarget(GlobalSearchTarget.ROOMS)) },
|
||||||
|
text = stringResource(R.string.search_section_chats),
|
||||||
|
)
|
||||||
|
|
||||||
|
SegmentedButton(
|
||||||
|
index = 1,
|
||||||
|
count = 2,
|
||||||
|
selected = state.currentTarget == GlobalSearchTarget.MESSAGES,
|
||||||
|
onClick = { state.eventSink(GlobalSearchEvent.UpdateTarget(GlobalSearchTarget.MESSAGES)) },
|
||||||
|
text = stringResource(R.string.search_section_messages),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
val lazyListState = rememberLazyListState()
|
||||||
|
OnVisibleRangeChangeEffect(lazyListState) { visibleRange ->
|
||||||
|
state.eventSink(GlobalSearchEvent.UpdateVisibleRange(visibleRange))
|
||||||
|
}
|
||||||
|
|
||||||
|
LazyColumn(
|
||||||
|
modifier = Modifier.fillMaxSize(),
|
||||||
|
contentPadding = lazyColumnContentPadding,
|
||||||
|
state = lazyListState,
|
||||||
|
) {
|
||||||
|
val results = state.results.dataOrNull()
|
||||||
|
when {
|
||||||
|
state.results.isUninitialized() -> startSearching()
|
||||||
|
state.results.isLoading() -> loading()
|
||||||
|
results?.isEmpty() == true -> emptySearchResults(query = state.queryState.text.toString())
|
||||||
|
results is GlobalSearchResults.RoomListResults -> roomListResults(
|
||||||
|
results = results.results,
|
||||||
|
onRoomClick = { roomId -> onSelectSearchResult(roomId, null) },
|
||||||
|
)
|
||||||
|
results is GlobalSearchResults.MessageSearchResults -> messageSearchResults(
|
||||||
|
results = results.results,
|
||||||
|
onSearchResultSelected = onSelectSearchResult,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun LazyListScope.startSearching() {
|
||||||
|
item {
|
||||||
|
IconTitleSubtitleMolecule(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.padding(40.dp),
|
||||||
|
title = stringResource(R.string.start_searching_title),
|
||||||
|
subTitle = stringResource(R.string.start_searching_subtitle),
|
||||||
|
iconStyle = BigIcon.Style.Default(CompoundIcons.Search()),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun LazyListScope.loading() {
|
||||||
|
item {
|
||||||
|
LinearProgressIndicator(modifier = Modifier.fillMaxWidth())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun LazyListScope.emptySearchResults(query: String) {
|
||||||
|
item {
|
||||||
|
IconTitleSubtitleMolecule(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.padding(40.dp),
|
||||||
|
title = stringResource(R.string.search_no_results_title),
|
||||||
|
subTitle = stringResource(R.string.search_no_results_subtitle, query),
|
||||||
|
iconStyle = BigIcon.Style.Default(CompoundIcons.Search()),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun LazyListScope.roomListResults(
|
||||||
|
results: ImmutableList<RoomListRoomSummary>,
|
||||||
|
onRoomClick: (RoomId) -> Unit,
|
||||||
|
) {
|
||||||
|
itemsIndexed(
|
||||||
|
items = results,
|
||||||
|
key = { _, roomSummary -> roomSummary.roomId },
|
||||||
|
) { index, result ->
|
||||||
|
Row(
|
||||||
|
modifier = Modifier
|
||||||
|
.niceClickable(onClick = { onRoomClick(result.roomId) })
|
||||||
|
.fillMaxWidth()
|
||||||
|
.addSeparatorLine(color = ElementTheme.colors.separatorSecondary, isLastItem = index == results.lastIndex)
|
||||||
|
.padding(horizontal = 16.dp, vertical = 12.dp),
|
||||||
|
horizontalArrangement = Arrangement.spacedBy(12.dp),
|
||||||
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
|
) {
|
||||||
|
Avatar(
|
||||||
|
avatarData = result.avatarData.copy(size = AvatarSize.SearchRoomListItem),
|
||||||
|
avatarType = AvatarType.Room(
|
||||||
|
heroes = result.heroes.map { it.copy(size = AvatarSize.SearchRoomListItem) }.toImmutableList(),
|
||||||
|
isTombstoned = result.isTombstoned,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
Column(
|
||||||
|
verticalArrangement = Arrangement.spacedBy(2.dp),
|
||||||
|
) {
|
||||||
|
Text(
|
||||||
|
text = result.name ?: result.roomId.value,
|
||||||
|
maxLines = 1,
|
||||||
|
overflow = TextOverflow.Ellipsis,
|
||||||
|
style = ElementTheme.typography.fontBodyLgRegular,
|
||||||
|
)
|
||||||
|
|
||||||
|
if (result.isDm) {
|
||||||
|
val userId = result.heroes.firstOrNull()?.id
|
||||||
|
userId?.let {
|
||||||
|
Text(
|
||||||
|
text = it,
|
||||||
|
maxLines = 1,
|
||||||
|
overflow = TextOverflow.Ellipsis,
|
||||||
|
style = ElementTheme.typography.fontBodyMdRegular,
|
||||||
|
color = ElementTheme.colors.textSecondary,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
result.canonicalAlias?.let {
|
||||||
|
Text(
|
||||||
|
text = it.value,
|
||||||
|
maxLines = 1,
|
||||||
|
overflow = TextOverflow.Ellipsis,
|
||||||
|
style = ElementTheme.typography.fontBodyMdRegular,
|
||||||
|
color = ElementTheme.colors.textSecondary,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun LazyListScope.messageSearchResults(
|
||||||
|
results: ImmutableList<MessageSearchResultItem>,
|
||||||
|
onSearchResultSelected: (RoomId, EventId?) -> Unit,
|
||||||
|
) {
|
||||||
|
if (results.isNotEmpty()) {
|
||||||
|
item {
|
||||||
|
Text(
|
||||||
|
modifier = Modifier.padding(horizontal = 16.dp, vertical = 12.dp),
|
||||||
|
text = stringResource(R.string.search_from_your_messages_header),
|
||||||
|
style = ElementTheme.typography.fontBodyMdMedium,
|
||||||
|
color = ElementTheme.colors.textSecondary,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
itemsIndexed(
|
||||||
|
items = results,
|
||||||
|
contentType = { _, messageSearchResult -> messageSearchResult::class.java },
|
||||||
|
key = { _, messageSearchResult -> messageSearchResult.eventId },
|
||||||
|
) { index, result ->
|
||||||
|
val clickableModifier = Modifier.niceClickable(onClick = { onSearchResultSelected(result.roomId, result.eventId) })
|
||||||
|
when (result) {
|
||||||
|
is MessageSearchResultItem.Message -> TextMessageSearchResultItemView(
|
||||||
|
modifier = clickableModifier.addSeparatorLine(color = ElementTheme.colors.separatorSecondary, isLastItem = index == results.lastIndex),
|
||||||
|
avatarData = result.roomInfo.getAvatarData(AvatarSize.RoomListItem),
|
||||||
|
avatarType = AvatarType.Room(
|
||||||
|
heroes = result.roomInfo.heroes.map { it.getAvatarData(AvatarSize.RoomListItem) }.toImmutableList(),
|
||||||
|
isTombstoned = result.roomInfo.successorRoom != null
|
||||||
|
),
|
||||||
|
roomName = result.roomInfo.name ?: result.roomInfo.id.value,
|
||||||
|
body = result.body,
|
||||||
|
formattedTimestamp = result.formattedTimestamp,
|
||||||
|
)
|
||||||
|
is MessageSearchResultItem.Media -> {
|
||||||
|
MediaMessageSearchResultItemView(
|
||||||
|
modifier = clickableModifier.addSeparatorLine(color = ElementTheme.colors.separatorSecondary, isLastItem = index == results.lastIndex),
|
||||||
|
avatarData = result.roomInfo.getAvatarData(AvatarSize.RoomListItem),
|
||||||
|
avatarType = AvatarType.Room(
|
||||||
|
heroes = result.roomInfo.heroes.map { it.getAvatarData(AvatarSize.RoomListItem) }.toImmutableList(),
|
||||||
|
isTombstoned = result.roomInfo.successorRoom != null
|
||||||
|
),
|
||||||
|
roomName = result.roomInfo.name ?: result.roomInfo.id.value,
|
||||||
|
content = result.mediaContent,
|
||||||
|
formattedTimestamp = result.formattedTimestamp,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
private fun TextMessageSearchResultItemView(
|
||||||
|
avatarData: AvatarData,
|
||||||
|
avatarType: AvatarType,
|
||||||
|
roomName: String,
|
||||||
|
body: String,
|
||||||
|
formattedTimestamp: String,
|
||||||
|
modifier: Modifier = Modifier,
|
||||||
|
) {
|
||||||
|
Row(
|
||||||
|
modifier = modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.padding(horizontal = 16.dp),
|
||||||
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
|
) {
|
||||||
|
Avatar(
|
||||||
|
avatarData = avatarData,
|
||||||
|
avatarType = avatarType,
|
||||||
|
)
|
||||||
|
|
||||||
|
Spacer(modifier = Modifier.width(16.dp))
|
||||||
|
|
||||||
|
Column(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.padding(top = 12.dp, bottom = 10.dp),
|
||||||
|
verticalArrangement = Arrangement.spacedBy(2.dp),
|
||||||
|
) {
|
||||||
|
Row(horizontalArrangement = Arrangement.spacedBy(16.dp)) {
|
||||||
|
Text(
|
||||||
|
modifier = Modifier.weight(1f),
|
||||||
|
text = roomName,
|
||||||
|
maxLines = 1,
|
||||||
|
style = ElementTheme.typography.fontBodyLgMedium,
|
||||||
|
)
|
||||||
|
Text(
|
||||||
|
text = formattedTimestamp,
|
||||||
|
maxLines = 1,
|
||||||
|
style = ElementTheme.typography.fontBodySmRegular,
|
||||||
|
color = ElementTheme.colors.textSecondary,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
Text(
|
||||||
|
text = body,
|
||||||
|
maxLines = 2,
|
||||||
|
overflow = TextOverflow.Ellipsis,
|
||||||
|
style = ElementTheme.typography.fontBodyMdRegular,
|
||||||
|
color = ElementTheme.colors.textSecondary,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
private fun MediaMessageSearchResultItemView(
|
||||||
|
avatarData: AvatarData,
|
||||||
|
avatarType: AvatarType,
|
||||||
|
roomName: String,
|
||||||
|
content: MediaSearchResultContent,
|
||||||
|
formattedTimestamp: String,
|
||||||
|
modifier: Modifier = Modifier,
|
||||||
|
) {
|
||||||
|
Row(
|
||||||
|
modifier = modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.padding(horizontal = 16.dp),
|
||||||
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
|
) {
|
||||||
|
Avatar(
|
||||||
|
avatarData = avatarData,
|
||||||
|
avatarType = avatarType,
|
||||||
|
)
|
||||||
|
|
||||||
|
Spacer(modifier = Modifier.width(16.dp))
|
||||||
|
|
||||||
|
Column(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.padding(vertical = 12.dp),
|
||||||
|
verticalArrangement = Arrangement.spacedBy(2.dp),
|
||||||
|
) {
|
||||||
|
Row(horizontalArrangement = Arrangement.spacedBy(16.dp)) {
|
||||||
|
Text(
|
||||||
|
modifier = Modifier.weight(1f),
|
||||||
|
text = roomName,
|
||||||
|
maxLines = 1,
|
||||||
|
style = ElementTheme.typography.fontBodyLgMedium,
|
||||||
|
)
|
||||||
|
Text(
|
||||||
|
text = formattedTimestamp,
|
||||||
|
maxLines = 1,
|
||||||
|
style = ElementTheme.typography.fontBodySmRegular,
|
||||||
|
color = ElementTheme.colors.textSecondary,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
content.caption?.let {
|
||||||
|
Text(
|
||||||
|
text = it,
|
||||||
|
maxLines = 2,
|
||||||
|
overflow = TextOverflow.Ellipsis,
|
||||||
|
style = ElementTheme.typography.fontBodyMdRegular,
|
||||||
|
color = ElementTheme.colors.textSecondary,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
Row(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth(1f)
|
||||||
|
.background(ElementTheme.colors.bgSubtleSecondary, shape = RoundedCornerShape(12.dp))
|
||||||
|
.padding(horizontal = 12.dp, vertical = 8.dp),
|
||||||
|
horizontalArrangement = Arrangement.spacedBy(8.dp),
|
||||||
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
|
) {
|
||||||
|
AttachmentThumbnail(
|
||||||
|
modifier = Modifier
|
||||||
|
.size(36.dp)
|
||||||
|
.clip(RoundedCornerShape(4.dp)),
|
||||||
|
info = AttachmentThumbnailInfo(
|
||||||
|
type = content.thumbnailType,
|
||||||
|
thumbnailSource = content.thumbnailSource,
|
||||||
|
textContent = null,
|
||||||
|
blurHash = content.blurhash,
|
||||||
|
),
|
||||||
|
thumbnailSize = 36.dp.roundToPx().toLong(),
|
||||||
|
backgroundColor = ElementTheme.colors.bgCanvasDefault,
|
||||||
|
)
|
||||||
|
|
||||||
|
Column {
|
||||||
|
Text(
|
||||||
|
text = content.filename,
|
||||||
|
maxLines = 1,
|
||||||
|
overflow = TextOverflow.Ellipsis,
|
||||||
|
style = ElementTheme.typography.fontBodyLgRegular,
|
||||||
|
)
|
||||||
|
|
||||||
|
Row(
|
||||||
|
horizontalArrangement = Arrangement.spacedBy(4.dp),
|
||||||
|
) {
|
||||||
|
content.extension?.let {
|
||||||
|
Text(
|
||||||
|
text = it,
|
||||||
|
maxLines = 1,
|
||||||
|
overflow = TextOverflow.Ellipsis,
|
||||||
|
style = ElementTheme.typography.fontBodySmRegular,
|
||||||
|
color = ElementTheme.colors.textSecondary,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
content.formattedSize?.let {
|
||||||
|
Text(
|
||||||
|
text = "($it)",
|
||||||
|
maxLines = 1,
|
||||||
|
overflow = TextOverflow.Ellipsis,
|
||||||
|
style = ElementTheme.typography.fontBodySmRegular,
|
||||||
|
color = ElementTheme.colors.textSecondary,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun Modifier.addSeparatorLine(color: Color, isLastItem: Boolean): Modifier {
|
||||||
|
if (isLastItem) return this
|
||||||
|
|
||||||
|
return this.drawBehind {
|
||||||
|
val strokeWidthPx = 1.dp.toPx()
|
||||||
|
drawLine(
|
||||||
|
color = color,
|
||||||
|
start = Offset(0f, size.height - strokeWidthPx),
|
||||||
|
end = Offset(size.width, size.height - strokeWidthPx),
|
||||||
|
strokeWidth = strokeWidthPx,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@PreviewsDayNight
|
||||||
|
@Composable
|
||||||
|
internal fun GlobalSearchViewPreview(
|
||||||
|
@PreviewParameter(GlobalSearchStatePreviewParam::class) state: GlobalSearchState,
|
||||||
|
) {
|
||||||
|
ElementPreview {
|
||||||
|
GlobalSearchView(
|
||||||
|
state = state,
|
||||||
|
onSelectSearchResult = { _, _ -> },
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
+2
@@ -46,6 +46,8 @@ class RoomListSearchDataSource(
|
|||||||
coroutineScope = coroutineScope
|
coroutineScope = coroutineScope
|
||||||
)
|
)
|
||||||
|
|
||||||
|
val loadingState = roomList.loadingState
|
||||||
|
|
||||||
val roomSummaries: Flow<ImmutableList<RoomListRoomSummary>> = roomList.summaries
|
val roomSummaries: Flow<ImmutableList<RoomListRoomSummary>> = roomList.summaries
|
||||||
.map { roomSummaries ->
|
.map { roomSummaries ->
|
||||||
roomSummaries
|
roomSummaries
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!--
|
||||||
|
~ Copyright (c) 2026 Element Creations Ltd.
|
||||||
|
~
|
||||||
|
~ SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial.
|
||||||
|
~ Please see LICENSE files in the repository root for full details.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<resources>
|
||||||
|
<string name="start_searching_title">Start searching…</string>
|
||||||
|
<string name="start_searching_subtitle">Search for chats and messages</string>
|
||||||
|
<string name="search_section_chats">Chats</string>
|
||||||
|
<string name="search_from_your_messages_header">From your messages</string>
|
||||||
|
<string name="search_section_messages">Messages</string>
|
||||||
|
<string name="search_no_results_title">No results</string>
|
||||||
|
<string name="search_no_results_subtitle">There are no results for “%1$s”. Try a new search term.</string>
|
||||||
|
</resources>
|
||||||
+4
-2
@@ -11,6 +11,8 @@ package io.element.android.features.home.impl
|
|||||||
import com.bumble.appyx.core.modality.BuildContext
|
import com.bumble.appyx.core.modality.BuildContext
|
||||||
import com.google.common.truth.Truth.assertThat
|
import com.google.common.truth.Truth.assertThat
|
||||||
import io.element.android.features.home.api.HomeEntryPoint
|
import io.element.android.features.home.api.HomeEntryPoint
|
||||||
|
import io.element.android.features.invite.test.declineandblock.FakeDeclineInviteAndBlockEntryPoint
|
||||||
|
import io.element.android.libraries.matrix.api.core.EventId
|
||||||
import io.element.android.libraries.matrix.api.core.RoomId
|
import io.element.android.libraries.matrix.api.core.RoomId
|
||||||
import io.element.android.libraries.matrix.api.room.JoinedRoom
|
import io.element.android.libraries.matrix.api.room.JoinedRoom
|
||||||
import io.element.android.libraries.matrix.test.FakeMatrixClient
|
import io.element.android.libraries.matrix.test.FakeMatrixClient
|
||||||
@@ -36,14 +38,14 @@ class DefaultHomeEntryPointTest : RobolectricTest() {
|
|||||||
acceptDeclineInviteView = { _, _, _, _ -> lambdaError() },
|
acceptDeclineInviteView = { _, _, _, _ -> lambdaError() },
|
||||||
directLogoutView = { _ -> lambdaError() },
|
directLogoutView = { _ -> lambdaError() },
|
||||||
reportRoomEntryPoint = { _, _, _ -> lambdaError() },
|
reportRoomEntryPoint = { _, _, _ -> lambdaError() },
|
||||||
declineInviteAndBlockUserEntryPoint = { _, _, _ -> lambdaError() },
|
declineInviteAndBlockUserEntryPoint = FakeDeclineInviteAndBlockEntryPoint(),
|
||||||
changeRoomMemberRolesEntryPoint = { _, _, _, _ -> lambdaError() },
|
changeRoomMemberRolesEntryPoint = { _, _, _, _ -> lambdaError() },
|
||||||
leaveRoomRenderer = { _, _, _ -> lambdaError() },
|
leaveRoomRenderer = { _, _, _ -> lambdaError() },
|
||||||
sessionCoroutineScope = backgroundScope,
|
sessionCoroutineScope = backgroundScope,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
val callback = object : HomeEntryPoint.Callback {
|
val callback = object : HomeEntryPoint.Callback {
|
||||||
override fun navigateToRoom(roomId: RoomId, joinedRoom: JoinedRoom?) = lambdaError()
|
override fun navigateToRoom(roomId: RoomId, eventId: EventId?, joinedRoom: JoinedRoom?) = lambdaError()
|
||||||
override fun navigateToCreateRoom() = lambdaError()
|
override fun navigateToCreateRoom() = lambdaError()
|
||||||
override fun navigateToCreateSpace() = lambdaError()
|
override fun navigateToCreateSpace() = lambdaError()
|
||||||
override fun navigateToSettings() = lambdaError()
|
override fun navigateToSettings() = lambdaError()
|
||||||
|
|||||||
+2
@@ -20,6 +20,7 @@ import io.element.android.features.home.impl.filters.aRoomListFiltersState
|
|||||||
import io.element.android.features.home.impl.model.createRoomListRoomSummary
|
import io.element.android.features.home.impl.model.createRoomListRoomSummary
|
||||||
import io.element.android.features.home.impl.search.RoomListSearchEvent
|
import io.element.android.features.home.impl.search.RoomListSearchEvent
|
||||||
import io.element.android.features.home.impl.search.RoomListSearchState
|
import io.element.android.features.home.impl.search.RoomListSearchState
|
||||||
|
import io.element.android.features.home.impl.search.aGlobalSearchState
|
||||||
import io.element.android.features.home.impl.search.aRoomListSearchState
|
import io.element.android.features.home.impl.search.aRoomListSearchState
|
||||||
import io.element.android.features.home.impl.spacefilters.SpaceFiltersState
|
import io.element.android.features.home.impl.spacefilters.SpaceFiltersState
|
||||||
import io.element.android.features.home.impl.spacefilters.aDisabledSpaceFiltersState
|
import io.element.android.features.home.impl.spacefilters.aDisabledSpaceFiltersState
|
||||||
@@ -680,6 +681,7 @@ class RoomListPresenterTest {
|
|||||||
analyticsService = FakeAnalyticsService(),
|
analyticsService = FakeAnalyticsService(),
|
||||||
),
|
),
|
||||||
searchPresenter = searchPresenter,
|
searchPresenter = searchPresenter,
|
||||||
|
globalSearchPresenter = { aGlobalSearchState() },
|
||||||
filtersPresenter = filtersPresenter,
|
filtersPresenter = filtersPresenter,
|
||||||
spaceFiltersPresenter = spaceFiltersPresenter,
|
spaceFiltersPresenter = spaceFiltersPresenter,
|
||||||
analyticsService = analyticsService,
|
analyticsService = analyticsService,
|
||||||
|
|||||||
+1
-1
@@ -277,7 +277,7 @@ private fun AndroidComposeUiTest<ComponentActivity>.setRoomListView(
|
|||||||
setSafeContent {
|
setSafeContent {
|
||||||
HomeView(
|
HomeView(
|
||||||
homeState = aHomeState(roomListState = state),
|
homeState = aHomeState(roomListState = state),
|
||||||
onRoomClick = onRoomClick,
|
onRoomClick = { roomId, _ -> onRoomClick(roomId) },
|
||||||
onSettingsClick = onSettingsClick,
|
onSettingsClick = onSettingsClick,
|
||||||
onSetUpRecoveryClick = onSetUpRecoveryClick,
|
onSetUpRecoveryClick = onSetUpRecoveryClick,
|
||||||
onConfirmRecoveryKeyClick = onConfirmRecoveryKeyClick,
|
onConfirmRecoveryKeyClick = onConfirmRecoveryKeyClick,
|
||||||
|
|||||||
+305
@@ -0,0 +1,305 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2026 Element Creations Ltd.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial.
|
||||||
|
* Please see LICENSE files in the repository root for full details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package io.element.android.features.home.impl.search
|
||||||
|
|
||||||
|
import com.google.common.truth.Truth.assertThat
|
||||||
|
import io.element.android.features.home.impl.datasource.aRoomListRoomSummaryFactory
|
||||||
|
import io.element.android.libraries.androidutils.filesize.FakeFileSizeFormatter
|
||||||
|
import io.element.android.libraries.androidutils.filesize.FileSizeFormatter
|
||||||
|
import io.element.android.libraries.architecture.AsyncData
|
||||||
|
import io.element.android.libraries.dateformatter.api.DateFormatter
|
||||||
|
import io.element.android.libraries.dateformatter.test.FakeDateFormatter
|
||||||
|
import io.element.android.libraries.eventformatter.api.RoomLatestEventFormatter
|
||||||
|
import io.element.android.libraries.eventformatter.test.FakeRoomLatestEventFormatter
|
||||||
|
import io.element.android.libraries.featureflag.api.FeatureFlagService
|
||||||
|
import io.element.android.libraries.featureflag.api.FeatureFlags
|
||||||
|
import io.element.android.libraries.featureflag.test.FakeFeatureFlagService
|
||||||
|
import io.element.android.libraries.matrix.api.MatrixClient
|
||||||
|
import io.element.android.libraries.matrix.api.permalink.PermalinkParser
|
||||||
|
import io.element.android.libraries.matrix.api.roomlist.RoomListService
|
||||||
|
import io.element.android.libraries.matrix.api.search.MessageSearchService
|
||||||
|
import io.element.android.libraries.matrix.test.FakeMatrixClient
|
||||||
|
import io.element.android.libraries.matrix.test.permalink.FakePermalinkParser
|
||||||
|
import io.element.android.libraries.matrix.test.room.aRoomSummary
|
||||||
|
import io.element.android.libraries.matrix.test.roomlist.FakeDynamicRoomList
|
||||||
|
import io.element.android.libraries.matrix.test.roomlist.FakeRoomListService
|
||||||
|
import io.element.android.libraries.matrix.test.search.FakeMessageSearch
|
||||||
|
import io.element.android.libraries.matrix.test.search.FakeMessageSearchService
|
||||||
|
import io.element.android.tests.testutils.consumeItemsUntilPredicate
|
||||||
|
import io.element.android.tests.testutils.test
|
||||||
|
import io.element.android.tests.testutils.testCoroutineDispatchers
|
||||||
|
import kotlinx.collections.immutable.persistentListOf
|
||||||
|
import kotlinx.coroutines.CoroutineScope
|
||||||
|
import kotlinx.coroutines.flow.flowOf
|
||||||
|
import kotlinx.coroutines.test.TestScope
|
||||||
|
import kotlinx.coroutines.test.runCurrent
|
||||||
|
import kotlinx.coroutines.test.runTest
|
||||||
|
import org.junit.Test
|
||||||
|
import java.util.Optional
|
||||||
|
|
||||||
|
class GlobalSearchPresenterTest {
|
||||||
|
@Test
|
||||||
|
fun `present - initial state`() = runTest {
|
||||||
|
val presenter = createGlobalSearchPresenter()
|
||||||
|
presenter.test {
|
||||||
|
awaitItem().let { state ->
|
||||||
|
assertThat(state.isEnabled).isFalse()
|
||||||
|
assertThat(state.isSearchActive).isFalse()
|
||||||
|
assertThat(state.queryState.text.toString()).isEmpty()
|
||||||
|
assertThat(state.currentTarget).isEqualTo(GlobalSearchTarget.ROOMS)
|
||||||
|
assertThat(state.results).isEqualTo(AsyncData.Uninitialized)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `present - isEnabled reflects the feature flag`() = runTest {
|
||||||
|
val presenter = createGlobalSearchPresenter(
|
||||||
|
featureFlagService = FakeFeatureFlagService(
|
||||||
|
initialState = mapOf(FeatureFlags.MessageSearch.key to true),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
presenter.test {
|
||||||
|
// isEnabled is emitted asynchronously via produceState, so it starts as false and flips to true
|
||||||
|
var state = awaitItem()
|
||||||
|
while (!state.isEnabled) {
|
||||||
|
state = awaitItem()
|
||||||
|
}
|
||||||
|
assertThat(state.isEnabled).isTrue()
|
||||||
|
cancelAndIgnoreRemainingEvents()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `present - toggle search visibility`() = runTest {
|
||||||
|
val presenter = createGlobalSearchPresenter()
|
||||||
|
presenter.test {
|
||||||
|
awaitItem().let { state ->
|
||||||
|
assertThat(state.isSearchActive).isFalse()
|
||||||
|
state.eventSink(GlobalSearchEvent.ToggleSearchVisibility)
|
||||||
|
}
|
||||||
|
awaitItem().let { state ->
|
||||||
|
assertThat(state.isSearchActive).isTrue()
|
||||||
|
state.eventSink(GlobalSearchEvent.ToggleSearchVisibility)
|
||||||
|
}
|
||||||
|
awaitItem().let { state ->
|
||||||
|
assertThat(state.isSearchActive).isFalse()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `present - update target`() = runTest {
|
||||||
|
val presenter = createGlobalSearchPresenter()
|
||||||
|
presenter.test {
|
||||||
|
awaitItem().let { state ->
|
||||||
|
assertThat(state.currentTarget).isEqualTo(GlobalSearchTarget.ROOMS)
|
||||||
|
state.eventSink(GlobalSearchEvent.UpdateTarget(GlobalSearchTarget.MESSAGES))
|
||||||
|
}
|
||||||
|
awaitItem().let { state ->
|
||||||
|
assertThat(state.currentTarget).isEqualTo(GlobalSearchTarget.MESSAGES)
|
||||||
|
}
|
||||||
|
cancelAndIgnoreRemainingEvents()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `present - clear query`() = runTest {
|
||||||
|
val presenter = createGlobalSearchPresenter()
|
||||||
|
presenter.test {
|
||||||
|
val initialState = awaitItem()
|
||||||
|
initialState.queryState.edit { append("A query") }
|
||||||
|
awaitItem().let { state ->
|
||||||
|
assertThat(state.queryState.text.toString()).isEqualTo("A query")
|
||||||
|
state.eventSink(GlobalSearchEvent.ClearQuery)
|
||||||
|
}
|
||||||
|
awaitItem().let { state ->
|
||||||
|
assertThat(state.queryState.text.toString()).isEmpty()
|
||||||
|
}
|
||||||
|
cancelAndIgnoreRemainingEvents()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `present - room search results are emitted when the room list changes`() = runTest {
|
||||||
|
val roomList = FakeDynamicRoomList()
|
||||||
|
val roomListService = FakeRoomListService(createRoomListLambda = { roomList })
|
||||||
|
val presenter = createGlobalSearchPresenter(roomListService = roomListService)
|
||||||
|
presenter.test {
|
||||||
|
val initialState = awaitItem()
|
||||||
|
assertThat(initialState.results).isEqualTo(AsyncData.Uninitialized)
|
||||||
|
|
||||||
|
initialState.queryState.edit { append("A query") }
|
||||||
|
// Let the query be propagated to the data source before emitting results
|
||||||
|
testScheduler.advanceUntilIdle()
|
||||||
|
roomList.summaries.emit(listOf(aRoomSummary()))
|
||||||
|
|
||||||
|
// Wait for the presenter to emit a loading state before the success state
|
||||||
|
consumeItemsUntilPredicate { it.results is AsyncData.Loading }
|
||||||
|
|
||||||
|
val successState = awaitItem()
|
||||||
|
val results = (successState.results.dataOrNull() as GlobalSearchResults.RoomListResults).results
|
||||||
|
assertThat(results).hasSize(1)
|
||||||
|
cancelAndIgnoreRemainingEvents()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `present - room search displays the uninitialized state when removing the query`() = runTest {
|
||||||
|
val roomList = FakeDynamicRoomList()
|
||||||
|
val roomListService = FakeRoomListService(createRoomListLambda = { roomList })
|
||||||
|
val presenter = createGlobalSearchPresenter(roomListService = roomListService)
|
||||||
|
presenter.test {
|
||||||
|
val initialState = awaitItem()
|
||||||
|
assertThat(initialState.results).isEqualTo(AsyncData.Uninitialized)
|
||||||
|
|
||||||
|
initialState.queryState.edit { append("A query") }
|
||||||
|
// Let the query be propagated to the data source before emitting results
|
||||||
|
testScheduler.advanceUntilIdle()
|
||||||
|
roomList.summaries.emit(listOf(aRoomSummary()))
|
||||||
|
|
||||||
|
// Wait for the presenter to emit a loading state before the success state
|
||||||
|
consumeItemsUntilPredicate { it.results is AsyncData.Loading }
|
||||||
|
|
||||||
|
val successState = awaitItem()
|
||||||
|
val results = (successState.results.dataOrNull() as GlobalSearchResults.RoomListResults).results
|
||||||
|
assertThat(results).hasSize(1)
|
||||||
|
|
||||||
|
// Remove the query
|
||||||
|
successState.queryState.edit { replace(0, length, "") }
|
||||||
|
// Skip the intermediate state where the query is empty but results are still present
|
||||||
|
skipItems(1)
|
||||||
|
// It's back to the uninitialized state
|
||||||
|
assertThat(awaitItem().results).isInstanceOf(AsyncData.Uninitialized::class.java)
|
||||||
|
// This happens even if for some reason the room results still contained any items
|
||||||
|
assertThat(roomList.summaries.value).isNotEmpty()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `present - message search results are mapped when the message search emits`() = runTest {
|
||||||
|
val messageSearch = FakeMessageSearch()
|
||||||
|
val matrixClient = FakeMatrixClient().apply {
|
||||||
|
getRoomInfoFlowLambda = { flowOf(Optional.of(aRoomInfo())) }
|
||||||
|
}
|
||||||
|
val presenter = createGlobalSearchPresenter(
|
||||||
|
messageSearchService = FakeMessageSearchService(messageSearch),
|
||||||
|
matrixClient = matrixClient,
|
||||||
|
)
|
||||||
|
presenter.test {
|
||||||
|
val initialState = awaitItem()
|
||||||
|
initialState.eventSink(GlobalSearchEvent.UpdateTarget(GlobalSearchTarget.MESSAGES))
|
||||||
|
initialState.queryState.edit { append("A query") }
|
||||||
|
testScheduler.advanceUntilIdle()
|
||||||
|
|
||||||
|
messageSearch.emitResults(persistentListOf(aMessageSearchResult()))
|
||||||
|
testScheduler.advanceUntilIdle()
|
||||||
|
|
||||||
|
val successState = consumeItemsUntilPredicate { it.results is AsyncData.Success }.last()
|
||||||
|
val results = (successState.results.dataOrNull() as GlobalSearchResults.MessageSearchResults).results
|
||||||
|
assertThat(results).hasSize(1)
|
||||||
|
assertThat(results.first()).isInstanceOf(MessageSearchResultItem.Message::class.java)
|
||||||
|
cancelAndIgnoreRemainingEvents()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `present - message search displays the uninitialized state after removing the query`() = runTest {
|
||||||
|
val messageSearch = FakeMessageSearch()
|
||||||
|
val matrixClient = FakeMatrixClient().apply {
|
||||||
|
getRoomInfoFlowLambda = { flowOf(Optional.of(aRoomInfo())) }
|
||||||
|
}
|
||||||
|
val presenter = createGlobalSearchPresenter(
|
||||||
|
messageSearchService = FakeMessageSearchService(messageSearch),
|
||||||
|
matrixClient = matrixClient,
|
||||||
|
)
|
||||||
|
presenter.test {
|
||||||
|
val initialState = awaitItem()
|
||||||
|
initialState.eventSink(GlobalSearchEvent.UpdateTarget(GlobalSearchTarget.MESSAGES))
|
||||||
|
initialState.queryState.edit { append("A query") }
|
||||||
|
testScheduler.advanceUntilIdle()
|
||||||
|
|
||||||
|
messageSearch.emitResults(persistentListOf(aMessageSearchResult()))
|
||||||
|
testScheduler.advanceUntilIdle()
|
||||||
|
|
||||||
|
val successState = consumeItemsUntilPredicate { it.results is AsyncData.Success }.last()
|
||||||
|
val results = (successState.results.dataOrNull() as GlobalSearchResults.MessageSearchResults).results
|
||||||
|
assertThat(results).hasSize(1)
|
||||||
|
assertThat(results.first()).isInstanceOf(MessageSearchResultItem.Message::class.java)
|
||||||
|
|
||||||
|
// Remove the query
|
||||||
|
successState.queryState.edit { replace(0, length, "") }
|
||||||
|
// Skip the intermediate state where the query is empty but results are still present
|
||||||
|
skipItems(1)
|
||||||
|
// It's back to the uninitialized state
|
||||||
|
assertThat(awaitItem().results).isInstanceOf(AsyncData.Uninitialized::class.java)
|
||||||
|
// This happens even if for some reason the message results still contained any items
|
||||||
|
assertThat(messageSearch.results.value).isNotEmpty()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `present - UpdateVisibleRange triggers pagination for messages when near the end`() = runTest {
|
||||||
|
val messageSearch = FakeMessageSearch()
|
||||||
|
val matrixClient = FakeMatrixClient().apply {
|
||||||
|
getRoomInfoFlowLambda = { flowOf(Optional.of(aRoomInfo())) }
|
||||||
|
}
|
||||||
|
val presenter = createGlobalSearchPresenter(
|
||||||
|
messageSearchService = FakeMessageSearchService(messageSearch),
|
||||||
|
matrixClient = matrixClient,
|
||||||
|
)
|
||||||
|
presenter.test {
|
||||||
|
val initialState = awaitItem()
|
||||||
|
initialState.eventSink(GlobalSearchEvent.UpdateTarget(GlobalSearchTarget.MESSAGES))
|
||||||
|
initialState.queryState.edit { append("A query") }
|
||||||
|
testScheduler.advanceUntilIdle()
|
||||||
|
|
||||||
|
messageSearch.emitResults(persistentListOf(aMessageSearchResult()))
|
||||||
|
val successState = consumeItemsUntilPredicate { it.results is AsyncData.Success }.last()
|
||||||
|
|
||||||
|
successState.eventSink(GlobalSearchEvent.UpdateVisibleRange(IntRange(0, 0)))
|
||||||
|
runCurrent()
|
||||||
|
testScheduler.advanceUntilIdle()
|
||||||
|
|
||||||
|
assertThat(messageSearch.paginateCallCount).isEqualTo(1)
|
||||||
|
cancelAndIgnoreRemainingEvents()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun TestScope.createGlobalSearchPresenter(
|
||||||
|
roomListService: RoomListService = FakeRoomListService(),
|
||||||
|
messageSearchService: MessageSearchService = FakeMessageSearchService(),
|
||||||
|
featureFlagService: FeatureFlagService = FakeFeatureFlagService(),
|
||||||
|
latestEventFormatter: RoomLatestEventFormatter = FakeRoomLatestEventFormatter(),
|
||||||
|
dateFormatter: DateFormatter = FakeDateFormatter(),
|
||||||
|
fileSizeFormatter: FileSizeFormatter = FakeFileSizeFormatter(),
|
||||||
|
permalinkParser: PermalinkParser = FakePermalinkParser(),
|
||||||
|
matrixClient: MatrixClient = FakeMatrixClient(),
|
||||||
|
): GlobalSearchPresenter {
|
||||||
|
return GlobalSearchPresenter(
|
||||||
|
roomListSearchDataSourceFactory = object : RoomListSearchDataSource.Factory {
|
||||||
|
override fun create(coroutineScope: CoroutineScope): RoomListSearchDataSource {
|
||||||
|
return RoomListSearchDataSource(
|
||||||
|
coroutineScope = coroutineScope,
|
||||||
|
roomListService = roomListService,
|
||||||
|
coroutineDispatchers = testCoroutineDispatchers(),
|
||||||
|
roomSummaryFactory = aRoomListRoomSummaryFactory(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
messageSearchService = messageSearchService,
|
||||||
|
featureFlagService = featureFlagService,
|
||||||
|
latestEventFormatter = latestEventFormatter,
|
||||||
|
dateFormatter = dateFormatter,
|
||||||
|
fileSizeFormatter = fileSizeFormatter,
|
||||||
|
permalinkParser = permalinkParser,
|
||||||
|
coroutineDispatchers = testCoroutineDispatchers(),
|
||||||
|
matrixClient = matrixClient,
|
||||||
|
)
|
||||||
|
}
|
||||||
+7
-1
@@ -10,13 +10,19 @@ package io.element.android.features.invite.api.declineandblock
|
|||||||
|
|
||||||
import com.bumble.appyx.core.modality.BuildContext
|
import com.bumble.appyx.core.modality.BuildContext
|
||||||
import com.bumble.appyx.core.node.Node
|
import com.bumble.appyx.core.node.Node
|
||||||
|
import com.bumble.appyx.core.plugin.Plugin
|
||||||
import io.element.android.features.invite.api.InviteData
|
import io.element.android.features.invite.api.InviteData
|
||||||
import io.element.android.libraries.architecture.FeatureEntryPoint
|
import io.element.android.libraries.architecture.FeatureEntryPoint
|
||||||
|
|
||||||
fun interface DeclineInviteAndBlockEntryPoint : FeatureEntryPoint {
|
interface DeclineInviteAndBlockEntryPoint : FeatureEntryPoint {
|
||||||
fun createNode(
|
fun createNode(
|
||||||
parentNode: Node,
|
parentNode: Node,
|
||||||
buildContext: BuildContext,
|
buildContext: BuildContext,
|
||||||
inviteData: InviteData,
|
inviteData: InviteData,
|
||||||
|
callback: Callback,
|
||||||
): Node
|
): Node
|
||||||
|
|
||||||
|
interface Callback : Plugin {
|
||||||
|
fun onDeclineSuccess()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+4
@@ -17,7 +17,9 @@ import dev.zacsweers.metro.Assisted
|
|||||||
import dev.zacsweers.metro.AssistedInject
|
import dev.zacsweers.metro.AssistedInject
|
||||||
import io.element.android.annotations.ContributesNode
|
import io.element.android.annotations.ContributesNode
|
||||||
import io.element.android.features.invite.api.InviteData
|
import io.element.android.features.invite.api.InviteData
|
||||||
|
import io.element.android.features.invite.api.declineandblock.DeclineInviteAndBlockEntryPoint
|
||||||
import io.element.android.libraries.architecture.NodeInputs
|
import io.element.android.libraries.architecture.NodeInputs
|
||||||
|
import io.element.android.libraries.architecture.callback
|
||||||
import io.element.android.libraries.architecture.inputs
|
import io.element.android.libraries.architecture.inputs
|
||||||
import io.element.android.libraries.di.SessionScope
|
import io.element.android.libraries.di.SessionScope
|
||||||
|
|
||||||
@@ -31,6 +33,7 @@ class DeclineAndBlockNode(
|
|||||||
data class Inputs(val inviteData: InviteData) : NodeInputs
|
data class Inputs(val inviteData: InviteData) : NodeInputs
|
||||||
|
|
||||||
private val inviteData = inputs<Inputs>().inviteData
|
private val inviteData = inputs<Inputs>().inviteData
|
||||||
|
private val callback: DeclineInviteAndBlockEntryPoint.Callback = callback()
|
||||||
private val presenter = presenterFactory.create(inviteData)
|
private val presenter = presenterFactory.create(inviteData)
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
@@ -39,6 +42,7 @@ class DeclineAndBlockNode(
|
|||||||
DeclineAndBlockView(
|
DeclineAndBlockView(
|
||||||
state = state,
|
state = state,
|
||||||
onBackClick = ::navigateUp,
|
onBackClick = ::navigateUp,
|
||||||
|
onDeclineSuccess = callback::onDeclineSuccess,
|
||||||
modifier = modifier
|
modifier = modifier
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-1
@@ -46,6 +46,7 @@ import io.element.android.libraries.ui.strings.CommonStrings
|
|||||||
fun DeclineAndBlockView(
|
fun DeclineAndBlockView(
|
||||||
state: DeclineAndBlockState,
|
state: DeclineAndBlockState,
|
||||||
onBackClick: () -> Unit,
|
onBackClick: () -> Unit,
|
||||||
|
onDeclineSuccess: () -> Unit,
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
) {
|
) {
|
||||||
val focusManager = LocalFocusManager.current
|
val focusManager = LocalFocusManager.current
|
||||||
@@ -53,7 +54,7 @@ fun DeclineAndBlockView(
|
|||||||
val isDeclining = state.declineAction is AsyncAction.Loading
|
val isDeclining = state.declineAction is AsyncAction.Loading
|
||||||
AsyncActionView(
|
AsyncActionView(
|
||||||
async = state.declineAction,
|
async = state.declineAction,
|
||||||
onSuccess = { onBackClick() },
|
onSuccess = { onDeclineSuccess() },
|
||||||
errorMessage = { stringResource(CommonStrings.error_unknown) },
|
errorMessage = { stringResource(CommonStrings.error_unknown) },
|
||||||
onRetry = { state.eventSink(DeclineAndBlockEvents.Decline) },
|
onRetry = { state.eventSink(DeclineAndBlockEvents.Decline) },
|
||||||
onErrorDismiss = { state.eventSink(DeclineAndBlockEvents.ClearDeclineAction) }
|
onErrorDismiss = { state.eventSink(DeclineAndBlockEvents.ClearDeclineAction) }
|
||||||
@@ -149,5 +150,6 @@ internal fun DeclineAndBlockViewPreview(
|
|||||||
DeclineAndBlockView(
|
DeclineAndBlockView(
|
||||||
state = state,
|
state = state,
|
||||||
onBackClick = {},
|
onBackClick = {},
|
||||||
|
onDeclineSuccess = {},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-1
@@ -22,8 +22,9 @@ class DefaultDeclineAndBlockEntryPoint : DeclineInviteAndBlockEntryPoint {
|
|||||||
parentNode: Node,
|
parentNode: Node,
|
||||||
buildContext: BuildContext,
|
buildContext: BuildContext,
|
||||||
inviteData: InviteData,
|
inviteData: InviteData,
|
||||||
|
callback: DeclineInviteAndBlockEntryPoint.Callback,
|
||||||
): Node {
|
): Node {
|
||||||
val inputs = DeclineAndBlockNode.Inputs(inviteData)
|
val inputs = DeclineAndBlockNode.Inputs(inviteData)
|
||||||
return parentNode.createNode<DeclineAndBlockNode>(buildContext, plugins = listOf(inputs))
|
return parentNode.createNode<DeclineAndBlockNode>(buildContext, plugins = listOf(inputs, callback))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+17
@@ -17,6 +17,7 @@ import androidx.compose.ui.test.onNodeWithText
|
|||||||
import androidx.compose.ui.test.performTextInput
|
import androidx.compose.ui.test.performTextInput
|
||||||
import androidx.compose.ui.test.v2.runAndroidComposeUiTest
|
import androidx.compose.ui.test.v2.runAndroidComposeUiTest
|
||||||
import io.element.android.features.invite.impl.R
|
import io.element.android.features.invite.impl.R
|
||||||
|
import io.element.android.libraries.architecture.AsyncAction
|
||||||
import io.element.android.libraries.ui.strings.CommonStrings
|
import io.element.android.libraries.ui.strings.CommonStrings
|
||||||
import io.element.android.tests.testutils.EnsureNeverCalled
|
import io.element.android.tests.testutils.EnsureNeverCalled
|
||||||
import io.element.android.tests.testutils.EventsRecorder
|
import io.element.android.tests.testutils.EventsRecorder
|
||||||
@@ -41,6 +42,20 @@ class DeclineAndBlockViewTest : RobolectricTest() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `a successful decline invokes the expected callback`() = runAndroidComposeUiTest {
|
||||||
|
val eventsRecorder = EventsRecorder<DeclineAndBlockEvents>(expectEvents = false)
|
||||||
|
ensureCalledOnce {
|
||||||
|
setDeclineAndBlockView(
|
||||||
|
aDeclineAndBlockState(
|
||||||
|
declineAction = AsyncAction.Success(Unit),
|
||||||
|
eventSink = eventsRecorder,
|
||||||
|
),
|
||||||
|
onDeclineSuccess = it,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `clicking on decline when enabled emits the expected event`() = runAndroidComposeUiTest {
|
fun `clicking on decline when enabled emits the expected event`() = runAndroidComposeUiTest {
|
||||||
val eventsRecorder = EventsRecorder<DeclineAndBlockEvents>()
|
val eventsRecorder = EventsRecorder<DeclineAndBlockEvents>()
|
||||||
@@ -112,11 +127,13 @@ class DeclineAndBlockViewTest : RobolectricTest() {
|
|||||||
private fun AndroidComposeUiTest<ComponentActivity>.setDeclineAndBlockView(
|
private fun AndroidComposeUiTest<ComponentActivity>.setDeclineAndBlockView(
|
||||||
state: DeclineAndBlockState,
|
state: DeclineAndBlockState,
|
||||||
onBackClick: () -> Unit = EnsureNeverCalled(),
|
onBackClick: () -> Unit = EnsureNeverCalled(),
|
||||||
|
onDeclineSuccess: () -> Unit = EnsureNeverCalled(),
|
||||||
) {
|
) {
|
||||||
setContent {
|
setContent {
|
||||||
DeclineAndBlockView(
|
DeclineAndBlockView(
|
||||||
state = state,
|
state = state,
|
||||||
onBackClick = onBackClick,
|
onBackClick = onBackClick,
|
||||||
|
onDeclineSuccess = onDeclineSuccess,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+8
-1
@@ -11,7 +11,9 @@ package io.element.android.features.invite.impl.declineandblock
|
|||||||
import androidx.arch.core.executor.testing.InstantTaskExecutorRule
|
import androidx.arch.core.executor.testing.InstantTaskExecutorRule
|
||||||
import com.bumble.appyx.core.modality.BuildContext
|
import com.bumble.appyx.core.modality.BuildContext
|
||||||
import com.google.common.truth.Truth.assertThat
|
import com.google.common.truth.Truth.assertThat
|
||||||
|
import io.element.android.features.invite.api.declineandblock.DeclineInviteAndBlockEntryPoint
|
||||||
import io.element.android.features.invite.test.anInviteData
|
import io.element.android.features.invite.test.anInviteData
|
||||||
|
import io.element.android.tests.testutils.lambda.lambdaError
|
||||||
import io.element.android.tests.testutils.node.TestParentNode
|
import io.element.android.tests.testutils.node.TestParentNode
|
||||||
import org.junit.Rule
|
import org.junit.Rule
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
@@ -31,12 +33,17 @@ class DefaultDeclineAndBlockEntryPointTest {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
val inviteData = anInviteData()
|
val inviteData = anInviteData()
|
||||||
|
val callback = object : DeclineInviteAndBlockEntryPoint.Callback {
|
||||||
|
override fun onDeclineSuccess() = lambdaError()
|
||||||
|
}
|
||||||
val result = entryPoint.createNode(
|
val result = entryPoint.createNode(
|
||||||
parentNode = parentNode,
|
parentNode = parentNode,
|
||||||
buildContext = BuildContext.root(null),
|
buildContext = BuildContext.root(null),
|
||||||
inviteData = inviteData
|
inviteData = inviteData,
|
||||||
|
callback = callback,
|
||||||
)
|
)
|
||||||
assertThat(result).isInstanceOf(DeclineAndBlockNode::class.java)
|
assertThat(result).isInstanceOf(DeclineAndBlockNode::class.java)
|
||||||
assertThat(result.plugins).contains(DeclineAndBlockNode.Inputs(inviteData))
|
assertThat(result.plugins).contains(DeclineAndBlockNode.Inputs(inviteData))
|
||||||
|
assertThat(result.plugins).contains(callback)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
@@ -19,6 +19,7 @@ class FakeDeclineInviteAndBlockEntryPoint : DeclineInviteAndBlockEntryPoint {
|
|||||||
parentNode: Node,
|
parentNode: Node,
|
||||||
buildContext: BuildContext,
|
buildContext: BuildContext,
|
||||||
inviteData: InviteData,
|
inviteData: InviteData,
|
||||||
|
callback: DeclineInviteAndBlockEntryPoint.Callback,
|
||||||
): Node {
|
): Node {
|
||||||
lambdaError()
|
lambdaError()
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-1
@@ -69,6 +69,9 @@ class JoinRoomFlowNode(
|
|||||||
parentNode = this,
|
parentNode = this,
|
||||||
buildContext = buildContext,
|
buildContext = buildContext,
|
||||||
inviteData = navTarget.inviteData,
|
inviteData = navTarget.inviteData,
|
||||||
|
callback = object : DeclineInviteAndBlockEntryPoint.Callback {
|
||||||
|
override fun onDeclineSuccess() = navigateUp()
|
||||||
|
},
|
||||||
)
|
)
|
||||||
NavTarget.Root -> rootNode(buildContext)
|
NavTarget.Root -> rootNode(buildContext)
|
||||||
}
|
}
|
||||||
@@ -99,7 +102,7 @@ class JoinRoomFlowNode(
|
|||||||
acceptDeclineInviteView.Render(
|
acceptDeclineInviteView.Render(
|
||||||
state = state.acceptDeclineInviteState,
|
state = state.acceptDeclineInviteState,
|
||||||
onAcceptInviteSuccess = {},
|
onAcceptInviteSuccess = {},
|
||||||
onDeclineInviteSuccess = {},
|
onDeclineInviteSuccess = { navigateUp() },
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
+11
-2
@@ -60,7 +60,13 @@ class LeaveRoomPresenter(
|
|||||||
roomId: RoomId,
|
roomId: RoomId,
|
||||||
leaveAction: MutableState<AsyncAction<Unit>>,
|
leaveAction: MutableState<AsyncAction<Unit>>,
|
||||||
) = launch(dispatchers.io) {
|
) = launch(dispatchers.io) {
|
||||||
client.getRoom(roomId)?.use { room ->
|
val room = client.getRoom(roomId)
|
||||||
|
if (room == null) {
|
||||||
|
Timber.e("Unable to find room $roomId to leave it")
|
||||||
|
leaveAction.value = AsyncAction.Failure(RoomNotFoundException(roomId))
|
||||||
|
return@launch
|
||||||
|
}
|
||||||
|
room.use {
|
||||||
val roomInfo = room.roomInfoFlow.first()
|
val roomInfo = room.roomInfoFlow.first()
|
||||||
leaveAction.value = when {
|
leaveAction.value = when {
|
||||||
roomInfo.isDm -> Confirmation.Dm(roomId)
|
roomInfo.isDm -> Confirmation.Dm(roomId)
|
||||||
@@ -78,7 +84,8 @@ class LeaveRoomPresenter(
|
|||||||
leaveAction: MutableState<AsyncAction<Unit>>,
|
leaveAction: MutableState<AsyncAction<Unit>>,
|
||||||
) = launch(dispatchers.io) {
|
) = launch(dispatchers.io) {
|
||||||
leaveAction.runCatchingUpdatingState {
|
leaveAction.runCatchingUpdatingState {
|
||||||
client.getRoom(roomId)!!.use { room ->
|
val room = client.getRoom(roomId) ?: throw RoomNotFoundException(roomId)
|
||||||
|
room.use {
|
||||||
room
|
room
|
||||||
.leave()
|
.leave()
|
||||||
.onSuccess { notificationConversationService.onLeftRoom(client.sessionId, roomId) }
|
.onSuccess { notificationConversationService.onLeftRoom(client.sessionId, roomId) }
|
||||||
@@ -100,3 +107,5 @@ class LeaveRoomPresenter(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal class RoomNotFoundException(roomId: RoomId) : IllegalStateException("Room $roomId not found")
|
||||||
|
|||||||
+26
@@ -175,6 +175,32 @@ class LeaveBaseRoomPresenterTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `present - show error if the room to confirm leaving is not found`() = runTest {
|
||||||
|
val presenter = createLeaveRoomPresenter(client = FakeMatrixClient())
|
||||||
|
presenter.stateFlow().test {
|
||||||
|
val initialState = awaitItem()
|
||||||
|
initialState.eventSink(LeaveRoomEvent.LeaveRoom(A_ROOM_ID, needsConfirmation = true))
|
||||||
|
val errorState = awaitItem()
|
||||||
|
assertThat(errorState.leaveAction).isInstanceOf(AsyncAction.Failure::class.java)
|
||||||
|
cancelAndIgnoreRemainingEvents()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `present - show error if the room to leave is not found`() = runTest {
|
||||||
|
val presenter = createLeaveRoomPresenter(client = FakeMatrixClient())
|
||||||
|
presenter.stateFlow().test {
|
||||||
|
val initialState = awaitItem()
|
||||||
|
initialState.eventSink(LeaveRoomEvent.LeaveRoom(A_ROOM_ID, needsConfirmation = false))
|
||||||
|
val progressState = awaitItem()
|
||||||
|
assertThat(progressState.leaveAction).isEqualTo(AsyncAction.Loading)
|
||||||
|
val errorState = awaitItem()
|
||||||
|
assertThat(errorState.leaveAction).isInstanceOf(AsyncAction.Failure::class.java)
|
||||||
|
cancelAndIgnoreRemainingEvents()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `present - reset state after error`() = runTest {
|
fun `present - reset state after error`() = runTest {
|
||||||
val presenter = createLeaveRoomPresenter(
|
val presenter = createLeaveRoomPresenter(
|
||||||
|
|||||||
+29
-3
@@ -39,6 +39,10 @@ class LinkNewDesktopHandler(
|
|||||||
LinkDesktopStep.Uninitialized
|
LinkDesktopStep.Uninitialized
|
||||||
)
|
)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A [StateFlow] that emits the current step of the link desktop process.
|
||||||
|
* It starts with [LinkDesktopStep.Uninitialized] and will emit other steps as they occur.
|
||||||
|
*/
|
||||||
val stepFlow: StateFlow<LinkDesktopStep>
|
val stepFlow: StateFlow<LinkDesktopStep>
|
||||||
get() = linkDesktopStepFlow.asStateFlow()
|
get() = linkDesktopStepFlow.asStateFlow()
|
||||||
|
|
||||||
@@ -53,15 +57,31 @@ class LinkNewDesktopHandler(
|
|||||||
timerJob = null
|
timerJob = null
|
||||||
}
|
}
|
||||||
|
|
||||||
fun createNewHandler() {
|
/**
|
||||||
resetJobs()
|
* Starts (or restarts) a timer that will emit an error in [stepFlow] after 2 minutes.
|
||||||
handler = matrixClient.createLinkDesktopHandler().getOrNull()
|
*/
|
||||||
|
fun startTimer() {
|
||||||
|
timerJob?.cancel()
|
||||||
timerJob = sessionScope.launch {
|
timerJob = sessionScope.launch {
|
||||||
delay(2.minutes)
|
delay(2.minutes)
|
||||||
linkDesktopStepFlow.emit(LinkDesktopStep.Error(ErrorType.Expired("Scanning QrCode took too long.")))
|
linkDesktopStepFlow.emit(LinkDesktopStep.Error(ErrorType.Expired("Scanning QrCode took too long.")))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new [LinkDesktopHandler] and cancels any existing job.
|
||||||
|
* This should be called when the user wants to retry scanning a QR code.
|
||||||
|
*/
|
||||||
|
fun createNewHandler() {
|
||||||
|
currentJob?.cancel()
|
||||||
|
currentJob = null
|
||||||
|
handler = matrixClient.createLinkDesktopHandler().getOrNull()
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resets the state of the handler and cancels any existing job.
|
||||||
|
* This should be called when the user wants to start over.
|
||||||
|
*/
|
||||||
fun reset() {
|
fun reset() {
|
||||||
resetJobs()
|
resetJobs()
|
||||||
sessionScope.launch {
|
sessionScope.launch {
|
||||||
@@ -69,6 +89,12 @@ class LinkNewDesktopHandler(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handles the scanned QR code data.
|
||||||
|
* This should be called when the user scans a QR code.
|
||||||
|
*
|
||||||
|
* @param data The scanned QR code data as a byte array.
|
||||||
|
*/
|
||||||
fun onScannedCode(data: ByteArray) {
|
fun onScannedCode(data: ByteArray) {
|
||||||
resetJobs()
|
resetJobs()
|
||||||
val currentHandler = handler
|
val currentHandler = handler
|
||||||
|
|||||||
+8
@@ -263,6 +263,8 @@ class LinkNewDeviceFlowNode(
|
|||||||
}
|
}
|
||||||
LinkDeviceType.Desktop -> {
|
LinkDeviceType.Desktop -> {
|
||||||
linkNewDesktopHandler.reset()
|
linkNewDesktopHandler.reset()
|
||||||
|
// Ensure unlock state does not last longer than the timeout for scanning the QR code, so start the timer after unlock
|
||||||
|
linkNewDesktopHandler.startTimer()
|
||||||
backstack.push(NavTarget.DesktopNotice)
|
backstack.push(NavTarget.DesktopNotice)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -278,10 +280,14 @@ class LinkNewDeviceFlowNode(
|
|||||||
NavTarget.DesktopNotice -> {
|
NavTarget.DesktopNotice -> {
|
||||||
val callback = object : DesktopNoticeNode.Callback {
|
val callback = object : DesktopNoticeNode.Callback {
|
||||||
override fun navigateBack() {
|
override fun navigateBack() {
|
||||||
|
// Stop the timer when the user leaves the screen (user will have to authenticate again)
|
||||||
|
linkNewDesktopHandler.reset()
|
||||||
backstack.pop()
|
backstack.pop()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun navigateToQrCodeScanner() {
|
override fun navigateToQrCodeScanner() {
|
||||||
|
// Start again the timer when the user enters the next screen (they clicked on "Ready to scan")
|
||||||
|
linkNewDesktopHandler.startTimer()
|
||||||
backstack.push(NavTarget.DesktopScanQrCode)
|
backstack.push(NavTarget.DesktopScanQrCode)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -290,6 +296,8 @@ class LinkNewDeviceFlowNode(
|
|||||||
NavTarget.DesktopScanQrCode -> {
|
NavTarget.DesktopScanQrCode -> {
|
||||||
val callback = object : ScanQrCodeNode.Callback {
|
val callback = object : ScanQrCodeNode.Callback {
|
||||||
override fun cancel() {
|
override fun cancel() {
|
||||||
|
// start again the timer when the user goes back to the DesktopNoticeNode
|
||||||
|
linkNewDesktopHandler.startTimer()
|
||||||
backstack.pop()
|
backstack.pop()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+22
@@ -40,9 +40,19 @@ class LinkNewMobileHandler(
|
|||||||
LinkMobileStep.Uninitialized
|
LinkMobileStep.Uninitialized
|
||||||
)
|
)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A [StateFlow] that emits the current step of the link mobile process.
|
||||||
|
* It starts with [LinkMobileStep.Uninitialized] and will emit other steps as they occur.
|
||||||
|
*/
|
||||||
val stepFlow: StateFlow<LinkMobileStep>
|
val stepFlow: StateFlow<LinkMobileStep>
|
||||||
get() = linkMobileStepFlow.asStateFlow()
|
get() = linkMobileStepFlow.asStateFlow()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new [LinkMobileHandler] and starts the linking process.
|
||||||
|
* If [forRotating] is true, it indicates that this is a rotation of the QR code.
|
||||||
|
*
|
||||||
|
* @param forRotating Whether this is a rotation of the QR code. Defaults to false.
|
||||||
|
*/
|
||||||
fun createAndStartNewHandler(forRotating: Boolean = false) {
|
fun createAndStartNewHandler(forRotating: Boolean = false) {
|
||||||
Timber.tag(loggerTag.value).d("createAndStartNewHandler()")
|
Timber.tag(loggerTag.value).d("createAndStartNewHandler()")
|
||||||
currentJob?.cancel()
|
currentJob?.cancel()
|
||||||
@@ -62,6 +72,10 @@ class LinkNewMobileHandler(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resets the handler and cancels any ongoing job.
|
||||||
|
* This will also emit [LinkMobileStep.Uninitialized] to the [stepFlow].
|
||||||
|
*/
|
||||||
fun reset() {
|
fun reset() {
|
||||||
currentJob?.cancel()
|
currentJob?.cancel()
|
||||||
currentJob = null
|
currentJob = null
|
||||||
@@ -70,10 +84,18 @@ class LinkNewMobileHandler(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Rotates the QR code by creating a new handler and starting the linking process.
|
||||||
|
* This is typically called when a timeout occurs for the current QR code.
|
||||||
|
*/
|
||||||
fun rotateQrCode() {
|
fun rotateQrCode() {
|
||||||
createAndStartNewHandler(forRotating = true)
|
createAndStartNewHandler(forRotating = true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handles the case where there are too many QR code rotations.
|
||||||
|
* This will reset the handler and emit an error to the [stepFlow].
|
||||||
|
*/
|
||||||
fun onTooManyRotation() {
|
fun onTooManyRotation() {
|
||||||
reset()
|
reset()
|
||||||
sessionScope.launch {
|
sessionScope.launch {
|
||||||
|
|||||||
@@ -71,6 +71,7 @@ dependencies {
|
|||||||
implementation(projects.libraries.matrixui)
|
implementation(projects.libraries.matrixui)
|
||||||
implementation(projects.libraries.uiStrings)
|
implementation(projects.libraries.uiStrings)
|
||||||
implementation(projects.libraries.wellknown.api)
|
implementation(projects.libraries.wellknown.api)
|
||||||
|
implementation(projects.features.enterprise.api)
|
||||||
implementation(libs.coil.compose)
|
implementation(libs.coil.compose)
|
||||||
implementation(libs.datetime)
|
implementation(libs.datetime)
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -8,7 +8,7 @@
|
|||||||
package io.element.android.features.location.api
|
package io.element.android.features.location.api
|
||||||
|
|
||||||
import androidx.compose.runtime.staticCompositionLocalOf
|
import androidx.compose.runtime.staticCompositionLocalOf
|
||||||
import io.element.android.libraries.wellknown.api.MapTilerConfig
|
import io.element.android.features.enterprise.api.remoteconfig.MapTilerConfig
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides a [MapTilerConfig] for the MapLibre maps.
|
* Provides a [MapTilerConfig] for the MapLibre maps.
|
||||||
|
|||||||
+1
-1
@@ -37,6 +37,7 @@ import coil3.compose.rememberAsyncImagePainter
|
|||||||
import coil3.request.ImageRequest
|
import coil3.request.ImageRequest
|
||||||
import coil3.request.SuccessResult
|
import coil3.request.SuccessResult
|
||||||
import io.element.android.compound.theme.ElementTheme
|
import io.element.android.compound.theme.ElementTheme
|
||||||
|
import io.element.android.features.enterprise.api.remoteconfig.MapTilerConfig
|
||||||
import io.element.android.features.location.api.internal.StaticMapPlaceholder
|
import io.element.android.features.location.api.internal.StaticMapPlaceholder
|
||||||
import io.element.android.features.location.api.internal.centerBottomEdge
|
import io.element.android.features.location.api.internal.centerBottomEdge
|
||||||
import io.element.android.features.location.api.internal.rememberStaticMapBuilder
|
import io.element.android.features.location.api.internal.rememberStaticMapBuilder
|
||||||
@@ -45,7 +46,6 @@ import io.element.android.libraries.designsystem.components.PinVariant
|
|||||||
import io.element.android.libraries.designsystem.preview.ElementPreview
|
import io.element.android.libraries.designsystem.preview.ElementPreview
|
||||||
import io.element.android.libraries.designsystem.preview.PreviewsDayNight
|
import io.element.android.libraries.designsystem.preview.PreviewsDayNight
|
||||||
import io.element.android.libraries.designsystem.utils.CommonDrawables
|
import io.element.android.libraries.designsystem.utils.CommonDrawables
|
||||||
import io.element.android.libraries.wellknown.api.MapTilerConfig
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Shows a static map image downloaded via a third party service's static maps API.
|
* Shows a static map image downloaded via a third party service's static maps API.
|
||||||
|
|||||||
+1
-1
@@ -8,8 +8,8 @@
|
|||||||
|
|
||||||
package io.element.android.features.location.api.internal
|
package io.element.android.features.location.api.internal
|
||||||
|
|
||||||
|
import io.element.android.features.enterprise.api.remoteconfig.MapTilerConfig
|
||||||
import io.element.android.features.location.api.BuildConfig
|
import io.element.android.features.location.api.BuildConfig
|
||||||
import io.element.android.libraries.wellknown.api.MapTilerConfig
|
|
||||||
import kotlin.math.roundToInt
|
import kotlin.math.roundToInt
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+1
-1
@@ -10,8 +10,8 @@
|
|||||||
|
|
||||||
package io.element.android.features.location.api.internal
|
package io.element.android.features.location.api.internal
|
||||||
|
|
||||||
|
import io.element.android.features.enterprise.api.remoteconfig.MapTilerConfig
|
||||||
import io.element.android.features.location.api.BuildConfig
|
import io.element.android.features.location.api.BuildConfig
|
||||||
import io.element.android.libraries.wellknown.api.MapTilerConfig
|
|
||||||
|
|
||||||
internal class MapTilerTileServerStyleUriBuilder(
|
internal class MapTilerTileServerStyleUriBuilder(
|
||||||
private val baseUrl: String,
|
private val baseUrl: String,
|
||||||
|
|||||||
+1
-2
@@ -10,8 +10,7 @@ package io.element.android.features.location.api.internal
|
|||||||
|
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
import io.element.android.libraries.wellknown.api.MapTilerConfig
|
import io.element.android.features.enterprise.api.remoteconfig.MapTilerConfig
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Builds an URL for a 3rd party service provider static maps API.
|
* Builds an URL for a 3rd party service provider static maps API.
|
||||||
*/
|
*/
|
||||||
|
|||||||
+1
-1
@@ -11,7 +11,7 @@ package io.element.android.features.location.api.internal
|
|||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
import io.element.android.compound.theme.ElementTheme
|
import io.element.android.compound.theme.ElementTheme
|
||||||
import io.element.android.libraries.wellknown.api.MapTilerConfig
|
import io.element.android.features.enterprise.api.remoteconfig.MapTilerConfig
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Builds a style URI for a MapLibre compatible tile server.
|
* Builds a style URI for a MapLibre compatible tile server.
|
||||||
|
|||||||
+1
-1
@@ -9,7 +9,7 @@
|
|||||||
package io.element.android.features.location.api.internal
|
package io.element.android.features.location.api.internal
|
||||||
|
|
||||||
import com.google.common.truth.Truth.assertThat
|
import com.google.common.truth.Truth.assertThat
|
||||||
import io.element.android.libraries.wellknown.api.MapTilerConfig
|
import io.element.android.features.enterprise.api.remoteconfig.MapTilerConfig
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
|
|
||||||
class MapTilerTileServerStyleUriBuilderTest {
|
class MapTilerTileServerStyleUriBuilderTest {
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user