Rename MentionSuggestionsProcessor to SuggestionsProcessor since it's not only used for mentions.

This commit is contained in:
Benoit Marty
2024-08-22 13:24:57 +02:00
parent ef015904ff
commit ccb3aef6a5
5 changed files with 29 additions and 29 deletions

View File

@@ -29,17 +29,17 @@ import io.element.android.libraries.textcomposer.model.SuggestionType
import javax.inject.Inject
/**
* This class is responsible for processing mention suggestions when `@`, `/` or `#` are type in the composer.
* This class is responsible for processing suggestions when `@`, `/` or `#` are type in the composer.
*/
class MentionSuggestionsProcessor @Inject constructor() {
class SuggestionsProcessor @Inject constructor() {
/**
* Process the mention suggestions.
* Process the suggestion.
* @param suggestion The current suggestion input
* @param roomMembersState The room members state, it contains the current users in the room
* @param roomAliasSuggestions The available room alias suggestions
* @param currentUserId The current user id
* @param canSendRoomMention Should return true if the current user can send room mentions
* @return The list of mentions to display
* @return The list of suggestions to display
*/
suspend fun process(
suggestion: Suggestion?,

View File

@@ -40,7 +40,7 @@ import im.vector.app.features.analytics.plan.Interaction
import io.element.android.features.messages.impl.attachments.Attachment
import io.element.android.features.messages.impl.attachments.preview.error.sendAttachmentError
import io.element.android.features.messages.impl.draft.ComposerDraftService
import io.element.android.features.messages.impl.mentions.MentionSuggestionsProcessor
import io.element.android.features.messages.impl.mentions.SuggestionsProcessor
import io.element.android.features.messages.impl.timeline.TimelineController
import io.element.android.features.messages.impl.utils.TextPillificationHelper
import io.element.android.libraries.architecture.Presenter
@@ -126,7 +126,7 @@ class MessageComposerPresenter @Inject constructor(
private val mentionSpanProvider: MentionSpanProvider,
private val pillificationHelper: TextPillificationHelper,
private val roomMemberProfilesCache: RoomMemberProfilesCache,
private val mentionSuggestionsProcessor: MentionSuggestionsProcessor,
private val suggestionsProcessor: SuggestionsProcessor,
) : Presenter<MessageComposerState> {
private val cameraPermissionPresenter = permissionsPresenterFactory.create(Manifest.permission.CAMERA)
private var pendingEvent: MessageComposerEvents? = null
@@ -235,7 +235,7 @@ class MessageComposerPresenter @Inject constructor(
merge(mentionStartTrigger, mentionCompletionTrigger)
.combine(room.membersStateFlow) { suggestion, roomMembersState ->
suggestions.clear()
val result = mentionSuggestionsProcessor.process(
val result = suggestionsProcessor.process(
suggestion = suggestion,
roomMembersState = roomMembersState,
roomAliasSuggestions = if (isRoomAliasSuggestionsEnabled) roomAliasSuggestions else emptyList(),

View File

@@ -28,7 +28,7 @@ import io.element.android.features.messages.impl.actionlist.model.TimelineItemAc
import io.element.android.features.messages.impl.draft.FakeComposerDraftService
import io.element.android.features.messages.impl.fixtures.aMessageEvent
import io.element.android.features.messages.impl.fixtures.aTimelineItemsFactory
import io.element.android.features.messages.impl.mentions.MentionSuggestionsProcessor
import io.element.android.features.messages.impl.mentions.SuggestionsProcessor
import io.element.android.features.messages.impl.messagecomposer.DefaultMessageComposerContext
import io.element.android.features.messages.impl.messagecomposer.FakeRoomAliasSuggestionsDataSource
import io.element.android.features.messages.impl.messagecomposer.MessageComposerPresenter
@@ -1019,7 +1019,7 @@ class MessagesPresenterTest {
mentionSpanProvider = mentionSpanProvider,
pillificationHelper = FakeTextPillificationHelper(),
roomMemberProfilesCache = RoomMemberProfilesCache(),
mentionSuggestionsProcessor = MentionSuggestionsProcessor(),
suggestionsProcessor = SuggestionsProcessor(),
).apply {
showTextFormatting = true
isTesting = true

View File

@@ -33,17 +33,17 @@ import kotlinx.collections.immutable.persistentListOf
import kotlinx.coroutines.test.runTest
import org.junit.Test
class MentionSuggestionsProcessorTest {
class SuggestionsProcessorTest {
private fun aMentionSuggestion(text: String) = Suggestion(0, 1, SuggestionType.Mention, text)
private fun aRoomSuggestion(text: String) = Suggestion(0, 1, SuggestionType.Room, text)
private val aCommandSuggestion = Suggestion(0, 1, SuggestionType.Command, "")
private val aCustomSuggestion = Suggestion(0, 1, SuggestionType.Custom("*"), "")
private val mentionSuggestionsProcessor = MentionSuggestionsProcessor()
private val suggestionsProcessor = SuggestionsProcessor()
@Test
fun `processing null suggestion will return empty suggestion`() = runTest {
val result = mentionSuggestionsProcessor.process(
val result = suggestionsProcessor.process(
suggestion = null,
roomMembersState = MatrixRoomMembersState.Ready(persistentListOf(aRoomMember())),
roomAliasSuggestions = emptyList(),
@@ -55,7 +55,7 @@ class MentionSuggestionsProcessorTest {
@Test
fun `processing Command will return empty suggestion`() = runTest {
val result = mentionSuggestionsProcessor.process(
val result = suggestionsProcessor.process(
suggestion = aCommandSuggestion,
roomMembersState = MatrixRoomMembersState.Ready(persistentListOf(aRoomMember())),
roomAliasSuggestions = emptyList(),
@@ -67,7 +67,7 @@ class MentionSuggestionsProcessorTest {
@Test
fun `processing Custom will return empty suggestion`() = runTest {
val result = mentionSuggestionsProcessor.process(
val result = suggestionsProcessor.process(
suggestion = aCustomSuggestion,
roomMembersState = MatrixRoomMembersState.Ready(persistentListOf(aRoomMember())),
roomAliasSuggestions = emptyList(),
@@ -79,7 +79,7 @@ class MentionSuggestionsProcessorTest {
@Test
fun `processing Mention suggestion with not loaded members will return empty suggestion`() = runTest {
val result = mentionSuggestionsProcessor.process(
val result = suggestionsProcessor.process(
suggestion = aMentionSuggestion(""),
roomMembersState = MatrixRoomMembersState.Unknown,
roomAliasSuggestions = emptyList(),
@@ -91,7 +91,7 @@ class MentionSuggestionsProcessorTest {
@Test
fun `processing Mention suggestion with no members will return empty suggestion`() = runTest {
val result = mentionSuggestionsProcessor.process(
val result = suggestionsProcessor.process(
suggestion = aMentionSuggestion(""),
roomMembersState = MatrixRoomMembersState.Ready(persistentListOf()),
roomAliasSuggestions = emptyList(),
@@ -103,7 +103,7 @@ class MentionSuggestionsProcessorTest {
@Test
fun `processing Room suggestion with no aliases will return empty suggestion`() = runTest {
val result = mentionSuggestionsProcessor.process(
val result = suggestionsProcessor.process(
suggestion = aRoomSuggestion(""),
roomMembersState = MatrixRoomMembersState.Ready(persistentListOf()),
roomAliasSuggestions = emptyList(),
@@ -116,7 +116,7 @@ class MentionSuggestionsProcessorTest {
@Test
fun `processing Room suggestion with aliases ignoring cases will return a suggestion`() = runTest {
val aRoomSummary = aRoomSummary(canonicalAlias = A_ROOM_ALIAS)
val result = mentionSuggestionsProcessor.process(
val result = suggestionsProcessor.process(
suggestion = aRoomSuggestion("ALI"),
roomMembersState = MatrixRoomMembersState.Ready(persistentListOf()),
roomAliasSuggestions = listOf(RoomAliasSuggestion(A_ROOM_ALIAS, aRoomSummary)),
@@ -133,7 +133,7 @@ class MentionSuggestionsProcessorTest {
@Test
fun `processing Room suggestion with aliases will return a suggestion`() = runTest {
val aRoomSummary = aRoomSummary(canonicalAlias = A_ROOM_ALIAS)
val result = mentionSuggestionsProcessor.process(
val result = suggestionsProcessor.process(
suggestion = aRoomSuggestion("ali"),
roomMembersState = MatrixRoomMembersState.Ready(persistentListOf()),
roomAliasSuggestions = listOf(RoomAliasSuggestion(A_ROOM_ALIAS, aRoomSummary)),
@@ -150,7 +150,7 @@ class MentionSuggestionsProcessorTest {
@Test
fun `processing Room suggestion with aliases not found will return no suggestions`() = runTest {
val aRoomSummary = aRoomSummary(canonicalAlias = A_ROOM_ALIAS)
val result = mentionSuggestionsProcessor.process(
val result = suggestionsProcessor.process(
suggestion = aRoomSuggestion("tot"),
roomMembersState = MatrixRoomMembersState.Ready(persistentListOf()),
roomAliasSuggestions = listOf(RoomAliasSuggestion(A_ROOM_ALIAS, aRoomSummary)),
@@ -163,7 +163,7 @@ class MentionSuggestionsProcessorTest {
@Test
fun `processing Mention suggestion with return matching matrix Id`() = runTest {
val aRoomMember = aRoomMember(userId = UserId("@alice:server.org"), displayName = null)
val result = mentionSuggestionsProcessor.process(
val result = suggestionsProcessor.process(
suggestion = aMentionSuggestion("ali"),
roomMembersState = MatrixRoomMembersState.Ready(persistentListOf(aRoomMember)),
roomAliasSuggestions = emptyList(),
@@ -180,7 +180,7 @@ class MentionSuggestionsProcessorTest {
@Test
fun `processing Mention suggestion with not return the current user`() = runTest {
val aRoomMember = aRoomMember(userId = UserId("@alice:server.org"), displayName = null)
val result = mentionSuggestionsProcessor.process(
val result = suggestionsProcessor.process(
suggestion = aMentionSuggestion("ali"),
roomMembersState = MatrixRoomMembersState.Ready(persistentListOf(aRoomMember)),
roomAliasSuggestions = emptyList(),
@@ -193,7 +193,7 @@ class MentionSuggestionsProcessorTest {
@Test
fun `processing Mention suggestion with return empty list if there is no matches`() = runTest {
val aRoomMember = aRoomMember(userId = UserId("@alice:server.org"), displayName = "alice")
val result = mentionSuggestionsProcessor.process(
val result = suggestionsProcessor.process(
suggestion = aMentionSuggestion("bo"),
roomMembersState = MatrixRoomMembersState.Ready(persistentListOf(aRoomMember)),
roomAliasSuggestions = emptyList(),
@@ -206,7 +206,7 @@ class MentionSuggestionsProcessorTest {
@Test
fun `processing Mention suggestion with not return not joined member`() = runTest {
val aRoomMember = aRoomMember(userId = UserId("@alice:server.org"), membership = RoomMembershipState.INVITE)
val result = mentionSuggestionsProcessor.process(
val result = suggestionsProcessor.process(
suggestion = aMentionSuggestion("ali"),
roomMembersState = MatrixRoomMembersState.Ready(persistentListOf(aRoomMember)),
roomAliasSuggestions = emptyList(),
@@ -219,7 +219,7 @@ class MentionSuggestionsProcessorTest {
@Test
fun `processing Mention suggestion with return matching display name`() = runTest {
val aRoomMember = aRoomMember(userId = UserId("@alice:server.org"), displayName = "bob")
val result = mentionSuggestionsProcessor.process(
val result = suggestionsProcessor.process(
suggestion = aMentionSuggestion("bo"),
roomMembersState = MatrixRoomMembersState.Ready(persistentListOf(aRoomMember)),
roomAliasSuggestions = emptyList(),
@@ -236,7 +236,7 @@ class MentionSuggestionsProcessorTest {
@Test
fun `processing Mention suggestion with return matching display name and room if allowed`() = runTest {
val aRoomMember = aRoomMember(userId = UserId("@alice:server.org"), displayName = "ro")
val result = mentionSuggestionsProcessor.process(
val result = suggestionsProcessor.process(
suggestion = aMentionSuggestion("ro"),
roomMembersState = MatrixRoomMembersState.Ready(persistentListOf(aRoomMember)),
roomAliasSuggestions = emptyList(),
@@ -254,7 +254,7 @@ class MentionSuggestionsProcessorTest {
@Test
fun `processing Mention suggestion with return matching display name but not room if not allowed`() = runTest {
val aRoomMember = aRoomMember(userId = UserId("@alice:server.org"), displayName = "ro")
val result = mentionSuggestionsProcessor.process(
val result = suggestionsProcessor.process(
suggestion = aMentionSuggestion("ro"),
roomMembersState = MatrixRoomMembersState.Ready(persistentListOf(aRoomMember)),
roomAliasSuggestions = emptyList(),

View File

@@ -29,7 +29,7 @@ import im.vector.app.features.analytics.plan.Composer
import im.vector.app.features.analytics.plan.Interaction
import io.element.android.features.messages.impl.draft.ComposerDraftService
import io.element.android.features.messages.impl.draft.FakeComposerDraftService
import io.element.android.features.messages.impl.mentions.MentionSuggestionsProcessor
import io.element.android.features.messages.impl.mentions.SuggestionsProcessor
import io.element.android.features.messages.impl.timeline.TimelineController
import io.element.android.features.messages.impl.utils.FakeTextPillificationHelper
import io.element.android.features.messages.impl.utils.TextPillificationHelper
@@ -1511,7 +1511,7 @@ class MessageComposerPresenterTest {
mentionSpanProvider = mentionSpanProvider,
pillificationHelper = textPillificationHelper,
roomMemberProfilesCache = roomMemberProfilesCache,
mentionSuggestionsProcessor = MentionSuggestionsProcessor(),
suggestionsProcessor = SuggestionsProcessor(),
).apply {
isTesting = true
showTextFormatting = isRichTextEditorEnabled