Fix the one-line events combining

When there's a one line (emote or non-message) event with its avatar
shown and combinable events follow it, that first event delegate's height
is supposed to be one line with the avatar overflowing into
the following event's blank space.

This behavior hasn't been working for a long time. This commit restores
it, along with improving the related code's quality.
This commit is contained in:
miruka 2020-09-01 13:22:51 -04:00
parent 27c3d08031
commit 39f159f0a3
3 changed files with 24 additions and 12 deletions

View File

@ -26,7 +26,7 @@ HRowLayout {
} }
readonly property string senderText: readonly property string senderText:
hideNameLine ? "" : ( asOneLine || onRight || combine ? "" : (
`<${compact ? "span" : "div"} class='sender'>` + `<${compact ? "span" : "div"} class='sender'>` +
utils.coloredNameHtml(model.sender_name, model.sender_id) + utils.coloredNameHtml(model.sender_name, model.sender_id) +
(compact ? ": " : "") + (compact ? ": " : "") +
@ -82,12 +82,25 @@ HRowLayout {
opacity: combine ? 0 : 1 opacity: combine ? 0 : 1
Layout.alignment: Qt.AlignTop Layout.alignment: Qt.AlignTop
Layout.preferredHeight: combine ? 1 : Layout.preferredWidth
Layout.preferredWidth: Layout.preferredWidth:
compact ? compact ?
theme.chat.message.collapsedAvatarSize : theme.chat.message.collapsedAvatarSize :
theme.chat.message.avatarSize theme.chat.message.avatarSize
Layout.preferredHeight:
combine ?
1 :
compact || (
asOneLine &&
nextModel &&
eventList.canCombine(model, nextModel)
) ?
theme.chat.message.collapsedAvatarSize :
theme.chat.message.avatarSize
HUserAvatar { HUserAvatar {
id: avatar id: avatar
clientUserId: chat.userId clientUserId: chat.userId
@ -97,7 +110,6 @@ HRowLayout {
width: parent.width width: parent.width
height: combine ? 1 : parent.Layout.preferredWidth height: combine ? 1 : parent.Layout.preferredWidth
radius: theme.chat.message.avatarRadius radius: theme.chat.message.avatarRadius
} }
} }

View File

@ -25,20 +25,12 @@ HColumnLayout {
readonly property bool isRedacted: model.event_type === "RedactedEvent" readonly property bool isRedacted: model.event_type === "RedactedEvent"
readonly property bool onRight: ! eventList.ownEventsOnLeft && isOwn readonly property bool onRight: ! eventList.ownEventsOnLeft && isOwn
readonly property bool combine: eventList.canCombine(previousModel, model) readonly property bool combine: eventList.canCombine(previousModel, model)
readonly property bool asOneLine: eventList.renderEventAsOneLine(model)
readonly property bool talkBreak: readonly property bool talkBreak:
eventList.canTalkBreak(previousModel, model) eventList.canTalkBreak(previousModel, model)
readonly property bool dayBreak: readonly property bool dayBreak:
eventList.canDayBreak(previousModel, model) eventList.canDayBreak(previousModel, model)
readonly property bool hideNameLine:
model.event_type === "RoomMessageEmote" ||
! (
model.event_type.startsWith("RoomMessage") ||
model.event_type.startsWith("RoomEncrypted")
) ||
onRight ||
combine
readonly property int cursorShape: readonly property int cursorShape:
eventContent.hoveredLink || hoveredMediaTypeUrl.length === 3 ? eventContent.hoveredLink || hoveredMediaTypeUrl.length === 3 ?
Qt.PointingHandCursor : Qt.PointingHandCursor :

View File

@ -323,6 +323,14 @@ Rectangle {
return item.date.getDate() !== itemAfter.date.getDate() return item.date.getDate() !== itemAfter.date.getDate()
} }
function renderEventAsOneLine(event) {
return (
event.event_type !== "RoomMessageEmote" &&
! event.event_type.startsWith("RoomMessage") &&
! event.event_type.startsWith("RoomEncrypted")
)
}
function loadPastEvents() { function loadPastEvents() {
loadPastEventsFuture = py.callClientCoro( loadPastEventsFuture = py.callClientCoro(
chat.userId, chat.userId,