2020-04-02 06:15:49 +11:00
|
|
|
// SPDX-License-Identifier: LGPL-3.0-or-later
|
|
|
|
|
2019-07-13 19:39:01 +10:00
|
|
|
import QtQuick 2.12
|
|
|
|
import QtQuick.Layouts 1.12
|
2019-12-28 00:06:42 +11:00
|
|
|
import Clipboard 0.1
|
2019-12-03 07:29:29 +11:00
|
|
|
import "../../.."
|
2019-12-18 19:53:08 +11:00
|
|
|
import "../../../Base"
|
2019-03-22 14:28:14 +11:00
|
|
|
|
2019-12-17 18:45:00 +11:00
|
|
|
HColumnLayout {
|
2019-07-20 13:07:26 +10:00
|
|
|
id: eventDelegate
|
2019-09-03 17:04:57 +10:00
|
|
|
width: eventList.width
|
|
|
|
|
2020-03-27 20:05:25 +11:00
|
|
|
ListView.onRemove: eventList.uncheck(model.id)
|
2020-03-26 14:06:51 +11:00
|
|
|
|
2019-03-22 14:28:14 +11:00
|
|
|
|
2019-09-15 08:33:32 +10:00
|
|
|
enum Media { Page, File, Image, Video, Audio }
|
|
|
|
|
|
|
|
property var hoveredMediaTypeUrl: []
|
|
|
|
|
2020-05-20 17:42:40 +10:00
|
|
|
property var fetchProfilesFuture: null
|
|
|
|
|
2019-07-20 13:07:26 +10:00
|
|
|
// Remember timeline goes from newest message at index 0 to oldest
|
2019-12-17 18:45:00 +11:00
|
|
|
readonly property var previousModel: eventList.model.get(model.index + 1)
|
|
|
|
readonly property var nextModel: eventList.model.get(model.index - 1)
|
|
|
|
readonly property QtObject currentModel: model
|
2019-07-03 13:32:39 +10:00
|
|
|
|
2020-03-27 20:05:25 +11:00
|
|
|
property bool checked: model.id in eventList.checked
|
2020-03-23 04:30:03 +11:00
|
|
|
property bool compact: window.settings.compactMode
|
2019-12-09 20:25:31 +11:00
|
|
|
property bool isOwn: chat.userId === model.sender_id
|
2020-05-17 04:36:00 +10:00
|
|
|
property bool onRight: ! eventList.ownEventsOnLeft && isOwn
|
2019-12-17 18:45:00 +11:00
|
|
|
property bool combine: eventList.canCombine(previousModel, model)
|
|
|
|
property bool talkBreak: eventList.canTalkBreak(previousModel, model)
|
|
|
|
property bool dayBreak: eventList.canDayBreak(previousModel, model)
|
2019-07-20 10:55:52 +10:00
|
|
|
|
2020-03-24 07:10:13 +11:00
|
|
|
readonly property bool smallAvatar: compact
|
2019-07-20 13:07:26 +10:00
|
|
|
readonly property bool collapseAvatar: combine
|
|
|
|
readonly property bool hideAvatar: onRight
|
2020-03-30 09:06:13 +11:00
|
|
|
readonly property bool isRedacted: model.event_type === "RedactedEvent"
|
2019-03-22 14:28:14 +11:00
|
|
|
|
2019-07-20 13:07:26 +10:00
|
|
|
readonly property bool hideNameLine:
|
2019-11-05 05:37:25 +11:00
|
|
|
model.event_type === "RoomMessageEmote" ||
|
2019-11-05 05:45:20 +11:00
|
|
|
! (
|
|
|
|
model.event_type.startsWith("RoomMessage") ||
|
|
|
|
model.event_type.startsWith("RoomEncrypted")
|
|
|
|
) ||
|
2019-07-20 13:07:26 +10:00
|
|
|
onRight ||
|
|
|
|
combine
|
2019-04-20 17:29:24 +10:00
|
|
|
|
2019-09-15 08:33:32 +10:00
|
|
|
readonly property int cursorShape:
|
|
|
|
eventContent.hoveredLink || hoveredMediaTypeUrl.length > 0 ?
|
|
|
|
Qt.PointingHandCursor :
|
|
|
|
|
|
|
|
eventContent.hoveredSelectable ? Qt.IBeamCursor :
|
|
|
|
|
|
|
|
Qt.ArrowCursor
|
|
|
|
|
2019-12-17 18:45:00 +11:00
|
|
|
readonly property int separationSpacing:
|
|
|
|
dayBreak ? theme.spacing * 4 :
|
|
|
|
talkBreak ? theme.spacing * 6 :
|
2020-03-23 04:20:16 +11:00
|
|
|
combine ? theme.spacing / (compact ? 4 : 2) :
|
|
|
|
theme.spacing * (compact ? 1 : 2)
|
2019-12-17 18:45:00 +11:00
|
|
|
|
2020-03-27 19:49:01 +11:00
|
|
|
readonly property alias eventContent: eventContent
|
|
|
|
|
2019-09-15 08:33:32 +10:00
|
|
|
// Needed because of eventList's MouseArea which steals the
|
|
|
|
// HSelectableLabel's MouseArea hover events
|
|
|
|
onCursorShapeChanged: eventList.cursorShape = cursorShape
|
|
|
|
|
2020-05-20 17:42:40 +10:00
|
|
|
Component.onCompleted: if (model.fetch_profile) py.callClientCoro(
|
|
|
|
chat.userId, "get_event_profiles", [chat.roomId, model.id],
|
|
|
|
)
|
|
|
|
|
|
|
|
Component.onDestruction:
|
|
|
|
if (fetchProfilesFuture) fetchProfilesFuture.cancel()
|
|
|
|
|
2019-09-01 19:16:47 +10:00
|
|
|
|
2019-09-06 06:24:49 +10:00
|
|
|
function json() {
|
2020-02-13 04:04:46 +11:00
|
|
|
let event = ModelStore.get(chat.userId, chat.roomId, "events")
|
2020-03-20 09:49:33 +11:00
|
|
|
.get(model.index)
|
2020-02-13 04:04:46 +11:00
|
|
|
event = JSON.parse(JSON.stringify(event))
|
|
|
|
event.source = JSON.parse(event.source)
|
|
|
|
return JSON.stringify(event, null, 4)
|
2019-09-06 06:24:49 +10:00
|
|
|
}
|
|
|
|
|
2019-09-15 08:52:43 +10:00
|
|
|
function openContextMenu() {
|
|
|
|
contextMenu.media = eventDelegate.hoveredMediaTypeUrl
|
|
|
|
contextMenu.link = eventContent.hoveredLink
|
|
|
|
contextMenu.popup()
|
|
|
|
}
|
|
|
|
|
2020-03-26 14:06:51 +11:00
|
|
|
function toggleChecked() {
|
2020-03-27 20:05:25 +11:00
|
|
|
eventList.toggleCheck(model.index)
|
2020-03-26 14:06:51 +11:00
|
|
|
}
|
|
|
|
|
2019-09-06 06:24:49 +10:00
|
|
|
|
2019-12-17 18:45:00 +11:00
|
|
|
Item {
|
|
|
|
Layout.fillWidth: true
|
|
|
|
Layout.preferredHeight:
|
|
|
|
model.event_type === "RoomCreateEvent" ? 0 : separationSpacing
|
|
|
|
}
|
|
|
|
|
2019-07-20 16:21:12 +10:00
|
|
|
Daybreak {
|
|
|
|
visible: dayBreak
|
2019-12-17 18:45:00 +11:00
|
|
|
|
|
|
|
Layout.fillWidth: true
|
|
|
|
Layout.minimumWidth: parent.width
|
2019-04-29 04:48:59 +10:00
|
|
|
}
|
2019-03-22 14:28:14 +11:00
|
|
|
|
2019-07-20 16:27:17 +10:00
|
|
|
Item {
|
|
|
|
visible: dayBreak
|
2019-12-17 18:45:00 +11:00
|
|
|
|
|
|
|
Layout.fillWidth: true
|
|
|
|
Layout.preferredHeight: separationSpacing
|
2019-07-20 16:27:17 +10:00
|
|
|
}
|
|
|
|
|
2019-07-03 12:29:09 +10:00
|
|
|
EventContent {
|
2019-09-02 09:03:32 +10:00
|
|
|
id: eventContent
|
2019-12-17 18:45:00 +11:00
|
|
|
|
|
|
|
Layout.fillWidth: true
|
2019-09-02 09:03:32 +10:00
|
|
|
|
2019-12-16 19:42:41 +11:00
|
|
|
Behavior on x { HNumberAnimation {} }
|
2019-04-29 04:48:59 +10:00
|
|
|
}
|
2019-09-02 09:03:32 +10:00
|
|
|
|
2020-03-26 14:06:51 +11:00
|
|
|
TapHandler {
|
|
|
|
acceptedButtons: Qt.LeftButton
|
2020-03-27 14:24:37 +11:00
|
|
|
acceptedModifiers: Qt.NoModifier
|
2020-03-26 14:06:51 +11:00
|
|
|
onTapped: toggleChecked()
|
|
|
|
}
|
2019-09-02 09:03:32 +10:00
|
|
|
|
2020-03-27 14:24:37 +11:00
|
|
|
TapHandler {
|
|
|
|
acceptedButtons: Qt.LeftButton
|
|
|
|
acceptedModifiers: Qt.ShiftModifier
|
2020-03-27 20:05:25 +11:00
|
|
|
onTapped: eventList.checkFromLastToHere(model.index)
|
2020-03-27 14:24:37 +11:00
|
|
|
}
|
|
|
|
|
2019-09-02 09:03:32 +10:00
|
|
|
TapHandler {
|
|
|
|
acceptedButtons: Qt.RightButton
|
2020-03-25 04:52:48 +11:00
|
|
|
acceptedPointerTypes: PointerDevice.GenericPointer | PointerDevice.Pen
|
2019-09-15 08:52:43 +10:00
|
|
|
onTapped: openContextMenu()
|
2019-09-02 09:03:32 +10:00
|
|
|
}
|
|
|
|
|
2020-03-25 01:42:41 +11:00
|
|
|
TapHandler {
|
|
|
|
acceptedPointerTypes: PointerDevice.Finger | PointerDevice.Pen
|
|
|
|
onLongPressed: openContextMenu()
|
|
|
|
}
|
|
|
|
|
2019-09-02 09:03:32 +10:00
|
|
|
HMenu {
|
|
|
|
id: contextMenu
|
|
|
|
|
2019-09-15 08:33:32 +10:00
|
|
|
property var media: []
|
2019-09-02 09:03:32 +10:00
|
|
|
property string link: ""
|
|
|
|
|
2019-09-15 08:33:32 +10:00
|
|
|
onClosed: { media = []; link = "" }
|
2019-09-03 17:04:57 +10:00
|
|
|
|
2020-03-26 14:06:51 +11:00
|
|
|
HMenuItem {
|
|
|
|
icon.name: "toggle-select-message"
|
2020-03-27 22:06:38 +11:00
|
|
|
text: eventDelegate.checked ? qsTr("Deselect") : qsTr("Select")
|
2020-03-26 14:06:51 +11:00
|
|
|
onTriggered: eventDelegate.toggleChecked()
|
|
|
|
}
|
|
|
|
|
|
|
|
HMenuItem {
|
|
|
|
visible: eventList.selectedCount >= 2
|
2020-03-27 22:06:38 +11:00
|
|
|
icon.name: "deselect-all-messages"
|
|
|
|
text: qsTr("Deselect all")
|
2020-03-27 20:05:25 +11:00
|
|
|
onTriggered: eventList.checked = {}
|
2020-03-26 14:06:51 +11:00
|
|
|
}
|
|
|
|
|
2020-03-27 14:24:37 +11:00
|
|
|
HMenuItem {
|
|
|
|
visible: model.index !== 0
|
|
|
|
icon.name: "select-until-here"
|
|
|
|
text: qsTr("Select until here")
|
2020-03-27 20:05:25 +11:00
|
|
|
onTriggered: eventList.checkFromLastToHere(model.index)
|
2020-03-27 14:24:37 +11:00
|
|
|
}
|
|
|
|
|
2019-09-03 17:04:57 +10:00
|
|
|
HMenuItem {
|
2019-09-15 08:33:32 +10:00
|
|
|
id: copyMedia
|
2019-09-03 17:04:57 +10:00
|
|
|
icon.name: "copy-link"
|
2019-09-15 08:33:32 +10:00
|
|
|
text:
|
|
|
|
contextMenu.media.length < 1 ? "" :
|
|
|
|
|
|
|
|
contextMenu.media[0] === EventDelegate.Media.Page ?
|
|
|
|
qsTr("Copy page address") :
|
|
|
|
|
|
|
|
contextMenu.media[0] === EventDelegate.Media.File ?
|
|
|
|
qsTr("Copy file address") :
|
|
|
|
|
|
|
|
contextMenu.media[0] === EventDelegate.Media.Image ?
|
|
|
|
qsTr("Copy image address") :
|
|
|
|
|
2019-09-18 13:23:47 +10:00
|
|
|
contextMenu.media[0] === EventDelegate.Media.Video ?
|
|
|
|
qsTr("Copy video address") :
|
|
|
|
|
|
|
|
contextMenu.media[0] === EventDelegate.Media.Audio ?
|
|
|
|
qsTr("Copy audio address") :
|
|
|
|
|
2019-09-15 08:33:32 +10:00
|
|
|
qsTr("Copy media address")
|
|
|
|
|
|
|
|
visible: Boolean(text)
|
2019-10-25 23:42:04 +11:00
|
|
|
onTriggered: Clipboard.text = contextMenu.media[1]
|
2019-09-03 17:04:57 +10:00
|
|
|
}
|
2019-09-02 09:03:32 +10:00
|
|
|
|
|
|
|
HMenuItem {
|
|
|
|
id: copyLink
|
|
|
|
icon.name: "copy-link"
|
|
|
|
text: qsTr("Copy link address")
|
|
|
|
visible: Boolean(contextMenu.link)
|
2019-10-25 23:42:04 +11:00
|
|
|
onTriggered: Clipboard.text = contextMenu.link
|
2019-09-02 09:03:32 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
HMenuItem {
|
|
|
|
icon.name: "copy-text"
|
2020-03-27 12:34:51 +11:00
|
|
|
text:
|
|
|
|
eventList.selectedCount ?
|
|
|
|
qsTr("Copy selection") :
|
|
|
|
|
|
|
|
copyMedia.visible ?
|
|
|
|
qsTr("Copy filename") :
|
|
|
|
|
|
|
|
qsTr("Copy text")
|
|
|
|
|
2020-03-26 14:06:51 +11:00
|
|
|
onTriggered: {
|
2020-04-03 20:36:55 +11:00
|
|
|
if (! eventList.selectedCount && ! eventList.currentItem){
|
2020-03-26 14:06:51 +11:00
|
|
|
Clipboard.text = JSON.parse(model.source).body
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-03-27 12:23:43 +11:00
|
|
|
eventList.copySelectedDelegates()
|
2020-03-26 14:06:51 +11:00
|
|
|
}
|
2019-09-02 09:03:32 +10:00
|
|
|
}
|
2019-09-06 06:09:04 +10:00
|
|
|
|
2020-03-27 07:31:57 +11:00
|
|
|
HMenuItemPopupSpawner {
|
|
|
|
icon.name: "remove-message"
|
|
|
|
text: qsTr("Remove")
|
2020-04-03 21:13:45 +11:00
|
|
|
enabled: properties.eventSenderAndIds.length
|
2020-03-27 07:31:57 +11:00
|
|
|
|
2020-04-02 06:15:49 +11:00
|
|
|
popup: "Popups/RedactPopup.qml"
|
2020-03-27 07:31:57 +11:00
|
|
|
popupParent: chat
|
|
|
|
properties: ({
|
2020-04-03 21:13:45 +11:00
|
|
|
preferUserId: chat.userId,
|
2020-03-27 07:31:57 +11:00
|
|
|
roomId: chat.roomId,
|
2020-04-03 21:50:24 +11:00
|
|
|
eventSenderAndIds: events.map(ev => [ev.sender_id, ev.id]),
|
2020-04-02 06:15:49 +11:00
|
|
|
|
|
|
|
onlyOwnMessageWarning:
|
|
|
|
! chat.roomInfo.can_redact_all &&
|
2020-04-03 01:19:43 +11:00
|
|
|
events.length < eventList.selectedCount
|
2020-03-27 07:31:57 +11:00
|
|
|
})
|
2020-04-02 06:15:49 +11:00
|
|
|
|
2020-04-03 01:19:43 +11:00
|
|
|
readonly property var events: {
|
|
|
|
eventList.selectedCount ?
|
|
|
|
eventList.redactableCheckedEvents :
|
|
|
|
|
|
|
|
eventList.canRedact(currentModel) ?
|
|
|
|
[model] :
|
|
|
|
|
|
|
|
[]
|
|
|
|
}
|
2020-03-27 07:31:57 +11:00
|
|
|
}
|
|
|
|
|
2019-12-21 01:39:10 +11:00
|
|
|
HMenuItem {
|
|
|
|
icon.name: "debug"
|
|
|
|
text: qsTr("Debug this event")
|
2020-04-01 20:37:44 +11:00
|
|
|
onTriggered:
|
|
|
|
mainUI.debugConsole.toggle(eventContent, "t.parent.json()")
|
2019-12-21 01:39:10 +11:00
|
|
|
}
|
|
|
|
|
2019-12-21 01:29:45 +11:00
|
|
|
HMenuItemPopupSpawner {
|
2019-09-09 01:40:39 +10:00
|
|
|
icon.name: "clear-messages"
|
|
|
|
text: qsTr("Clear messages")
|
2019-12-21 01:29:45 +11:00
|
|
|
|
|
|
|
popup: "Popups/ClearMessagesPopup.qml"
|
|
|
|
popupParent: chat
|
|
|
|
properties: ({userId: chat.userId, roomId: chat.roomId})
|
2019-09-09 01:40:39 +10:00
|
|
|
}
|
2019-09-02 09:03:32 +10:00
|
|
|
}
|
2019-03-22 14:28:14 +11:00
|
|
|
}
|