2019-03-22 14:28:14 +11:00
|
|
|
import QtQuick 2.7
|
|
|
|
import QtQuick.Controls 2.0
|
|
|
|
import QtQuick.Layouts 1.4
|
2019-04-29 04:34:29 +10:00
|
|
|
import "../../Base" as Base
|
|
|
|
import "../utils.js" as ChatJS
|
2019-03-22 14:28:14 +11:00
|
|
|
|
|
|
|
Column {
|
2019-04-29 04:34:29 +10:00
|
|
|
id: roomEventDelegate
|
2019-03-22 14:28:14 +11:00
|
|
|
|
2019-04-21 07:36:21 +10:00
|
|
|
function minsBetween(date1, date2) {
|
2019-03-22 14:28:14 +11:00
|
|
|
return Math.round((((date2 - date1) % 86400000) % 3600000) / 60000)
|
|
|
|
}
|
|
|
|
|
2019-04-21 07:36:21 +10:00
|
|
|
function getIsMessage(type_) { return type_.startsWith("RoomMessage") }
|
2019-04-18 06:43:18 +10:00
|
|
|
|
2019-04-21 07:36:21 +10:00
|
|
|
function getPreviousItem() {
|
2019-04-29 04:34:29 +10:00
|
|
|
return index < roomEventListView.model.count - 1 ?
|
|
|
|
roomEventListView.model.get(index + 1) : null
|
2019-04-20 17:29:24 +10:00
|
|
|
}
|
|
|
|
|
2019-04-21 07:36:21 +10:00
|
|
|
property var previousItem: getPreviousItem()
|
2019-04-20 17:29:24 +10:00
|
|
|
signal reloadPreviousItem()
|
2019-04-21 07:36:21 +10:00
|
|
|
onReloadPreviousItem: previousItem = getPreviousItem()
|
2019-04-18 06:43:18 +10:00
|
|
|
|
2019-04-21 07:36:21 +10:00
|
|
|
readonly property bool isMessage: getIsMessage(type)
|
2019-04-15 02:56:30 +10:00
|
|
|
|
|
|
|
readonly property bool isUndecryptableEvent:
|
|
|
|
type === "OlmEvent" || type === "MegolmEvent"
|
|
|
|
|
2019-04-19 16:07:01 +10:00
|
|
|
readonly property var displayName:
|
|
|
|
Backend.getUserDisplayName(dict.sender)
|
2019-03-22 14:28:14 +11:00
|
|
|
|
|
|
|
readonly property bool isOwn:
|
2019-04-21 07:36:21 +10:00
|
|
|
chatPage.userId === dict.sender
|
2019-03-22 14:28:14 +11:00
|
|
|
|
2019-04-20 17:29:24 +10:00
|
|
|
readonly property bool isFirstEvent: type == "RoomCreateEvent"
|
2019-03-22 14:28:14 +11:00
|
|
|
|
|
|
|
readonly property bool combine:
|
2019-04-20 17:29:24 +10:00
|
|
|
previousItem &&
|
2019-04-18 06:43:18 +10:00
|
|
|
! talkBreak &&
|
|
|
|
! dayBreak &&
|
2019-04-21 07:36:21 +10:00
|
|
|
getIsMessage(previousItem.type) === isMessage &&
|
2019-04-18 06:43:18 +10:00
|
|
|
previousItem.dict.sender === dict.sender &&
|
2019-04-21 07:36:21 +10:00
|
|
|
minsBetween(previousItem.dateTime, dateTime) <= 5
|
2019-03-22 14:28:14 +11:00
|
|
|
|
|
|
|
readonly property bool dayBreak:
|
2019-04-20 17:29:24 +10:00
|
|
|
isFirstEvent ||
|
|
|
|
previousItem &&
|
2019-04-22 10:55:24 +10:00
|
|
|
dateTime.getDate() != previousItem.dateTime.getDate()
|
2019-03-22 14:28:14 +11:00
|
|
|
|
|
|
|
readonly property bool talkBreak:
|
2019-04-20 17:29:24 +10:00
|
|
|
previousItem &&
|
2019-03-22 14:28:14 +11:00
|
|
|
! dayBreak &&
|
2019-04-21 07:36:21 +10:00
|
|
|
minsBetween(previousItem.dateTime, dateTime) >= 20
|
2019-03-22 14:28:14 +11:00
|
|
|
|
|
|
|
|
2019-04-18 06:43:18 +10:00
|
|
|
property int standardSpacing: 16
|
2019-03-22 14:28:14 +11:00
|
|
|
property int horizontalPadding: 7
|
|
|
|
property int verticalPadding: 5
|
|
|
|
|
2019-04-20 17:29:24 +10:00
|
|
|
ListView.onAdd: {
|
2019-04-29 04:34:29 +10:00
|
|
|
var nextDelegate = roomEventListView.contentItem.children[index]
|
2019-04-21 07:36:21 +10:00
|
|
|
if (nextDelegate) { nextDelegate.reloadPreviousItem() }
|
2019-04-20 17:29:24 +10:00
|
|
|
}
|
|
|
|
|
2019-03-22 14:28:14 +11:00
|
|
|
width: parent.width
|
2019-04-20 17:29:24 +10:00
|
|
|
|
2019-03-22 14:28:14 +11:00
|
|
|
topPadding:
|
2019-04-20 17:29:24 +10:00
|
|
|
isFirstEvent ? 0 :
|
2019-04-29 01:01:38 +10:00
|
|
|
dayBreak ? standardSpacing * 2 :
|
2019-04-18 06:43:18 +10:00
|
|
|
talkBreak ? standardSpacing * 3 :
|
|
|
|
combine ? standardSpacing / 4 :
|
|
|
|
standardSpacing
|
|
|
|
|
2019-04-29 04:48:59 +10:00
|
|
|
Loader {
|
|
|
|
source: dayBreak ? "Daybreak.qml" : ""
|
|
|
|
width: roomEventDelegate.width
|
|
|
|
}
|
2019-03-22 14:28:14 +11:00
|
|
|
|
2019-04-29 01:01:38 +10:00
|
|
|
Item {
|
|
|
|
visible: dayBreak
|
|
|
|
width: parent.width
|
|
|
|
height: topPadding
|
|
|
|
}
|
|
|
|
|
2019-04-29 04:48:59 +10:00
|
|
|
Loader {
|
|
|
|
source: isMessage ? "MessageContent.qml" : "EventContent.qml"
|
|
|
|
anchors.right: isOwn ? parent.right : undefined
|
|
|
|
}
|
2019-03-22 14:28:14 +11:00
|
|
|
}
|