2019-07-13 05:39:01 -04:00
|
|
|
import QtQuick 2.12
|
|
|
|
import QtQuick.Layouts 1.12
|
2019-12-18 04:53:08 -04:00
|
|
|
import "../../../Base"
|
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-09-03 03:04:57 -04:00
|
|
|
width: eventList.width
|
|
|
|
|
2019-03-21 23:28:14 -04:00
|
|
|
|
2019-09-14 18:33:32 -04:00
|
|
|
enum Media { Page, File, Image, Video, Audio }
|
|
|
|
|
|
|
|
property var hoveredMediaTypeUrl: []
|
|
|
|
|
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
|
|
|
|
2019-12-09 05:25:31 -04:00
|
|
|
property bool isOwn: chat.userId === model.sender_id
|
2019-07-19 23:07:26 -04:00
|
|
|
property bool onRight: eventList.ownEventsOnRight && isOwn
|
2019-12-17 03:45:00 -04:00
|
|
|
property bool combine: eventList.canCombine(previousModel, model)
|
|
|
|
property bool talkBreak: eventList.canTalkBreak(previousModel, model)
|
|
|
|
property bool dayBreak: eventList.canDayBreak(previousModel, model)
|
2019-07-19 20:55:52 -04:00
|
|
|
|
2019-07-19 23:07:26 -04:00
|
|
|
readonly property bool smallAvatar:
|
2019-12-17 03:45:00 -04:00
|
|
|
eventList.canCombine(model, nextModel) &&
|
2019-11-04 14:37:25 -04:00
|
|
|
(model.event_type === "RoomMessageEmote" ||
|
2019-11-04 14:45:20 -04:00
|
|
|
! (model.event_type.startsWith("RoomMessage") ||
|
|
|
|
model.event_type.startsWith("RoomEncrypted")))
|
2019-03-21 23:28:14 -04:00
|
|
|
|
2019-07-19 23:07:26 -04:00
|
|
|
readonly property bool collapseAvatar: combine
|
|
|
|
readonly property bool hideAvatar: onRight
|
2019-03-21 23:28:14 -04:00
|
|
|
|
2019-07-19 23:07:26 -04:00
|
|
|
readonly property bool hideNameLine:
|
2019-11-04 14:37:25 -04:00
|
|
|
model.event_type === "RoomMessageEmote" ||
|
2019-11-04 14:45:20 -04:00
|
|
|
! (
|
|
|
|
model.event_type.startsWith("RoomMessage") ||
|
|
|
|
model.event_type.startsWith("RoomEncrypted")
|
|
|
|
) ||
|
2019-07-19 23:07:26 -04:00
|
|
|
onRight ||
|
|
|
|
combine
|
2019-04-20 03:29:24 -04:00
|
|
|
|
2019-09-14 18:33:32 -04:00
|
|
|
readonly property int cursorShape:
|
|
|
|
eventContent.hoveredLink || hoveredMediaTypeUrl.length > 0 ?
|
|
|
|
Qt.PointingHandCursor :
|
|
|
|
|
|
|
|
eventContent.hoveredSelectable ? Qt.IBeamCursor :
|
|
|
|
|
|
|
|
Qt.ArrowCursor
|
|
|
|
|
2019-12-17 03:45:00 -04:00
|
|
|
readonly property int separationSpacing:
|
|
|
|
dayBreak ? theme.spacing * 4 :
|
|
|
|
talkBreak ? theme.spacing * 6 :
|
|
|
|
combine ? theme.spacing / 2 :
|
|
|
|
theme.spacing * 2
|
|
|
|
|
2019-09-14 18:33:32 -04:00
|
|
|
// Needed because of eventList's MouseArea which steals the
|
|
|
|
// HSelectableLabel's MouseArea hover events
|
|
|
|
onCursorShapeChanged: eventList.cursorShape = cursorShape
|
|
|
|
|
2019-09-01 05:16:47 -04:00
|
|
|
|
2019-09-05 16:24:49 -04:00
|
|
|
function json() {
|
|
|
|
return JSON.stringify(
|
2019-12-08 04:53:51 -04:00
|
|
|
{
|
2019-12-17 17:59:53 -04:00
|
|
|
"model": utils.getItem(
|
2019-12-08 04:53:51 -04:00
|
|
|
modelSources[[
|
2019-12-09 05:25:31 -04:00
|
|
|
"Event", chat.userId, chat.roomId
|
2019-12-08 04:53:51 -04:00
|
|
|
]],
|
|
|
|
"client_id",
|
|
|
|
model.client_id
|
|
|
|
),
|
|
|
|
"source": py.getattr(model.source, "__dict__"),
|
|
|
|
},
|
2019-09-05 16:24:49 -04:00
|
|
|
null, 4)
|
|
|
|
}
|
|
|
|
|
2019-09-14 18:52:43 -04:00
|
|
|
function openContextMenu() {
|
|
|
|
contextMenu.media = eventDelegate.hoveredMediaTypeUrl
|
|
|
|
contextMenu.link = eventContent.hoveredLink
|
|
|
|
contextMenu.popup()
|
|
|
|
}
|
|
|
|
|
2019-09-05 16:24:49 -04:00
|
|
|
|
2019-12-17 03:45:00 -04:00
|
|
|
Item {
|
|
|
|
|
|
|
|
Layout.fillWidth: true
|
|
|
|
Layout.preferredHeight:
|
|
|
|
model.event_type === "RoomCreateEvent" ? 0 : separationSpacing
|
|
|
|
}
|
|
|
|
|
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
|
2019-04-28 14:48:59 -04:00
|
|
|
}
|
2019-03-21 23:28:14 -04:00
|
|
|
|
2019-07-20 02:27:17 -04:00
|
|
|
Item {
|
|
|
|
visible: dayBreak
|
2019-12-17 03:45:00 -04:00
|
|
|
|
|
|
|
Layout.fillWidth: true
|
|
|
|
Layout.preferredHeight: 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
|
|
|
|
|
|
|
|
|
|
|
TapHandler {
|
|
|
|
acceptedButtons: Qt.RightButton
|
2019-09-14 18:52:43 -04:00
|
|
|
onTapped: openContextMenu()
|
2019-09-01 19:03:32 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
HMenu {
|
|
|
|
id: contextMenu
|
|
|
|
|
2019-09-14 18:33:32 -04:00
|
|
|
property var media: []
|
2019-09-01 19:03:32 -04:00
|
|
|
property string link: ""
|
|
|
|
|
2019-09-14 18:33:32 -04:00
|
|
|
onClosed: { media = []; link = "" }
|
2019-09-03 03:04:57 -04:00
|
|
|
|
|
|
|
HMenuItem {
|
2019-09-14 18:33:32 -04:00
|
|
|
id: copyMedia
|
2019-09-03 03:04:57 -04:00
|
|
|
icon.name: "copy-link"
|
2019-09-14 18:33:32 -04: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-17 23:23:47 -04:00
|
|
|
contextMenu.media[0] === EventDelegate.Media.Video ?
|
|
|
|
qsTr("Copy video address") :
|
|
|
|
|
|
|
|
contextMenu.media[0] === EventDelegate.Media.Audio ?
|
|
|
|
qsTr("Copy audio address") :
|
|
|
|
|
2019-09-14 18:33:32 -04:00
|
|
|
qsTr("Copy media address")
|
|
|
|
|
|
|
|
visible: Boolean(text)
|
2019-10-25 08:42:04 -04:00
|
|
|
onTriggered: Clipboard.text = contextMenu.media[1]
|
2019-09-03 03:04:57 -04:00
|
|
|
}
|
2019-09-01 19:03:32 -04:00
|
|
|
|
|
|
|
HMenuItem {
|
|
|
|
id: copyLink
|
|
|
|
icon.name: "copy-link"
|
|
|
|
text: qsTr("Copy link address")
|
|
|
|
visible: Boolean(contextMenu.link)
|
2019-10-25 08:42:04 -04:00
|
|
|
onTriggered: Clipboard.text = contextMenu.link
|
2019-09-01 19:03:32 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
HMenuItem {
|
|
|
|
icon.name: "copy-text"
|
|
|
|
text: qsTr("Copy text")
|
2019-09-14 18:33:32 -04:00
|
|
|
visible: enabled || (! copyLink.visible && ! copyMedia.visible)
|
2019-09-01 19:03:32 -04:00
|
|
|
enabled: Boolean(selectableLabelContainer.joinedSelection)
|
|
|
|
onTriggered:
|
2019-10-25 08:42:04 -04:00
|
|
|
Clipboard.text = selectableLabelContainer.joinedSelection
|
2019-09-01 19:03:32 -04:00
|
|
|
}
|
2019-09-05 16:09:04 -04:00
|
|
|
|
2019-09-08 11:40:39 -04:00
|
|
|
HMenuItem {
|
|
|
|
icon.name: "clear-messages"
|
|
|
|
text: qsTr("Clear messages")
|
2019-12-17 17:59:53 -04:00
|
|
|
onTriggered: utils.makePopup(
|
2019-09-09 08:57:38 -04:00
|
|
|
"Popups/ClearMessagesPopup.qml",
|
2019-12-09 05:25:31 -04:00
|
|
|
chat,
|
|
|
|
{userId: chat.userId, roomId: chat.roomId},
|
2019-09-08 11:40:39 -04:00
|
|
|
)
|
|
|
|
}
|
2019-09-01 19:03:32 -04:00
|
|
|
}
|
2019-03-21 23:28:14 -04:00
|
|
|
}
|