moment/src/qml/Chat/RoomEventList/RoomEventDelegate.qml

80 lines
2.1 KiB
QML
Raw Normal View History

2019-03-22 14:28:14 +11:00
import QtQuick 2.7
import QtQuick.Layouts 1.3
import "../../Base"
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() {
return index < roomEventListView.model.count - 1 ?
roomEventListView.model.get(index + 1) : null
}
property var previousItem: getPreviousItem()
signal reloadPreviousItem()
onReloadPreviousItem: previousItem = getPreviousItem()
property var senderInfo: null
Component.onCompleted:
senderInfo = models.users.getUser(chatPage.userId, senderId)
2019-04-15 02:56:30 +10:00
readonly property bool isOwn: chatPage.userId === senderId
2019-03-22 14:28:14 +11:00
readonly property bool isFirstEvent: model.event_type == "RoomCreateEvent"
2019-03-22 14:28:14 +11:00
readonly property bool combine:
previousItem &&
! talkBreak &&
! dayBreak &&
previousItem.senderId === senderId &&
minsBetween(previousItem.date, model.date) <= 5
2019-03-22 14:28:14 +11:00
readonly property bool dayBreak:
isFirstEvent ||
previousItem &&
model.date.getDate() != previousItem.date.getDate()
2019-03-22 14:28:14 +11:00
readonly property bool talkBreak:
previousItem &&
2019-03-22 14:28:14 +11:00
! dayBreak &&
minsBetween(previousItem.date, model.date) >= 20
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
Item { // TODO: put this in Daybreak.qml?
2019-04-29 01:01:38 +10:00
visible: dayBreak
width: parent.width
height: topPadding
}
MessageContent {
2019-04-29 04:48:59 +10:00
anchors.right: isOwn ? parent.right : undefined
}
2019-03-22 14:28:14 +11:00
}