mirror of
https://github.com/vector-im/element-android.git
synced 2024-11-15 01:35:07 +08:00
Render pills for room links
This commit is contained in:
parent
05a788453f
commit
543c07fd69
@ -52,6 +52,13 @@ interface RoomService {
|
||||
*/
|
||||
fun getRoom(roomId: String): Room?
|
||||
|
||||
/**
|
||||
* Get a roomSummary from a roomId or a room alias
|
||||
* @param roomIdOrAlias the roomId or the alias of a room to look for.
|
||||
* @return a matching room summary or null
|
||||
*/
|
||||
fun getRoomSummary(roomIdOrAlias: String): RoomSummary?
|
||||
|
||||
/**
|
||||
* Get a live list of room summaries. This list is refreshed as soon as the data changes.
|
||||
* @return the [LiveData] of [RoomSummary]
|
||||
|
@ -30,6 +30,7 @@ import im.vector.matrix.android.internal.database.mapper.RoomSummaryMapper
|
||||
import im.vector.matrix.android.internal.database.model.RoomEntity
|
||||
import im.vector.matrix.android.internal.database.model.RoomSummaryEntity
|
||||
import im.vector.matrix.android.internal.database.model.RoomSummaryEntityFields
|
||||
import im.vector.matrix.android.internal.database.query.findByAlias
|
||||
import im.vector.matrix.android.internal.database.query.where
|
||||
import im.vector.matrix.android.internal.session.room.alias.GetRoomIdByAliasTask
|
||||
import im.vector.matrix.android.internal.session.room.create.CreateRoomTask
|
||||
@ -38,6 +39,7 @@ import im.vector.matrix.android.internal.session.room.read.MarkAllRoomsReadTask
|
||||
import im.vector.matrix.android.internal.session.user.accountdata.UpdateBreadcrumbsTask
|
||||
import im.vector.matrix.android.internal.task.TaskExecutor
|
||||
import im.vector.matrix.android.internal.task.configureWith
|
||||
import im.vector.matrix.android.internal.util.fetchCopyMap
|
||||
import io.realm.Realm
|
||||
import javax.inject.Inject
|
||||
|
||||
@ -69,6 +71,21 @@ internal class DefaultRoomService @Inject constructor(private val monarchy: Mona
|
||||
}
|
||||
}
|
||||
|
||||
override fun getRoomSummary(roomIdOrAlias: String): RoomSummary? {
|
||||
return monarchy
|
||||
.fetchCopyMap({
|
||||
if (roomIdOrAlias.startsWith("!")) {
|
||||
// It's a roomId
|
||||
RoomSummaryEntity.where(it, roomId = roomIdOrAlias).findFirst()
|
||||
} else {
|
||||
// Assume it's a room alias
|
||||
RoomSummaryEntity.findByAlias(it, roomIdOrAlias)
|
||||
}
|
||||
}, { entity, _ ->
|
||||
roomSummaryMapper.map(entity)
|
||||
})
|
||||
}
|
||||
|
||||
override fun liveRoomSummaries(): LiveData<List<RoomSummary>> {
|
||||
return monarchy.findAllMappedWithChanges(
|
||||
{ realm ->
|
||||
|
@ -20,6 +20,7 @@ import android.content.Context
|
||||
import android.text.style.URLSpan
|
||||
import im.vector.matrix.android.api.permalinks.PermalinkData
|
||||
import im.vector.matrix.android.api.permalinks.PermalinkParser
|
||||
import im.vector.matrix.android.api.session.room.model.RoomSummary
|
||||
import im.vector.matrix.android.api.util.MatrixItem
|
||||
import im.vector.riotx.core.di.ActiveSessionHolder
|
||||
import im.vector.riotx.core.glide.GlideRequests
|
||||
@ -39,26 +40,42 @@ class MxLinkTagHandler(private val glideRequests: GlideRequests,
|
||||
val link = tag.attributes()["href"]
|
||||
if (link != null) {
|
||||
val permalinkData = PermalinkParser.parse(link)
|
||||
when (permalinkData) {
|
||||
is PermalinkData.UserLink -> {
|
||||
val matrixItem = when (permalinkData) {
|
||||
is PermalinkData.UserLink -> {
|
||||
val user = sessionHolder.getSafeActiveSession()?.getUser(permalinkData.userId)
|
||||
val span = PillImageSpan(glideRequests, avatarRenderer, context, MatrixItem.UserItem(permalinkData.userId, user?.displayName
|
||||
?: permalinkData.userId, user?.avatarUrl))
|
||||
SpannableBuilder.setSpans(
|
||||
visitor.builder(),
|
||||
span,
|
||||
tag.start(),
|
||||
tag.end()
|
||||
)
|
||||
// also add clickable span
|
||||
SpannableBuilder.setSpans(
|
||||
visitor.builder(),
|
||||
URLSpan(link),
|
||||
tag.start(),
|
||||
tag.end()
|
||||
)
|
||||
MatrixItem.UserItem(permalinkData.userId, user?.displayName, user?.avatarUrl)
|
||||
}
|
||||
else -> super.handle(visitor, renderer, tag)
|
||||
is PermalinkData.RoomLink -> {
|
||||
val room: RoomSummary? = sessionHolder.getSafeActiveSession()?.getRoomSummary(permalinkData.roomIdOrAlias)
|
||||
if (permalinkData.isRoomAlias) {
|
||||
MatrixItem.RoomAliasItem(permalinkData.roomIdOrAlias, room?.displayName, room?.avatarUrl)
|
||||
} else {
|
||||
MatrixItem.RoomItem(permalinkData.roomIdOrAlias, room?.displayName, room?.avatarUrl)
|
||||
}
|
||||
}
|
||||
is PermalinkData.GroupLink -> {
|
||||
// TODO val group = sessionHolder.getSafeActiveSession()?.getGroup(permalinkData.groupId)
|
||||
MatrixItem.RoomItem(permalinkData.groupId /* TODO Group display name and avatar */)
|
||||
}
|
||||
else -> null
|
||||
}
|
||||
|
||||
if (matrixItem == null) {
|
||||
super.handle(visitor, renderer, tag)
|
||||
} else {
|
||||
val span = PillImageSpan(glideRequests, avatarRenderer, context, matrixItem)
|
||||
SpannableBuilder.setSpans(
|
||||
visitor.builder(),
|
||||
span,
|
||||
tag.start(),
|
||||
tag.end()
|
||||
)
|
||||
SpannableBuilder.setSpans(
|
||||
visitor.builder(),
|
||||
URLSpan(link),
|
||||
tag.start(),
|
||||
tag.end()
|
||||
)
|
||||
}
|
||||
} else {
|
||||
super.handle(visitor, renderer, tag)
|
||||
|
Loading…
Reference in New Issue
Block a user