Skip to content

Commit

Permalink
Merge branch 'release/tchap_v2.10.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
yostyle committed Feb 23, 2024
2 parents d050ef9 + 9961fe3 commit e5748a6
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 87 deletions.
8 changes: 8 additions & 0 deletions TCHAP_CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
Changes in Tchap 2.10.3 (2024-02-23)
====================================

Bugfixes 🐛
----------
- Restore rust crypto migration. ([#1013](https://github.com/tchapgouv/tchap-android/issues/1013))


Changes in Tchap 2.10.2 (2024-02-20)
====================================

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@
<string name="tchap_settings_hide_from_users_directory_title">Inscrire mon compte sur liste rouge</string>
<string name="tchap_settings_hide_from_users_directory_summary">Les autres utilisateurs ne pourront pas découvrir mon compte lors de leurs recherches</string>
<string name="tchap_settings_show_external_user_in_users_directory_prompt">Pour désactiver cette option, vous devez accepter que votre adresse e\u2011mail soit visible des autres utilisateurs lors de leurs recherches.</string>
<string name="tchap_settings_christmas_title">🎄 Joyeuses Fêtes 🎄</string>

<!-- Verification -->
<string name="tchap_verification_conclusion_not_secure">La vérification de votre nouvelle session a échoué.</string>
Expand Down
1 change: 0 additions & 1 deletion library/ui-strings/src/main/res/values/strings_tchap.xml
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@
<string name="tchap_settings_hide_from_users_directory_title">Subscribe to the red list.</string>
<string name="tchap_settings_hide_from_users_directory_summary">"Other users won't be able to find my account in their search results."</string>
<string name="tchap_settings_show_external_user_in_users_directory_prompt">To disable this option, you must accept that your email address is visible to the other users.</string>
<string name="tchap_settings_christmas_title">🎄 Happy Holidays 🎄</string>

<!-- Verification -->
<string name="tchap_verification_conclusion_not_secure">Failed to verify your new session.</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,23 @@ import dagger.Lazy
import kotlinx.coroutines.CoroutineName
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.launch
import org.matrix.android.sdk.api.auth.UserInteractiveAuthInterceptor
import org.matrix.android.sdk.api.extensions.tryOrNull
import org.matrix.android.sdk.api.failure.Failure
import org.matrix.android.sdk.api.failure.MatrixError
import org.matrix.android.sdk.api.session.crypto.keysbackup.KeysBackupLastVersionResult
import org.matrix.android.sdk.api.session.crypto.keysbackup.KeysVersion
import org.matrix.android.sdk.api.session.crypto.keysbackup.KeysVersionResult
import org.matrix.android.sdk.api.session.crypto.model.GossipingToDeviceObject
import org.matrix.android.sdk.api.session.crypto.model.MXUsersDevicesMap
import org.matrix.android.sdk.api.session.events.model.Content
import org.matrix.android.sdk.api.session.events.model.Event
import org.matrix.android.sdk.api.session.events.model.EventType
import org.matrix.android.sdk.api.session.uia.UiaResult
import org.matrix.android.sdk.internal.auth.registration.handleUIA
import org.matrix.android.sdk.internal.crypto.OlmMachine
import org.matrix.android.sdk.internal.crypto.PerSessionBackupQueryRateLimiter
import org.matrix.android.sdk.internal.crypto.keysbackup.model.rest.BackupKeysResult
import org.matrix.android.sdk.internal.crypto.keysbackup.model.rest.CreateKeysBackupVersionBody
import org.matrix.android.sdk.internal.crypto.keysbackup.model.rest.KeysBackupData
Expand All @@ -53,6 +59,7 @@ import org.matrix.android.sdk.internal.crypto.model.rest.KeysUploadBody
import org.matrix.android.sdk.internal.crypto.model.rest.KeysUploadResponse
import org.matrix.android.sdk.internal.crypto.model.rest.RestKeyInfo
import org.matrix.android.sdk.internal.crypto.model.rest.SignatureUploadResponse
import org.matrix.android.sdk.internal.crypto.store.IMXCommonCryptoStore
import org.matrix.android.sdk.internal.crypto.tasks.ClaimOneTimeKeysForUsersDeviceTask
import org.matrix.android.sdk.internal.crypto.tasks.DefaultSendVerificationMessageTask
import org.matrix.android.sdk.internal.crypto.tasks.DownloadKeysForUsersTask
Expand Down Expand Up @@ -95,7 +102,10 @@ internal class RequestSender @Inject constructor(
private val getRoomSessionDataTask: GetRoomSessionDataTask,
private val moshi: Moshi,
cryptoCoroutineScope: CoroutineScope,
private val rateLimiter: PerSessionBackupQueryRateLimiter,
private val cryptoStore: IMXCommonCryptoStore,
private val localEchoRepository: LocalEchoRepository,
private val olmMachine: Lazy<OlmMachine>
) {

private val scope = CoroutineScope(
Expand Down Expand Up @@ -236,9 +246,44 @@ internal class RequestSender @Inject constructor(
.newBuilder()
.add(CheckNumberType.JSON_ADAPTER_FACTORY)
.build()
.adapter<Map<String, HashMap<String, Any>>>(Map::class.java)
.adapter<Map<String, Map<String, Any>>>(Map::class.java)
val jsonBody = adapter.fromJson(body)!!

if (eventType == EventType.ROOM_KEY_REQUEST) {
scope.launch {
Timber.v("Intercepting key request, try backup")
/**
* It's a bit hacky, check how this can be better integrated with rust?
*/
try {
jsonBody.forEach { (_, deviceToContent) ->
deviceToContent.forEach { (_, content) ->
val hashMap = content as? Map<*, *>
val action = hashMap?.get("action")?.toString()
if (GossipingToDeviceObject.ACTION_SHARE_REQUEST == action) {
val requestBody = hashMap["body"] as? Map<*, *>
val roomId = requestBody?.get("room_id") as? String
val sessionId = requestBody?.get("session_id") as? String
val senderKey = requestBody?.get("sender_key") as? String
if (roomId != null && sessionId != null) {
// try to perform a lazy migration from legacy store
val legacy = tryOrNull("Failed to access legacy crypto store") {
cryptoStore.getInboundGroupSession(sessionId, senderKey.orEmpty())
}
if (legacy == null || olmMachine.get().importRoomKey(legacy).isFailure) {
rateLimiter.tryFromBackupIfPossible(sessionId, roomId)
}
}
}
}
}
Timber.v("Intercepting key request, try backup")
} catch (failure: Throwable) {
Timber.v(failure, "Failed to use backup")
}
}
}

val userMap = MXUsersDevicesMap<Any>()
userMap.join(jsonBody)

Expand Down
2 changes: 1 addition & 1 deletion towncrier.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tool.towncrier]
version = "2.10.2"
version = "2.10.3"
directory = "changelog.d"
filename = "TCHAP_CHANGES.md"
name = "Changes in Tchap"
Expand Down
2 changes: 1 addition & 1 deletion vector-app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ ext.versionMinor = 10
// Note: even values are reserved for regular release, odd values for hotfix release.
// When creating a hotfix, you should decrease the value, since the current value
// is the value for the next regular release.
ext.versionPatch = 2
ext.versionPatch = 3

static def getGitTimestamp() {
def cmd = 'git show -s --format=%ct'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,6 @@ class VectorPreferences @Inject constructor(
private const val DID_ASK_TO_ENABLE_SESSION_PUSH = "DID_ASK_TO_ENABLE_SESSION_PUSH"

const val TCHAP_SETTINGS_HIDE_FROM_USERS_DIRECTORY_PREFERENCE_KEY = "TCHAP_SETTINGS_HIDE_FROM_USERS_DIRECTORY_PREFERENCE_KEY"
const val TCHAP_SETTINGS_CHRISTMAS_PREFERENCE_KEY = "TCHAP_SETTINGS_CHRISTMAS_PREFERENCE_KEY"

// Location Sharing
const val SETTINGS_PREF_ENABLE_LOCATION_SHARING = "SETTINGS_PREF_ENABLE_LOCATION_SHARING"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,7 @@ import im.vector.app.R
import im.vector.app.core.extensions.replaceFragment
import im.vector.app.core.platform.VectorBaseActivity
import im.vector.app.databinding.ActivityVectorSettingsBinding
import im.vector.app.features.analytics.plan.ViewRoom
import im.vector.app.features.discovery.DiscoverySettingsFragment
import im.vector.app.features.matrixto.MatrixToBottomSheet
import im.vector.app.features.navigation.Navigator
import im.vector.app.features.navigation.SettingsActivityPayload
import im.vector.app.features.settings.devices.VectorSettingsDevicesFragment
import im.vector.app.features.settings.notifications.VectorSettingsNotificationFragment
Expand All @@ -51,33 +48,9 @@ private const val KEY_ACTIVITY_PAYLOAD = "settings-activity-payload"
@AndroidEntryPoint
class VectorSettingsActivity : VectorBaseActivity<ActivityVectorSettingsBinding>(),
PreferenceFragmentCompat.OnPreferenceStartFragmentCallback,
MatrixToBottomSheet.InteractionListener,
FragmentManager.OnBackStackChangedListener,
VectorSettingsFragmentInteractionListener {

// Tchap: Manage Christmas entry
private val fragmentLifecycleCallbacks = object : FragmentManager.FragmentLifecycleCallbacks() {
override fun onFragmentResumed(fm: FragmentManager, f: Fragment) {
if (f is MatrixToBottomSheet) {
f.interactionListener = this@VectorSettingsActivity
}
super.onFragmentResumed(fm, f)
}

override fun onFragmentPaused(fm: FragmentManager, f: Fragment) {
if (f is MatrixToBottomSheet) {
f.interactionListener = null
}
super.onFragmentPaused(fm, f)
}
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

supportFragmentManager.registerFragmentLifecycleCallbacks(fragmentLifecycleCallbacks, false)
}

override fun getBinding() = ActivityVectorSettingsBinding.inflate(layoutInflater)

override fun getCoordinatorLayout() = views.coordinatorLayout
Expand Down Expand Up @@ -133,7 +106,6 @@ class VectorSettingsActivity : VectorBaseActivity<ActivityVectorSettingsBinding>
}

override fun onDestroy() {
supportFragmentManager.unregisterFragmentLifecycleCallbacks(fragmentLifecycleCallbacks)
supportFragmentManager.removeOnBackStackChangedListener(this)
super.onDestroy()
}
Expand Down Expand Up @@ -189,14 +161,6 @@ class VectorSettingsActivity : VectorBaseActivity<ActivityVectorSettingsBinding>
}
}

// Tchap: Manage Christmas entry
override fun mxToBottomSheetNavigateToRoom(roomId: String, trigger: ViewRoom.Trigger?) {
navigator.openRoom(this, roomId, trigger = trigger)
}
override fun mxToBottomSheetSwitchToSpace(spaceId: String) {
navigator.switchToSpace(this, spaceId, Navigator.PostSwitchSpaceAction.None)
}

fun <T : Fragment> navigateTo(fragmentClass: Class<T>, arguments: Bundle? = null) {
supportFragmentManager.beginTransaction()
.setCustomAnimations(R.anim.right_in, R.anim.fade_out, R.anim.fade_in, R.anim.right_out)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,14 @@

package im.vector.app.features.settings

import android.content.Context
import android.os.Bundle
import androidx.preference.Preference
import dagger.hilt.android.AndroidEntryPoint
import im.vector.app.R
import im.vector.app.core.extensions.singletonEntryPoint
import im.vector.app.core.preference.VectorPreference
import im.vector.app.core.utils.FirstThrottler
import im.vector.app.core.utils.openUrlInChromeCustomTab
import im.vector.app.features.analytics.plan.MobileScreen
import im.vector.app.features.matrixto.OriginOfMatrixTo
import im.vector.app.features.navigation.Navigator
import org.matrix.android.sdk.api.session.getRoomSummary
import org.matrix.android.sdk.api.session.room.model.Membership
import java.util.Calendar

@AndroidEntryPoint
class VectorSettingsRootFragment :
Expand All @@ -41,14 +34,6 @@ class VectorSettingsRootFragment :

private val firstThrottler = FirstThrottler(1000)

private lateinit var navigator: Navigator

override fun onAttach(context: Context) {
val singletonEntryPoint = context.singletonEntryPoint()
navigator = singletonEntryPoint.navigator()
super.onAttach(context)
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
analyticsScreenName = MobileScreen.ScreenName.Settings
Expand All @@ -65,30 +50,6 @@ class VectorSettingsRootFragment :
}
false
}

// Tchap: Manage Christmas entry
if (Calendar.getInstance().before(Calendar.getInstance().apply { set(2024, 1, 10) })) {
findPreference<VectorPreference>(VectorPreferences.TCHAP_SETTINGS_CHRISTMAS_PREFERENCE_KEY)!!.let {
it.isVisible = true
it.onPreferenceClickListener = Preference.OnPreferenceClickListener {
if (firstThrottler.canHandle() is FirstThrottler.CanHandlerResult.Yes) {
val roomAlias = "#JoyeusesFtesdelapartdelquipeTchapGl2gFYK2OD:agent.dinum.tchap.gouv.fr"
val eventId = "\$xW9f1eJGxQ1xstdPCVReUKQO_sFU4242SfaMIfNh3NU"

session.getRoomSummary(roomAlias).let { roomSummary ->
if (roomSummary?.membership == Membership.JOIN) {
navigator.openRoom(requireContext(), roomSummary.roomId)
} else {
session.permalinkService().createPermalink(roomAlias, eventId).let { link ->
navigator.openMatrixToBottomSheet(requireActivity(), link, OriginOfMatrixTo.LINK)
}
}
}
}
false
}
}
}
}

private fun tintIcons() {
Expand Down
6 changes: 0 additions & 6 deletions vector/src/main/res/xml/vector_settings_root.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,4 @@
app:fragment="im.vector.app.features.settings.legals.LegalsFragment"
app:isPreferenceVisible="@bool/settings_root_legals_visible" />

<im.vector.app.core.preference.VectorPreference
android:icon="@drawable/ic_notification"
android:key="TCHAP_SETTINGS_CHRISTMAS_PREFERENCE_KEY"
android:title="@string/tchap_settings_christmas_title"
app:isPreferenceVisible="@bool/false_tchap_hidden" />

</androidx.preference.PreferenceScreen>

0 comments on commit e5748a6

Please sign in to comment.