mirror of
https://github.com/ProtonMail/android-mail.git
synced 2026-06-14 09:54:47 +00:00
Remove deprecated observe message method
ET-6108
This commit is contained in:
+5
-11
@@ -43,7 +43,6 @@ import ch.protonmail.android.mailmessage.domain.repository.MessageRepository
|
||||
import ch.protonmail.android.mailpagination.domain.model.PageKey
|
||||
import ch.protonmail.android.mailpagination.domain.model.PaginationError
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.flow
|
||||
import kotlinx.coroutines.flow.flowOf
|
||||
import kotlinx.coroutines.flow.map
|
||||
import me.proton.core.domain.entity.UserId
|
||||
@@ -93,17 +92,12 @@ class RustMessageRepositoryImpl @Inject constructor(
|
||||
rustMessageDataSource.observeMessage(userId, messageId.toLocalMessageId())
|
||||
.map { either -> either.map { it.toMessage() } }
|
||||
|
||||
@Deprecated(
|
||||
message = "Observing is faked! This won't reflect changes to the message after the first emission",
|
||||
replaceWith = ReplaceWith("getMessage(userId, messageId)")
|
||||
)
|
||||
override fun observeMessage(userId: UserId, remoteMessageId: RemoteMessageId): Flow<Either<DataError, Message>> =
|
||||
flow {
|
||||
val message = rustMessageDataSource.getMessage(userId, remoteMessageId.toRemoteMessageId())
|
||||
.map { it.toMessage() }
|
||||
override suspend fun getMessageByRemoteId(
|
||||
userId: UserId,
|
||||
remoteMessageId: RemoteMessageId
|
||||
): Either<DataError, Message> = rustMessageDataSource.getMessage(userId, remoteMessageId.toRemoteMessageId())
|
||||
.map { it.toMessage() }
|
||||
|
||||
emit(message)
|
||||
}
|
||||
|
||||
override suspend fun getConversationCursor(
|
||||
anchorItemId: CursorId,
|
||||
|
||||
+10
-17
@@ -126,15 +126,11 @@ internal class RustMessageRepositoryImplTest {
|
||||
} returns LocalMessageTestData.AugWeatherForecast.right()
|
||||
|
||||
// When
|
||||
repository.observeMessage(userId, messageId.toRemoteMessageId()).test {
|
||||
val result = awaitItem().getOrElse { null }
|
||||
val result = repository.getMessageByRemoteId(userId, messageId.toRemoteMessageId()).getOrElse { null }
|
||||
|
||||
// Then
|
||||
assertEquals(expectedMessage, result)
|
||||
coVerify { rustMessageDataSource.getMessage(userId, messageId) }
|
||||
|
||||
awaitComplete()
|
||||
}
|
||||
// Then
|
||||
assertEquals(expectedMessage, result)
|
||||
coVerify { rustMessageDataSource.getMessage(userId, messageId) }
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -167,19 +163,16 @@ internal class RustMessageRepositoryImplTest {
|
||||
DataError.Local.NoDataCached.left()
|
||||
|
||||
// When
|
||||
repository.observeMessage(userId, messageId).test {
|
||||
val result = awaitItem()
|
||||
val result = repository.getMessageByRemoteId(userId, messageId)
|
||||
|
||||
// Then
|
||||
coVerify { rustMessageDataSource.getMessage(userId, messageId.toRemoteMessageId()) }
|
||||
assert(result.isLeft())
|
||||
assertEquals(DataError.Local.NoDataCached, result.swap().getOrElse { null })
|
||||
awaitComplete()
|
||||
}
|
||||
// Then
|
||||
coVerify { rustMessageDataSource.getMessage(userId, messageId.toRemoteMessageId()) }
|
||||
assert(result.isLeft())
|
||||
assertEquals(DataError.Local.NoDataCached, result.swap().getOrElse { null })
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `when getConversationCursor returns a cursor with the first messsageId`() = runTest {
|
||||
fun `when getConversationCursor returns a cursor with the first messageId`() = runTest {
|
||||
// Given
|
||||
val conversationCursor = mockk<ConversationCursor> {
|
||||
every { current } returns CursorResult.Cursor(ConversationId("100"))
|
||||
|
||||
+1
-1
@@ -76,7 +76,7 @@ interface MessageRepository {
|
||||
* Gets a [Message] metadata for [userId] from the local storage from a [RemoteMessageId].
|
||||
* @return either the [Message] or a [DataError.Local]
|
||||
*/
|
||||
fun observeMessage(userId: UserId, remoteMessageId: RemoteMessageId): Flow<Either<DataError, Message>>
|
||||
suspend fun getMessageByRemoteId(userId: UserId, remoteMessageId: RemoteMessageId): Either<DataError, Message>
|
||||
|
||||
/**
|
||||
* Used to JIT swipe through conversations/ pages with methods exposed to get next and get previous and move to next
|
||||
|
||||
+1
-2
@@ -23,7 +23,6 @@ import ch.protonmail.android.mailcommon.domain.model.DataError
|
||||
import ch.protonmail.android.mailmessage.domain.model.Message
|
||||
import ch.protonmail.android.mailmessage.domain.model.RemoteMessageId
|
||||
import ch.protonmail.android.mailmessage.domain.repository.MessageRepository
|
||||
import kotlinx.coroutines.flow.first
|
||||
import me.proton.core.domain.entity.UserId
|
||||
import timber.log.Timber
|
||||
import javax.inject.Inject
|
||||
@@ -53,7 +52,7 @@ class GetMessageByRemoteId @Inject constructor(
|
||||
}
|
||||
|
||||
private suspend fun getByRemoteId(userId: UserId, messageId: RemoteMessageId): Either<DataError, Message> =
|
||||
messageRepository.observeMessage(userId, messageId).first()
|
||||
messageRepository.getMessageByRemoteId(userId, messageId)
|
||||
}
|
||||
|
||||
private const val MAX_RETRY_ATTEMPTS = 3
|
||||
|
||||
+3
-4
@@ -28,7 +28,6 @@ import ch.protonmail.android.testdata.message.rust.RemoteMessageIdSample
|
||||
import io.mockk.coEvery
|
||||
import io.mockk.coVerify
|
||||
import io.mockk.mockk
|
||||
import kotlinx.coroutines.flow.flowOf
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import org.junit.Test
|
||||
import kotlin.test.assertEquals
|
||||
@@ -45,7 +44,7 @@ class GetMessageByRemoteIdTest {
|
||||
val userId = UserIdSample.Primary
|
||||
val message = MessageSample.SepWeatherForecast
|
||||
val remoteId = RemoteMessageIdSample.SepWeatherForecast
|
||||
coEvery { repository.observeMessage(userId, remoteId) } returns flowOf(message.right())
|
||||
coEvery { repository.getMessageByRemoteId(userId, remoteId) } returns message.right()
|
||||
|
||||
// When
|
||||
val actual = getMessage(userId, remoteId)
|
||||
@@ -60,14 +59,14 @@ class GetMessageByRemoteIdTest {
|
||||
val userId = UserIdSample.Primary
|
||||
val error = DataError.Local.NoDataCached
|
||||
val remoteId = RemoteMessageIdSample.SepWeatherForecast
|
||||
coEvery { repository.observeMessage(userId, remoteId) } returns flowOf(error.left())
|
||||
coEvery { repository.getMessageByRemoteId(userId, remoteId) } returns error.left()
|
||||
|
||||
// When
|
||||
val actual = getMessage(userId, remoteId)
|
||||
|
||||
// Then
|
||||
assertEquals(error.left(), actual)
|
||||
coVerify(exactly = 3) { repository.observeMessage(userId, remoteId) }
|
||||
coVerify(exactly = 3) { repository.getMessageByRemoteId(userId, remoteId) }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+3
-4
@@ -28,7 +28,6 @@ import ch.protonmail.android.mailmessage.domain.repository.MessageRepository
|
||||
import ch.protonmail.android.testdata.message.MessageTestData
|
||||
import ch.protonmail.android.testdata.user.UserIdTestData.userId
|
||||
import io.mockk.coEvery
|
||||
import io.mockk.every
|
||||
import io.mockk.mockk
|
||||
import kotlinx.coroutines.flow.flowOf
|
||||
import kotlinx.coroutines.test.runTest
|
||||
@@ -38,9 +37,9 @@ import kotlin.test.assertEquals
|
||||
internal class ObserveMessageTest {
|
||||
|
||||
private val repository = mockk<MessageRepository> {
|
||||
every {
|
||||
this@mockk.observeMessage(userId, any<RemoteMessageId>())
|
||||
} returns flowOf(DataError.Local.NoDataCached.left())
|
||||
coEvery {
|
||||
this@mockk.getMessageByRemoteId(userId, any<RemoteMessageId>())
|
||||
} returns DataError.Local.NoDataCached.left()
|
||||
|
||||
coEvery {
|
||||
this@mockk.observeMessage(userId, any<MessageId>())
|
||||
|
||||
Reference in New Issue
Block a user