2020-04-01 15:15:49 -04:00
|
|
|
// SPDX-License-Identifier: LGPL-3.0-or-later
|
|
|
|
|
2019-07-13 05:39:01 -04:00
|
|
|
import QtQuick 2.12
|
|
|
|
import QtQuick.Layouts 1.12
|
2019-12-27 09:06:42 -04:00
|
|
|
import Clipboard 0.1
|
2019-12-02 16:29:29 -04:00
|
|
|
import "../../.."
|
2019-12-18 04:53:08 -04:00
|
|
|
import "../../../Base"
|
2020-07-20 00:22:12 -04:00
|
|
|
import "../../../PythonBridge"
|
2019-03-21 23:28:14 -04:00
|
|
|
|
2019-12-17 03:45:00 -04:00
|
|
|
HColumnLayout {
|
2019-07-19 23:07:26 -04:00
|
|
|
id: eventDelegate
|
2019-03-21 23:28:14 -04:00
|
|
|
|
2020-07-20 00:22:12 -04:00
|
|
|
property var hoveredMediaTypeUrl: [] // [] or [mediaType, url, title]
|
2019-09-14 18:33:32 -04:00
|
|
|
|
2020-05-20 03:42:40 -04:00
|
|
|
property var fetchProfilesFuture: null
|
|
|
|
|
2019-07-19 23:07:26 -04:00
|
|
|
// Remember timeline goes from newest message at index 0 to oldest
|
2019-12-17 03:45:00 -04: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-02 23:32:39 -04:00
|
|
|
|
2020-09-01 12:45:55 -04:00
|
|
|
readonly property bool compact: window.settings.compactMode
|
|
|
|
readonly property bool checked: model.id in eventList.checked
|
|
|
|
readonly property bool isOwn: chat.userId === model.sender_id
|
2020-03-29 19:06:13 -03:00
|
|
|
readonly property bool isRedacted: model.event_type === "RedactedEvent"
|
2020-09-01 12:45:55 -04:00
|
|
|
readonly property bool onRight: ! eventList.ownEventsOnLeft && isOwn
|
|
|
|
readonly property bool combine: eventList.canCombine(previousModel, model)
|
2020-09-01 13:22:51 -04:00
|
|
|
readonly property bool asOneLine: eventList.renderEventAsOneLine(model)
|
2020-09-01 12:45:55 -04:00
|
|
|
readonly property bool talkBreak:
|
|
|
|
eventList.canTalkBreak(previousModel, model)
|
|
|
|
readonly property bool dayBreak:
|
|
|
|
eventList.canDayBreak(previousModel, model)
|
2019-03-21 23:28:14 -04:00
|
|
|
|
2019-09-14 18:33:32 -04:00
|
|
|
readonly property int cursorShape:
|
2020-07-20 00:22:12 -04:00
|
|
|
eventContent.hoveredLink || hoveredMediaTypeUrl.length === 3 ?
|
2019-09-14 18:33:32 -04:00
|
|
|
Qt.PointingHandCursor :
|
|
|
|
|
|
|
|
eventContent.hoveredSelectable ? Qt.IBeamCursor :
|
|
|
|
|
|
|
|
Qt.ArrowCursor
|
|
|
|
|
2019-12-17 03:45:00 -04:00
|
|
|
readonly property int separationSpacing:
|
2020-09-01 13:29:27 -04:00
|
|
|
dayBreak ? theme.spacing * 4 :
|
|
|
|
talkBreak ? theme.spacing * 6 :
|
|
|
|
combine ? theme.spacing / (compact ? 4 : 2) :
|
|
|
|
theme.spacing * (compact ? 1 : 2)
|
2019-12-17 03:45:00 -04:00
|
|
|
|
2020-03-27 04:49:01 -04:00
|
|
|
readonly property alias eventContent: eventContent
|
|
|
|
|
2019-09-05 16:24:49 -04:00
|
|
|
function json() {
|
2020-02-12 13:04:46 -04:00
|
|
|
let event = ModelStore.get(chat.userId, chat.roomId, "events")
|
2020-03-19 18:49:33 -04:00
|
|
|
.get(model.index)
|
2020-02-12 13:04:46 -04:00
|
|
|
event = JSON.parse(JSON.stringify(event))
|
|
|
|
event.source = JSON.parse(event.source)
|
|
|
|
return JSON.stringify(event, null, 4)
|
2019-09-05 16:24:49 -04:00
|
|
|
}
|
|
|
|
|
2019-09-14 18:52:43 -04:00
|
|
|
function openContextMenu() {
|
2020-09-02 09:47:42 -04:00
|
|
|
eventList.contextMenu.spawn(
|
|
|
|
model.index,
|
|
|
|
eventDelegate,
|
|
|
|
hoveredMediaTypeUrl,
|
|
|
|
eventContent.hoveredLink,
|
|
|
|
)
|
2019-09-14 18:52:43 -04:00
|
|
|
}
|
|
|
|
|
2020-03-25 23:06:51 -04:00
|
|
|
function toggleChecked() {
|
2020-03-27 05:05:25 -04:00
|
|
|
eventList.toggleCheck(model.index)
|
2020-03-25 23:06:51 -04:00
|
|
|
}
|
|
|
|
|
2019-09-05 16:24:49 -04:00
|
|
|
|
2020-07-12 00:25:57 -04:00
|
|
|
width: eventList.width - eventList.leftMargin - eventList.rightMargin
|
|
|
|
|
|
|
|
// Needed because of eventList's MouseArea which steals the
|
|
|
|
// HSelectableLabel's MouseArea hover events
|
|
|
|
onCursorShapeChanged: eventList.cursorShape = cursorShape
|
|
|
|
|
2020-07-27 04:22:34 -04:00
|
|
|
Component.onCompleted: if (model.fetch_profile)
|
|
|
|
fetchProfilesFuture = py.callClientCoro(
|
|
|
|
chat.userId,
|
|
|
|
"get_event_profiles",
|
|
|
|
[chat.roomId, model.id],
|
|
|
|
() => { fetchProfilesFuture = null }
|
|
|
|
)
|
2020-07-12 00:25:57 -04:00
|
|
|
|
|
|
|
Component.onDestruction:
|
|
|
|
if (fetchProfilesFuture) fetchProfilesFuture.cancel()
|
|
|
|
|
|
|
|
ListView.onRemove: eventList.uncheck(model.id)
|
|
|
|
|
2019-12-17 03:45:00 -04:00
|
|
|
Item {
|
|
|
|
Layout.fillWidth: true
|
2020-07-18 15:02:19 -04:00
|
|
|
visible: model.event_type !== "RoomCreateEvent"
|
|
|
|
Layout.preferredHeight: separationSpacing
|
2019-12-17 03:45:00 -04:00
|
|
|
}
|
|
|
|
|
2019-07-20 02:21:12 -04:00
|
|
|
Daybreak {
|
|
|
|
visible: dayBreak
|
2019-12-17 03:45:00 -04:00
|
|
|
|
|
|
|
Layout.fillWidth: true
|
|
|
|
Layout.minimumWidth: parent.width
|
2020-07-18 15:02:19 -04:00
|
|
|
Layout.bottomMargin: separationSpacing
|
2019-07-20 02:27:17 -04:00
|
|
|
}
|
|
|
|
|
2019-07-02 22:29:09 -04:00
|
|
|
EventContent {
|
2019-09-01 19:03:32 -04:00
|
|
|
id: eventContent
|
2019-12-17 03:45:00 -04:00
|
|
|
|
|
|
|
Layout.fillWidth: true
|
2019-09-01 19:03:32 -04:00
|
|
|
|
2019-12-16 04:42:41 -04:00
|
|
|
Behavior on x { HNumberAnimation {} }
|
2019-04-28 14:48:59 -04:00
|
|
|
}
|
2019-09-01 19:03:32 -04:00
|
|
|
|
2020-03-25 23:06:51 -04:00
|
|
|
TapHandler {
|
|
|
|
acceptedButtons: Qt.LeftButton
|
2020-03-26 23:24:37 -04:00
|
|
|
acceptedModifiers: Qt.NoModifier
|
2020-03-25 23:06:51 -04:00
|
|
|
onTapped: toggleChecked()
|
|
|
|
}
|
2019-09-01 19:03:32 -04:00
|
|
|
|
2020-03-26 23:24:37 -04:00
|
|
|
TapHandler {
|
|
|
|
acceptedButtons: Qt.LeftButton
|
|
|
|
acceptedModifiers: Qt.ShiftModifier
|
2020-03-27 05:05:25 -04:00
|
|
|
onTapped: eventList.checkFromLastToHere(model.index)
|
2020-03-26 23:24:37 -04:00
|
|
|
}
|
|
|
|
|
2019-09-01 19:03:32 -04:00
|
|
|
TapHandler {
|
|
|
|
acceptedButtons: Qt.RightButton
|
2020-03-24 19:52:48 +02:00
|
|
|
acceptedPointerTypes: PointerDevice.GenericPointer | PointerDevice.Pen
|
2019-09-14 18:52:43 -04:00
|
|
|
onTapped: openContextMenu()
|
2019-09-01 19:03:32 -04:00
|
|
|
}
|
|
|
|
|
2020-03-24 16:42:41 +02:00
|
|
|
TapHandler {
|
|
|
|
acceptedPointerTypes: PointerDevice.Finger | PointerDevice.Pen
|
|
|
|
onLongPressed: openContextMenu()
|
|
|
|
}
|
2019-03-21 23:28:14 -04:00
|
|
|
}
|