| 1 |
// SPDX-FileCopyrightText: Nheko Contributors |
| 2 |
// |
| 3 |
// SPDX-License-Identifier: GPL-3.0-or-later |
| 4 |
|
| 5 |
import QtQuick |
| 6 |
import QtQuick.Controls |
| 7 |
import QtQuick.Window |
| 8 |
import im.nheko |
| 9 |
|
| 10 |
import "./components" |
| 11 |
|
| 12 |
Column { |
| 13 |
|
| 14 |
required property var day |
| 15 |
required property bool isSender |
| 16 |
required property bool isStateEvent |
| 17 |
required property int parentWidth |
| 18 |
required property var previousMessageDay |
| 19 |
required property var previousMessageTimestamp |
| 20 |
required property bool previousMessageIsStateEvent |
| 21 |
required property string previousMessageUserId |
| 22 |
required property date timestamp |
| 23 |
required property string userId |
| 24 |
required property string userName |
| 25 |
required property string userPowerlevel |
| 26 |
|
| 27 |
property int oneHour: 60 * 60 * 1000 |
| 28 |
property bool dayChanged: previousMessageDay !== day |
| 29 |
property bool showLabel: dayChanged || timestamp - previousMessageTimestamp > oneHour |
| 30 |
|
| 31 |
bottomPadding: Settings.bubbles ? (isSender && !showLabel ? 0 : 2) : 3 |
| 32 |
spacing: 8 |
| 33 |
topPadding: userName_.visible ? 4 : 0 |
| 34 |
visible: (previousMessageUserId !== userId || showLabel || isStateEvent !== previousMessageIsStateEvent) |
| 35 |
width: parentWidth |
| 36 |
|
| 37 |
Label { |
| 38 |
id: dateBubble |
| 39 |
|
| 40 |
anchors.horizontalCenter: parent ? parent.horizontalCenter : undefined |
| 41 |
color: palette.text |
| 42 |
height: Math.round(fontMetrics.height * 1.4) |
| 43 |
horizontalAlignment: Text.AlignHCenter |
| 44 |
text: room ? (dayChanged ? room.formatDateSeparator(timestamp) : room.formatLaterSeparator(previousMessageTimestamp, timestamp)) : "" |
| 45 |
verticalAlignment: Text.AlignVCenter |
| 46 |
visible: room && showLabel |
| 47 |
width: contentWidth * 1.2 |
| 48 |
|
| 49 |
background: Rectangle { |
| 50 |
color: palette.window |
| 51 |
radius: parent.height / 2 |
| 52 |
} |
| 53 |
} |
| 54 |
Row { |
| 55 |
id: userInfo |
| 56 |
|
| 57 |
property int remainingWidth: chat.delegateMaxWidth - spacing - messageUserAvatar.width |
| 58 |
|
| 59 |
height: userName_.height |
| 60 |
spacing: 8 |
| 61 |
visible: !isStateEvent && (!isSender || !Settings.bubbles) |
| 62 |
|
| 63 |
Avatar { |
| 64 |
id: messageUserAvatar |
| 65 |
|
| 66 |
ToolTip.delay: Nheko.tooltipDelay |
| 67 |
ToolTip.text: userid |
| 68 |
ToolTip.visible: messageUserAvatar.hovered |
| 69 |
displayName: userName |
| 70 |
height: Nheko.avatarSize * (Settings.smallAvatars ? 0.5 : 1) |
| 71 |
url: !room ? "" : room.avatarUrl(userId).replace("mxc://", "image://MxcImage/") |
| 72 |
userid: userId |
| 73 |
width: Nheko.avatarSize * (Settings.smallAvatars ? 0.5 : 1) |
| 74 |
|
| 75 |
onClicked: room.openUserProfile(userId) |
| 76 |
} |
| 77 |
Connections { |
| 78 |
function onRoomAvatarUrlChanged() { |
| 79 |
messageUserAvatar.url = room.avatarUrl(userId).replace("mxc://", "image://MxcImage/"); |
| 80 |
} |
| 81 |
target: room |
| 82 |
} |
| 83 |
|
| 84 |
AbstractButton { |
| 85 |
id: userNameButton |
| 86 |
|
| 87 |
PowerlevelIndicator { |
| 88 |
id: powerlevelIndicator |
| 89 |
anchors.left: parent.left |
| 90 |
anchors.verticalCenter: parent.verticalCenter |
| 91 |
|
| 92 |
powerlevel: userPowerlevel |
| 93 |
height: fontMetrics.ascent |
| 94 |
width: height |
| 95 |
|
| 96 |
sourceSize.width: width |
| 97 |
sourceSize.height: height |
| 98 |
|
| 99 |
permissions: room ? room.permissions : null |
| 100 |
visible: isAdmin || isModerator |
| 101 |
} |
| 102 |
|
| 103 |
ToolTip.delay: Nheko.tooltipDelay |
| 104 |
ToolTip.text: userId |
| 105 |
ToolTip.visible: hovered |
| 106 |
leftPadding: powerlevelIndicator.visible ? 16 : 0 |
| 107 |
leftInset: 0 |
| 108 |
rightInset: 0 |
| 109 |
rightPadding: 0 |
| 110 |
|
| 111 |
contentItem: Label { |
| 112 |
id: userName_ |
| 113 |
|
| 114 |
color: TimelineManager.userColor(userId, palette.base) |
| 115 |
text: TimelineManager.escapeEmoji(userNameTextMetrics.elidedText) |
| 116 |
textFormat: Text.RichText |
| 117 |
} |
| 118 |
|
| 119 |
onClicked: room.openUserProfile(userId) |
| 120 |
|
| 121 |
TextMetrics { |
| 122 |
id: userNameTextMetrics |
| 123 |
|
| 124 |
elide: Text.ElideRight |
| 125 |
elideWidth: userInfo.remainingWidth - Math.min(statusMsg.implicitWidth, userInfo.remainingWidth / 3) |
| 126 |
text: userName |
| 127 |
} |
| 128 |
NhekoCursorShape { |
| 129 |
anchors.fill: parent |
| 130 |
cursorShape: Qt.PointingHandCursor |
| 131 |
} |
| 132 |
} |
| 133 |
Label { |
| 134 |
id: statusMsg |
| 135 |
|
| 136 |
property string userStatus: Presence.userStatus(userId) |
| 137 |
|
| 138 |
ToolTip.delay: Nheko.tooltipDelay |
| 139 |
ToolTip.text: qsTr("%1's status message").arg(userName) |
| 140 |
ToolTip.visible: statusMsgHoverHandler.hovered |
| 141 |
anchors.baseline: userNameButton.baseline |
| 142 |
color: palette.buttonText |
| 143 |
elide: Text.ElideRight |
| 144 |
font.italic: true |
| 145 |
font.pointSize: Math.floor(fontMetrics.font.pointSize * 0.8) |
| 146 |
text: userStatus.replace(/\n/g, " ") |
| 147 |
textFormat: Text.PlainText |
| 148 |
width: Math.min(implicitWidth, userInfo.remainingWidth - userName_.width - parent.spacing) |
| 149 |
|
| 150 |
HoverHandler { |
| 151 |
id: statusMsgHoverHandler |
| 152 |
|
| 153 |
} |
| 154 |
Connections { |
| 155 |
function onPresenceChanged(id) { |
| 156 |
if (id == userId) |
| 157 |
statusMsg.userStatus = Presence.userStatus(userId); |
| 158 |
} |
| 159 |
|
| 160 |
target: Presence |
| 161 |
} |
| 162 |
} |
| 163 |
} |
| 164 |
} |
| 165 |
|