From 39f159f0a370bcc5b9aa8503df62cf87df395fb7 Mon Sep 17 00:00:00 2001 From: miruka Date: Tue, 1 Sep 2020 13:22:51 -0400 Subject: [PATCH] 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. --- src/gui/Pages/Chat/Timeline/EventContent.qml | 18 +++++++++++++++--- src/gui/Pages/Chat/Timeline/EventDelegate.qml | 10 +--------- src/gui/Pages/Chat/Timeline/EventList.qml | 8 ++++++++ 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/src/gui/Pages/Chat/Timeline/EventContent.qml b/src/gui/Pages/Chat/Timeline/EventContent.qml index d4726348..d2c5bfe4 100644 --- a/src/gui/Pages/Chat/Timeline/EventContent.qml +++ b/src/gui/Pages/Chat/Timeline/EventContent.qml @@ -26,7 +26,7 @@ HRowLayout { } readonly property string senderText: - hideNameLine ? "" : ( + asOneLine || onRight || combine ? "" : ( `<${compact ? "span" : "div"} class='sender'>` + utils.coloredNameHtml(model.sender_name, model.sender_id) + (compact ? ": " : "") + @@ -82,12 +82,25 @@ HRowLayout { opacity: combine ? 0 : 1 Layout.alignment: Qt.AlignTop - Layout.preferredHeight: combine ? 1 : Layout.preferredWidth + Layout.preferredWidth: compact ? theme.chat.message.collapsedAvatarSize : theme.chat.message.avatarSize + Layout.preferredHeight: + combine ? + 1 : + + compact || ( + asOneLine && + nextModel && + eventList.canCombine(model, nextModel) + ) ? + theme.chat.message.collapsedAvatarSize : + + theme.chat.message.avatarSize + HUserAvatar { id: avatar clientUserId: chat.userId @@ -97,7 +110,6 @@ HRowLayout { width: parent.width height: combine ? 1 : parent.Layout.preferredWidth radius: theme.chat.message.avatarRadius - } } diff --git a/src/gui/Pages/Chat/Timeline/EventDelegate.qml b/src/gui/Pages/Chat/Timeline/EventDelegate.qml index a0e23103..91a97ea2 100644 --- a/src/gui/Pages/Chat/Timeline/EventDelegate.qml +++ b/src/gui/Pages/Chat/Timeline/EventDelegate.qml @@ -25,20 +25,12 @@ HColumnLayout { readonly property bool isRedacted: model.event_type === "RedactedEvent" readonly property bool onRight: ! eventList.ownEventsOnLeft && isOwn readonly property bool combine: eventList.canCombine(previousModel, model) + readonly property bool asOneLine: eventList.renderEventAsOneLine(model) readonly property bool talkBreak: eventList.canTalkBreak(previousModel, model) readonly property bool dayBreak: 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: eventContent.hoveredLink || hoveredMediaTypeUrl.length === 3 ? Qt.PointingHandCursor : diff --git a/src/gui/Pages/Chat/Timeline/EventList.qml b/src/gui/Pages/Chat/Timeline/EventList.qml index ddbbaebc..e85b5cdf 100644 --- a/src/gui/Pages/Chat/Timeline/EventList.qml +++ b/src/gui/Pages/Chat/Timeline/EventList.qml @@ -323,6 +323,14 @@ Rectangle { 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() { loadPastEventsFuture = py.callClientCoro( chat.userId,