moment/harmonyqml/components/chat/MessageDelegate.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.Controls 2.0
import QtQuick.Layouts 1.4
import "../base" as Base
import "utils.js" as ChatJS
2019-03-22 14:28:14 +11:00
Column {
id: messageDelegate
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 getIsMessage(type_) { return type_.startsWith("RoomMessage") }
function getPreviousItem() {
return index < messageListView.model.count - 1 ?
messageListView.model.get(index + 1) : null
}
property var previousItem: getPreviousItem()
signal reloadPreviousItem()
onReloadPreviousItem: previousItem = getPreviousItem()
readonly property bool isMessage: getIsMessage(type)
2019-04-15 02:56:30 +10:00
readonly property bool isUndecryptableEvent:
type === "OlmEvent" || type === "MegolmEvent"
readonly property var displayName:
Backend.getUserDisplayName(dict.sender)
2019-03-22 14:28:14 +11:00
readonly property bool isOwn:
chatPage.userId === dict.sender
2019-03-22 14:28:14 +11:00
readonly property bool isFirstEvent: type == "RoomCreateEvent"
2019-03-22 14:28:14 +11:00
readonly property bool combine:
previousItem &&
! talkBreak &&
! dayBreak &&
getIsMessage(previousItem.type) === isMessage &&
previousItem.dict.sender === dict.sender &&
minsBetween(previousItem.dateTime, dateTime) <= 5
2019-03-22 14:28:14 +11:00
readonly property bool dayBreak:
isFirstEvent ||
previousItem &&
dateTime.getDay() != previousItem.dateTime.getDay()
2019-03-22 14:28:14 +11:00
readonly property bool talkBreak:
previousItem &&
2019-03-22 14:28:14 +11:00
! dayBreak &&
minsBetween(previousItem.dateTime, dateTime) >= 20
2019-03-22 14:28:14 +11:00
property int standardSpacing: 16
2019-03-22 14:28:14 +11:00
property int horizontalPadding: 7
property int verticalPadding: 5
ListView.onAdd: {
var nextDelegate = messageListView.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 :
talkBreak ? standardSpacing * 3 :
combine ? standardSpacing / 4 :
standardSpacing
Daybreak { visible: dayBreak }
2019-03-22 14:28:14 +11:00
MessageContent { visible: isMessage }
2019-03-22 14:28:14 +11:00
EventContent { visible: ! isMessage }
2019-03-22 14:28:14 +11:00
}