Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ data class SpanAttributes(
sealed interface MatrixToLink {
val rawUrl: String
@Serializable
data class UserMention(val userId: String, override val rawUrl: String) : MatrixToLink
data class UserMention(val userId: String, override val rawUrl: String, val isAutoLink: Boolean) : MatrixToLink
@Serializable
data class RoomLink(val roomId: String, val via: List<String>?, override val rawUrl: String) : MatrixToLink
@Serializable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -423,9 +423,13 @@ open class DefaultMatrixBodyStyledFormatter(
}

override fun formatUserMention(mention: MatrixToLink.UserMention, context: FormatContext): List<AnnotatedString.Annotation>? {
return listOf(
SpanStyle(color = Color.White, fontWeight = FontWeight.Bold)
)
return if (mention.isAutoLink) {
formatWebLink(mention.rawUrl, context)
} else {
listOf(
SpanStyle(color = Color.White, fontWeight = FontWeight.Bold)
)
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
}

override fun formatRoomLink(roomLink: MatrixToLink.RoomLink, context: FormatContext): List<AnnotatedString.Annotation>? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ class MatrixHtmlParser(
}
val url = text.substring(startInText, endInText)
// Handle matrix.to links specifically for user mentions and room / message links
val matrixLink = MatrixPatterns.parseMatrixToUrl(url)
val matrixLink = MatrixPatterns.parseMatrixToUrl(url, isAutoLink = true)
// Custom formatting of auto-linked url contents disabled for now -
// let's call it a feature, maybe it wasn't supposed to be a link?
val tag = when (matrixLink) {
Expand Down Expand Up @@ -479,7 +479,7 @@ class MatrixHtmlParser(
"a" -> {
val href = el.attr("href")
// Handle matrix.to links specifically for user mentions and room / message links
val matrixLink = MatrixPatterns.parseMatrixToUrl(href)
val matrixLink = MatrixPatterns.parseMatrixToUrl(href, isAutoLink = false)
if (matrixLink == null) {
withAnnotation(ctx, MatrixBodyAnnotations.WEB_LINK, href) { ctx ->
appendNodes(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ object MatrixPatterns {
private fun String.isRoomIdOrAlias() =
ROOM_ID_REGEX.matches(this) || ROOM_ALIAS_REGEX.matches(this)

fun parseMatrixToUrl(url: String): MatrixToLink? {
fun parseMatrixToUrl(url: String, isAutoLink: Boolean): MatrixToLink? {
if (!url.startsWith(MATRIX_TO_LINK_PREFIX)) {
return null
}
Expand All @@ -37,7 +37,7 @@ object MatrixPatterns {
1 -> {
val segment = segments.first()
if (USER_ID_REGEX.matches(segment)) {
return MatrixToLink.UserMention(segment, url)
return MatrixToLink.UserMention(segment, url, isAutoLink)
}
if (segment.isRoomIdOrAlias()) {
val via = parsed.parameters.getAll("via")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ dendri 380 365 -15 -3.95%
<br>
Auto-linked email address: test@example.com
<br>
Auto-linkified user link: https://matrix.to/#/@spiritcroc:matrix.org
<br>
<a href="https://matrix.to/#/@spiritcroc:beeper.com">Very long mention very long mention very long mention very long mention very long mention very long mention very long mention very long mention very long mention very long mention very long mention very long mention very long mention very long mention very long mention very long mention very long mention very long mention very long mention very long mention very long mention very long mention very long mention very long mention very long mention very long mention</a>
</p>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,10 @@ fun TextRenderScreen() {
onTextLayout = { textLayoutResult = it },
drawStyle = remember {
MatrixBodyDrawStyle(
drawBehindUserMention = { _, pos ->
drawBehindUserMention = { mention, pos ->
if (mention.isAutoLink) {
return@MatrixBodyDrawStyle
}
val rect = pos.rect
val leftRadius = this.density * if (pos.leftHasContinuation) {
2f
Expand Down