Skip to content

Commit bc967fe

Browse files
committed
Iterate on previous solution, add MentionSpan.Type.EVERYONE
1 parent 3c5ef56 commit bc967fe

File tree

5 files changed

+21
-21
lines changed

5 files changed

+21
-21
lines changed

features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/event/TimelineItemTextView.kt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,16 +88,16 @@ private fun updateMentionSpans(text: CharSequence?, cache: RoomMemberProfilesCac
8888
for (mentionSpan in text.getMentionSpans()) {
8989
when (mentionSpan.type) {
9090
MentionSpan.Type.USER -> {
91-
if (mentionSpan.rawValue != "@room") {
92-
val displayName = cache.getDisplayName(UserId(mentionSpan.rawValue)) ?: mentionSpan.rawValue
93-
if (mentionSpan.text != displayName) {
94-
changedContents = true
95-
mentionSpan.text = displayName
96-
}
91+
val displayName = cache.getDisplayName(UserId(mentionSpan.rawValue)) ?: mentionSpan.rawValue
92+
if (mentionSpan.text != displayName) {
93+
changedContents = true
94+
mentionSpan.text = displayName
9795
}
9896
}
97+
// There's no need to do anything for `@room` pills
98+
MentionSpan.Type.EVERYONE -> Unit
9999
// Nothing yet for room mentions
100-
else -> Unit
100+
MentionSpan.Type.ROOM -> Unit
101101
}
102102
}
103103
}

libraries/textcomposer/impl/src/main/kotlin/io/element/android/libraries/textcomposer/mentions/MentionSpan.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ class MentionSpan(
8787
append("#")
8888
}
8989
}
90+
Type.EVERYONE -> Unit
9091
}
9192
append(mentionText.substring(0, min(mentionText.length, MAX_LENGTH)))
9293
if (mentionText.length > MAX_LENGTH) {
@@ -98,6 +99,7 @@ class MentionSpan(
9899
enum class Type {
99100
USER,
100101
ROOM,
102+
EVERYONE,
101103
}
102104
}
103105

libraries/textcomposer/impl/src/main/kotlin/io/element/android/libraries/textcomposer/mentions/MentionSpanProvider.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ class MentionSpanProvider @AssistedInject constructor(
108108
MentionSpan(
109109
text = text,
110110
rawValue = "@room",
111-
type = MentionSpan.Type.USER,
111+
type = MentionSpan.Type.EVERYONE,
112112
backgroundColor = otherBackgroundColor,
113113
textColor = otherTextColor,
114114
startPadding = startPaddingPx,

libraries/textcomposer/impl/src/main/kotlin/io/element/android/libraries/textcomposer/model/MarkdownTextEditorState.kt

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,16 @@ class MarkdownTextEditorState(
9393
for (mention in mentions.reversed()) {
9494
val start = charSequence.getSpanStart(mention)
9595
val end = charSequence.getSpanEnd(mention)
96-
if (mention.type == MentionSpan.Type.USER) {
97-
if (mention.rawValue == "@room") {
98-
replace(start, end, "@room")
99-
} else {
96+
when (mention.type) {
97+
MentionSpan.Type.USER -> {
10098
val link = permalinkBuilder.permalinkForUser(UserId(mention.rawValue)).getOrNull() ?: continue
10199
replace(start, end, "[${mention.rawValue}]($link)")
102100
}
101+
MentionSpan.Type.EVERYONE -> {
102+
replace(start, end, "@room")
103+
}
104+
// Nothing to do here yet
105+
MentionSpan.Type.ROOM -> Unit
103106
}
104107
}
105108
}
@@ -114,14 +117,9 @@ class MarkdownTextEditorState(
114117
val mentionSpans = text.getSpans<MentionSpan>(0, text.length)
115118
return mentionSpans.mapNotNull { mentionSpan ->
116119
when (mentionSpan.type) {
117-
MentionSpan.Type.USER -> {
118-
if (mentionSpan.rawValue == "@room") {
119-
Mention.AtRoom
120-
} else {
121-
Mention.User(UserId(mentionSpan.rawValue))
122-
}
123-
}
124-
else -> null
120+
MentionSpan.Type.USER -> Mention.User(UserId(mentionSpan.rawValue))
121+
MentionSpan.Type.EVERYONE -> Mention.AtRoom
122+
MentionSpan.Type.ROOM -> null
125123
}
126124
}
127125
}

libraries/textcomposer/impl/src/test/kotlin/io/element/android/libraries/textcomposer/impl/model/MarkdownTextEditorStateTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ class MarkdownTextEditorStateTest {
156156

157157
private fun aMarkdownTextWithMentions(): CharSequence {
158158
val userMentionSpan = MentionSpan("@Alice", "@alice:matrix.org", MentionSpan.Type.USER, 0, 0, 0, 0)
159-
val atRoomMentionSpan = MentionSpan("@room", "@room", MentionSpan.Type.USER, 0, 0, 0, 0)
159+
val atRoomMentionSpan = MentionSpan("@room", "@room", MentionSpan.Type.EVERYONE, 0, 0, 0, 0)
160160
return buildSpannedString {
161161
append("Hello ")
162162
inSpans(userMentionSpan) {

0 commit comments

Comments
 (0)