Convert MentionSuggestionsProcessor to a class and inject it in the constructor of MessageComposerPresenter

This commit is contained in:
Benoit Marty 2024-08-21 17:41:10 +02:00
parent 6309137a53
commit 5df3e6d684
4 changed files with 13 additions and 5 deletions

View file

@ -26,14 +26,12 @@ import io.element.android.libraries.matrix.api.room.roomMembers
import io.element.android.libraries.textcomposer.mentions.ResolvedSuggestion
import io.element.android.libraries.textcomposer.model.Suggestion
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.
*/
object MentionSuggestionsProcessor {
// We don't want to retrieve thousands of members
private const val MAX_BATCH_ITEMS = 100
class MentionSuggestionsProcessor @Inject constructor() {
/**
* Process the mention suggestions.
* @param suggestion The current suggestion input
@ -114,4 +112,9 @@ object MentionSuggestionsProcessor {
}
}
}
companion object {
// We don't want to retrieve thousands of members
private const val MAX_BATCH_ITEMS = 100
}
}

View file

@ -126,6 +126,7 @@ class MessageComposerPresenter @Inject constructor(
private val mentionSpanProvider: MentionSpanProvider,
private val pillificationHelper: TextPillificationHelper,
private val roomMemberProfilesCache: RoomMemberProfilesCache,
private val mentionSuggestionsProcessor: MentionSuggestionsProcessor,
) : Presenter<MessageComposerState> {
private val cameraPermissionPresenter = permissionsPresenterFactory.create(Manifest.permission.CAMERA)
private var pendingEvent: MessageComposerEvents? = null
@ -234,7 +235,7 @@ class MessageComposerPresenter @Inject constructor(
merge(mentionStartTrigger, mentionCompletionTrigger)
.combine(room.membersStateFlow) { suggestion, roomMembersState ->
suggestions.clear()
val result = MentionSuggestionsProcessor.process(
val result = mentionSuggestionsProcessor.process(
suggestion = suggestion,
roomMembersState = roomMembersState,
roomAliasSuggestions = if (isRoomAliasSuggestionsEnabled) roomAliasSuggestions else emptyList(),

View file

@ -28,6 +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.messagecomposer.DefaultMessageComposerContext
import io.element.android.features.messages.impl.messagecomposer.FakeRoomAliasSuggestionsDataSource
import io.element.android.features.messages.impl.messagecomposer.MessageComposerPresenter
@ -1018,6 +1019,7 @@ class MessagesPresenterTest {
mentionSpanProvider = mentionSpanProvider,
pillificationHelper = FakeTextPillificationHelper(),
roomMemberProfilesCache = RoomMemberProfilesCache(),
mentionSuggestionsProcessor = MentionSuggestionsProcessor(),
).apply {
showTextFormatting = true
isTesting = true

View file

@ -29,6 +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.timeline.TimelineController
import io.element.android.features.messages.impl.utils.FakeTextPillificationHelper
import io.element.android.features.messages.impl.utils.TextPillificationHelper
@ -1510,6 +1511,7 @@ class MessageComposerPresenterTest {
mentionSpanProvider = mentionSpanProvider,
pillificationHelper = textPillificationHelper,
roomMemberProfilesCache = roomMemberProfilesCache,
mentionSuggestionsProcessor = MentionSuggestionsProcessor(),
).apply {
isTesting = true
showTextFormatting = isRichTextEditorEnabled