Fix @room mentions crashing in debug builds (#3107)
* Fix `@room` mentions crashing in debug builds * Iterate on previous solution, add `MentionSpan.Type.EVERYONE`
This commit is contained in:
parent
bef0d85415
commit
a95d610464
5 changed files with 17 additions and 15 deletions
|
|
@ -94,8 +94,10 @@ private fun updateMentionSpans(text: CharSequence?, cache: RoomMemberProfilesCac
|
||||||
mentionSpan.text = displayName
|
mentionSpan.text = displayName
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// There's no need to do anything for `@room` pills
|
||||||
|
MentionSpan.Type.EVERYONE -> Unit
|
||||||
// Nothing yet for room mentions
|
// Nothing yet for room mentions
|
||||||
else -> Unit
|
MentionSpan.Type.ROOM -> Unit
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -87,6 +87,7 @@ class MentionSpan(
|
||||||
append("#")
|
append("#")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Type.EVERYONE -> Unit
|
||||||
}
|
}
|
||||||
append(mentionText.substring(0, min(mentionText.length, MAX_LENGTH)))
|
append(mentionText.substring(0, min(mentionText.length, MAX_LENGTH)))
|
||||||
if (mentionText.length > MAX_LENGTH) {
|
if (mentionText.length > MAX_LENGTH) {
|
||||||
|
|
@ -98,6 +99,7 @@ class MentionSpan(
|
||||||
enum class Type {
|
enum class Type {
|
||||||
USER,
|
USER,
|
||||||
ROOM,
|
ROOM,
|
||||||
|
EVERYONE,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -108,7 +108,7 @@ class MentionSpanProvider @AssistedInject constructor(
|
||||||
MentionSpan(
|
MentionSpan(
|
||||||
text = text,
|
text = text,
|
||||||
rawValue = "@room",
|
rawValue = "@room",
|
||||||
type = MentionSpan.Type.USER,
|
type = MentionSpan.Type.EVERYONE,
|
||||||
backgroundColor = otherBackgroundColor,
|
backgroundColor = otherBackgroundColor,
|
||||||
textColor = otherTextColor,
|
textColor = otherTextColor,
|
||||||
startPadding = startPaddingPx,
|
startPadding = startPaddingPx,
|
||||||
|
|
|
||||||
|
|
@ -93,13 +93,16 @@ class MarkdownTextEditorState(
|
||||||
for (mention in mentions.reversed()) {
|
for (mention in mentions.reversed()) {
|
||||||
val start = charSequence.getSpanStart(mention)
|
val start = charSequence.getSpanStart(mention)
|
||||||
val end = charSequence.getSpanEnd(mention)
|
val end = charSequence.getSpanEnd(mention)
|
||||||
if (mention.type == MentionSpan.Type.USER) {
|
when (mention.type) {
|
||||||
if (mention.rawValue == "@room") {
|
MentionSpan.Type.USER -> {
|
||||||
replace(start, end, "@room")
|
|
||||||
} else {
|
|
||||||
val link = permalinkBuilder.permalinkForUser(UserId(mention.rawValue)).getOrNull() ?: continue
|
val link = permalinkBuilder.permalinkForUser(UserId(mention.rawValue)).getOrNull() ?: continue
|
||||||
replace(start, end, "[${mention.rawValue}]($link)")
|
replace(start, end, "[${mention.rawValue}]($link)")
|
||||||
}
|
}
|
||||||
|
MentionSpan.Type.EVERYONE -> {
|
||||||
|
replace(start, end, "@room")
|
||||||
|
}
|
||||||
|
// Nothing to do here yet
|
||||||
|
MentionSpan.Type.ROOM -> Unit
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -114,14 +117,9 @@ class MarkdownTextEditorState(
|
||||||
val mentionSpans = text.getSpans<MentionSpan>(0, text.length)
|
val mentionSpans = text.getSpans<MentionSpan>(0, text.length)
|
||||||
return mentionSpans.mapNotNull { mentionSpan ->
|
return mentionSpans.mapNotNull { mentionSpan ->
|
||||||
when (mentionSpan.type) {
|
when (mentionSpan.type) {
|
||||||
MentionSpan.Type.USER -> {
|
MentionSpan.Type.USER -> Mention.User(UserId(mentionSpan.rawValue))
|
||||||
if (mentionSpan.rawValue == "@room") {
|
MentionSpan.Type.EVERYONE -> Mention.AtRoom
|
||||||
Mention.AtRoom
|
MentionSpan.Type.ROOM -> null
|
||||||
} else {
|
|
||||||
Mention.User(UserId(mentionSpan.rawValue))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else -> null
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -156,7 +156,7 @@ class MarkdownTextEditorStateTest {
|
||||||
|
|
||||||
private fun aMarkdownTextWithMentions(): CharSequence {
|
private fun aMarkdownTextWithMentions(): CharSequence {
|
||||||
val userMentionSpan = MentionSpan("@Alice", "@alice:matrix.org", MentionSpan.Type.USER, 0, 0, 0, 0)
|
val userMentionSpan = MentionSpan("@Alice", "@alice:matrix.org", MentionSpan.Type.USER, 0, 0, 0, 0)
|
||||||
val atRoomMentionSpan = MentionSpan("@room", "@room", MentionSpan.Type.USER, 0, 0, 0, 0)
|
val atRoomMentionSpan = MentionSpan("@room", "@room", MentionSpan.Type.EVERYONE, 0, 0, 0, 0)
|
||||||
return buildSpannedString {
|
return buildSpannedString {
|
||||||
append("Hello ")
|
append("Hello ")
|
||||||
inSpans(userMentionSpan) {
|
inSpans(userMentionSpan) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue