2019-07-08 13:52:41 +10:00
|
|
|
// Copyright 2019 miruka
|
|
|
|
// This file is part of harmonyqml, licensed under LGPLv3.
|
|
|
|
|
2019-07-13 19:39:01 +10:00
|
|
|
import QtQuick 2.12
|
|
|
|
import QtQuick.Layouts 1.12
|
2019-04-29 05:18:36 +10:00
|
|
|
import "../../Base"
|
2019-07-04 14:24:21 +10:00
|
|
|
import "../../utils.js" as Utils
|
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-07-18 17:35:30 +10:00
|
|
|
function getPreviousItem(nth=1) {
|
2019-07-03 13:32:39 +10:00
|
|
|
// Remember, index 0 = newest bottomest message
|
2019-07-14 10:15:20 +10:00
|
|
|
return eventList.model.count - 1 > model.index + nth ?
|
|
|
|
eventList.model.get(model.index + nth) : null
|
2019-07-03 13:32:39 +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-07-03 03:59:52 +10:00
|
|
|
property var senderInfo: null
|
2019-07-08 12:41:32 +10:00
|
|
|
Component.onCompleted: senderInfo = users.find(model.senderId)
|
2019-04-15 02:56:30 +10:00
|
|
|
|
2019-07-03 13:32:39 +10:00
|
|
|
readonly property bool isOwn: chatPage.userId === model.senderId
|
2019-07-18 20:23:31 +10:00
|
|
|
readonly property bool onRight: eventList.ownEventsOnRight && isOwn
|
2019-03-22 14:28:14 +11:00
|
|
|
|
2019-07-03 13:32:39 +10:00
|
|
|
readonly property bool isFirstEvent: model.eventType == "RoomCreateEvent"
|
2019-03-22 14:28:14 +11:00
|
|
|
|
2019-07-04 11:20:49 +10:00
|
|
|
// Item roles may not be loaded yet, reason for all these checks
|
|
|
|
readonly property bool combine: Boolean(
|
|
|
|
model.date &&
|
|
|
|
previousItem && previousItem.eventType && previousItem.date &&
|
2019-07-04 14:24:21 +10:00
|
|
|
Utils.eventIsMessage(previousItem) == Utils.eventIsMessage(model) &&
|
2019-04-18 06:43:18 +10:00
|
|
|
! talkBreak &&
|
|
|
|
! dayBreak &&
|
2019-07-03 13:32:39 +10:00
|
|
|
previousItem.senderId === model.senderId &&
|
2019-07-03 03:59:52 +10:00
|
|
|
minsBetween(previousItem.date, model.date) <= 5
|
2019-07-04 11:20:49 +10:00
|
|
|
)
|
2019-03-22 14:28:14 +11:00
|
|
|
|
2019-07-04 11:20:49 +10:00
|
|
|
readonly property bool dayBreak: Boolean(
|
2019-04-20 17:29:24 +10:00
|
|
|
isFirstEvent ||
|
2019-07-04 11:20:49 +10:00
|
|
|
model.date && previousItem && previousItem.date &&
|
2019-07-03 03:59:52 +10:00
|
|
|
model.date.getDate() != previousItem.date.getDate()
|
2019-07-04 11:20:49 +10:00
|
|
|
)
|
2019-03-22 14:28:14 +11:00
|
|
|
|
2019-07-04 11:20:49 +10:00
|
|
|
readonly property bool talkBreak: Boolean(
|
|
|
|
model.date && previousItem && previousItem.date &&
|
2019-03-22 14:28:14 +11:00
|
|
|
! dayBreak &&
|
2019-07-03 03:59:52 +10:00
|
|
|
minsBetween(previousItem.date, model.date) >= 20
|
2019-07-04 11:20:49 +10:00
|
|
|
)
|
2019-03-22 14:28:14 +11:00
|
|
|
|
|
|
|
|
2019-07-16 19:29:47 +10:00
|
|
|
readonly property int horizontalPadding: theme.spacing
|
|
|
|
readonly property int verticalPadding: theme.spacing / 2
|
2019-03-22 14:28:14 +11:00
|
|
|
|
2019-04-20 17:29:24 +10:00
|
|
|
ListView.onAdd: {
|
2019-07-18 19:18:13 +10:00
|
|
|
let nextDelegate = eventList.contentItem.children[index]
|
2019-04-21 07:36:21 +10:00
|
|
|
if (nextDelegate) { nextDelegate.reloadPreviousItem() }
|
2019-04-20 17:29:24 +10:00
|
|
|
}
|
|
|
|
|
2019-07-18 20:23:31 +10:00
|
|
|
width: eventList.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-07-16 19:29:47 +10:00
|
|
|
dayBreak ? theme.spacing * 4 :
|
|
|
|
talkBreak ? theme.spacing * 6 :
|
|
|
|
combine ? theme.spacing / 2 :
|
|
|
|
theme.spacing * 2
|
2019-04-18 06:43:18 +10:00
|
|
|
|
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-07-03 12:29:09 +10:00
|
|
|
EventContent {
|
2019-07-18 21:22:41 +10:00
|
|
|
// anchors.left: parent.left
|
|
|
|
// anchors.right: onRight ? parent.right : undefined
|
|
|
|
x: onRight ? parent.width - width : 0
|
|
|
|
Behavior on x { HNumberAnimation {} }
|
2019-04-29 04:48:59 +10:00
|
|
|
}
|
2019-03-22 14:28:14 +11:00
|
|
|
}
|