Skip to content

Commit

Permalink
chore: added more logs in import media screen [WPB-15656] (#3821)
Browse files Browse the repository at this point in the history
  • Loading branch information
Garzas authored Jan 23, 2025
1 parent 400baca commit 9afc756
Showing 1 changed file with 15 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import com.wire.android.appLogger
import com.wire.android.model.ImageAsset
import com.wire.android.model.SnackBarMessage
import com.wire.android.ui.common.textfield.textAsFlow
import com.wire.android.ui.home.conversations.ConversationSnackbarMessages
import com.wire.android.ui.home.conversations.search.DEFAULT_SEARCH_QUERY_DEBOUNCE
import com.wire.android.ui.home.conversations.usecase.GetConversationsFromSearchUseCase
import com.wire.android.ui.home.conversations.usecase.HandleUriAssetUseCase
Expand All @@ -45,10 +44,8 @@ import com.wire.android.ui.home.messagecomposer.SelfDeletionDuration
import com.wire.android.util.EMPTY
import com.wire.android.util.dispatchers.DispatcherProvider
import com.wire.android.util.parcelableArrayList
import com.wire.kalium.logic.data.id.ConversationId
import com.wire.kalium.logic.data.message.SelfDeletionTimer
import com.wire.kalium.logic.data.message.SelfDeletionTimer.Companion.SELF_DELETION_LOG_TAG
import com.wire.kalium.logic.feature.asset.ScheduleNewAssetMessageResult
import com.wire.kalium.logic.feature.selfDeletingMessages.ObserveSelfDeletionTimerSettingsForConversationUseCase
import com.wire.kalium.logic.feature.selfDeletingMessages.PersistNewSelfDeletionTimerUseCase
import com.wire.kalium.logic.feature.user.ObserveSelfUserUseCase
Expand Down Expand Up @@ -168,11 +165,13 @@ class ImportMediaAuthenticatedViewModel @Inject constructor(
}

private fun handleSharedText(text: String) {
appLogger.d("$TAG: handleSharedText")
importMediaState = importMediaState.copy(importedText = text)
}

private suspend fun handleSingleIntent(incomingIntent: ShareCompat.IntentReader) {
incomingIntent.stream?.let { uri ->
appLogger.d("$TAG: handleSingleIntent")
handleImportedAsset(uri)?.let { importedAsset ->
if (importedAsset.assetSizeExceeded != null) {
onSnackbarMessage(
Expand All @@ -185,6 +184,7 @@ class ImportMediaAuthenticatedViewModel @Inject constructor(
}

private suspend fun handleMultipleActionIntent(activity: AppCompatActivity) {
appLogger.d("$TAG: handleMultipleActionIntent")
val importedMediaAssets = activity.intent.parcelableArrayList<Parcelable>(Intent.EXTRA_STREAM)?.mapNotNull {
val fileUri = it.toString().toUri()
handleImportedAsset(fileUri)
Expand All @@ -197,27 +197,6 @@ class ImportMediaAuthenticatedViewModel @Inject constructor(
}
}

private fun handleError(result: ScheduleNewAssetMessageResult, conversationId: ConversationId) {
when (result) {
is ScheduleNewAssetMessageResult.Success -> appLogger.d(
"Successfully imported asset message to conversationId=${conversationId.toLogString()}"
)

is ScheduleNewAssetMessageResult.Failure.Generic ->
appLogger.e(
"Failed to import asset message to conversationId=${conversationId.toLogString()}"
)

ScheduleNewAssetMessageResult.Failure.RestrictedFileType,
ScheduleNewAssetMessageResult.Failure.DisabledByTeam -> {
onSnackbarMessage(ConversationSnackbarMessages.ErrorAssetRestriction)
appLogger.e(
"Failed to import asset message to conversationId=${conversationId.toLogString()}"
)
}
}
}

fun onNewSelfDeletionTimerPicked(selfDeletionDuration: SelfDeletionDuration) =
viewModelScope.launch {
importMediaState.selectedConversationItem.first().let {
Expand All @@ -237,14 +216,24 @@ class ImportMediaAuthenticatedViewModel @Inject constructor(

private suspend fun handleImportedAsset(uri: Uri): ImportedMediaAsset? = withContext(dispatchers.io()) {
when (val result = handleUriAsset.invoke(uri, saveToDeviceIfInvalid = false)) {
is HandleUriAssetUseCase.Result.Failure.AssetTooLarge -> ImportedMediaAsset(result.assetBundle, result.maxLimitInMB)
is HandleUriAssetUseCase.Result.Failure.AssetTooLarge -> {
appLogger.w("$TAG: Failed to import asset message: Asset too large")
ImportedMediaAsset(result.assetBundle, result.maxLimitInMB)
}

HandleUriAssetUseCase.Result.Failure.Unknown -> null
HandleUriAssetUseCase.Result.Failure.Unknown -> {
appLogger.e("$TAG: Failed to import asset message: Unknown error")
null
}
is HandleUriAssetUseCase.Result.Success -> ImportedMediaAsset(result.assetBundle, null)
}
}

private fun onSnackbarMessage(type: SnackBarMessage) = viewModelScope.launch {
_infoMessage.emit(type)
}

companion object {
private const val TAG = "[ImportMediaAuthenticatedViewModel]"
}
}

0 comments on commit 9afc756

Please sign in to comment.