Skip to content

Commit

Permalink
Merge branch 'develop' into feat/mls-addparticipants-federation-v2
Browse files Browse the repository at this point in the history
  • Loading branch information
yamilmedina authored Nov 30, 2023
2 parents ca9fd4b + 2c6d056 commit 7302b9a
Show file tree
Hide file tree
Showing 13 changed files with 162 additions and 380 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ actual interface MessageRepositoryExtensions {
pagingConfig: PagingConfig,
startingOffset: Int
): Flow<PagingData<Message.Standalone>>

suspend fun getPaginatedMessagesSearchBySearchQueryAndConversationId(
searchQuery: String,
conversationId: ConversationId,
pagingConfig: PagingConfig,
startingOffset: Int
): Flow<PagingData<Message.Standalone>>
}

actual class MessageRepositoryExtensionsImpl actual constructor(
Expand All @@ -60,4 +67,22 @@ actual class MessageRepositoryExtensionsImpl actual constructor(
pagingData.map(messageMapper::fromEntityToMessage)
}
}

override suspend fun getPaginatedMessagesSearchBySearchQueryAndConversationId(
searchQuery: String,
conversationId: ConversationId,
pagingConfig: PagingConfig,
startingOffset: Int
): Flow<PagingData<Message.Standalone>> {
val pager: KaliumPager<MessageEntity> = messageDAO.platformExtensions.getPagerForMessagesSearch(
searchQuery = searchQuery,
conversationId = conversationId.toDao(),
pagingConfig = pagingConfig,
startingOffset = startingOffset
)

return pager.pagingDataFlow.map { pagingData: PagingData<MessageEntity> ->
pagingData.map(messageMapper::fromEntityToMessage)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,35 +17,31 @@
*/
package com.wire.kalium.logic.feature.message

import com.wire.kalium.logic.CoreFailure
import androidx.paging.PagingConfig
import androidx.paging.PagingData
import com.wire.kalium.logic.data.id.ConversationId
import com.wire.kalium.logic.data.message.Message
import com.wire.kalium.logic.data.message.MessageRepository
import com.wire.kalium.logic.functional.Either
import com.wire.kalium.util.KaliumDispatcher
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flowOn

/**
* Retrieves a list of messages defined by the search query.
* @param searchQuery The search term used to define which messages will be returned.
* @param conversationId The conversation ID that it will look for messages in.
* @return A [Either<CoreFailure, List<Message.Standalone>>] indicating the success of the operation.
* This use case will observe and return a flow of paginated searched messages for a given conversation.
* @see PagingData
* @see Message
*/
interface GetConversationMessagesFromSearchQueryUseCase {

suspend operator fun invoke(
searchQuery: String,
conversationId: ConversationId
): Either<CoreFailure, List<Message.Standalone>>
}

internal class GetConversationMessagesFromSearchQueryUseCaseImpl internal constructor(
class GetPaginatedFlowOfMessagesBySearchQueryAndConversationIdUseCase internal constructor(
private val dispatcher: KaliumDispatcher,
private val messageRepository: MessageRepository
) : GetConversationMessagesFromSearchQueryUseCase {
) {

override suspend fun invoke(
suspend operator fun invoke(
searchQuery: String,
conversationId: ConversationId
): Either<CoreFailure, List<Message.Standalone>> = messageRepository.getConversationMessagesFromSearch(
searchQuery = searchQuery,
conversationId = conversationId
)
conversationId: ConversationId,
startingOffset: Int,
pagingConfig: PagingConfig
): Flow<PagingData<Message.Standalone>> = messageRepository.extensions.getPaginatedMessagesSearchBySearchQueryAndConversationId(
searchQuery, conversationId, pagingConfig, startingOffset
).flowOn(dispatcher.io)
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,6 @@ package com.wire.kalium.logic.feature.message

val MessageScope.getPaginatedFlowOfMessagesByConversation
get() = GetPaginatedFlowOfMessagesByConversationUseCase(dispatcher, messageRepository)

val MessageScope.getPaginatedFlowOfMessagesBySearchQueryAndConversation
get() = GetPaginatedFlowOfMessagesBySearchQueryAndConversationIdUseCase(dispatcher, messageRepository)
Original file line number Diff line number Diff line change
Expand Up @@ -218,11 +218,6 @@ interface MessageRepository {
targetConversation: ConversationId
): Either<StorageFailure, Unit>

suspend fun getConversationMessagesFromSearch(
searchQuery: String,
conversationId: ConversationId
): Either<CoreFailure, List<Message.Standalone>>

suspend fun getSearchedConversationMessagePosition(
conversationId: ConversationId,
messageId: String
Expand Down Expand Up @@ -646,16 +641,6 @@ class MessageDataSource(
)
}

override suspend fun getConversationMessagesFromSearch(
searchQuery: String,
conversationId: ConversationId
): Either<CoreFailure, List<Message.Standalone>> = wrapStorageRequest {
messageDAO.getConversationMessagesFromSearch(
searchQuery = searchQuery,
conversationId = conversationId.toDao()
).map(messageMapper::fromEntityToMessage)
}

override suspend fun getSearchedConversationMessagePosition(
conversationId: ConversationId,
messageId: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,11 +324,6 @@ class MessageScope internal constructor(
selfConversationIdProvider = selfConversationIdProvider
)

val getConversationMessagesFromSearchQuery: GetConversationMessagesFromSearchQueryUseCase
get() = GetConversationMessagesFromSearchQueryUseCaseImpl(
messageRepository = messageRepository
)

val getSearchedConversationMessagePosition: GetSearchedConversationMessagePositionUseCase
get() = GetSearchedConversationMessagePositionUseCaseImpl(
messageRepository = messageRepository
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -469,58 +469,6 @@ class MessageRepositoryTest {
}
}

@Test
fun givenConversationWithMessages_whenSearchingForSpecificMessages_thenReturnOnlyMetCriteriaMessages() = runTest {
// given
val qualifiedIdEntity = TEST_QUALIFIED_ID_ENTITY
val conversationId = TEST_CONVERSATION_ID
val searchTerm = "message 1"

val messageEntity1 = TEST_MESSAGE_ENTITY.copy(
id = "msg1",
conversationId = qualifiedIdEntity,
content = MessageEntityContent.Text("message 10")
)

val messages = listOf(messageEntity1)

val message1 = TEST_MESSAGE.copy(
id = "msg1",
conversationId = conversationId,
content = MessageContent.Text("message 10")
)

val expectedMessages = listOf(message1)

val (_, messageRepository) = Arrangement()
.withMessagesFromSearch(
searchTerm = searchTerm,
conversationId = qualifiedIdEntity,
messages = messages
)
.withMappedMessageModel(
result = message1,
param = messageEntity1
)
.arrange()

// when
val result = messageRepository.getConversationMessagesFromSearch(
searchQuery = searchTerm,
conversationId = conversationId
)

// then
assertEquals(
expectedMessages.size,
(result as Either.Right).value.size
)
assertEquals(
expectedMessages.first().id,
(result as Either.Right).value.first().id
)
}

@Test
fun givenSearchedMessages_whenMessageIsSelected_thenReturnMessagePosition() = runTest {
// given
Expand Down Expand Up @@ -694,17 +642,6 @@ class MessageRepositoryTest {
.thenThrow(throwable)
}

fun withMessagesFromSearch(
searchTerm: String,
conversationId: QualifiedIDEntity,
messages: List<MessageEntity>
) = apply {
given(messageDAO)
.suspendFunction(messageDAO::getConversationMessagesFromSearch)
.whenInvokedWith(eq(searchTerm), eq(conversationId))
.thenReturn(messages)
}

fun withSelectedMessagePosition(
conversationId: QualifiedIDEntity,
messageId: String,
Expand Down

This file was deleted.

Loading

0 comments on commit 7302b9a

Please sign in to comment.