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 8d3237b3ba
commit 1e30574d44
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(),