moment/src/qml/Chat/Timeline/EventDelegate.qml

85 lines
2.5 KiB
QML
Raw Normal View History

2019-07-08 13:52:41 +10:00
// Copyright 2019 miruka
// This file is part of harmonyqml, licensed under LGPLv3.
2019-03-22 14:28:14 +11:00
import QtQuick 2.7
import QtQuick.Layouts 1.3
import "../../Base"
import "../../utils.js" as Utils
2019-03-22 14:28:14 +11:00
Column {
id: roomEventDelegate
2019-03-22 14:28:14 +11:00
function minsBetween(date1, date2) {
2019-03-22 14:28:14 +11:00
return Math.round((((date2 - date1) % 86400000) % 3600000) / 60000)
}
function getPreviousItem(nth) {
// Remember, index 0 = newest bottomest message
nth = nth || 1
2019-07-04 11:20:49 +10:00
return roomEventListView.model.count - 1 > model.index + nth ?
roomEventListView.model.get(model.index + nth) : null
}
property var previousItem: getPreviousItem()
signal reloadPreviousItem()
onReloadPreviousItem: previousItem = getPreviousItem()
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
readonly property bool isOwn: chatPage.userId === model.senderId
2019-03-22 14:28:14 +11: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 &&
Utils.eventIsMessage(previousItem) == Utils.eventIsMessage(model) &&
! talkBreak &&
! dayBreak &&
previousItem.senderId === model.senderId &&
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(
isFirstEvent ||
2019-07-04 11:20:49 +10:00
model.date && previousItem && previousItem.date &&
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 &&
minsBetween(previousItem.date, model.date) >= 20
2019-07-04 11:20:49 +10:00
)
2019-03-22 14:28:14 +11:00
property int standardSpacing: 16
2019-05-16 07:01:58 +10:00
property int horizontalPadding: 6
property int verticalPadding: 4
2019-03-22 14:28:14 +11:00
ListView.onAdd: {
var nextDelegate = roomEventListView.contentItem.children[index]
if (nextDelegate) { nextDelegate.reloadPreviousItem() }
}
2019-03-22 14:28:14 +11:00
width: parent.width
2019-03-22 14:28:14 +11:00
topPadding:
isFirstEvent ? 0 :
2019-04-29 01:01:38 +10:00
dayBreak ? standardSpacing * 2 :
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-07-03 12:29:09 +10:00
EventContent {
2019-04-29 04:48:59 +10:00
anchors.right: isOwn ? parent.right : undefined
}
2019-03-22 14:28:14 +11:00
}