mirror of
https://github.com/ProtonMail/android-mail.git
synced 2026-05-15 09:50:40 +00:00
fix(deps): update dependency me.proton.mail.common:lib to v0.157.8
This commit is contained in:
@@ -68,7 +68,7 @@ material = "1.13.0"
|
||||
mockk = "1.14.6"
|
||||
paparazzi = "1.3.5"
|
||||
proton-core = "34.1.0"
|
||||
proton-rust-core = "0.157.4"
|
||||
proton-rust-core = "0.157.8"
|
||||
robolectric = "4.15.1" # 4.16.0 requires Java 21
|
||||
kotlinpoet-ksp = "2.2.0"
|
||||
leakcanary = "2.14"
|
||||
|
||||
+4
@@ -23,6 +23,7 @@ import uniffi.proton_mail_uniffi.AppProtection
|
||||
import uniffi.proton_mail_uniffi.AppSettings
|
||||
import uniffi.proton_mail_uniffi.AppSettingsDiff
|
||||
import uniffi.proton_mail_uniffi.AttachmentData
|
||||
import uniffi.proton_mail_uniffi.AttachmentDataError
|
||||
import uniffi.proton_mail_uniffi.AttachmentMetadata
|
||||
import uniffi.proton_mail_uniffi.AttachmentMimeType
|
||||
import uniffi.proton_mail_uniffi.AutoDeleteBanner
|
||||
@@ -239,4 +240,7 @@ typealias LocalRsvpAnswer = RsvpAnswer
|
||||
typealias LocalMobileSignatureStatus = MobileSignatureStatus
|
||||
typealias LocalMobileSignature = MobileSignature
|
||||
typealias LocalHiddenMessagesBanner = HiddenMessagesBanner
|
||||
typealias LocalAttachmentDataError = AttachmentDataError
|
||||
typealias LocalAttachmentDataErrorProxyFailed = AttachmentDataError.ProxyFailed
|
||||
typealias LocalAttachmentDataErrorOther = AttachmentDataError.Other
|
||||
|
||||
|
||||
+2
-1
@@ -37,6 +37,7 @@ import ch.protonmail.android.mailcomposer.domain.model.SendDraftError
|
||||
import ch.protonmail.android.mailcomposer.domain.model.SenderEmail
|
||||
import ch.protonmail.android.mailcomposer.domain.model.Subject
|
||||
import ch.protonmail.android.mailcomposer.domain.model.ValidatedRecipients
|
||||
import ch.protonmail.android.mailmessage.domain.model.AttachmentDataError
|
||||
import ch.protonmail.android.mailmessage.domain.model.DraftAction
|
||||
import ch.protonmail.android.mailmessage.domain.model.MessageId
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
@@ -76,7 +77,7 @@ interface RustDraftDataSource {
|
||||
suspend fun validateSendWithExpiration(): Either<DataError, DraftRecipientExpirationFeatureReport>
|
||||
suspend fun validateDraftSenderAddress(): DraftAddressValidationResult?
|
||||
|
||||
fun loadImage(url: String): Either<DataError, LocalAttachmentData>
|
||||
fun loadImage(url: String): Either<AttachmentDataError, LocalAttachmentData>
|
||||
fun getScheduleSendOptions(): Either<DataError, DraftScheduleSendOptions>
|
||||
|
||||
/**
|
||||
|
||||
+4
-2
@@ -64,8 +64,10 @@ import ch.protonmail.android.mailcomposer.domain.model.SendDraftError
|
||||
import ch.protonmail.android.mailcomposer.domain.model.SenderEmail
|
||||
import ch.protonmail.android.mailcomposer.domain.model.Subject
|
||||
import ch.protonmail.android.mailcomposer.domain.model.ValidatedRecipients
|
||||
import ch.protonmail.android.mailmessage.data.mapper.toAttachmentDataError
|
||||
import ch.protonmail.android.mailmessage.data.mapper.toLocalMessageId
|
||||
import ch.protonmail.android.mailmessage.data.mapper.toMessageId
|
||||
import ch.protonmail.android.mailmessage.domain.model.AttachmentDataError
|
||||
import ch.protonmail.android.mailmessage.domain.model.DraftAction
|
||||
import ch.protonmail.android.mailmessage.domain.model.MessageId
|
||||
import ch.protonmail.android.mailsession.domain.repository.UserSessionRepository
|
||||
@@ -265,9 +267,9 @@ class RustDraftDataSourceImpl @Inject constructor(
|
||||
return wrapper.attachmentList().right()
|
||||
}
|
||||
|
||||
override fun loadImage(url: String): Either<DataError, LocalAttachmentData> =
|
||||
override fun loadImage(url: String): Either<AttachmentDataError, LocalAttachmentData> =
|
||||
when (val result = draftCache.get().loadImage(url)) {
|
||||
is AttachmentDataResult.Error -> result.v1.toDataError().left()
|
||||
is AttachmentDataResult.Error -> result.v1.toAttachmentDataError().left()
|
||||
is AttachmentDataResult.Ok -> result.v1.right()
|
||||
}
|
||||
|
||||
|
||||
+2
-1
@@ -43,6 +43,7 @@ import ch.protonmail.android.mailcomposer.domain.model.SenderEmail
|
||||
import ch.protonmail.android.mailcomposer.domain.model.Subject
|
||||
import ch.protonmail.android.mailcomposer.domain.model.ValidatedRecipients
|
||||
import ch.protonmail.android.mailcomposer.domain.repository.DraftRepository
|
||||
import ch.protonmail.android.mailmessage.domain.model.AttachmentDataError
|
||||
import ch.protonmail.android.mailmessage.domain.model.DraftAction
|
||||
import ch.protonmail.android.mailmessage.domain.model.MessageBodyImage
|
||||
import ch.protonmail.android.mailmessage.domain.model.MessageId
|
||||
@@ -61,7 +62,7 @@ class DraftRepositoryImpl @Inject constructor(
|
||||
|
||||
override suspend fun getMessageId(): Either<DataError, MessageId> = draftDataSource.getMessageId()
|
||||
|
||||
override fun loadImage(url: String): Either<DataError, MessageBodyImage> =
|
||||
override fun loadImage(url: String): Either<AttachmentDataError, MessageBodyImage> =
|
||||
draftDataSource.loadImage(url).map { it.toMessageBodyImage() }
|
||||
|
||||
override suspend fun openDraft(
|
||||
|
||||
+1
-2
@@ -26,7 +26,6 @@ import ch.protonmail.android.composer.data.wrapper.DraftWrapper
|
||||
import ch.protonmail.android.mailcomposer.domain.model.OpenDraftError
|
||||
import ch.protonmail.android.mailsession.domain.wrapper.MailUserSessionWrapper
|
||||
import uniffi.proton_mail_uniffi.DraftCreateMode
|
||||
import uniffi.proton_mail_uniffi.ImagePolicy
|
||||
import uniffi.proton_mail_uniffi.NewDraftResult
|
||||
import uniffi.proton_mail_uniffi.newDraft
|
||||
import javax.inject.Inject
|
||||
@@ -37,7 +36,7 @@ class CreateRustDraft @Inject constructor() {
|
||||
mailSession: MailUserSessionWrapper,
|
||||
createMode: DraftCreateMode
|
||||
): Either<OpenDraftError, DraftWrapper> =
|
||||
when (val result = newDraft(mailSession.getRustUserSession(), createMode, ImagePolicy.SAFE)) {
|
||||
when (val result = newDraft(mailSession.getRustUserSession(), createMode)) {
|
||||
is NewDraftResult.Error -> result.v1.toOpenDraftError().left()
|
||||
is NewDraftResult.Ok -> DraftWrapper(result.v1).right()
|
||||
}
|
||||
|
||||
+2
-1
@@ -22,6 +22,7 @@ import ch.protonmail.android.mailcommon.data.mapper.LocalMimeType
|
||||
import uniffi.proton_mail_uniffi.Draft
|
||||
import uniffi.proton_mail_uniffi.DraftExpirationTime
|
||||
import uniffi.proton_mail_uniffi.DraftScheduleSendOptionsResult
|
||||
import uniffi.proton_mail_uniffi.ImagePolicy
|
||||
import uniffi.proton_mail_uniffi.UnixTimestamp
|
||||
import uniffi.proton_mail_uniffi.VoidDraftSaveResult
|
||||
import uniffi.proton_mail_uniffi.VoidDraftSendResult
|
||||
@@ -31,7 +32,7 @@ class DraftWrapper(private val rustDraft: Draft) {
|
||||
|
||||
fun attachmentList(): AttachmentsWrapper = AttachmentsWrapper(rustDraft.attachmentList())
|
||||
|
||||
fun loadImage(url: String) = rustDraft.loadImageSync(url)
|
||||
fun loadImage(url: String) = rustDraft.loadImageSync(url, ImagePolicy.SAFE)
|
||||
|
||||
fun subject(): String = rustDraft.subject()
|
||||
|
||||
|
||||
+4
-2
@@ -14,6 +14,7 @@ import ch.protonmail.android.composer.data.wrapper.ComposerRecipientListWrapper
|
||||
import ch.protonmail.android.composer.data.wrapper.DraftWrapper
|
||||
import ch.protonmail.android.composer.data.wrapper.DraftWrapperWithSyncStatus
|
||||
import ch.protonmail.android.mailcommon.data.mapper.LocalAttachmentData
|
||||
import ch.protonmail.android.mailcommon.data.mapper.LocalAttachmentDataErrorOther
|
||||
import ch.protonmail.android.mailcommon.data.mapper.LocalMessageId
|
||||
import ch.protonmail.android.mailcommon.data.mapper.LocalMimeType
|
||||
import ch.protonmail.android.mailcommon.data.worker.Enqueuer
|
||||
@@ -33,6 +34,7 @@ import ch.protonmail.android.mailcomposer.domain.model.SenderEmail
|
||||
import ch.protonmail.android.mailcomposer.domain.model.Subject
|
||||
import ch.protonmail.android.mailmessage.data.mapper.toLocalMessageId
|
||||
import ch.protonmail.android.mailmessage.data.mapper.toMessageId
|
||||
import ch.protonmail.android.mailmessage.domain.model.AttachmentDataError
|
||||
import ch.protonmail.android.mailmessage.domain.model.DraftAction
|
||||
import ch.protonmail.android.mailmessage.domain.model.MessageId
|
||||
import ch.protonmail.android.mailmessage.domain.sample.MessageIdSample
|
||||
@@ -673,12 +675,12 @@ class RustDraftDataSourceImplTest {
|
||||
@Test
|
||||
fun `load image returns DataError when unsuccessful`() = runTest {
|
||||
// Given
|
||||
val expected = DataError.Remote.NoNetwork
|
||||
val expected = AttachmentDataError.Other(DataError.Remote.NoNetwork)
|
||||
val cid = "image-content-id"
|
||||
val expectedDraftWrapper = expectDraftWrapperReturns()
|
||||
every { draftCache.get() } returns expectedDraftWrapper
|
||||
coEvery { expectedDraftWrapper.loadImage(cid) } returns AttachmentDataResult.Error(
|
||||
ProtonError.Network
|
||||
LocalAttachmentDataErrorOther(ProtonError.Network)
|
||||
)
|
||||
|
||||
// When
|
||||
|
||||
+3
-2
@@ -16,6 +16,7 @@ import ch.protonmail.android.mailcomposer.domain.model.SaveDraftError
|
||||
import ch.protonmail.android.mailcomposer.domain.model.ScheduleSendOptions
|
||||
import ch.protonmail.android.mailcomposer.domain.model.SendDraftError
|
||||
import ch.protonmail.android.mailcomposer.domain.model.Subject
|
||||
import ch.protonmail.android.mailmessage.domain.model.AttachmentDataError
|
||||
import ch.protonmail.android.mailmessage.domain.model.DraftAction
|
||||
import ch.protonmail.android.mailmessage.domain.model.MessageBodyImage
|
||||
import ch.protonmail.android.mailmessage.domain.sample.MessageIdSample
|
||||
@@ -290,13 +291,13 @@ class DraftRepositoryImplTest {
|
||||
fun `returns error when load image failed`() = runTest {
|
||||
// Given
|
||||
val url = "url"
|
||||
every { draftDataSource.loadImage(url) } returns DataError.Local.CryptoError.left()
|
||||
every { draftDataSource.loadImage(url) } returns AttachmentDataError.Other(DataError.Local.CryptoError).left()
|
||||
|
||||
// When
|
||||
val actual = draftRepository.loadImage(url)
|
||||
|
||||
// Then
|
||||
assertEquals(DataError.Local.CryptoError.left(), actual)
|
||||
assertEquals(AttachmentDataError.Other(DataError.Local.CryptoError).left(), actual)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+2
-1
@@ -36,6 +36,7 @@ import ch.protonmail.android.mailcomposer.domain.model.SenderAddresses
|
||||
import ch.protonmail.android.mailcomposer.domain.model.SenderEmail
|
||||
import ch.protonmail.android.mailcomposer.domain.model.Subject
|
||||
import ch.protonmail.android.mailcomposer.domain.model.ValidatedRecipients
|
||||
import ch.protonmail.android.mailmessage.domain.model.AttachmentDataError
|
||||
import ch.protonmail.android.mailmessage.domain.model.DraftAction
|
||||
import ch.protonmail.android.mailmessage.domain.model.MessageBodyImage
|
||||
import ch.protonmail.android.mailmessage.domain.model.MessageId
|
||||
@@ -46,7 +47,7 @@ import kotlin.time.Instant
|
||||
interface DraftRepository {
|
||||
|
||||
suspend fun getMessageId(): Either<DataError, MessageId>
|
||||
fun loadImage(url: String): Either<DataError, MessageBodyImage>
|
||||
fun loadImage(url: String): Either<AttachmentDataError, MessageBodyImage>
|
||||
suspend fun openDraft(userId: UserId, messageId: MessageId): Either<OpenDraftError, DraftFieldsWithSyncStatus>
|
||||
suspend fun createDraft(userId: UserId, action: DraftAction): Either<OpenDraftError, DraftFields>
|
||||
suspend fun discardDraft(userId: UserId, messageId: MessageId): Either<DiscardDraftError, Unit>
|
||||
|
||||
+2
-2
@@ -19,8 +19,8 @@
|
||||
package ch.protonmail.android.mailcomposer.domain.usecase
|
||||
|
||||
import arrow.core.Either
|
||||
import ch.protonmail.android.mailcommon.domain.model.DataError
|
||||
import ch.protonmail.android.mailcomposer.domain.repository.DraftRepository
|
||||
import ch.protonmail.android.mailmessage.domain.model.AttachmentDataError
|
||||
import ch.protonmail.android.mailmessage.domain.model.MessageBodyImage
|
||||
import javax.inject.Inject
|
||||
|
||||
@@ -28,5 +28,5 @@ class LoadMessageBodyImage @Inject constructor(
|
||||
private val draftRepository: DraftRepository
|
||||
) {
|
||||
|
||||
operator fun invoke(url: String): Either<DataError, MessageBodyImage> = draftRepository.loadImage(url)
|
||||
operator fun invoke(url: String): Either<AttachmentDataError, MessageBodyImage> = draftRepository.loadImage(url)
|
||||
}
|
||||
|
||||
+5
-2
@@ -4,6 +4,7 @@ import arrow.core.left
|
||||
import arrow.core.right
|
||||
import ch.protonmail.android.mailcommon.domain.model.DataError
|
||||
import ch.protonmail.android.mailcomposer.domain.repository.DraftRepository
|
||||
import ch.protonmail.android.mailmessage.domain.model.AttachmentDataError
|
||||
import ch.protonmail.android.mailmessage.domain.model.MessageBodyImage
|
||||
import io.mockk.coEvery
|
||||
import io.mockk.mockk
|
||||
@@ -36,12 +37,14 @@ class LoadMessageBodyImageTest {
|
||||
@Test
|
||||
fun `returns error when loading image fails`() = runTest {
|
||||
// Given
|
||||
coEvery { draftRepository.loadImage(url) } returns DataError.Local.NoDataCached.left()
|
||||
coEvery {
|
||||
draftRepository.loadImage(url)
|
||||
} returns AttachmentDataError.Other(DataError.Local.NoDataCached).left()
|
||||
|
||||
// When
|
||||
val actual = loadMessageBodyImage(url)
|
||||
|
||||
// Then
|
||||
assertEquals(DataError.Local.NoDataCached.left(), actual)
|
||||
assertEquals(AttachmentDataError.Other(DataError.Local.NoDataCached).left(), actual)
|
||||
}
|
||||
}
|
||||
|
||||
+2
-1
@@ -22,6 +22,7 @@ import arrow.core.left
|
||||
import arrow.core.right
|
||||
import ch.protonmail.android.mailcommon.domain.model.DataError
|
||||
import ch.protonmail.android.mailcommon.domain.sample.UserIdSample
|
||||
import ch.protonmail.android.mailmessage.domain.model.AttachmentDataError
|
||||
import ch.protonmail.android.mailmessage.domain.model.MessageBodyImage
|
||||
import ch.protonmail.android.mailmessage.domain.sample.MessageIdSample
|
||||
import ch.protonmail.android.mailmessage.domain.usecase.LoadMessageBodyImage
|
||||
@@ -66,7 +67,7 @@ class LoadImageAvoidDuplicatedExecutionTest {
|
||||
// Given
|
||||
coEvery {
|
||||
loadMessageBodyImage(userId, messageId, url)
|
||||
} returns DataError.Local.NoDataCached.left()
|
||||
} returns AttachmentDataError.Other(DataError.Local.NoDataCached).left()
|
||||
|
||||
// When
|
||||
val result = loadImageAvoidDuplicatedExecution(userId, messageId, url, coroutineContext)
|
||||
|
||||
+2
-1
@@ -22,6 +22,7 @@ import arrow.core.Either
|
||||
import ch.protonmail.android.mailcommon.data.mapper.LocalAttachmentData
|
||||
import ch.protonmail.android.mailcommon.data.mapper.LocalMessageId
|
||||
import ch.protonmail.android.mailcommon.domain.model.DataError
|
||||
import ch.protonmail.android.mailmessage.domain.model.AttachmentDataError
|
||||
import ch.protonmail.android.mailmessage.domain.model.MessageBody
|
||||
import ch.protonmail.android.mailmessage.domain.model.MessageBodyTransformations
|
||||
import me.proton.core.domain.entity.UserId
|
||||
@@ -38,7 +39,7 @@ interface MessageBodyDataSource {
|
||||
userId: UserId,
|
||||
messageId: LocalMessageId,
|
||||
url: String
|
||||
): Either<DataError, LocalAttachmentData>
|
||||
): Either<AttachmentDataError, LocalAttachmentData>
|
||||
|
||||
suspend fun unsubscribeFromNewsletter(userId: UserId, messageId: LocalMessageId): Either<DataError, Unit>
|
||||
}
|
||||
|
||||
+7
-3
@@ -30,6 +30,7 @@ import ch.protonmail.android.mailmessage.data.mapper.toLocalThemeOptions
|
||||
import ch.protonmail.android.mailmessage.data.mapper.toMessageBody
|
||||
import ch.protonmail.android.mailmessage.data.mapper.toMessageId
|
||||
import ch.protonmail.android.mailmessage.data.usecase.CreateRustMessageBodyAccessor
|
||||
import ch.protonmail.android.mailmessage.domain.model.AttachmentDataError
|
||||
import ch.protonmail.android.mailmessage.domain.model.MessageBody
|
||||
import ch.protonmail.android.mailmessage.domain.model.MessageBodyTransformations
|
||||
import kotlinx.coroutines.CoroutineDispatcher
|
||||
@@ -75,14 +76,17 @@ class RustMessageBodyDataSource @Inject constructor(
|
||||
userId: UserId,
|
||||
messageId: LocalMessageId,
|
||||
url: String
|
||||
): Either<DataError, LocalAttachmentData> = withContext(ioDispatcher) {
|
||||
): Either<AttachmentDataError, LocalAttachmentData> = withContext(ioDispatcher) {
|
||||
// Hardcoded rust mailbox to "AllMail" to avoid this method having labelId as param;
|
||||
// the current labelId is not needed to get the body and is planned to be dropped on this API
|
||||
val mailbox = rustMailboxFactory.createAllMail(userId).getOrNull()
|
||||
?: return@withContext DataError.Local.IllegalStateError.left()
|
||||
?: return@withContext AttachmentDataError.Other(DataError.Local.IllegalStateError).left()
|
||||
|
||||
return@withContext createRustMessageBodyAccessor(mailbox, messageId)
|
||||
.onLeft { Timber.e("rust-message: Failed to build message body accessor $it") }
|
||||
.mapLeft {
|
||||
Timber.e("rust-message: Failed to build message body accessor $it")
|
||||
AttachmentDataError.Other(it)
|
||||
}
|
||||
.flatMap { decryptedMessage ->
|
||||
decryptedMessage.loadImage(url)
|
||||
}
|
||||
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Copyright (c) 2025 Proton Technologies AG
|
||||
* This file is part of Proton Technologies AG and Proton Mail.
|
||||
*
|
||||
* Proton Mail is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Proton Mail is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Proton Mail. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package ch.protonmail.android.mailmessage.data.mapper
|
||||
|
||||
import ch.protonmail.android.mailcommon.data.mapper.LocalAttachmentDataError
|
||||
import ch.protonmail.android.mailcommon.data.mapper.LocalAttachmentDataErrorOther
|
||||
import ch.protonmail.android.mailcommon.data.mapper.LocalAttachmentDataErrorProxyFailed
|
||||
import ch.protonmail.android.mailcommon.data.mapper.toDataError
|
||||
import ch.protonmail.android.mailmessage.domain.model.AttachmentDataError
|
||||
|
||||
fun LocalAttachmentDataError.toAttachmentDataError() = when (this) {
|
||||
is LocalAttachmentDataErrorProxyFailed -> AttachmentDataError.ProxyFailed
|
||||
is LocalAttachmentDataErrorOther -> AttachmentDataError.Other(this.v1.toDataError())
|
||||
}
|
||||
+7
-5
@@ -22,6 +22,7 @@ import arrow.core.Either
|
||||
import ch.protonmail.android.mailcommon.domain.model.DataError
|
||||
import ch.protonmail.android.mailmessage.data.local.MessageBodyDataSource
|
||||
import ch.protonmail.android.mailmessage.data.mapper.toLocalMessageId
|
||||
import ch.protonmail.android.mailmessage.domain.model.AttachmentDataError
|
||||
import ch.protonmail.android.mailmessage.domain.model.MessageBodyImage
|
||||
import ch.protonmail.android.mailmessage.domain.model.MessageBody
|
||||
import ch.protonmail.android.mailmessage.domain.model.MessageBodyTransformations
|
||||
@@ -46,11 +47,12 @@ class RustMessageBodyRepository @Inject constructor(
|
||||
userId: UserId,
|
||||
messageId: MessageId,
|
||||
url: String
|
||||
): Either<DataError, MessageBodyImage> = messageBodyDataSource.loadImage(userId, messageId.toLocalMessageId(), url)
|
||||
.map { localAttachmentData ->
|
||||
Timber.d("RustMessage: Loaded image: $url; mime ${localAttachmentData.mime};")
|
||||
MessageBodyImage(localAttachmentData.data, localAttachmentData.mime)
|
||||
}
|
||||
): Either<AttachmentDataError, MessageBodyImage> =
|
||||
messageBodyDataSource.loadImage(userId, messageId.toLocalMessageId(), url)
|
||||
.map { localAttachmentData ->
|
||||
Timber.d("RustMessage: Loaded image: $url; mime ${localAttachmentData.mime};")
|
||||
MessageBodyImage(localAttachmentData.data, localAttachmentData.mime)
|
||||
}
|
||||
|
||||
override suspend fun unsubscribeFromNewsletter(userId: UserId, messageId: MessageId): Either<DataError, Unit> =
|
||||
messageBodyDataSource.unsubscribeFromNewsletter(userId, messageId.toLocalMessageId())
|
||||
|
||||
+4
-2
@@ -25,6 +25,8 @@ import ch.protonmail.android.mailcommon.data.mapper.LocalAttachmentData
|
||||
import ch.protonmail.android.mailcommon.data.mapper.LocalMimeType
|
||||
import ch.protonmail.android.mailcommon.data.mapper.toDataError
|
||||
import ch.protonmail.android.mailcommon.domain.model.DataError
|
||||
import ch.protonmail.android.mailmessage.data.mapper.toAttachmentDataError
|
||||
import ch.protonmail.android.mailmessage.domain.model.AttachmentDataError
|
||||
import timber.log.Timber
|
||||
import uniffi.proton_mail_uniffi.AttachmentDataResult
|
||||
import uniffi.proton_mail_uniffi.BodyOutput
|
||||
@@ -42,11 +44,11 @@ class DecryptedMessageWrapper(private val decryptedMessage: DecryptedMessage) {
|
||||
is BodyOutputResult.Ok -> result.v1.right()
|
||||
}
|
||||
|
||||
suspend fun loadImage(url: String): Either<DataError, LocalAttachmentData> =
|
||||
suspend fun loadImage(url: String): Either<AttachmentDataError, LocalAttachmentData> =
|
||||
when (val result = decryptedMessage.loadImage(url, ImagePolicy.SAFE)) {
|
||||
is AttachmentDataResult.Error -> {
|
||||
Timber.d("DecryptedMessageWrapper: Failed to load image: $url: ${result.v1}")
|
||||
result.v1.toDataError().left()
|
||||
result.v1.toAttachmentDataError().left()
|
||||
}
|
||||
is AttachmentDataResult.Ok -> result.v1.right()
|
||||
}
|
||||
|
||||
+3
-3
@@ -27,6 +27,7 @@ import ch.protonmail.android.maillabel.data.local.RustMailboxFactory
|
||||
import ch.protonmail.android.maillabel.data.wrapper.MailboxWrapper
|
||||
import ch.protonmail.android.mailmessage.data.usecase.CreateRustMessageBodyAccessor
|
||||
import ch.protonmail.android.mailmessage.data.wrapper.DecryptedMessageWrapper
|
||||
import ch.protonmail.android.mailmessage.domain.model.AttachmentDataError
|
||||
import ch.protonmail.android.mailmessage.domain.model.MessageBodyTransformations
|
||||
import ch.protonmail.android.mailsession.domain.repository.UserSessionRepository
|
||||
import ch.protonmail.android.mailsession.domain.wrapper.MailUserSessionWrapper
|
||||
@@ -148,16 +149,15 @@ class RustMessageBodyDataSourceTest {
|
||||
val userId = UserIdTestData.userId
|
||||
val messageId = LocalMessageIdSample.AugWeatherForecast
|
||||
val mailbox = mockk<MailboxWrapper>()
|
||||
val expectedError = DataError.Local.NoDataCached
|
||||
coEvery { rustMailboxFactory.createAllMail(userId) } returns mailbox.right()
|
||||
coEvery { createRustMessageBodyAccessor(mailbox, messageId) } returns expectedError.left()
|
||||
coEvery { createRustMessageBodyAccessor(mailbox, messageId) } returns DataError.Local.NoDataCached.left()
|
||||
|
||||
// When
|
||||
val result = dataSource.loadImage(userId, messageId, "url")
|
||||
|
||||
// Then
|
||||
coVerify { rustMailboxFactory.createAllMail(userId) }
|
||||
assertEquals(expectedError.left(), result)
|
||||
assertEquals(AttachmentDataError.Other(DataError.Local.NoDataCached).left(), result)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Copyright (c) 2025 Proton Technologies AG
|
||||
* This file is part of Proton Technologies AG and Proton Mail.
|
||||
*
|
||||
* Proton Mail is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Proton Mail is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Proton Mail. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package ch.protonmail.android.mailmessage.domain.model
|
||||
|
||||
import ch.protonmail.android.mailcommon.domain.model.DataError
|
||||
|
||||
sealed interface AttachmentDataError {
|
||||
|
||||
data object ProxyFailed : AttachmentDataError
|
||||
|
||||
data class Other(val dataError: DataError) : AttachmentDataError
|
||||
}
|
||||
+2
-1
@@ -20,6 +20,7 @@ package ch.protonmail.android.mailmessage.domain.repository
|
||||
|
||||
import arrow.core.Either
|
||||
import ch.protonmail.android.mailcommon.domain.model.DataError
|
||||
import ch.protonmail.android.mailmessage.domain.model.AttachmentDataError
|
||||
import ch.protonmail.android.mailmessage.domain.model.MessageBodyImage
|
||||
import ch.protonmail.android.mailmessage.domain.model.MessageBody
|
||||
import ch.protonmail.android.mailmessage.domain.model.MessageBodyTransformations
|
||||
@@ -38,7 +39,7 @@ interface MessageBodyRepository {
|
||||
userId: UserId,
|
||||
messageId: MessageId,
|
||||
url: String
|
||||
): Either<DataError, MessageBodyImage>
|
||||
): Either<AttachmentDataError, MessageBodyImage>
|
||||
|
||||
suspend fun unsubscribeFromNewsletter(userId: UserId, messageId: MessageId): Either<DataError, Unit>
|
||||
}
|
||||
|
||||
+2
-2
@@ -19,7 +19,7 @@
|
||||
package ch.protonmail.android.mailmessage.domain.usecase
|
||||
|
||||
import arrow.core.Either
|
||||
import ch.protonmail.android.mailcommon.domain.model.DataError
|
||||
import ch.protonmail.android.mailmessage.domain.model.AttachmentDataError
|
||||
import ch.protonmail.android.mailmessage.domain.model.MessageBodyImage
|
||||
import ch.protonmail.android.mailmessage.domain.model.MessageId
|
||||
import ch.protonmail.android.mailmessage.domain.repository.MessageBodyRepository
|
||||
@@ -34,6 +34,6 @@ class LoadMessageBodyImage @Inject constructor(
|
||||
userId: UserId,
|
||||
messageId: MessageId,
|
||||
url: String
|
||||
): Either<DataError, MessageBodyImage> = messageBodyRepository.loadImage(userId, messageId, url)
|
||||
): Either<AttachmentDataError, MessageBodyImage> = messageBodyRepository.loadImage(userId, messageId, url)
|
||||
|
||||
}
|
||||
|
||||
+3
-2
@@ -22,6 +22,7 @@ import arrow.core.left
|
||||
import arrow.core.right
|
||||
import ch.protonmail.android.mailcommon.domain.model.DataError
|
||||
import ch.protonmail.android.mailcommon.domain.sample.UserIdSample
|
||||
import ch.protonmail.android.mailmessage.domain.model.AttachmentDataError
|
||||
import ch.protonmail.android.mailmessage.domain.model.MessageBodyImage
|
||||
import ch.protonmail.android.mailmessage.domain.repository.MessageBodyRepository
|
||||
import ch.protonmail.android.mailmessage.domain.sample.MessageIdSample
|
||||
@@ -59,12 +60,12 @@ class LoadMessageBodyImageTest {
|
||||
fun `returns error when loading image fails`() = runTest {
|
||||
// Given
|
||||
coEvery { messageBodyRepository.loadImage(userId, messageId, url) } returns
|
||||
DataError.Local.NoDataCached.left()
|
||||
AttachmentDataError.Other(DataError.Local.NoDataCached).left()
|
||||
|
||||
// When
|
||||
val actual = loadMessageBodyImage(userId, messageId, url)
|
||||
|
||||
// Then
|
||||
assertEquals(DataError.Local.NoDataCached.left(), actual)
|
||||
assertEquals(AttachmentDataError.Other(DataError.Local.NoDataCached).left(), actual)
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -24,8 +24,8 @@ import arrow.core.left
|
||||
import arrow.core.right
|
||||
import ch.protonmail.android.mailattachments.presentation.ExternalAttachmentErrorResult
|
||||
import ch.protonmail.android.mailattachments.presentation.ExternalAttachmentsHandler
|
||||
import ch.protonmail.android.mailcommon.domain.model.DataError
|
||||
import ch.protonmail.android.mailcommon.domain.sample.UserIdSample
|
||||
import ch.protonmail.android.mailmessage.domain.model.AttachmentDataError
|
||||
import ch.protonmail.android.mailmessage.domain.model.MessageBodyImage
|
||||
import ch.protonmail.android.mailmessage.domain.sample.MessageIdSample
|
||||
import ch.protonmail.android.mailmessage.domain.usecase.LoadMessageBodyImage
|
||||
@@ -117,7 +117,7 @@ internal class MessageBodyImageSaverViewModelTest {
|
||||
MessageIdSample.MessageWithAttachments,
|
||||
testImageUrl
|
||||
)
|
||||
} returns mockk<DataError>().left()
|
||||
} returns mockk<AttachmentDataError>().left()
|
||||
|
||||
// When + Then
|
||||
viewModel.saveState.test {
|
||||
|
||||
Reference in New Issue
Block a user