moment/harmonyqml/components/chat/MessageDelegate.qml

62 lines
1.6 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
2019-03-22 14:28:14 +11:00
Column {
id: rootCol
function mins_between(date1, date2) {
return Math.round((((date2 - date1) % 86400000) % 3600000) / 60000)
}
2019-04-15 02:56:30 +10:00
readonly property bool isMessage: type.startsWith("RoomMessage")
readonly property bool isUndecryptableEvent:
type === "OlmEvent" || type === "MegolmEvent"
2019-03-22 14:28:14 +11:00
readonly property string displayName:
2019-04-15 02:56:30 +10:00
Backend.getUser(dict.sender).display_name
2019-03-22 14:28:14 +11:00
readonly property bool isOwn:
2019-04-15 02:56:30 +10:00
chatPage.user_id === dict.sender
2019-03-22 14:28:14 +11:00
readonly property var previousData:
index > 0 ? messageListView.model.get(index - 1) : null
readonly property bool isFirstMessage: ! previousData
readonly property bool combine:
! isFirstMessage &&
2019-04-15 02:56:30 +10:00
previousData.isMessage === isMessage &&
previousData.dict.sender === dict.sender &&
2019-03-22 14:28:14 +11:00
mins_between(previousData.date_time, date_time) <= 5
readonly property bool dayBreak:
isFirstMessage ||
previousData.date_time.getDay() != date_time.getDay()
readonly property bool talkBreak:
! isFirstMessage &&
! dayBreak &&
mins_between(previousData.date_time, date_time) >= 20
property int standardSpacing: 8
property int horizontalPadding: 7
property int verticalPadding: 5
width: parent.width
topPadding:
previousData === null ? 0 :
talkBreak ? standardSpacing * 6 :
combine ? standardSpacing / 2 :
standardSpacing * 1.2
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
}