Convert MentionSuggestionsProcessor to a class and inject it in the constructor of MessageComposerPresenter
This commit is contained in:
parent
8d3237b3ba
commit
1e30574d44
4 changed files with 13 additions and 5 deletions
|
|
@ -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.mentions.ResolvedSuggestion
|
||||||
import io.element.android.libraries.textcomposer.model.Suggestion
|
import io.element.android.libraries.textcomposer.model.Suggestion
|
||||||
import io.element.android.libraries.textcomposer.model.SuggestionType
|
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 mention suggestions when `@`, `/` or `#` are type in the composer.
|
||||||
*/
|
*/
|
||||||
object MentionSuggestionsProcessor {
|
class MentionSuggestionsProcessor @Inject constructor() {
|
||||||
// We don't want to retrieve thousands of members
|
|
||||||
private const val MAX_BATCH_ITEMS = 100
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Process the mention suggestions.
|
* Process the mention suggestions.
|
||||||
* @param suggestion The current suggestion input
|
* @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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -126,6 +126,7 @@ class MessageComposerPresenter @Inject constructor(
|
||||||
private val mentionSpanProvider: MentionSpanProvider,
|
private val mentionSpanProvider: MentionSpanProvider,
|
||||||
private val pillificationHelper: TextPillificationHelper,
|
private val pillificationHelper: TextPillificationHelper,
|
||||||
private val roomMemberProfilesCache: RoomMemberProfilesCache,
|
private val roomMemberProfilesCache: RoomMemberProfilesCache,
|
||||||
|
private val mentionSuggestionsProcessor: MentionSuggestionsProcessor,
|
||||||
) : Presenter<MessageComposerState> {
|
) : Presenter<MessageComposerState> {
|
||||||
private val cameraPermissionPresenter = permissionsPresenterFactory.create(Manifest.permission.CAMERA)
|
private val cameraPermissionPresenter = permissionsPresenterFactory.create(Manifest.permission.CAMERA)
|
||||||
private var pendingEvent: MessageComposerEvents? = null
|
private var pendingEvent: MessageComposerEvents? = null
|
||||||
|
|
@ -234,7 +235,7 @@ class MessageComposerPresenter @Inject constructor(
|
||||||
merge(mentionStartTrigger, mentionCompletionTrigger)
|
merge(mentionStartTrigger, mentionCompletionTrigger)
|
||||||
.combine(room.membersStateFlow) { suggestion, roomMembersState ->
|
.combine(room.membersStateFlow) { suggestion, roomMembersState ->
|
||||||
suggestions.clear()
|
suggestions.clear()
|
||||||
val result = MentionSuggestionsProcessor.process(
|
val result = mentionSuggestionsProcessor.process(
|
||||||
suggestion = suggestion,
|
suggestion = suggestion,
|
||||||
roomMembersState = roomMembersState,
|
roomMembersState = roomMembersState,
|
||||||
roomAliasSuggestions = if (isRoomAliasSuggestionsEnabled) roomAliasSuggestions else emptyList(),
|
roomAliasSuggestions = if (isRoomAliasSuggestionsEnabled) roomAliasSuggestions else emptyList(),
|
||||||
|
|
|
||||||
|
|
@ -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.draft.FakeComposerDraftService
|
||||||
import io.element.android.features.messages.impl.fixtures.aMessageEvent
|
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.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.DefaultMessageComposerContext
|
||||||
import io.element.android.features.messages.impl.messagecomposer.FakeRoomAliasSuggestionsDataSource
|
import io.element.android.features.messages.impl.messagecomposer.FakeRoomAliasSuggestionsDataSource
|
||||||
import io.element.android.features.messages.impl.messagecomposer.MessageComposerPresenter
|
import io.element.android.features.messages.impl.messagecomposer.MessageComposerPresenter
|
||||||
|
|
@ -1018,6 +1019,7 @@ class MessagesPresenterTest {
|
||||||
mentionSpanProvider = mentionSpanProvider,
|
mentionSpanProvider = mentionSpanProvider,
|
||||||
pillificationHelper = FakeTextPillificationHelper(),
|
pillificationHelper = FakeTextPillificationHelper(),
|
||||||
roomMemberProfilesCache = RoomMemberProfilesCache(),
|
roomMemberProfilesCache = RoomMemberProfilesCache(),
|
||||||
|
mentionSuggestionsProcessor = MentionSuggestionsProcessor(),
|
||||||
).apply {
|
).apply {
|
||||||
showTextFormatting = true
|
showTextFormatting = true
|
||||||
isTesting = true
|
isTesting = true
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,7 @@ import im.vector.app.features.analytics.plan.Composer
|
||||||
import im.vector.app.features.analytics.plan.Interaction
|
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.ComposerDraftService
|
||||||
import io.element.android.features.messages.impl.draft.FakeComposerDraftService
|
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.timeline.TimelineController
|
||||||
import io.element.android.features.messages.impl.utils.FakeTextPillificationHelper
|
import io.element.android.features.messages.impl.utils.FakeTextPillificationHelper
|
||||||
import io.element.android.features.messages.impl.utils.TextPillificationHelper
|
import io.element.android.features.messages.impl.utils.TextPillificationHelper
|
||||||
|
|
@ -1510,6 +1511,7 @@ class MessageComposerPresenterTest {
|
||||||
mentionSpanProvider = mentionSpanProvider,
|
mentionSpanProvider = mentionSpanProvider,
|
||||||
pillificationHelper = textPillificationHelper,
|
pillificationHelper = textPillificationHelper,
|
||||||
roomMemberProfilesCache = roomMemberProfilesCache,
|
roomMemberProfilesCache = roomMemberProfilesCache,
|
||||||
|
mentionSuggestionsProcessor = MentionSuggestionsProcessor(),
|
||||||
).apply {
|
).apply {
|
||||||
isTesting = true
|
isTesting = true
|
||||||
showTextFormatting = isRichTextEditorEnabled
|
showTextFormatting = isRichTextEditorEnabled
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue