Skip to content

Commit

Permalink
add error messages and detekt
Browse files Browse the repository at this point in the history
  • Loading branch information
MohamadJaara committed Jun 21, 2024
1 parent ce58c91 commit 46fb1d3
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 17 deletions.
10 changes: 4 additions & 6 deletions app/src/main/kotlin/com/wire/android/ui/home/FeatureFlagState.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
package com.wire.android.ui.home

import com.wire.android.ui.home.messagecomposer.SelfDeletionDuration
import com.wire.kalium.logic.configuration.FileSharingStatus
import kotlin.time.Duration

data class FeatureFlagState(
Expand All @@ -37,11 +36,10 @@ data class FeatureFlagState(
) {

sealed interface FileSharingState {
data object NoUser: FileSharingState
data object AllowAll: FileSharingState
data class AllowSome(val allowedList: List<String>): FileSharingState
data object DisabledByTeam: FileSharingState

data object NoUser : FileSharingState
data object AllowAll : FileSharingState
data class AllowSome(val allowedList: List<String>) : FileSharingState
data object DisabledByTeam : FileSharingState
}

data class E2EISnooze(val timeLeft: Duration)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ sealed class ConversationSnackbarMessages(override val uiText: UIText) : SnackBa
object ErrorDownloadingAsset : ConversationSnackbarMessages(UIText.StringResource(R.string.error_conversation_downloading_asset))
object ErrorOpeningAssetFile : ConversationSnackbarMessages(UIText.StringResource(R.string.error_conversation_opening_asset_file))
object ErrorDeletingMessage : ConversationSnackbarMessages(UIText.StringResource(R.string.error_conversation_deleting_message))
data object ErrorAssetRestriction : ConversationSnackbarMessages(UIText.StringResource(R.string.restricted_asset_error_toast_message))
data class ErrorMaxAssetSize(val maxLimitInMB: Int) :
ConversationSnackbarMessages(UIText.StringResource(R.string.error_conversation_max_asset_size_limit, maxLimitInMB))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

package com.wire.android.ui.home.conversations

import android.content.Context
import android.net.Uri
import android.webkit.URLUtil
import androidx.compose.runtime.getValue
Expand Down Expand Up @@ -54,6 +55,7 @@ import com.wire.kalium.logic.data.asset.KaliumFileSystem
import com.wire.kalium.logic.data.id.QualifiedID
import com.wire.kalium.logic.data.user.OtherUser
import com.wire.kalium.logic.feature.asset.GetAssetSizeLimitUseCase
import com.wire.kalium.logic.feature.asset.ScheduleNewAssetMessageResult
import com.wire.kalium.logic.feature.asset.ScheduleNewAssetMessageUseCase
import com.wire.kalium.logic.feature.conversation.InteractionAvailability
import com.wire.kalium.logic.feature.conversation.IsInteractionAvailableResult
Expand All @@ -72,6 +74,7 @@ import com.wire.kalium.logic.feature.selfDeletingMessages.SelfDeletionTimer
import com.wire.kalium.logic.feature.user.IsFileSharingEnabledUseCase
import com.wire.kalium.logic.functional.onFailure
import dagger.hilt.android.lifecycle.HiltViewModel
import dagger.hilt.android.qualifiers.ApplicationContext
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.asSharedFlow
import kotlinx.coroutines.launch
Expand All @@ -84,6 +87,7 @@ import javax.inject.Inject
@Suppress("LongParameterList", "TooManyFunctions")
@HiltViewModel
class MessageComposerViewModel @Inject constructor(
@ApplicationContext private val context: Context,
override val savedStateHandle: SavedStateHandle,
private val sendAssetMessage: ScheduleNewAssetMessageUseCase,
private val sendTextMessage: SendTextMessageUseCase,
Expand Down Expand Up @@ -283,6 +287,7 @@ class MessageComposerViewModel @Inject constructor(
}
}

@Suppress("LongMethod")
internal fun sendAttachment(attachmentBundle: AssetBundle?) {
viewModelScope.launch {
withContext(dispatchers.io()) {
Expand All @@ -302,7 +307,21 @@ class MessageComposerViewModel @Inject constructor(
assetDataSize = dataSize,
assetMimeType = mimeType,
audioLengthInMs = 0L
)
).also {
when (it) {
is ScheduleNewAssetMessageResult.Failure.Generic,
is ScheduleNewAssetMessageResult.Success -> {
/* no-op */
}

ScheduleNewAssetMessageResult.Failure.DisabledByTeam,
ScheduleNewAssetMessageResult.Failure.RestrictedFileType -> {
withContext(dispatchers.main()) {
onSnackbarMessage(ConversationSnackbarMessages.ErrorAssetRestriction)
}
}
}
}
}

AttachmentType.VIDEO,
Expand All @@ -321,7 +340,21 @@ class MessageComposerViewModel @Inject constructor(
dataPath = dataPath,
mimeType = mimeType
)
)
).also {
when (it) {
is ScheduleNewAssetMessageResult.Failure.Generic,
is ScheduleNewAssetMessageResult.Success -> {
/* no-op */
}

ScheduleNewAssetMessageResult.Failure.DisabledByTeam,
ScheduleNewAssetMessageResult.Failure.RestrictedFileType -> {
withContext(dispatchers.main()) {
onSnackbarMessage(ConversationSnackbarMessages.ErrorAssetRestriction)
}
}
}
}
} catch (e: OutOfMemoryError) {
appLogger.e("There was an OutOfMemory error while uploading the asset")
onSnackbarMessage(ConversationSnackbarMessages.ErrorSendingAsset)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
package com.wire.android.ui.home.conversations

import com.wire.android.ui.home.newconversation.model.Contact
import com.wire.kalium.logic.configuration.FileSharingStatus
import com.wire.kalium.logic.data.asset.AttachmentType
import com.wire.kalium.logic.feature.conversation.InteractionAvailability
import com.wire.kalium.logic.feature.selfDeletingMessages.SelfDeletionTimer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.content.Context
import android.content.Intent
import android.net.Uri
import android.os.Parcelable
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.compose.runtime.Stable
import androidx.compose.runtime.getValue
Expand All @@ -14,6 +15,7 @@ import androidx.core.app.ShareCompat
import androidx.core.net.toUri
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.wire.android.R
import com.wire.android.appLogger
import com.wire.android.mapper.UserTypeMapper
import com.wire.android.mapper.toUIPreview
Expand Down Expand Up @@ -51,6 +53,7 @@ import com.wire.kalium.logic.feature.selfDeletingMessages.SelfDeletionTimer
import com.wire.kalium.logic.feature.selfDeletingMessages.SelfDeletionTimer.Companion.SELF_DELETION_LOG_TAG
import com.wire.kalium.logic.feature.user.GetSelfUserUseCase
import dagger.hilt.android.lifecycle.HiltViewModel
import dagger.hilt.android.qualifiers.ApplicationContext
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.FlowPreview
import kotlinx.coroutines.Job
Expand All @@ -72,6 +75,7 @@ import javax.inject.Inject
@OptIn(FlowPreview::class)
@Suppress("LongParameterList", "TooManyFunctions")
class ImportMediaAuthenticatedViewModel @Inject constructor(
@ApplicationContext private val context: Context,
private val getSelf: GetSelfUserUseCase,
private val userTypeMapper: UserTypeMapper,
private val observeConversationListDetails: ObserveConversationListDetailsUseCase,
Expand Down Expand Up @@ -326,11 +330,26 @@ class ImportMediaAuthenticatedViewModel @Inject constructor(
mimeType = importedAsset.mimeType
)
).also {
if (it is ScheduleNewAssetMessageResult.Failure) {

appLogger.e("Failed to import asset message to conversationId=${conversation.conversationId.toLogString()} ")
} else {
appLogger.d("Success importing asset message to conversationId=${conversation.conversationId.toLogString()}")
when (it) {
is ScheduleNewAssetMessageResult.Success -> appLogger.d(
"Successfully imported asset message to conversationId=${conversation.conversationId.toLogString()}"
)

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

ScheduleNewAssetMessageResult.Failure.RestrictedFileType,
ScheduleNewAssetMessageResult.Failure.DisabledByTeam -> {
Toast.makeText(
context,
R.string.restricted_asset_error_toast_message,
Toast.LENGTH_SHORT
).show()
appLogger.e(
"Failed to import asset message to conversationId=${conversation.conversationId.toLogString()}"
)
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,6 @@ fun PreviewImportMediaScreenAllowSome() {
ImportMediaRestrictedContent(FeatureFlagState.FileSharingState.AllowSome(listOf("wire")), ImportMediaAuthenticatedState()) {}
}


@Preview(showBackground = true)
@Composable
fun PreviewImportMediaScreenRegular() {
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1189,4 +1189,5 @@
<string name="conversation_options_create_password_protected_guest_link_password_description">Use at least 8 characters, with one lowercase letter, one capital letter, a number, and a special character.</string>
<string name="conversation_options_create_password_protected_guest_link_password_generated">New password generated</string>

<string name="restricted_asset_error_toast_message">Sending of files is forbidden due to company restrictions</string>
</resources>
3 changes: 1 addition & 2 deletions default.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,9 @@
"enable_blacklist": true,
"allow_email_change": true,
"enable_guest_room_link": true,
"file_restriction_enabled": true,
"file_restriction_enabled": false,
"file_restriction_list": "3gpp, aac, amr, avi, bmp, css, csv, dib, doc, docx, eml, flac, gif, html, ico, jfif, jpeg, jpg, jpg-large, key, m4a, m4v, md, midi, mkv, mov, mp3, mp4, mpeg, mpeg3, mpg, msg, ods, odt, ogg, pdf, pjp, pjpeg, png, pps, ppt, pptx, psd, pst, rtf, sql, svg, tex, tiff, txt, vcf, vid, wav, webm, webp, wmv, xls, xlsx, xml",
"force_constant_bitrate_calls": false,

"mls_support_enabled": true,
"encrypt_proteus_storage": false,
"self_deleting_messages": true,
Expand Down

0 comments on commit 46fb1d3

Please sign in to comment.