| 1 |
// SPDX-FileCopyrightText: Nheko Contributors |
| 2 |
// |
| 3 |
// SPDX-License-Identifier: GPL-3.0-or-later |
| 4 |
|
| 5 |
import "./components" |
| 6 |
import "./emoji" |
| 7 |
import "./ui" |
| 8 |
import "./voip" |
| 9 |
import QtQuick |
| 10 |
import QtQuick.Controls |
| 11 |
import QtQuick.Layouts |
| 12 |
import QtQuick.Window |
| 13 |
import im.nheko |
| 14 |
|
| 15 |
Item { |
| 16 |
id: timelineView |
| 17 |
|
| 18 |
required property PrivacyScreen privacyScreen |
| 19 |
property var room: null |
| 20 |
property var roomPreview: null |
| 21 |
property bool shouldEffectsRun: false |
| 22 |
property bool showBackButton: false |
| 23 |
|
| 24 |
clip: true |
| 25 |
|
| 26 |
// focus message input on key press, but not on Ctrl-C and such. |
| 27 |
Keys.onPressed: event => { |
| 28 |
if (event.text && event.key !== Qt.Key_Enter && event.key !== Qt.Key_Return && !topBar.searchHasFocus) { |
| 29 |
TimelineManager.focusMessageInput(); |
| 30 |
if (event.modifiers != Qt.ControlModifier) { |
| 31 |
room.input.setText(room.input.text + event.text); |
| 32 |
} |
| 33 |
} |
| 34 |
} |
| 35 |
onRoomChanged: if (room != null) |
| 36 |
room.triggerSpecialEffects() |
| 37 |
|
| 38 |
StickerPicker { |
| 39 |
id: emojiPopup |
| 40 |
|
| 41 |
emoji: true |
| 42 |
} |
| 43 |
Shortcut { |
| 44 |
sequences: [StandardKey.Close] |
| 45 |
|
| 46 |
onActivated: Rooms.resetCurrentRoom() |
| 47 |
} |
| 48 |
Label { |
| 49 |
anchors.centerIn: parent |
| 50 |
font.pointSize: 24 |
| 51 |
text: qsTr("No room open") |
| 52 |
color: palette.text |
| 53 |
visible: !room && !TimelineManager.isInitialSync && (!roomPreview || !roomPreview.roomid) |
| 54 |
} |
| 55 |
Spinner { |
| 56 |
anchors.centerIn: parent |
| 57 |
foreground: palette.mid |
| 58 |
// height is somewhat arbitrary here... don't set width because width scales w/ height |
| 59 |
height: parent.height / 16 |
| 60 |
opacity: hh.hovered ? 0.3 : 1 |
| 61 |
running: TimelineManager.isInitialSync |
| 62 |
visible: TimelineManager.isInitialSync |
| 63 |
z: 3 |
| 64 |
|
| 65 |
Behavior on opacity { |
| 66 |
NumberAnimation { |
| 67 |
duration: 100 |
| 68 |
} |
| 69 |
} |
| 70 |
|
| 71 |
HoverHandler { |
| 72 |
id: hh |
| 73 |
|
| 74 |
} |
| 75 |
} |
| 76 |
ColumnLayout { |
| 77 |
id: timelineLayout |
| 78 |
|
| 79 |
anchors.fill: parent |
| 80 |
enabled: visible |
| 81 |
spacing: 0 |
| 82 |
visible: room != null && !room.isSpace |
| 83 |
|
| 84 |
TopBar { |
| 85 |
id: topBar |
| 86 |
|
| 87 |
showBackButton: timelineView.showBackButton |
| 88 |
} |
| 89 |
Rectangle { |
| 90 |
Layout.fillWidth: true |
| 91 |
color: Nheko.theme.separator |
| 92 |
implicitHeight: 1 |
| 93 |
z: 3 |
| 94 |
} |
| 95 |
Rectangle { |
| 96 |
id: msgView |
| 97 |
|
| 98 |
Layout.fillHeight: true |
| 99 |
Layout.fillWidth: true |
| 100 |
color: palette.base |
| 101 |
|
| 102 |
ColumnLayout { |
| 103 |
anchors.fill: parent |
| 104 |
spacing: 0 |
| 105 |
|
| 106 |
StackLayout { |
| 107 |
id: stackLayout |
| 108 |
|
| 109 |
currentIndex: 0 |
| 110 |
|
| 111 |
Connections { |
| 112 |
function onRoomChanged() { |
| 113 |
stackLayout.currentIndex = 0; |
| 114 |
} |
| 115 |
|
| 116 |
target: timelineView |
| 117 |
} |
| 118 |
MessageView { |
| 119 |
Layout.fillWidth: true |
| 120 |
implicitHeight: msgView.height - typingIndicator.height |
| 121 |
searchString: topBar.searchString |
| 122 |
} |
| 123 |
Loader { |
| 124 |
source: CallManager.isOnCall && CallManager.callType != Voip.VOICE ? (Qt.platform.os != "windows" ? "voip/VideoCall.qml" : "voip/VideoCallD3D11.qml") : "" |
| 125 |
|
| 126 |
onLoaded: TimelineManager.setVideoCallItem() |
| 127 |
} |
| 128 |
} |
| 129 |
TypingIndicator { |
| 130 |
id: typingIndicator |
| 131 |
|
| 132 |
} |
| 133 |
} |
| 134 |
} |
| 135 |
CallInviteBar { |
| 136 |
id: callInviteBar |
| 137 |
|
| 138 |
Layout.fillWidth: true |
| 139 |
z: 3 |
| 140 |
} |
| 141 |
ActiveCallBar { |
| 142 |
Layout.fillWidth: true |
| 143 |
z: 3 |
| 144 |
} |
| 145 |
Rectangle { |
| 146 |
Layout.fillWidth: true |
| 147 |
color: Nheko.theme.separator |
| 148 |
implicitHeight: 1 |
| 149 |
z: 3 |
| 150 |
} |
| 151 |
UploadBox { |
| 152 |
} |
| 153 |
Repeater { |
| 154 |
model: room ? room.input.mentions : null |
| 155 |
|
| 156 |
MessageInputWarning { |
| 157 |
required property string modelData |
| 158 |
bubbleColor: modelData == "@room" ? Nheko.theme.error : Nheko.theme.orange |
| 159 |
text: modelData == "@room" ? qsTr("You are about to notify the whole room") : qsTr("You will be mentioning %1").arg(modelData) |
| 160 |
showRemove: true |
| 161 |
onRemoveClicked: room.input.removeMention(modelData); |
| 162 |
} |
| 163 |
} |
| 164 |
MessageInputWarning { |
| 165 |
text: qsTr("The command /%1 is not recognized and will be sent as part of your message").arg(room ? room.input.currentCommand : "") |
| 166 |
visible: room ? room.input.containsInvalidCommand && !room.input.containsIncompleteCommand : false |
| 167 |
} |
| 168 |
MessageInputWarning { |
| 169 |
bubbleColor: Nheko.theme.orange |
| 170 |
text: qsTr("/%1 looks like an incomplete command. To send it anyway, add a space to the end of your message.").arg(room ? room.input.currentCommand : "") |
| 171 |
visible: room ? room.input.containsIncompleteCommand : false |
| 172 |
} |
| 173 |
ReplyPopup { |
| 174 |
} |
| 175 |
MessageInput { |
| 176 |
} |
| 177 |
} |
| 178 |
ColumnLayout { |
| 179 |
id: preview |
| 180 |
|
| 181 |
property string avatarUrl: room ? room.roomAvatarUrl : (roomPreview ? roomPreview.roomAvatarUrl : "") |
| 182 |
property string reason: roomPreview ? roomPreview.reason : "" |
| 183 |
property string roomId: room ? room.roomId : (roomPreview ? roomPreview.roomid : "") |
| 184 |
property string roomName: room ? room.roomName : (roomPreview ? roomPreview.roomName : "") |
| 185 |
property string roomTopic: room ? room.roomTopic : (roomPreview ? roomPreview.roomTopic : "") |
| 186 |
|
| 187 |
anchors.fill: parent |
| 188 |
anchors.margins: Nheko.paddingLarge |
| 189 |
enabled: visible |
| 190 |
spacing: Nheko.paddingLarge |
| 191 |
visible: room != null && room.isSpace || roomPreview != null |
| 192 |
|
| 193 |
Item { |
| 194 |
Layout.fillHeight: true |
| 195 |
Layout.fillWidth: true |
| 196 |
} |
| 197 |
Avatar { |
| 198 |
Layout.alignment: Qt.AlignHCenter |
| 199 |
displayName: parent.roomName |
| 200 |
enabled: false |
| 201 |
implicitHeight: 130 |
| 202 |
roomid: parent.roomId |
| 203 |
url: parent.avatarUrl.replace("mxc://", "image://MxcImage/") |
| 204 |
implicitWidth: 130 |
| 205 |
} |
| 206 |
|
| 207 |
MatrixText { |
| 208 |
horizontalAlignment: TextEdit.AlignHCenter |
| 209 |
Layout.fillWidth: true |
| 210 |
font.pixelSize: 24 |
| 211 |
text: (!room && !(roomPreview?.isFetched ?? false)) ? qsTr("No preview available") : preview.roomName |
| 212 |
|
| 213 |
} |
| 214 |
ImageButton { |
| 215 |
Layout.alignment: Qt.AlignHCenter |
| 216 |
ToolTip.text: qsTr("Settings") |
| 217 |
ToolTip.visible: hovered |
| 218 |
Layout.bottomMargin: Nheko.paddingMedium |
| 219 |
|
| 220 |
hoverEnabled: true |
| 221 |
image: ":/icons/icons/ui/settings.svg" |
| 222 |
visible: !!room |
| 223 |
|
| 224 |
onClicked: TimelineManager.openRoomSettings(room.roomId) |
| 225 |
} |
| 226 |
|
| 227 |
RowLayout { |
| 228 |
Layout.alignment: Qt.AlignHCenter |
| 229 |
spacing: Nheko.paddingMedium |
| 230 |
visible: !!room |
| 231 |
Layout.fillWidth: true |
| 232 |
|
| 233 |
MatrixText { |
| 234 |
Layout.preferredWidth: contentWidth |
| 235 |
text: qsTr("%n member(s)", "", room ? room.roomMemberCount : 0) |
| 236 |
} |
| 237 |
ImageButton { |
| 238 |
ToolTip.text: qsTr("View members of %1").arg(room ? room.roomName : "") |
| 239 |
ToolTip.visible: hovered |
| 240 |
hoverEnabled: true |
| 241 |
image: ":/icons/icons/ui/people.svg" |
| 242 |
|
| 243 |
onClicked: TimelineManager.openRoomMembers(room) |
| 244 |
} |
| 245 |
} |
| 246 |
ScrollView { |
| 247 |
Layout.alignment: Qt.AlignHCenter |
| 248 |
Layout.fillWidth: true |
| 249 |
Layout.leftMargin: Nheko.paddingLarge |
| 250 |
Layout.rightMargin: Nheko.paddingLarge |
| 251 |
Layout.maximumHeight: timelineView.height / 3 |
| 252 |
|
| 253 |
MatrixText { |
| 254 |
background: null |
| 255 |
horizontalAlignment: TextEdit.AlignHCenter |
| 256 |
text: (room || (roomPreview?.isFetched ?? false)) ? TimelineManager.escapeEmoji(preview.roomTopic) : qsTr("This room is possibly inaccessible. If this room is private, you should remove it from this community.") |
| 257 |
textFormat: TextEdit.RichText |
| 258 |
} |
| 259 |
} |
| 260 |
FlatButton { |
| 261 |
Layout.alignment: Qt.AlignHCenter |
| 262 |
text: qsTr("join the conversation") |
| 263 |
visible: roomPreview && !roomPreview.isInvite |
| 264 |
|
| 265 |
onClicked: Rooms.joinPreview(roomPreview.roomid) |
| 266 |
} |
| 267 |
FlatButton { |
| 268 |
Layout.alignment: Qt.AlignHCenter |
| 269 |
text: qsTr("accept invite") |
| 270 |
visible: roomPreview && roomPreview.isInvite |
| 271 |
|
| 272 |
onClicked: Rooms.acceptInvite(roomPreview.roomid) |
| 273 |
} |
| 274 |
FlatButton { |
| 275 |
Layout.alignment: Qt.AlignHCenter |
| 276 |
text: qsTr("decline invite") |
| 277 |
visible: roomPreview && roomPreview.isInvite |
| 278 |
|
| 279 |
onClicked: Rooms.declineInvite(roomPreview.roomid) |
| 280 |
} |
| 281 |
FlatButton { |
| 282 |
Layout.alignment: Qt.AlignHCenter |
| 283 |
text: qsTr("decline invite and ignore user") |
| 284 |
visible: roomPreview && roomPreview.isInvite |
| 285 |
|
| 286 |
onClicked: { |
| 287 |
var inviter = TimelineManager.getGlobalUserProfile(roomPreview.inviterUserId) |
| 288 |
inviter.ignored = true |
| 289 |
} |
| 290 |
} |
| 291 |
FlatButton { |
| 292 |
Layout.alignment: Qt.AlignHCenter |
| 293 |
text: qsTr("leave") |
| 294 |
visible: !!room |
| 295 |
|
| 296 |
onClicked: TimelineManager.openLeaveRoomDialog(room.roomId) |
| 297 |
} |
| 298 |
RowLayout { |
| 299 |
Layout.alignment: Qt.AlignHCenter |
| 300 |
Layout.fillWidth: true |
| 301 |
spacing: Nheko.paddingMedium |
| 302 |
visible: roomPreview && roomPreview.isInvite && reasonField.showReason |
| 303 |
|
| 304 |
MatrixText { |
| 305 |
Layout.maximumWidth: contentWidth |
| 306 |
Layout.preferredWidth: contentWidth |
| 307 |
Layout.fillWidth: true |
| 308 |
text: qsTr("Invited by %1 (%2)").arg(TimelineManager.escapeEmoji(inviterAvatar.displayName)).arg(TimelineManager.escapeEmoji(TimelineManager.htmlEscape(inviterAvatar.userid))) |
| 309 |
} |
| 310 |
Avatar { |
| 311 |
id: inviterAvatar |
| 312 |
|
| 313 |
Layout.alignment: Qt.AlignHCenter |
| 314 |
displayName: roomPreview?.inviterDisplayName ?? "" |
| 315 |
enabled: true |
| 316 |
implicitHeight: 48 |
| 317 |
roomid: preview.roomId |
| 318 |
url: (roomPreview?.inviterAvatarUrl ?? "").replace("mxc://", "image://MxcImage/") |
| 319 |
userid: roomPreview?.inviterUserId ?? "" |
| 320 |
implicitWidth: 48 |
| 321 |
|
| 322 |
onClicked: TimelineManager.openGlobalUserProfile(roomPreview.inviterUserId) |
| 323 |
} |
| 324 |
} |
| 325 |
ScrollView { |
| 326 |
id: reasonField |
| 327 |
|
| 328 |
property bool showReason: false |
| 329 |
|
| 330 |
Layout.alignment: Qt.AlignHCenter |
| 331 |
Layout.fillWidth: true |
| 332 |
visible: preview.reason !== "" && showReason |
| 333 |
|
| 334 |
TextArea { |
| 335 |
background: null |
| 336 |
horizontalAlignment: TextEdit.AlignHCenter |
| 337 |
readOnly: true |
| 338 |
selectByMouse: true |
| 339 |
text: TimelineManager.escapeEmoji(preview.reason) |
| 340 |
textFormat: TextEdit.RichText |
| 341 |
wrapMode: TextEdit.WordWrap |
| 342 |
} |
| 343 |
} |
| 344 |
Button { |
| 345 |
id: showReasonButton |
| 346 |
|
| 347 |
Layout.alignment: Qt.AlignHCenter |
| 348 |
//Layout.fillWidth: true |
| 349 |
Layout.leftMargin: Nheko.paddingLarge |
| 350 |
Layout.rightMargin: Nheko.paddingLarge |
| 351 |
text: reasonField.showReason ? qsTr("Hide invite reason") : qsTr("Show invite reason") |
| 352 |
visible: roomPreview && roomPreview.isInvite |
| 353 |
|
| 354 |
onClicked: { |
| 355 |
reasonField.showReason = !reasonField.showReason; |
| 356 |
} |
| 357 |
} |
| 358 |
Item { |
| 359 |
Layout.preferredHeight: Math.ceil(fontMetrics.lineSpacing * 2) |
| 360 |
visible: room != null |
| 361 |
} |
| 362 |
Item { |
| 363 |
Layout.fillHeight: true |
| 364 |
} |
| 365 |
} |
| 366 |
|
| 367 |
ImageButton { |
| 368 |
id: backToRoomsButton |
| 369 |
|
| 370 |
ToolTip.text: qsTr("Back to room list") |
| 371 |
ToolTip.visible: hovered |
| 372 |
anchors.left: parent.left |
| 373 |
anchors.margins: Nheko.paddingMedium |
| 374 |
anchors.top: parent.top |
| 375 |
enabled: visible |
| 376 |
height: Nheko.avatarSize |
| 377 |
image: ":/icons/icons/ui/angle-arrow-left.svg" |
| 378 |
visible: (room == null || room.isSpace) && showBackButton |
| 379 |
width: Nheko.avatarSize |
| 380 |
|
| 381 |
onClicked: Rooms.resetCurrentRoom() |
| 382 |
} |
| 383 |
TimelineEffects { |
| 384 |
id: timelineEffects |
| 385 |
|
| 386 |
anchors.fill: parent |
| 387 |
shouldEffectsRun: timelineView.shouldEffectsRun |
| 388 |
} |
| 389 |
NhekoDropArea { |
| 390 |
anchors.fill: parent |
| 391 |
roomid: room ? room.roomId : "" |
| 392 |
} |
| 393 |
Timer { |
| 394 |
id: effectsTimer |
| 395 |
|
| 396 |
interval: timelineEffects.maxLifespan |
| 397 |
repeat: false |
| 398 |
running: false |
| 399 |
|
| 400 |
onTriggered: { |
| 401 |
timelineEffects.removeParticles() |
| 402 |
shouldEffectsRun = false |
| 403 |
} |
| 404 |
} |
| 405 |
Connections { |
| 406 |
function onConfetti() { |
| 407 |
if (!Settings.fancyEffects) |
| 408 |
return; |
| 409 |
shouldEffectsRun = true; |
| 410 |
timelineEffects.pulseConfetti(); |
| 411 |
room.markSpecialEffectsDone(); |
| 412 |
} |
| 413 |
function onConfettiDone() { |
| 414 |
if (!Settings.fancyEffects) |
| 415 |
return; |
| 416 |
effectsTimer.restart(); |
| 417 |
} |
| 418 |
function onOpenReadReceiptsDialog(rr) { |
| 419 |
var dialog = readReceiptsDialog.createObject(timelineRoot, { |
| 420 |
"readReceipts": rr, |
| 421 |
"room": room |
| 422 |
}); |
| 423 |
dialog.show(); |
| 424 |
timelineRoot.destroyOnClose(dialog); |
| 425 |
} |
| 426 |
function onRainfall() { |
| 427 |
if (!Settings.fancyEffects) |
| 428 |
return; |
| 429 |
shouldEffectsRun = true; |
| 430 |
timelineEffects.pulseRainfall(); |
| 431 |
room.markSpecialEffectsDone(); |
| 432 |
} |
| 433 |
function onRainfallDone() { |
| 434 |
if (!Settings.fancyEffects) |
| 435 |
return; |
| 436 |
effectsTimer.restart(); |
| 437 |
} |
| 438 |
function onShowRawMessageDialog(rawMessage) { |
| 439 |
var component = Qt.createComponent("qrc:/resources/qml/dialogs/RawMessageDialog.qml"); |
| 440 |
if (component.status == Component.Ready) { |
| 441 |
var dialog = component.createObject(timelineRoot, { |
| 442 |
"rawMessage": rawMessage |
| 443 |
}); |
| 444 |
dialog.show(); |
| 445 |
timelineRoot.destroyOnClose(dialog); |
| 446 |
} else { |
| 447 |
console.error("Failed to create component: " + component.errorString()); |
| 448 |
} |
| 449 |
} |
| 450 |
|
| 451 |
target: room |
| 452 |
} |
| 453 |
} |