Bubbles: fix types using wrong layout
This commit is contained in:
parent
b9cc795996
commit
baee076e41
|
@ -172,9 +172,7 @@ class MessageItemFactory @Inject constructor(
|
|||
is MessagePollContent -> buildPollContent(messageContent, informationData, highlight, callback, attributes)
|
||||
else -> buildNotHandledMessageItem(messageContent, informationData, highlight, callback, attributes)
|
||||
}
|
||||
return messageItem?.takeIf {
|
||||
it.layout == R.layout.item_timeline_event_base
|
||||
}?.apply {
|
||||
return messageItem?.apply {
|
||||
layout(informationData.messageLayout.layoutRes)
|
||||
}
|
||||
}
|
||||
|
@ -650,6 +648,7 @@ class MessageItemFactory @Inject constructor(
|
|||
private fun buildRedactedItem(attributes: AbsMessageItem.Attributes,
|
||||
highlight: Boolean): RedactedMessageItem? {
|
||||
return RedactedMessageItem_()
|
||||
.layout(attributes.informationData.messageLayout.layoutRes)
|
||||
.leftGuideline(avatarSizeProvider.leftGuideline)
|
||||
.attributes(attributes)
|
||||
.highlighted(highlight)
|
||||
|
|
|
@ -27,10 +27,11 @@ sealed interface TimelineMessageLayout : Parcelable {
|
|||
val showTimestamp: Boolean
|
||||
|
||||
@Parcelize
|
||||
data class Modern(override val showAvatar: Boolean,
|
||||
override val showDisplayName: Boolean,
|
||||
override val showTimestamp: Boolean,
|
||||
override val layoutRes: Int = R.layout.item_timeline_event_base) : TimelineMessageLayout
|
||||
data class Default(override val showAvatar: Boolean,
|
||||
override val showDisplayName: Boolean,
|
||||
override val showTimestamp: Boolean,
|
||||
// Keep defaultLayout generated on epoxy items
|
||||
override val layoutRes: Int = 0) : TimelineMessageLayout
|
||||
|
||||
@Parcelize
|
||||
data class Bubble(override val showAvatar: Boolean,
|
||||
|
|
|
@ -21,6 +21,7 @@ import im.vector.app.features.home.room.detail.timeline.factory.TimelineItemFact
|
|||
import im.vector.app.features.settings.VectorPreferences
|
||||
import org.matrix.android.sdk.api.session.Session
|
||||
import org.matrix.android.sdk.api.session.events.model.EventType
|
||||
import org.matrix.android.sdk.api.session.room.model.message.MessageType
|
||||
import org.matrix.android.sdk.api.session.room.model.message.MessageVerificationRequestContent
|
||||
import org.matrix.android.sdk.api.session.room.timeline.TimelineEvent
|
||||
import org.matrix.android.sdk.api.session.room.timeline.getLastMessageContent
|
||||
|
@ -31,6 +32,18 @@ class TimelineMessageLayoutFactory @Inject constructor(private val session: Sess
|
|||
private val layoutSettingsProvider: TimelineLayoutSettingsProvider,
|
||||
private val vectorPreferences: VectorPreferences) {
|
||||
|
||||
companion object {
|
||||
private val EVENT_TYPES_WITH_BUBBLE_LAYOUT = setOf(
|
||||
EventType.MESSAGE,
|
||||
EventType.ENCRYPTED,
|
||||
EventType.STICKER
|
||||
)
|
||||
private val MSG_TYPES_WITHOUT_BUBBLE_LAYOUT = setOf(
|
||||
MessageType.MSGTYPE_POLL_START,
|
||||
MessageType.MSGTYPE_VERIFICATION_REQUEST
|
||||
)
|
||||
}
|
||||
|
||||
fun create(params: TimelineItemFactoryParams): TimelineMessageLayout {
|
||||
|
||||
val event = params.event
|
||||
|
@ -55,27 +68,42 @@ class TimelineMessageLayoutFactory @Inject constructor(private val session: Sess
|
|||
|
||||
val messageLayout = when (layoutSettingsProvider.getLayoutSettings()) {
|
||||
TimelineLayoutSettings.MODERN -> {
|
||||
TimelineMessageLayout.Modern(
|
||||
showAvatar = showInformation,
|
||||
showDisplayName = showInformation,
|
||||
showTimestamp = showInformation || vectorPreferences.alwaysShowTimeStamps()
|
||||
)
|
||||
buildModernLayout(showInformation)
|
||||
}
|
||||
TimelineLayoutSettings.BUBBLE -> {
|
||||
val isFirstFromThisSender = nextDisplayableEvent?.root?.senderId != event.root.senderId || addDaySeparator
|
||||
val isLastFromThisSender = prevDisplayableEvent?.root?.senderId != event.root.senderId || prevDisplayableEvent?.root?.localDateTime()?.toLocalDate() != date.toLocalDate()
|
||||
TimelineMessageLayout.Bubble(
|
||||
showAvatar = showInformation && !isSentByMe,
|
||||
showDisplayName = showInformation && !isSentByMe,
|
||||
isIncoming = !isSentByMe,
|
||||
isFirstFromThisSender = isFirstFromThisSender,
|
||||
isLastFromThisSender = isLastFromThisSender
|
||||
)
|
||||
val type = event.root.getClearType()
|
||||
if (type in EVENT_TYPES_WITH_BUBBLE_LAYOUT) {
|
||||
val messageContent = if (type == EventType.MESSAGE) params.event.getLastMessageContent() else null
|
||||
if (messageContent?.msgType in MSG_TYPES_WITHOUT_BUBBLE_LAYOUT) {
|
||||
buildModernLayout(showInformation)
|
||||
}
|
||||
val isFirstFromThisSender = nextDisplayableEvent?.root?.senderId != event.root.senderId || addDaySeparator
|
||||
val isLastFromThisSender = prevDisplayableEvent?.root?.senderId != event.root.senderId
|
||||
|| prevDisplayableEvent?.root?.localDateTime()?.toLocalDate() != date.toLocalDate()
|
||||
|
||||
TimelineMessageLayout.Bubble(
|
||||
showAvatar = showInformation && !isSentByMe,
|
||||
showDisplayName = showInformation && !isSentByMe,
|
||||
isIncoming = !isSentByMe,
|
||||
isFirstFromThisSender = isFirstFromThisSender,
|
||||
isLastFromThisSender = isLastFromThisSender
|
||||
)
|
||||
} else {
|
||||
buildModernLayout(showInformation)
|
||||
}
|
||||
}
|
||||
}
|
||||
return messageLayout
|
||||
}
|
||||
|
||||
private fun buildModernLayout(showInformation: Boolean): TimelineMessageLayout.Default {
|
||||
return TimelineMessageLayout.Default(
|
||||
showAvatar = showInformation,
|
||||
showDisplayName = showInformation,
|
||||
showTimestamp = showInformation || vectorPreferences.alwaysShowTimeStamps()
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Tiles type message never show the sender information (like verification request), so we should repeat it for next message
|
||||
* even if same sender
|
||||
|
|
Loading…
Reference in New Issue