2019-03-21 23:28:14 -04:00
|
|
|
import QtQuick 2.7
|
2019-04-28 15:45:42 -04:00
|
|
|
import QtQuick.Layouts 1.3
|
2019-04-28 15:18:36 -04:00
|
|
|
import "../../Base"
|
2019-07-04 00:24:21 -04:00
|
|
|
import "../../utils.js" as Utils
|
2019-03-21 23:28:14 -04:00
|
|
|
|
|
|
|
Column {
|
2019-04-28 14:34:29 -04:00
|
|
|
id: roomEventDelegate
|
2019-03-21 23:28:14 -04:00
|
|
|
|
2019-04-20 17:36:21 -04:00
|
|
|
function minsBetween(date1, date2) {
|
2019-03-21 23:28:14 -04:00
|
|
|
return Math.round((((date2 - date1) % 86400000) % 3600000) / 60000)
|
|
|
|
}
|
|
|
|
|
2019-07-02 23:32:39 -04:00
|
|
|
function getPreviousItem(nth) {
|
|
|
|
// Remember, index 0 = newest bottomest message
|
|
|
|
nth = nth || 1
|
2019-07-03 21:20:49 -04:00
|
|
|
return roomEventListView.model.count - 1 > model.index + nth ?
|
|
|
|
roomEventListView.model.get(model.index + nth) : null
|
2019-07-02 23:32:39 -04:00
|
|
|
}
|
|
|
|
|
2019-04-20 17:36:21 -04:00
|
|
|
property var previousItem: getPreviousItem()
|
2019-04-20 03:29:24 -04:00
|
|
|
signal reloadPreviousItem()
|
2019-04-20 17:36:21 -04:00
|
|
|
onReloadPreviousItem: previousItem = getPreviousItem()
|
2019-04-17 16:43:18 -04:00
|
|
|
|
2019-07-02 13:59:52 -04:00
|
|
|
property var senderInfo: null
|
2019-07-04 00:24:21 -04:00
|
|
|
Component.onCompleted: senderInfo = models.users.getUser(model.senderId)
|
2019-04-14 12:56:30 -04:00
|
|
|
|
2019-07-02 23:32:39 -04:00
|
|
|
readonly property bool isOwn: chatPage.userId === model.senderId
|
2019-03-21 23:28:14 -04:00
|
|
|
|
2019-07-02 23:32:39 -04:00
|
|
|
readonly property bool isFirstEvent: model.eventType == "RoomCreateEvent"
|
2019-03-21 23:28:14 -04:00
|
|
|
|
2019-07-03 21:20:49 -04: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 00:24:21 -04:00
|
|
|
Utils.eventIsMessage(previousItem) == Utils.eventIsMessage(model) &&
|
2019-04-17 16:43:18 -04:00
|
|
|
! talkBreak &&
|
|
|
|
! dayBreak &&
|
2019-07-02 23:32:39 -04:00
|
|
|
previousItem.senderId === model.senderId &&
|
2019-07-02 13:59:52 -04:00
|
|
|
minsBetween(previousItem.date, model.date) <= 5
|
2019-07-03 21:20:49 -04:00
|
|
|
)
|
2019-03-21 23:28:14 -04:00
|
|
|
|
2019-07-03 21:20:49 -04:00
|
|
|
readonly property bool dayBreak: Boolean(
|
2019-04-20 03:29:24 -04:00
|
|
|
isFirstEvent ||
|
2019-07-03 21:20:49 -04:00
|
|
|
model.date && previousItem && previousItem.date &&
|
2019-07-02 13:59:52 -04:00
|
|
|
model.date.getDate() != previousItem.date.getDate()
|
2019-07-03 21:20:49 -04:00
|
|
|
)
|
2019-03-21 23:28:14 -04:00
|
|
|
|
2019-07-03 21:20:49 -04:00
|
|
|
readonly property bool talkBreak: Boolean(
|
|
|
|
model.date && previousItem && previousItem.date &&
|
2019-03-21 23:28:14 -04:00
|
|
|
! dayBreak &&
|
2019-07-02 13:59:52 -04:00
|
|
|
minsBetween(previousItem.date, model.date) >= 20
|
2019-07-03 21:20:49 -04:00
|
|
|
)
|
2019-03-21 23:28:14 -04:00
|
|
|
|
|
|
|
|
2019-04-17 16:43:18 -04:00
|
|
|
property int standardSpacing: 16
|
2019-05-15 17:01:58 -04:00
|
|
|
property int horizontalPadding: 6
|
|
|
|
property int verticalPadding: 4
|
2019-03-21 23:28:14 -04:00
|
|
|
|
2019-04-20 03:29:24 -04:00
|
|
|
ListView.onAdd: {
|
2019-04-28 14:34:29 -04:00
|
|
|
var nextDelegate = roomEventListView.contentItem.children[index]
|
2019-04-20 17:36:21 -04:00
|
|
|
if (nextDelegate) { nextDelegate.reloadPreviousItem() }
|
2019-04-20 03:29:24 -04:00
|
|
|
}
|
|
|
|
|
2019-03-21 23:28:14 -04:00
|
|
|
width: parent.width
|
2019-04-20 03:29:24 -04:00
|
|
|
|
2019-03-21 23:28:14 -04:00
|
|
|
topPadding:
|
2019-04-20 03:29:24 -04:00
|
|
|
isFirstEvent ? 0 :
|
2019-04-28 11:01:38 -04:00
|
|
|
dayBreak ? standardSpacing * 2 :
|
2019-04-17 16:43:18 -04:00
|
|
|
talkBreak ? standardSpacing * 3 :
|
|
|
|
combine ? standardSpacing / 4 :
|
|
|
|
standardSpacing
|
|
|
|
|
2019-04-28 14:48:59 -04:00
|
|
|
Loader {
|
|
|
|
source: dayBreak ? "Daybreak.qml" : ""
|
|
|
|
width: roomEventDelegate.width
|
|
|
|
}
|
2019-03-21 23:28:14 -04:00
|
|
|
|
2019-07-02 22:22:29 -04:00
|
|
|
Item { // TODO: put this in Daybreak.qml?
|
2019-04-28 11:01:38 -04:00
|
|
|
visible: dayBreak
|
|
|
|
width: parent.width
|
|
|
|
height: topPadding
|
|
|
|
}
|
|
|
|
|
2019-07-02 22:29:09 -04:00
|
|
|
EventContent {
|
2019-04-28 14:48:59 -04:00
|
|
|
anchors.right: isOwn ? parent.right : undefined
|
|
|
|
}
|
2019-03-21 23:28:14 -04:00
|
|
|
}
|