From 867bd363fd49f23ba7ae9dfc25c23af7fe34fb1a Mon Sep 17 00:00:00 2001 From: Michael Kaye <1917473+michaelkaye@users.noreply.github.com> Date: Mon, 9 May 2022 11:48:40 +0100 Subject: [PATCH 01/25] Document need for public_baseurl to be correctly set. --- docs/integration_tests.md | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/docs/integration_tests.md b/docs/integration_tests.md index 0fa1998499..b528724444 100644 --- a/docs/integration_tests.md +++ b/docs/integration_tests.md @@ -43,14 +43,17 @@ virtualenv -p python3 env source env/bin/activate pip install -e . demo/start.sh --no-rate-limit + ``` -Alternatively, to install the latest Synapse release package (and not a cloned branch) you can run the following instead of `pip install -e .`: +Alternatively, to install the latest Synapse release package (and not a cloned branch) you can run the following instead of `git clone` and `pip install -e .`: ```bash pip install matrix-synapse ``` +### Integration test failures + You should now have 3 running federated Synapse instances 🎉, at http://127.0.0.1:8080/, http://127.0.0.1:8081/ and http://127.0.0.1:8082/, which should display a "It Works! Synapse is running" message. ## Run the test @@ -87,6 +90,18 @@ You'll need python3 to be able to run synapse Try on the Emulator browser to open "http://10.0.2.2:8080". You should see the "Synapse is running" message. +### Tests partially run but some fail with "Unable to contact localhost:8080" + +This is because the `public_baseurl` of synapse is not consistent with the endpoint that the tests are connecting to. + +Ensure you have the following configuration in `demo/etc/8080.config`. + +``` +public_baseurl: http://10.0.2.2:8080/ +``` + +After changing this you will need to restart synapse using `demo/stop.sh` and `demo/start.sh` to load the new configuration. + ### virtualenv command fails You can try using From 21fc4e31b4adea5f5a7432230121d97d2b569a22 Mon Sep 17 00:00:00 2001 From: Michael Kaye <1917473+michaelkaye@users.noreply.github.com> Date: Mon, 9 May 2022 11:54:59 +0100 Subject: [PATCH 02/25] Towncrier --- changelog.d/5973.doc | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/5973.doc diff --git a/changelog.d/5973.doc b/changelog.d/5973.doc new file mode 100644 index 0000000000..cd3b31dd21 --- /dev/null +++ b/changelog.d/5973.doc @@ -0,0 +1 @@ +Note public_baseurl requirement in integration tests documentation. From 251e3a0a83a0aa0b370a72d449febcc5e75665dd Mon Sep 17 00:00:00 2001 From: Michael Kaye <1917473+michaelkaye@users.noreply.github.com> Date: Fri, 13 May 2022 10:40:03 +0100 Subject: [PATCH 03/25] Ensure we print the user in the post-PR merge tests. --- .github/workflows/post-pr.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/post-pr.yml b/.github/workflows/post-pr.yml index 54107475c7..9cd33143ad 100644 --- a/.github/workflows/post-pr.yml +++ b/.github/workflows/post-pr.yml @@ -325,5 +325,5 @@ jobs: with: github_token: ${{ secrets.GITHUB_TOKEN }} hookshot_url: ${{ secrets.ELEMENT_ANDROID_HOOKSHOT_URL }} - text_template: "Post-merge validation of ${{ github.head_ref }} into ${{ github.base_ref }} by ${{ github.event.merged_by }} failed: {{#each job_statuses }}{{#with this }}{{#if completed }} {{name}} {{conclusion}} at {{completed_at}}, {{/if}}{{/with}}{{/each}}" - html_template: "Post-merge validation of ${{ github.head_ref }} into ${{ github.base_ref }} by ${{ github.event.merged_by }} failed: {{#each job_statuses }}{{#with this }}{{#if completed }}
{{icon conclusion}} {{name}} {{conclusion}} at {{completed_at}} [details]{{/if}}{{/with}}{{/each}}" + text_template: "Post-merge validation of ${{ github.head_ref }} into ${{ github.base_ref }} by ${{ github.event.pull_request.merged_by }} failed: {{#each job_statuses }}{{#with this }}{{#if completed }} {{name}} {{conclusion}} at {{completed_at}}, {{/if}}{{/with}}{{/each}}" + html_template: "Post-merge validation of ${{ github.head_ref }} into ${{ github.base_ref }} by ${{ github.event.pull_request.merged_by }} failed: {{#each job_statuses }}{{#with this }}{{#if completed }}
{{icon conclusion}} {{name}} {{conclusion}} at {{completed_at}} [details]{{/if}}{{/with}}{{/each}}" From 37db397e06df372940b62fadb85da8210e181a33 Mon Sep 17 00:00:00 2001 From: Michael Kaye <1917473+michaelkaye@users.noreply.github.com> Date: Fri, 13 May 2022 11:40:26 +0100 Subject: [PATCH 04/25] Remove accidental header --- docs/integration_tests.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/docs/integration_tests.md b/docs/integration_tests.md index b528724444..68fcbe18e5 100644 --- a/docs/integration_tests.md +++ b/docs/integration_tests.md @@ -52,8 +52,6 @@ Alternatively, to install the latest Synapse release package (and not a cloned b pip install matrix-synapse ``` -### Integration test failures - You should now have 3 running federated Synapse instances 🎉, at http://127.0.0.1:8080/, http://127.0.0.1:8081/ and http://127.0.0.1:8082/, which should display a "It Works! Synapse is running" message. ## Run the test From 2bd89e6ec09918db9e7006b8b25f31361f831e90 Mon Sep 17 00:00:00 2001 From: Michael Kaye <1917473+michaelkaye@users.noreply.github.com> Date: Fri, 13 May 2022 11:44:47 +0100 Subject: [PATCH 05/25] Note in installation section the need to change public_baseurl as well. --- docs/integration_tests.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/integration_tests.md b/docs/integration_tests.md index 68fcbe18e5..e79f966d1f 100644 --- a/docs/integration_tests.md +++ b/docs/integration_tests.md @@ -52,6 +52,8 @@ Alternatively, to install the latest Synapse release package (and not a cloned b pip install matrix-synapse ``` +On your first run, you will want to stop the demo and edit the config to correct the `public_baseurl` to http://10.0.2.2:8080 and restart the server. + You should now have 3 running federated Synapse instances 🎉, at http://127.0.0.1:8080/, http://127.0.0.1:8081/ and http://127.0.0.1:8082/, which should display a "It Works! Synapse is running" message. ## Run the test From 9f033ed6233e46438d1a856ea987e862bbceb33f Mon Sep 17 00:00:00 2001 From: chagai95 <31655082+chagai95@users.noreply.github.com> Date: Fri, 13 May 2022 13:55:10 +0200 Subject: [PATCH 06/25] add presence indicator busy and away --- .../ui-styles/src/main/res/values/colors.xml | 8 +++++++ .../ui-styles/src/main/res/values/palette.xml | 1 + .../src/main/res/values/theme_dark.xml | 2 ++ .../src/main/res/values/theme_light.xml | 2 ++ .../session/presence/model/PresenceEnum.kt | 5 +++- .../sdk/internal/session/sync/SyncPresence.kt | 2 ++ .../core/ui/views/PresenceStateImageView.kt | 6 ++++- .../main/res/drawable/ic_presence_away.xml | 24 +++++++++++++++++++ .../main/res/drawable/ic_presence_busy.xml | 24 +++++++++++++++++++ 9 files changed, 72 insertions(+), 2 deletions(-) create mode 100644 vector/src/main/res/drawable/ic_presence_away.xml create mode 100644 vector/src/main/res/drawable/ic_presence_busy.xml diff --git a/library/ui-styles/src/main/res/values/colors.xml b/library/ui-styles/src/main/res/values/colors.xml index d887e7774e..2104b49ab5 100644 --- a/library/ui-styles/src/main/res/values/colors.xml +++ b/library/ui-styles/src/main/res/values/colors.xml @@ -126,6 +126,14 @@ @color/palette_element_green @color/palette_element_green + + @color/element_alert_light + @color/element_alert_dark + + + @color/palette_element_orange + @color/palette_element_orange + @color/palette_prune diff --git a/library/ui-styles/src/main/res/values/palette.xml b/library/ui-styles/src/main/res/values/palette.xml index e6cee80b59..73ac768919 100644 --- a/library/ui-styles/src/main/res/values/palette.xml +++ b/library/ui-styles/src/main/res/values/palette.xml @@ -17,6 +17,7 @@ #FF812D #0DBD8B + #D9B072 #FFFFFF #FF5B55 diff --git a/library/ui-styles/src/main/res/values/theme_dark.xml b/library/ui-styles/src/main/res/values/theme_dark.xml index 7177687fdd..eeff039b71 100644 --- a/library/ui-styles/src/main/res/values/theme_dark.xml +++ b/library/ui-styles/src/main/res/values/theme_dark.xml @@ -44,6 +44,8 @@ @color/vctr_presence_indicator_offline_dark @color/vctr_presence_indicator_online_dark + @color/vctr_presence_indicator_busy_dark + @color/vctr_presence_indicator_away_dark ?vctr_system diff --git a/library/ui-styles/src/main/res/values/theme_light.xml b/library/ui-styles/src/main/res/values/theme_light.xml index c90c021591..0c363b583d 100644 --- a/library/ui-styles/src/main/res/values/theme_light.xml +++ b/library/ui-styles/src/main/res/values/theme_light.xml @@ -44,6 +44,8 @@ @color/vctr_presence_indicator_offline_light @color/vctr_presence_indicator_online_light + @color/vctr_presence_indicator_busy_light + @color/vctr_presence_indicator_away_light ?vctr_system diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/presence/model/PresenceEnum.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/presence/model/PresenceEnum.kt index 6d9994ef1c..c678e2a706 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/presence/model/PresenceEnum.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/presence/model/PresenceEnum.kt @@ -28,7 +28,10 @@ enum class PresenceEnum(val value: String) { OFFLINE("offline"), @Json(name = "unavailable") - UNAVAILABLE("unavailable"); + UNAVAILABLE("unavailable"), + + @Json(name = "org.matrix.msc3026.busy") + BUSY("busy"); companion object { fun from(s: String): PresenceEnum? = values().find { it.value == s } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/sync/SyncPresence.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/sync/SyncPresence.kt index 42cd972e0c..ce41a4568c 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/sync/SyncPresence.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/sync/SyncPresence.kt @@ -29,6 +29,7 @@ import org.matrix.android.sdk.api.session.presence.model.PresenceEnum internal enum class SyncPresence(val value: String) { Offline("offline"), Online("online"), + Busy("busy"), Unavailable("unavailable"); companion object { @@ -36,6 +37,7 @@ internal enum class SyncPresence(val value: String) { return when (presenceEnum) { PresenceEnum.ONLINE -> Online PresenceEnum.OFFLINE -> Offline + PresenceEnum.BUSY -> Busy PresenceEnum.UNAVAILABLE -> Unavailable } } diff --git a/vector/src/main/java/im/vector/app/core/ui/views/PresenceStateImageView.kt b/vector/src/main/java/im/vector/app/core/ui/views/PresenceStateImageView.kt index 82675e8c11..0024f706b6 100644 --- a/vector/src/main/java/im/vector/app/core/ui/views/PresenceStateImageView.kt +++ b/vector/src/main/java/im/vector/app/core/ui/views/PresenceStateImageView.kt @@ -42,13 +42,17 @@ class PresenceStateImageView @JvmOverloads constructor( contentDescription = context.getString(R.string.a11y_presence_online) } PresenceEnum.UNAVAILABLE -> { - setImageResource(R.drawable.ic_presence_offline) + setImageResource(R.drawable.ic_presence_away) contentDescription = context.getString(R.string.a11y_presence_unavailable) } PresenceEnum.OFFLINE -> { setImageResource(R.drawable.ic_presence_offline) contentDescription = context.getString(R.string.a11y_presence_offline) } + PresenceEnum.BUSY -> { + setImageResource(R.drawable.ic_presence_busy) + contentDescription = context.getString(R.string.a11y_presence_busy) + } null -> Unit } } diff --git a/vector/src/main/res/drawable/ic_presence_away.xml b/vector/src/main/res/drawable/ic_presence_away.xml new file mode 100644 index 0000000000..617fe735b6 --- /dev/null +++ b/vector/src/main/res/drawable/ic_presence_away.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + + diff --git a/vector/src/main/res/drawable/ic_presence_busy.xml b/vector/src/main/res/drawable/ic_presence_busy.xml new file mode 100644 index 0000000000..9155a6b4a5 --- /dev/null +++ b/vector/src/main/res/drawable/ic_presence_busy.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + + From 491b3c351b7b54c12e7ed9c3e84496490aa2db0c Mon Sep 17 00:00:00 2001 From: chagai95 <31655082+chagai95@users.noreply.github.com> Date: Fri, 13 May 2022 14:00:32 +0200 Subject: [PATCH 07/25] Create 6047.feature --- changelog.d/6047.feature | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/6047.feature diff --git a/changelog.d/6047.feature b/changelog.d/6047.feature new file mode 100644 index 0000000000..59d37e21e9 --- /dev/null +++ b/changelog.d/6047.feature @@ -0,0 +1 @@ +Add presence indicator busy and away. From c27958d77279a558a1e70976a871d527c59f00f9 Mon Sep 17 00:00:00 2001 From: chagai95 <31655082+chagai95@users.noreply.github.com> Date: Mon, 16 May 2022 10:50:58 +0200 Subject: [PATCH 08/25] Add Busy string and change Unavailable to Away --- vector/src/main/res/values/strings.xml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/vector/src/main/res/values/strings.xml b/vector/src/main/res/values/strings.xml index 1868d1ff5b..923c19dbb4 100644 --- a/vector/src/main/res/values/strings.xml +++ b/vector/src/main/res/values/strings.xml @@ -2729,7 +2729,8 @@ Public room Online Offline - Unavailable + Busy + Away Dev Tools Explore Room State From 7040369529a93c6481eb57c9c5e16507d8688442 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Mon, 2 May 2022 11:44:51 +0200 Subject: [PATCH 09/25] Add documentation to the class Matrix --- .../java/org/matrix/android/sdk/api/Matrix.kt | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/Matrix.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/Matrix.kt index e7d1e64a2b..57ef48a8d8 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/Matrix.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/Matrix.kt @@ -73,24 +73,52 @@ class Matrix private constructor(context: Context, matrixConfiguration: MatrixCo ProcessLifecycleOwner.get().lifecycle.addObserver(backgroundDetectionObserver) } + /** + * Return the User Agent used for any request that the SDK is making to the homeserver. + * There is no way to change the user agent at the moment + */ fun getUserAgent() = userAgentHolder.userAgent + /** + * Return the AuthenticationService + */ fun authenticationService() = authenticationService + /** + * Return the RawService + */ fun rawService() = rawService + /** + * Return the LightweightSettingsStorage + */ fun lightweightSettingsStorage() = lightweightSettingsStorage + /** + * Return the HomeServerHistoryService + */ fun homeServerHistoryService() = homeServerHistoryService + /** + * Return the legacy session importer, useful if you want to migrate an app, which was using the legacy Matrix Android Sdk + */ fun legacySessionImporter() = legacySessionImporter + /** + * Get the worker factory. The returned value has to be provided to `WorkConfiguration.Builder()` + */ fun workerFactory(): WorkerFactory = matrixWorkerFactory + /** + * Register an API interceptor, to be able to be notified when the specified API got a response + */ fun registerApiInterceptorListener(path: ApiPath, listener: ApiInterceptorListener) { apiInterceptor.addListener(path, listener) } + /** + * Un-register an API interceptor + */ fun unregisterApiInterceptorListener(path: ApiPath, listener: ApiInterceptorListener) { apiInterceptor.removeListener(path, listener) } From 92c0d971108086ef791e2e808cb9fad44bf31901 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Mon, 2 May 2022 11:45:34 +0200 Subject: [PATCH 10/25] Rename API --- .../src/main/java/org/matrix/android/sdk/api/Matrix.kt | 2 +- vector/src/main/java/im/vector/app/VectorApplication.kt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/Matrix.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/Matrix.kt index 57ef48a8d8..d5b75bb6c1 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/Matrix.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/Matrix.kt @@ -107,7 +107,7 @@ class Matrix private constructor(context: Context, matrixConfiguration: MatrixCo /** * Get the worker factory. The returned value has to be provided to `WorkConfiguration.Builder()` */ - fun workerFactory(): WorkerFactory = matrixWorkerFactory + fun getWorkerFactory(): WorkerFactory = matrixWorkerFactory /** * Register an API interceptor, to be able to be notified when the specified API got a response diff --git a/vector/src/main/java/im/vector/app/VectorApplication.kt b/vector/src/main/java/im/vector/app/VectorApplication.kt index 0bf4eb13b6..a55351f74b 100644 --- a/vector/src/main/java/im/vector/app/VectorApplication.kt +++ b/vector/src/main/java/im/vector/app/VectorApplication.kt @@ -224,7 +224,7 @@ class VectorApplication : override fun getWorkManagerConfiguration(): WorkConfiguration { return WorkConfiguration.Builder() - .setWorkerFactory(matrix.workerFactory()) + .setWorkerFactory(matrix.getWorkerFactory()) .setExecutor(Executors.newCachedThreadPool()) .build() } From 11e1fdf332e811346e5a6800c205323094e31327 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Mon, 2 May 2022 11:56:17 +0200 Subject: [PATCH 11/25] Remove the deprecated way to create a Matrix object --- .../java/org/matrix/android/sdk/api/Matrix.kt | 39 ------------------- .../android/sdk/api/MatrixConfiguration.kt | 11 +----- 2 files changed, 1 insertion(+), 49 deletions(-) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/Matrix.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/Matrix.kt index d5b75bb6c1..ac2ecbb033 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/Matrix.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/Matrix.kt @@ -38,7 +38,6 @@ import org.matrix.android.sdk.internal.util.BackgroundDetectionObserver import org.matrix.android.sdk.internal.worker.MatrixWorkerFactory import org.matrix.olm.OlmManager import java.util.concurrent.Executors -import java.util.concurrent.atomic.AtomicBoolean import javax.inject.Inject /** @@ -124,10 +123,6 @@ class Matrix private constructor(context: Context, matrixConfiguration: MatrixCo } companion object { - - private lateinit var instance: Matrix - private val isInit = AtomicBoolean(false) - /** * Creates a new instance of Matrix, it's recommended to manage this instance as a singleton. * To make use of the built in singleton use Matrix.initialize() and/or Matrix.getInstance(context) instead @@ -136,40 +131,6 @@ class Matrix private constructor(context: Context, matrixConfiguration: MatrixCo return Matrix(context.applicationContext, matrixConfiguration) } - /** - * Initializes a singleton instance of Matrix for the given MatrixConfiguration - * This instance will be returned by Matrix.getInstance(context) - */ - @Deprecated("Use Matrix.createInstance and manage the instance manually") - fun initialize(context: Context, matrixConfiguration: MatrixConfiguration) { - if (isInit.compareAndSet(false, true)) { - instance = Matrix(context.applicationContext, matrixConfiguration) - } - } - - /** - * Either provides an already initialized singleton Matrix instance or queries the application context for a MatrixConfiguration.Provider - * to lazily create and store the instance. - */ - @Suppress("deprecation") // suppressing warning as this method is unused but is still provided for SDK clients - @Deprecated("Use Matrix.createInstance and manage the instance manually") - fun getInstance(context: Context): Matrix { - if (isInit.compareAndSet(false, true)) { - val appContext = context.applicationContext - if (appContext is MatrixConfiguration.Provider) { - val matrixConfiguration = (appContext as MatrixConfiguration.Provider).providesMatrixConfiguration() - instance = Matrix(appContext, matrixConfiguration) - } else { - throw IllegalStateException( - "Matrix is not initialized properly." + - " If you want to manage your own Matrix instance use Matrix.createInstance" + - " otherwise you should call Matrix.initialize or let your application implement MatrixConfiguration.Provider." - ) - } - } - return instance - } - /** * @return a String with details about the Matrix SDK version */ diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/MatrixConfiguration.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/MatrixConfiguration.kt index f8472319fd..3c666998b3 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/MatrixConfiguration.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/MatrixConfiguration.kt @@ -65,13 +65,4 @@ data class MatrixConfiguration( * Thread messages default enable/disabled value */ val threadMessagesEnabledDefault: Boolean = false, -) { - - /** - * Can be implemented by your Application class. - */ - @Deprecated("Use Matrix.createInstance and manage the instance manually instead of Matrix.getInstance") - interface Provider { - fun providesMatrixConfiguration(): MatrixConfiguration - } -} +) From 3fc4083aca43b62bdb06311c9c13aa17c6760d04 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Mon, 2 May 2022 11:58:48 +0200 Subject: [PATCH 12/25] Make the constructor public --- .../java/org/matrix/android/sdk/api/Matrix.kt | 22 +++++++------------ .../vector/app/core/utils/TestMatrixHelper.kt | 2 +- .../im/vector/app/core/di/SingletonModule.kt | 2 +- 3 files changed, 10 insertions(+), 16 deletions(-) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/Matrix.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/Matrix.kt index ac2ecbb033..3362d0e06a 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/Matrix.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/Matrix.kt @@ -43,9 +43,10 @@ import javax.inject.Inject /** * This is the main entry point to the matrix sdk. *
- * See [Companion.createInstance] to create an instance. The app should create and manage the instance itself. + * @param context the application context + * @param matrixConfiguration global configuration that will be used for every [org.matrix.android.sdk.api.session.Session] */ -class Matrix private constructor(context: Context, matrixConfiguration: MatrixConfiguration) { +class Matrix(context: Context, matrixConfiguration: MatrixConfiguration) { @Inject internal lateinit var legacySessionImporter: LegacySessionImporter @Inject internal lateinit var authenticationService: AuthenticationService @@ -60,14 +61,15 @@ class Matrix private constructor(context: Context, matrixConfiguration: MatrixCo @Inject internal lateinit var lightweightSettingsStorage: LightweightSettingsStorage init { - Monarchy.init(context) - DaggerMatrixComponent.factory().create(context, matrixConfiguration).inject(this) - if (context.applicationContext !is Configuration.Provider) { + val appContext = context.applicationContext + Monarchy.init(appContext) + DaggerMatrixComponent.factory().create(appContext, matrixConfiguration).inject(this) + if (appContext.applicationContext !is Configuration.Provider) { val configuration = Configuration.Builder() .setExecutor(Executors.newCachedThreadPool()) .setWorkerFactory(matrixWorkerFactory) .build() - WorkManager.initialize(context, configuration) + WorkManager.initialize(appContext, configuration) } ProcessLifecycleOwner.get().lifecycle.addObserver(backgroundDetectionObserver) } @@ -123,14 +125,6 @@ class Matrix private constructor(context: Context, matrixConfiguration: MatrixCo } companion object { - /** - * Creates a new instance of Matrix, it's recommended to manage this instance as a singleton. - * To make use of the built in singleton use Matrix.initialize() and/or Matrix.getInstance(context) instead - **/ - fun createInstance(context: Context, matrixConfiguration: MatrixConfiguration): Matrix { - return Matrix(context.applicationContext, matrixConfiguration) - } - /** * @return a String with details about the Matrix SDK version */ diff --git a/vector/src/androidTest/java/im/vector/app/core/utils/TestMatrixHelper.kt b/vector/src/androidTest/java/im/vector/app/core/utils/TestMatrixHelper.kt index 322f5fa23d..48fc1343b1 100644 --- a/vector/src/androidTest/java/im/vector/app/core/utils/TestMatrixHelper.kt +++ b/vector/src/androidTest/java/im/vector/app/core/utils/TestMatrixHelper.kt @@ -26,5 +26,5 @@ fun getMatrixInstance(): Matrix { val configuration = MatrixConfiguration( roomDisplayNameFallbackProvider = VectorRoomDisplayNameFallbackProvider(context) ) - return Matrix.createInstance(context, configuration) + return Matrix(context, configuration) } diff --git a/vector/src/main/java/im/vector/app/core/di/SingletonModule.kt b/vector/src/main/java/im/vector/app/core/di/SingletonModule.kt index 7e2e786b18..2945ae7d87 100644 --- a/vector/src/main/java/im/vector/app/core/di/SingletonModule.kt +++ b/vector/src/main/java/im/vector/app/core/di/SingletonModule.kt @@ -129,7 +129,7 @@ object VectorStaticModule { @Provides @Singleton fun providesMatrix(context: Context, configuration: MatrixConfiguration): Matrix { - return Matrix.createInstance(context, configuration) + return Matrix(context, configuration) } @Provides From 08c67eaf0ef0c17511a8b1a7d8bb75338b0aee74 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Mon, 2 May 2022 11:59:31 +0200 Subject: [PATCH 13/25] Remove unecessary indirection --- .../src/main/java/org/matrix/android/sdk/api/Matrix.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/Matrix.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/Matrix.kt index 3362d0e06a..5811ba469e 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/Matrix.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/Matrix.kt @@ -64,7 +64,7 @@ class Matrix(context: Context, matrixConfiguration: MatrixConfiguration) { val appContext = context.applicationContext Monarchy.init(appContext) DaggerMatrixComponent.factory().create(appContext, matrixConfiguration).inject(this) - if (appContext.applicationContext !is Configuration.Provider) { + if (appContext !is Configuration.Provider) { val configuration = Configuration.Builder() .setExecutor(Executors.newCachedThreadPool()) .setWorkerFactory(matrixWorkerFactory) From 6f29a7ab94cc11f2a639e02fafb786f1eb6c4e94 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Mon, 2 May 2022 12:04:04 +0200 Subject: [PATCH 14/25] Also update TextMatrix --- .../android/sdk/common/CommonTestHelper.kt | 5 ++-- .../matrix/android/sdk/common/TestMatrix.kt | 27 ++++--------------- 2 files changed, 8 insertions(+), 24 deletions(-) diff --git a/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/common/CommonTestHelper.kt b/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/common/CommonTestHelper.kt index 4b9e605cd0..e33e4faea2 100644 --- a/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/common/CommonTestHelper.kt +++ b/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/common/CommonTestHelper.kt @@ -63,8 +63,9 @@ class CommonTestHelper(context: Context) { fun getTestInterceptor(session: Session): MockOkHttpInterceptor? = TestModule.interceptorForSession(session.sessionId) as? MockOkHttpInterceptor init { + var _matrix: TestMatrix? = null UiThreadStatement.runOnUiThread { - TestMatrix.initialize( + _matrix = TestMatrix( context, MatrixConfiguration( applicationFlavor = "TestFlavor", @@ -72,7 +73,7 @@ class CommonTestHelper(context: Context) { ) ) } - matrix = TestMatrix.getInstance() + matrix = _matrix!! } fun createAccount(userNamePrefix: String, testParams: SessionTestParams): Session { diff --git a/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/common/TestMatrix.kt b/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/common/TestMatrix.kt index fa44167a8f..e663cc1865 100644 --- a/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/common/TestMatrix.kt +++ b/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/common/TestMatrix.kt @@ -38,13 +38,12 @@ import org.matrix.android.sdk.internal.util.BackgroundDetectionObserver import org.matrix.android.sdk.internal.worker.MatrixWorkerFactory import org.matrix.olm.OlmManager import java.util.concurrent.Executors -import java.util.concurrent.atomic.AtomicBoolean import javax.inject.Inject /** * This mimics the Matrix class but using TestMatrixComponent internally instead of regular MatrixComponent. */ -internal class TestMatrix constructor(context: Context, matrixConfiguration: MatrixConfiguration) { +internal class TestMatrix(context: Context, matrixConfiguration: MatrixConfiguration) { @Inject internal lateinit var legacySessionImporter: LegacySessionImporter @Inject internal lateinit var authenticationService: AuthenticationService @@ -60,13 +59,14 @@ internal class TestMatrix constructor(context: Context, matrixConfiguration: Mat private val uiHandler = Handler(Looper.getMainLooper()) init { - Monarchy.init(context) - DaggerTestMatrixComponent.factory().create(context, matrixConfiguration).inject(this) + val appContext = context.applicationContext + Monarchy.init(appContext) + DaggerTestMatrixComponent.factory().create(appContext, matrixConfiguration).inject(this) val configuration = Configuration.Builder() .setExecutor(Executors.newCachedThreadPool()) .setWorkerFactory(matrixWorkerFactory) .build() - WorkManager.initialize(context, configuration) + WorkManager.initialize(appContext, configuration) uiHandler.post { ProcessLifecycleOwner.get().lifecycle.addObserver(backgroundDetectionObserver) } @@ -95,23 +95,6 @@ internal class TestMatrix constructor(context: Context, matrixConfiguration: Mat } companion object { - - private lateinit var instance: TestMatrix - private val isInit = AtomicBoolean(false) - - fun initialize(context: Context, matrixConfiguration: MatrixConfiguration) { - if (isInit.compareAndSet(false, true)) { - instance = TestMatrix(context.applicationContext, matrixConfiguration) - } - } - - fun getInstance(): TestMatrix { - if (isInit.compareAndSet(false, false)) { - throw IllegalStateException("Matrix is not initialized properly. You should call TestMatrix.initialize first") - } - return instance - } - fun getSdkVersion(): String { return BuildConfig.SDK_VERSION + " (" + BuildConfig.GIT_SDK_REVISION + ")" } From 26e6d56cf11320ae630461d24911e15c8c6d2ccd Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Mon, 2 May 2022 14:07:51 +0200 Subject: [PATCH 15/25] Improve doc --- .../src/main/java/org/matrix/android/sdk/api/Matrix.kt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/Matrix.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/Matrix.kt index 5811ba469e..99ed117078 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/Matrix.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/Matrix.kt @@ -43,6 +43,9 @@ import javax.inject.Inject /** * This is the main entry point to the matrix sdk. *
+ * + * The constructor creates a new instance of Matrix, it's recommended to manage this instance as a singleton. + * * @param context the application context * @param matrixConfiguration global configuration that will be used for every [org.matrix.android.sdk.api.session.Session] */ From f1995503ff679cc3b0b769841bf5774d7b7ecea6 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Mon, 2 May 2022 14:09:04 +0200 Subject: [PATCH 16/25] Small improvement on lint.xml file --- vector/lint.xml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/vector/lint.xml b/vector/lint.xml index e219ac1eed..d9ca761e7a 100644 --- a/vector/lint.xml +++ b/vector/lint.xml @@ -1,5 +1,9 @@ + + + + From dfe75de76ea493fdc09f55f3ae43c6affefd4b03 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Wed, 4 May 2022 14:55:51 +0200 Subject: [PATCH 17/25] Add links to the doc (I've finally found a way to do it) --- matrix-sdk-android/docs/modules.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/matrix-sdk-android/docs/modules.md b/matrix-sdk-android/docs/modules.md index b19bc73534..fb082c1bc2 100644 --- a/matrix-sdk-android/docs/modules.md +++ b/matrix-sdk-android/docs/modules.md @@ -11,11 +11,11 @@ This pages list the complete API that this SDK is exposing to a client applicati A few entry points: -- **Matrix**: The app will have to create and manage a Matrix object. -- From this **Matrix** object, you will be able to get various services, including the **AuthenticationService**. -- With this **AuthenticationService** you will be able to get an existing **Session**, or create one using a **LoginWizard** or a **RegistrationWizard**, which will finally give you a **Session**. -- From the **Session**, you will be able to retrieve many Services, including the **RoomService**. -- From the **RoomService**, you will be able to list the rooms, create a **Room**, and get a specific **Room**. -- And from a **Room**, you will be able to do many things, including get a **Timeline**, send messages, etc. +- **[Matrix](org.matrix.android.sdk.api.Matrix)**: The app will have to create and manage a **[Matrix](org.matrix.android.sdk.api.Matrix)** object. +- From this **[Matrix](org.matrix.android.sdk.api.Matrix)** object, you will be able to get various services, including the **[AuthenticationService](org.matrix.android.sdk.api.auth.AuthenticationService)**. +- With this **[AuthenticationService](org.matrix.android.sdk.api.auth.AuthenticationService)** you will be able to get an existing **[Session](org.matrix.android.sdk.api.session.Session)**, or create one using a **[LoginWizard](org.matrix.android.sdk.api.auth.login.LoginWizard)** or a **[RegistrationWizard](org.matrix.android.sdk.api.auth.registration.RegistrationWizard)**, which will finally give you a **[Session](org.matrix.android.sdk.api.session.Session)**. +- From the **[Session](org.matrix.android.sdk.api.session.Session)**, you will be able to retrieve many Services, including the **[RoomService](org.matrix.android.sdk.api.session.room.RoomService)**. +- From the **[RoomService](org.matrix.android.sdk.api.session.room.RoomService)**, you will be able to list the rooms, create a **[Room](org.matrix.android.sdk.api.session.room.Room)**, and get a specific **[Room](org.matrix.android.sdk.api.session.room.Room)**. +- And from a **[Room](org.matrix.android.sdk.api.session.room.Room)**, you will be able to do many things, including get a **[Timeline](org.matrix.android.sdk.api.session.room.timeline.Timeline)**, send messages, etc. Please read the whole documentation to learn more! From 1eb97f6cb8b22c4a0982f2293c2d776dcbde5226 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Wed, 4 May 2022 14:56:11 +0200 Subject: [PATCH 18/25] Disable the undocumented warnings, there are too many :/ --- matrix-sdk-android/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/matrix-sdk-android/build.gradle b/matrix-sdk-android/build.gradle index c840b9a6e9..dfa99d0f8a 100644 --- a/matrix-sdk-android/build.gradle +++ b/matrix-sdk-android/build.gradle @@ -21,7 +21,7 @@ dokkaHtml { dokkaSourceSets { configureEach { // Emit warnings about not documented members. - reportUndocumented.set(true) + // reportUndocumented.set(true) // Suppress legacy Riot's packages. perPackageOption { matchingRegex.set("org.matrix.android.sdk.internal.legacy.riot") From 9e106990c80487bc31740a67040a7e0f3527f352 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Wed, 4 May 2022 15:52:51 +0200 Subject: [PATCH 19/25] Setup knit --- build.gradle | 1 + vector/build.gradle | 1 + 2 files changed, 2 insertions(+) diff --git a/build.gradle b/build.gradle index 51e84567fe..8553428b49 100644 --- a/build.gradle +++ b/build.gradle @@ -30,6 +30,7 @@ buildscript { classpath "com.likethesalad.android:stem-plugin:2.0.0" classpath 'org.owasp:dependency-check-gradle:7.1.0.1' classpath "org.jetbrains.dokka:dokka-gradle-plugin:1.6.21" + classpath "org.jetbrains.kotlinx:kotlinx-knit:0.4.0" // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } diff --git a/vector/build.gradle b/vector/build.gradle index c4b1f3fa4e..5a9a7f723c 100644 --- a/vector/build.gradle +++ b/vector/build.gradle @@ -7,6 +7,7 @@ apply plugin: 'kotlin-parcelize' apply plugin: 'kotlin-kapt' apply plugin: 'com.likethesalad.stem' apply plugin: 'dagger.hilt.android.plugin' +apply plugin: 'kotlinx-knit' kapt { correctErrorTypes = true From d562ab35ad0ac0c7279669d0173a3d7c12df970d Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Wed, 4 May 2022 16:05:21 +0200 Subject: [PATCH 20/25] Setup Knit in the CI to check content of `md` files --- .github/workflows/quality.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/.github/workflows/quality.yml b/.github/workflows/quality.yml index fab98e8e91..a97d532644 100644 --- a/.github/workflows/quality.yml +++ b/.github/workflows/quality.yml @@ -14,6 +14,16 @@ jobs: - name: Run code quality check suite run: ./tools/check/check_code_quality.sh +# Knit for all the modules (https://github.com/Kotlin/kotlinx-knit) + knit: + name: Knit + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Run knit + run: | + ./gradlew knit + # ktlint for all the modules ktlint: name: Kotlin Linter From 480a60a6558ddb0f0055f176936aa6c0e275b739 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Wed, 4 May 2022 17:14:41 +0200 Subject: [PATCH 21/25] Exclude some files from check --- vector/build.gradle | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/vector/build.gradle b/vector/build.gradle index 5a9a7f723c..affe10e57b 100644 --- a/vector/build.gradle +++ b/vector/build.gradle @@ -13,6 +13,18 @@ kapt { correctErrorTypes = true } +knit { + files = fileTree(project.rootDir) { + include '**/*.md' + include '**/*.kt' + include '**/*.kts' + exclude '**/build/**' + exclude '**/.gradle/**' + exclude '**/towncrier/template.md' + exclude '**/CHANGES.md' + } +} + // Note: 2 digits max for each value ext.versionMajor = 1 ext.versionMinor = 4 From fce1552349d17f4659e0fc5c08fee734117984a8 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Wed, 4 May 2022 17:14:51 +0200 Subject: [PATCH 22/25] Fix link --- docs/pull_request.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/pull_request.md b/docs/pull_request.md index 473d5a259b..94f8f3b6d8 100644 --- a/docs/pull_request.md +++ b/docs/pull_request.md @@ -116,7 +116,7 @@ Review such PR is the same recipe than for PR from Dependabot ##### Sync analytics plan This tools imports any update in the analytics plan. See instruction in the PR itself to handle it. -More info can be found in the file [analytics.md] +More info can be found in the file [analytics.md](./analytics.md) ## Reviewing PR @@ -247,4 +247,4 @@ Also "Resolve conversation" should probably be hit by the creator of the convers PR submitter is responsible of the incoming change. PR reviewers who approved the PR take a part of responsibility on the code which will land to develop, and then be used by our users, and the user of our forks. -That said, bug may still be merged on `develop`, this is still acceptable of course. In this case, please make sure an issue is created and correctly labelled. Ideally, such issues should be fixed before the next release candidate, i.e. with a higher priority. But as we release the application every 10 working days, it can be hard to fix every bugs. That's why PR should be fully tested and reviewed before being merge and we should never comment code review remark with "will be handled later", or similar comments. \ No newline at end of file +That said, bug may still be merged on `develop`, this is still acceptable of course. In this case, please make sure an issue is created and correctly labelled. Ideally, such issues should be fixed before the next release candidate, i.e. with a higher priority. But as we release the application every 10 working days, it can be hard to fix every bugs. That's why PR should be fully tested and reviewed before being merge and we should never comment code review remark with "will be handled later", or similar comments. From ebb9538372d0e44a5f1525df7a85253abba21829 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Wed, 4 May 2022 17:15:11 +0200 Subject: [PATCH 23/25] Fix warning and typo --- docs/add_threePids.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/add_threePids.md b/docs/add_threePids.md index 89fc92f329..6fb0aff426 100644 --- a/docs/add_threePids.md +++ b/docs/add_threePids.md @@ -37,9 +37,9 @@ Wording: "We've sent you an email to verify your address. Please follow the inst } ``` -## User receive an e-mail +## User receives an e-mail -> [homeserver.org] Validate your email +> `homeserver.org` Validate your email > > A request to add an email address to your Matrix account has been received. If this was you, please click the link below to confirm adding this email: https://homeserver.org/_matrix/client/unstable/add_threepid/email/submit_token?token=WUnEhQAmJrXupdEbXgdWvnVIKaGYZFsU&client_secret=TixzvOnw7nLEUdiQEmkHzkXKrY4HhiGh&sid=bxyDHuJKsdkjMlTJ From 5387c9101e301cfeba40faa66d2371f047da80fa Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Wed, 4 May 2022 17:19:31 +0200 Subject: [PATCH 24/25] Changelog --- changelog.d/5887.sdk | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/5887.sdk diff --git a/changelog.d/5887.sdk b/changelog.d/5887.sdk new file mode 100644 index 0000000000..0f128938dd --- /dev/null +++ b/changelog.d/5887.sdk @@ -0,0 +1 @@ +Small change in the Matrix class: deprecated methods have been removed and the constructor is now public. Also the fun `workerFactory()` has been renamed to `getWorkerFactory()` From 0ed647d379c7f5cc6f33a981d783a65bf86aacad Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Mon, 16 May 2022 12:25:10 +0200 Subject: [PATCH 25/25] Add missing end period. --- .../java/org/matrix/android/sdk/api/Matrix.kt | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/Matrix.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/Matrix.kt index 99ed117078..979201706b 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/Matrix.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/Matrix.kt @@ -79,49 +79,49 @@ class Matrix(context: Context, matrixConfiguration: MatrixConfiguration) { /** * Return the User Agent used for any request that the SDK is making to the homeserver. - * There is no way to change the user agent at the moment + * There is no way to change the user agent at the moment. */ fun getUserAgent() = userAgentHolder.userAgent /** - * Return the AuthenticationService + * Return the AuthenticationService. */ fun authenticationService() = authenticationService /** - * Return the RawService + * Return the RawService. */ fun rawService() = rawService /** - * Return the LightweightSettingsStorage + * Return the LightweightSettingsStorage. */ fun lightweightSettingsStorage() = lightweightSettingsStorage /** - * Return the HomeServerHistoryService + * Return the HomeServerHistoryService. */ fun homeServerHistoryService() = homeServerHistoryService /** - * Return the legacy session importer, useful if you want to migrate an app, which was using the legacy Matrix Android Sdk + * Return the legacy session importer, useful if you want to migrate an app, which was using the legacy Matrix Android Sdk. */ fun legacySessionImporter() = legacySessionImporter /** - * Get the worker factory. The returned value has to be provided to `WorkConfiguration.Builder()` + * Get the worker factory. The returned value has to be provided to `WorkConfiguration.Builder()`. */ fun getWorkerFactory(): WorkerFactory = matrixWorkerFactory /** - * Register an API interceptor, to be able to be notified when the specified API got a response + * Register an API interceptor, to be able to be notified when the specified API got a response. */ fun registerApiInterceptorListener(path: ApiPath, listener: ApiInterceptorListener) { apiInterceptor.addListener(path, listener) } /** - * Un-register an API interceptor + * Un-register an API interceptor. */ fun unregisterApiInterceptorListener(path: ApiPath, listener: ApiInterceptorListener) { apiInterceptor.removeListener(path, listener) @@ -129,7 +129,7 @@ class Matrix(context: Context, matrixConfiguration: MatrixConfiguration) { companion object { /** - * @return a String with details about the Matrix SDK version + * @return a String with details about the Matrix SDK version. */ fun getSdkVersion(): String { return BuildConfig.SDK_VERSION + " (" + BuildConfig.GIT_SDK_REVISION + ")"