Skip to content

Commit

Permalink
FIx PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
yostyle committed Mar 17, 2023
1 parent e6d9c40 commit 88a5a73
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 51 deletions.
1 change: 0 additions & 1 deletion library/ui-strings/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3546,5 +3546,4 @@
<string name="pill_message_in_room">Message in %s</string>
<string name="pill_message_in_unknown_room">Message in room</string>
<string name="pill_message_unknown_room_or_space">Room/Space</string>
<string name="pill_message_unknown_user">User</string>
</resources>
4 changes: 2 additions & 2 deletions library/ui-styles/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

<item name="dialog_width_ratio" format="float" type="dimen">0.75</item>

<dimen name="pill_avatar_size">20dp</dimen>
<dimen name="pill_min_height">26dp</dimen>
<dimen name="pill_avatar_size">20sp</dimen>
<dimen name="pill_min_height">26sp</dimen>
<dimen name="pill_text_padding">4dp</dimen>

<dimen name="call_pip_height">128dp</dimen>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import im.vector.app.features.home.AvatarRenderer
import im.vector.app.features.html.PillImageSpan
import org.matrix.android.sdk.api.MatrixPatterns
import org.matrix.android.sdk.api.session.getRoomSummary
import org.matrix.android.sdk.api.session.getUser
import org.matrix.android.sdk.api.session.getUserOrDefault
import org.matrix.android.sdk.api.session.permalinks.PermalinkData
import org.matrix.android.sdk.api.session.permalinks.PermalinkParser
import org.matrix.android.sdk.api.session.room.model.RoomSummary
Expand Down Expand Up @@ -98,21 +98,17 @@ class EventTextRenderer @AssistedInject constructor(

private fun addPermalinksSpans(text: Spannable) {
for (match in Patterns.WEB_URL.toRegex().findAll(text)) {
val startPos = match.range.first
if (startPos == 0 || text[startPos - 1] != '/') {
val endPos = match.range.last + 1
val url = text.substring(match.range)
val matrixItem = if (MatrixPatterns.isPermalink(url)) {
when (val permalinkData = PermalinkParser.parse(url)) {
is PermalinkData.UserLink -> permalinkData.toMatrixItem()
is PermalinkData.RoomLink -> permalinkData.toMatrixItem()
else -> null
}
} else null

if (matrixItem != null) {
addPillSpan(text, createPillImageSpan(matrixItem), startPos, endPos)
val url = text.substring(match.range)
val matrixItem = if (MatrixPatterns.isPermalink(url)) {
when (val permalinkData = PermalinkParser.parse(url)) {
is PermalinkData.UserLink -> permalinkData.toMatrixItem()
is PermalinkData.RoomLink -> permalinkData.toMatrixItem()
else -> null
}
} else null

if (matrixItem != null) {
addPillSpan(text, createPillImageSpan(matrixItem), match.range.first, match.range.last + 1)
}
}
}
Expand All @@ -130,17 +126,8 @@ class EventTextRenderer @AssistedInject constructor(
}

private fun PermalinkData.UserLink.toMatrixItem(): MatrixItem? =
if (roomId == null) {
sessionHolder.getSafeActiveSession()?.getUser(userId)?.toMatrixItem()
} else {
val session = sessionHolder.getSafeActiveSession()
session?.roomService()?.getRoomMember(userId, roomId)?.toMatrixItem()
?: session?.getUser(userId)?.toMatrixItem()
?: MatrixItem.UserItem(
userId,
context.getString(R.string.pill_message_unknown_user)
)
}
roomId?.let { sessionHolder.getSafeActiveSession()?.roomService()?.getRoomMember(userId, it)?.toMatrixItem() }
?: sessionHolder.getSafeActiveSession()?.getUserOrDefault(userId)?.toMatrixItem()

private fun PermalinkData.RoomLink.toMatrixItem(): MatrixItem =
if (eventId.isNullOrEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import android.text.style.ReplacementSpan
import android.widget.TextView
import androidx.annotation.UiThread
import androidx.core.content.ContextCompat
import androidx.core.graphics.drawable.DrawableCompat
import com.bumptech.glide.request.target.SimpleTarget
import com.bumptech.glide.request.transition.Transition
import com.google.android.material.chip.ChipDrawable
Expand Down Expand Up @@ -116,16 +115,11 @@ class PillImageSpan(
val hasRoomAvatar = matrixItem is MatrixItem.RoomItem && matrixItem.avatarUrl.isNullOrEmpty()
val icon = when {
hasRoomAvatar && matrixItem.displayName == context.getString(R.string.pill_message_from_unknown_user) -> null
hasRoomAvatar &&
(matrixItem.displayName == context.getString(R.string.pill_message_in_unknown_room) ||
matrixItem.displayName == context.getString(R.string.pill_message_unknown_room_or_space)) -> {
hasRoomAvatar && (matrixItem.displayName == context.getString(R.string.pill_message_in_unknown_room) || matrixItem.displayName == context.getString(
R.string.pill_message_unknown_room_or_space
)) -> {
ContextCompat.getDrawable(context, R.drawable.ic_permalink_round)
}
matrixItem is MatrixItem.UserItem && matrixItem.avatarUrl.isNullOrEmpty() &&
matrixItem.displayName == context.getString(R.string.pill_message_unknown_user) -> {
ContextCompat.getDrawable(context, R.drawable.ic_user_round)?.also {
DrawableCompat.setTint(it, ThemeUtils.getColor(context, R.attr.vctr_content_secondary)) }
}
else -> {
try {
avatarRenderer.getCachedDrawable(glideRequests, matrixItem)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,8 @@ class PillsPostProcessor @AssistedInject constructor(
}

private fun PermalinkData.UserLink.toMatrixItem(): MatrixItem? =
if (roomId == null) {
sessionHolder.getSafeActiveSession()?.getUser(userId)?.toMatrixItem()
} else {
val session = sessionHolder.getSafeActiveSession()
session?.roomService()?.getRoomMember(userId, roomId)?.toMatrixItem() ?: session?.getUser(userId)?.toMatrixItem()
}
roomId?.let { sessionHolder.getSafeActiveSession()?.roomService()?.getRoomMember(userId, it)?.toMatrixItem() }
?: sessionHolder.getSafeActiveSession()?.getUser(userId)?.toMatrixItem()

private fun PermalinkData.RoomLink.toMatrixItem(): MatrixItem? =
if (eventId == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,8 @@ class PermalinkHandler @Inject constructor(

val rootThreadEventId = permalinkData.eventId?.let { eventId ->
val room = roomId?.let { session?.getRoom(it) }

val rootThreadEventId = room?.getTimelineEvent(eventId)?.root?.getRootThreadEventId()
rootThreadEventId ?: if (room?.getTimelineEvent(eventId)?.isRootThread() == true) {
eventId
} else {
null
}
val event = room?.getTimelineEvent(eventId)
event?.root?.getRootThreadEventId() ?: eventId.takeIf { event?.isRootThread() == true }
}
openRoom(
navigationInterceptor,
Expand Down

0 comments on commit 88a5a73

Please sign in to comment.