Skip to content

Commit

Permalink
Merge branch 'release/1.5.8' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
bmarty committed Nov 23, 2022
2 parents 4ff02d0 + aa97272 commit 6e87d1e
Show file tree
Hide file tree
Showing 43 changed files with 1,079 additions and 101 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,5 @@ lint/generated/
lint/outputs/
lint/tmp/
# lint/reports/

/tmp
11 changes: 11 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
Please also refer to the Changelog of Element Android: https://github.com/vector-im/element-android/blob/main/CHANGES.md

Changes in Matrix-SDK v1.5.8 (2022-11-23)
=========================================

Imported from Element 1.5.8. (https://github.com/vector-im/element-android/releases/tag/v1.5.8)

SDK API changes ⚠️
------------------
- [Metrics] Add `SpannableMetricPlugin` to support spans within transactions. ([#7514](https://github.com/vector-im/element-android/issues/7514))
- Fix a bug that caused messages with no formatted text to be quoted as "null". ([#7530](https://github.com/vector-im/element-android/issues/7530))
- If message content has no `formattedBody`, default to `body` when editing. ([#7574](https://github.com/vector-im/element-android/issues/7574))

Changes in Matrix-SDK v1.5.7 (2022-11-16)
=======================================

Expand Down
12 changes: 6 additions & 6 deletions dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ ext.versions = [

def gradle = "7.3.1"
// Ref: https://kotlinlang.org/releases.html
def kotlin = "1.7.20"
def kotlin = "1.7.21"
def kotlinCoroutines = "1.6.4"
def dagger = "2.44"
def appDistribution = "16.0.0-beta05"
Expand All @@ -17,7 +17,7 @@ def markwon = "4.6.2"
def moshi = "1.14.0"
def lifecycle = "2.5.1"
def flowBinding = "1.2.0"
def flipper = "0.171.1"
def flipper = "0.174.0"
def epoxy = "5.0.0"
def mavericks = "3.0.1"
def glide = "4.14.2"
Expand All @@ -26,13 +26,13 @@ def jjwt = "0.11.5"
// Temporary version to unblock #6929. Once 0.16.0 is released we should use it, and revert
// the whole commit which set version 0.16.0-SNAPSHOT
def vanniktechEmoji = "0.16.0-SNAPSHOT"
def sentry = "6.6.0"
def sentry = "6.7.0"
def fragment = "1.5.4"
// Testing
def mockk = "1.12.3" // We need to use 1.12.3 to have mocking in androidTest until a new version is released: https://github.com/mockk/mockk/issues/819
def espresso = "3.4.0"
def androidxTest = "1.4.0"
def androidxOrchestrator = "1.4.1"
def androidxOrchestrator = "1.4.2"
def paparazzi = "1.1.0"

ext.libs = [
Expand Down Expand Up @@ -83,7 +83,7 @@ ext.libs = [
'appdistributionApi' : "com.google.firebase:firebase-appdistribution-api-ktx:$appDistribution",
'appdistribution' : "com.google.firebase:firebase-appdistribution:$appDistribution",
// Phone number https://github.com/google/libphonenumber
'phonenumber' : "com.googlecode.libphonenumber:libphonenumber:8.12.57"
'phonenumber' : "com.googlecode.libphonenumber:libphonenumber:8.13.0"
],
dagger : [
'dagger' : "com.google.dagger:dagger:$dagger",
Expand All @@ -98,7 +98,7 @@ ext.libs = [
],
element : [
'opusencoder' : "io.element.android:opusencoder:1.1.0",
'wysiwyg' : "io.element.android:wysiwyg:0.2.1"
'wysiwyg' : "io.element.android:wysiwyg:0.4.0"
],
squareup : [
'moshi' : "com.squareup.moshi:moshi:$moshi",
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ vector.httpLogLevel=NONE
# Ref: https://github.com/vanniktech/gradle-maven-publish-plugin
GROUP=org.matrix.android
POM_ARTIFACT_ID=matrix-android-sdk2
VERSION_NAME=1.5.7
VERSION_NAME=1.5.8

POM_PACKAGING=aar

Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionPath=wrapper/dists
distributionSha256Sum=db9c8211ed63f61f60292c69e80d89196f9eb36665e369e7f00ac4cc841c2219
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
zipStorePath=wrapper/dists
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package org.matrix.android.sdk.session.search

import org.amshove.kluent.shouldBeEqualTo
import org.junit.Assert.assertTrue
import org.junit.FixMethodOrder
import org.junit.Test
Expand Down Expand Up @@ -43,7 +44,7 @@ class SearchMessagesTest : InstrumentedTest {
cryptoTestData.firstSession
.searchService()
.search(
searchTerm = "lore",
searchTerm = "lorem",
limit = 10,
includeProfile = true,
afterLimit = 0,
Expand All @@ -61,7 +62,7 @@ class SearchMessagesTest : InstrumentedTest {
cryptoTestData.firstSession
.searchService()
.search(
searchTerm = "lore",
searchTerm = "lorem",
roomId = cryptoTestData.roomId,
limit = 10,
includeProfile = true,
Expand All @@ -73,7 +74,28 @@ class SearchMessagesTest : InstrumentedTest {
}
}

private fun doTest(block: suspend (CryptoTestData) -> SearchResult) = runCryptoTest(context()) { cryptoTestHelper, commonTestHelper ->
@Test
fun sendTextMessageAndSearchPartOfItIncompleteWord() {
doTest(expectedNumberOfResult = 0) { cryptoTestData ->
cryptoTestData.firstSession
.searchService()
.search(
searchTerm = "lore", /* incomplete word */
roomId = cryptoTestData.roomId,
limit = 10,
includeProfile = true,
afterLimit = 0,
beforeLimit = 10,
orderByRecent = true,
nextBatch = null
)
}
}

private fun doTest(
expectedNumberOfResult: Int = 2,
block: suspend (CryptoTestData) -> SearchResult,
) = runCryptoTest(context()) { cryptoTestHelper, commonTestHelper ->
val cryptoTestData = cryptoTestHelper.doE2ETestWithAliceInARoom(false)
val aliceSession = cryptoTestData.firstSession
val aliceRoomId = cryptoTestData.roomId
Expand All @@ -87,7 +109,7 @@ class SearchMessagesTest : InstrumentedTest {

val data = block.invoke(cryptoTestData)

assertTrue(data.results?.size == 2)
data.results?.size shouldBeEqualTo expectedNumberOfResult
assertTrue(
data.results
?.all {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,51 @@
package org.matrix.android.sdk.api.extensions

import org.matrix.android.sdk.api.metrics.MetricPlugin
import org.matrix.android.sdk.api.metrics.SpannableMetricPlugin
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.InvocationKind
import kotlin.contracts.contract

/**
* Executes the given [block] while measuring the transaction.
*
* @param block Action/Task to be executed within this span.
*/
@OptIn(ExperimentalContracts::class)
inline fun List<MetricPlugin>.measureMetric(block: () -> Unit) {
contract {
callsInPlace(block, InvocationKind.EXACTLY_ONCE)
}
try {
this.forEach { plugin -> plugin.startTransaction() } // Start the transaction.
block()
} catch (throwable: Throwable) {
this.forEach { plugin -> plugin.onError(throwable) } // Capture if there is any exception thrown.
throw throwable
} finally {
this.forEach { plugin -> plugin.finishTransaction() } // Finally, finish this transaction.
}
}

/**
* Executes the given [block] while measuring a span.
*
* @param operation Name of the new span.
* @param description Description of the new span.
* @param block Action/Task to be executed within this span.
*/
@OptIn(ExperimentalContracts::class)
inline fun measureMetric(metricMeasurementPlugins: List<MetricPlugin>, block: () -> Unit) {
inline fun List<SpannableMetricPlugin>.measureSpan(operation: String, description: String, block: () -> Unit) {
contract {
callsInPlace(block, InvocationKind.EXACTLY_ONCE)
}
try {
metricMeasurementPlugins.forEach { plugin -> plugin.startTransaction() } // Start the transaction.
this.forEach { plugin -> plugin.startSpan(operation, description) } // Start the transaction.
block()
} catch (throwable: Throwable) {
metricMeasurementPlugins.forEach { plugin -> plugin.onError(throwable) } // Capture if there is any exception thrown.
this.forEach { plugin -> plugin.onError(throwable) } // Capture if there is any exception thrown.
throw throwable
} finally {
metricMeasurementPlugins.forEach { plugin -> plugin.finishTransaction() } // Finally, finish this transaction.
this.forEach { plugin -> plugin.finishSpan() } // Finally, finish this transaction.
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright (c) 2022 The Matrix.org Foundation C.I.C.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.matrix.android.sdk.api.metrics

/**
* A plugin that tracks span along with transactions.
*/
interface SpannableMetricPlugin : MetricPlugin {

/**
* Starts the span for a sub-task.
*
* @param operation Name of the new span.
* @param description Description of the new span.
*/
fun startSpan(operation: String, description: String)

/**
* Finish the span when sub-task is completed.
*/
fun finishSpan()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright 2022 The Matrix.org Foundation C.I.C.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.matrix.android.sdk.api.metrics

import org.matrix.android.sdk.api.logger.LoggerTag
import timber.log.Timber

private val loggerTag = LoggerTag("SyncDurationMetricPlugin", LoggerTag.CRYPTO)

/**
* An spannable metric plugin for sync response handling task.
*/
interface SyncDurationMetricPlugin : SpannableMetricPlugin {

override fun logTransaction(message: String?) {
Timber.tag(loggerTag.value).v("## syncResponseHandler() : $message")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.matrix.android.sdk.api.session.crypto

import android.content.Context
import androidx.annotation.Size
import androidx.lifecycle.LiveData
import androidx.paging.PagedList
import org.matrix.android.sdk.api.MatrixCallback
Expand Down Expand Up @@ -55,6 +56,8 @@ interface CryptoService {

fun deleteDevice(deviceId: String, userInteractiveAuthInterceptor: UserInteractiveAuthInterceptor, callback: MatrixCallback<Unit>)

fun deleteDevices(@Size(min = 1) deviceIds: List<String>, userInteractiveAuthInterceptor: UserInteractiveAuthInterceptor, callback: MatrixCallback<Unit>)

fun getCryptoVersion(context: Context, longFormat: Boolean): String

fun isCryptoEnabled(): Boolean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ inline fun <reified T> Content?.toModel(catchError: Boolean = true): T? {
val moshiAdapter = moshi.adapter(T::class.java)
return try {
moshiAdapter.fromJsonValue(this)
} catch (e: Exception) {
} catch (e: Throwable) {
if (catchError) {
Timber.e(e, "To model failed : $e")
null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ data class HomeServerCapabilities(
* True if the home server supports threaded read receipts and unread notifications.
*/
val canUseThreadReadReceiptsAndNotifications: Boolean = false,

/**
* True if the home server supports remote toggle of Pusher for a given device.
*/
val canRemotelyTogglePushNotificationsOfDevices: Boolean = false,
) {

enum class RoomCapabilitySupport {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@

package org.matrix.android.sdk.api.session.homeserver

import androidx.lifecycle.LiveData
import org.matrix.android.sdk.api.util.Optional

/**
* This interface defines a method to retrieve the homeserver capabilities.
*/
Expand All @@ -30,4 +33,9 @@ interface HomeServerCapabilitiesService {
* Get the HomeServer capabilities.
*/
fun getHomeServerCapabilities(): HomeServerCapabilities

/**
* Get a LiveData on the HomeServer capabilities.
*/
fun getHomeServerCapabilitiesLive(): LiveData<Optional<HomeServerCapabilities>>
}
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,13 @@ fun TimelineEvent.isRootThread(): Boolean {

/**
* Get the latest message body, after a possible edition, stripping the reply prefix if necessary.
* @param formatted Indicates whether the formatted HTML body of the message should be retrieved of the plain text one.
* @return If [formatted] is `true`, the HTML body of the message will be retrieved if available. Otherwise, the plain text/markdown version will be returned.
*/
fun TimelineEvent.getTextEditableContent(formatted: Boolean): String {
val lastMessageContent = getLastMessageContent()
val lastContentBody = if (formatted && lastMessageContent is MessageContentWithFormattedBody) {
lastMessageContent.formattedBody
lastMessageContent.formattedBody ?: lastMessageContent.body
} else {
lastMessageContent?.body
} ?: return ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package org.matrix.android.sdk.internal.auth.version

import com.squareup.moshi.Json
import com.squareup.moshi.JsonClass
import org.matrix.android.sdk.api.extensions.orFalse

/**
* Model for https://matrix.org/docs/spec/client_server/latest#get-matrix-client-versions.
Expand Down Expand Up @@ -56,6 +57,7 @@ private const val FEATURE_THREADS_MSC3440_STABLE = "org.matrix.msc3440.stable"
private const val FEATURE_QR_CODE_LOGIN = "org.matrix.msc3882"
private const val FEATURE_THREADS_MSC3771 = "org.matrix.msc3771"
private const val FEATURE_THREADS_MSC3773 = "org.matrix.msc3773"
private const val FEATURE_REMOTE_TOGGLE_PUSH_NOTIFICATIONS_MSC3881 = "org.matrix.msc3881"

/**
* Return true if the SDK supports this homeserver version.
Expand Down Expand Up @@ -142,3 +144,12 @@ private fun Versions.getMaxVersion(): HomeServerVersion {
?.maxOrNull()
?: HomeServerVersion.r0_0_0
}

/**
* Indicate if the server supports MSC3881: https://github.com/matrix-org/matrix-spec-proposals/pull/3881.
*
* @return true if remote toggle of push notifications is supported
*/
internal fun Versions.doesServerSupportRemoteToggleOfPushNotifications(): Boolean {
return unstableFeatures?.get(FEATURE_REMOTE_TOGGLE_PUSH_NOTIFICATIONS_MSC3881).orFalse()
}
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,12 @@ internal class DefaultCryptoService @Inject constructor(
}

override fun deleteDevice(deviceId: String, userInteractiveAuthInterceptor: UserInteractiveAuthInterceptor, callback: MatrixCallback<Unit>) {
deleteDevices(listOf(deviceId), userInteractiveAuthInterceptor, callback)
}

override fun deleteDevices(deviceIds: List<String>, userInteractiveAuthInterceptor: UserInteractiveAuthInterceptor, callback: MatrixCallback<Unit>) {
deleteDeviceTask
.configureWith(DeleteDeviceTask.Params(deviceId, userInteractiveAuthInterceptor, null)) {
.configureWith(DeleteDeviceTask.Params(deviceIds, userInteractiveAuthInterceptor, null)) {
this.executionThread = TaskThread.CRYPTO
this.callback = callback
}
Expand Down
Loading

0 comments on commit 6e87d1e

Please sign in to comment.