Skip to content

Commit

Permalink
feat: add an intent for importing external events (WPB-10756) (#3384)
Browse files Browse the repository at this point in the history
  • Loading branch information
typfel authored Sep 6, 2024
1 parent 98be6a7 commit e9adb43
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 1 deletion.
15 changes: 15 additions & 0 deletions app/src/debug/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.wire.android">

<application android:name=".WireApplication">
<activity android:name=".ui.WireActivity">
<intent-filter>
<action android:name="android.intent.action.SYNC" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="file" />
</intent-filter>
</activity>
</application>
</manifest>
19 changes: 19 additions & 0 deletions app/src/main/kotlin/com/wire/android/ui/WireActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,12 @@ class WireActivity : AppCompatActivity() {

override fun onNewIntent(intent: Intent) {
super.onNewIntent(intent)

if (intent.action?.equals(Intent.ACTION_SYNC) == true) {
handleSynchronizeExternalData(intent)
return
}

setIntent(intent)
if (isNavigationCollecting) {
/*
Expand Down Expand Up @@ -539,6 +545,19 @@ class WireActivity : AppCompatActivity() {
}
}

private fun handleSynchronizeExternalData(intent: Intent) {
if (!BuildConfig.DEBUG) {
appLogger.e("Synchronizing external data is only allowed on debug builds")
return
}

intent.data?.lastPathSegment.let { eventsPath ->
openFileInput(eventsPath)?.let { inputStream ->
viewModel.handleSynchronizeExternalData(inputStream)
}
}
}

@Suppress("ComplexCondition", "LongMethod")
private fun handleDeepLink(
intent: Intent?,
Expand Down
27 changes: 27 additions & 0 deletions app/src/main/kotlin/com/wire/android/ui/WireActivityViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ import com.wire.kalium.logic.feature.client.ClearNewClientsForUserUseCase
import com.wire.kalium.logic.feature.client.NewClientResult
import com.wire.kalium.logic.feature.client.ObserveNewClientsUseCase
import com.wire.kalium.logic.feature.conversation.CheckConversationInviteCodeUseCase
import com.wire.kalium.logic.feature.debug.SynchronizeExternalDataResult
import com.wire.kalium.logic.feature.server.GetServerConfigResult
import com.wire.kalium.logic.feature.server.GetServerConfigUseCase
import com.wire.kalium.logic.feature.session.CurrentSessionFlowUseCase
Expand Down Expand Up @@ -92,6 +93,8 @@ import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.shareIn
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import java.io.InputStream
import java.io.InputStreamReader
import javax.inject.Inject

@Suppress("LongParameterList", "TooManyFunctions")
Expand Down Expand Up @@ -306,6 +309,30 @@ class WireActivityViewModel @Inject constructor(
return intent?.action == Intent.ACTION_SEND || intent?.action == Intent.ACTION_SEND_MULTIPLE
}

fun handleSynchronizeExternalData(
data: InputStream
) {
viewModelScope.launch(dispatchers.io()) {
when (val currentSession = coreLogic.getGlobalScope().session.currentSession()) {
is CurrentSessionResult.Failure.Generic -> null
CurrentSessionResult.Failure.SessionNotFound -> null
is CurrentSessionResult.Success -> {
coreLogic.sessionScope(currentSession.accountInfo.userId) {
when (val result = debug.synchronizeExternalData(InputStreamReader(data).readText())) {
is SynchronizeExternalDataResult.Success -> {
appLogger.d("Synchronized external data")
}

is SynchronizeExternalDataResult.Failure -> {
appLogger.d("Failed to Synchronize external data: ${result.coreFailure}")
}
}
}
}
}
}
}

@Suppress("ComplexMethod")
fun handleDeepLink(
intent: Intent?,
Expand Down
2 changes: 1 addition & 1 deletion kalium
Submodule kalium updated 21 files
+1 βˆ’1 .github/workflows/semantic-commit-lint.yml
+75 βˆ’0 build.gradle.kts
+2 βˆ’0 cli/build.gradle.kts
+3 βˆ’1 cli/src/appleMain/kotlin/main.kt
+90 βˆ’0 cli/src/commonMain/kotlin/com/wire/kalium/cli/commands/GenerateEventsCommand.kt
+3 βˆ’1 cli/src/jvmMain/kotlin/com/wire/kalium/cli/main.kt
+4 βˆ’1 cryptography/src/appleMain/kotlin/com/wire/kalium/cryptography/ProteusClientCoreCryptoImpl.kt
+19 βˆ’9 cryptography/src/commonJvmAndroid/kotlin/com.wire.kalium.cryptography/ProteusClientCoreCryptoImpl.kt
+1 βˆ’0 detekt/baseline.xml
+3 βˆ’0 docs/notebooks/README.md
+5,158 βˆ’0 docs/notebooks/event-performance-investigation/PerformanceImprovements.ipynb
+152 βˆ’0 docs/notebooks/event-performance-investigation/logs/InitialData.txt
+156 βˆ’0 docs/notebooks/event-performance-investigation/logs/NotSavingSession.txt
+208 βˆ’0 docs/notebooks/event-performance-investigation/logs/WithExistingSessionCache.txt
+2 βˆ’0 gradle/libs.versions.toml
+118 βˆ’0 logic/src/commonMain/kotlin/com/wire/kalium/logic/data/event/EventGenerator.kt
+16 βˆ’0 logic/src/commonMain/kotlin/com/wire/kalium/logic/data/event/EventRepository.kt
+1 βˆ’0 logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/UserSessionScope.kt
+11 βˆ’0 logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/debug/DebugScope.kt
+59 βˆ’0 logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/debug/EstablishSessionUseCase.kt
+61 βˆ’0 logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/debug/SynchronizeExternalDataUseCase.kt

0 comments on commit e9adb43

Please sign in to comment.