@@ -101,6 +101,7 @@ import kotlinx.coroutines.flow.map
101
101
import kotlinx.coroutines.flow.onEach
102
102
import org.matrix.android.sdk.api.session.Session
103
103
import org.matrix.android.sdk.api.session.content.ContentAttachmentData
104
+ import org.matrix.android.sdk.api.session.permalinks.PermalinkService
104
105
import org.matrix.android.sdk.api.util.MatrixItem
105
106
import reactivecircus.flowbinding.android.view.focusChanges
106
107
import reactivecircus.flowbinding.android.widget.textChanges
@@ -123,6 +124,9 @@ class MessageComposerFragment : VectorBaseFragment<FragmentComposerBinding>(), A
123
124
@Inject lateinit var session: Session
124
125
@Inject lateinit var errorTracker: ErrorTracker
125
126
127
+ private val permalinkService: PermalinkService
128
+ get() = session.permalinkService()
129
+
126
130
private val roomId: String get() = withState(timelineViewModel) { it.roomId }
127
131
128
132
private val autoCompleters: MutableMap <EditText , AutoCompleter > = hashMapOf()
@@ -792,30 +796,37 @@ class MessageComposerFragment : VectorBaseFragment<FragmentComposerBinding>(), A
792
796
} else {
793
797
val roomMember = timelineViewModel.getMember(userId)
794
798
val displayName = sanitizeDisplayName(roomMember?.displayName ? : userId)
795
- val pill = buildSpannedString {
796
- append(displayName)
797
- setSpan(
798
- PillImageSpan (
799
- glideRequests,
800
- avatarRenderer,
801
- requireContext(),
802
- MatrixItem .UserItem (userId, displayName, roomMember?.avatarUrl)
803
- )
804
- .also { it.bind(composer.editText) },
805
- 0 ,
806
- displayName.length,
807
- Spannable .SPAN_EXCLUSIVE_EXCLUSIVE
808
- )
809
- append(if (startToCompose) " : " else " " )
810
- }
811
- if (startToCompose && displayName.startsWith(" /" )) {
812
- // Ensure displayName will not be interpreted as a Slash command
813
- composer.editText.append(" \\ " )
799
+ if ((composer as ? RichTextComposerLayout )?.isTextFormattingEnabled == true ) {
800
+ // Rich text editor is enabled so we need to use its APIs
801
+ permalinkService.createPermalink(userId)?.let { url ->
802
+ (composer as RichTextComposerLayout ).insertMention(url, displayName)
803
+ }
804
+ } else {
805
+ val pill = buildSpannedString {
806
+ append(displayName)
807
+ setSpan(
808
+ PillImageSpan (
809
+ glideRequests,
810
+ avatarRenderer,
811
+ requireContext(),
812
+ MatrixItem .UserItem (userId, displayName, roomMember?.avatarUrl),
813
+ )
814
+ .also { it.bind(composer.editText) },
815
+ 0 ,
816
+ displayName.length,
817
+ Spannable .SPAN_EXCLUSIVE_EXCLUSIVE
818
+ )
819
+ append(if (startToCompose) " : " else " " )
820
+ }
821
+ if (startToCompose && displayName.startsWith(" /" )) {
822
+ // Ensure displayName will not be interpreted as a Slash command
823
+ composer.editText.append(" \\ " )
824
+ }
825
+ // Always use EditText.getText().insert for adding pills as TextView.append doesn't appear
826
+ // to upgrade to BufferType.Spannable as hinted at in the docs:
827
+ // https://developer.android.com/reference/android/widget/TextView#append(java.lang.CharSequence)
828
+ composer.editText.text.insert(composer.editText.selectionStart, pill)
814
829
}
815
- // Always use EditText.getText().insert for adding pills as TextView.append doesn't appear
816
- // to upgrade to BufferType.Spannable as hinted at in the docs:
817
- // https://developer.android.com/reference/android/widget/TextView#append(java.lang.CharSequence)
818
- composer.editText.text.insert(composer.editText.selectionStart, pill)
819
830
}
820
831
focusComposerAndShowKeyboard()
821
832
}
0 commit comments