Fix date and top padding when loading previous msg

This commit is contained in:
miruka 2019-04-20 03:29:24 -04:00
parent 99c06e4034
commit b33f5f1d34
3 changed files with 27 additions and 12 deletions

View File

@ -21,6 +21,7 @@ Controls1.SplitView {
pageStack.replace( pageStack.replace(
"chat/Root.qml", { user_id: user_id, room: room_obj } "chat/Root.qml", { user_id: user_id, room: room_obj }
) )
console.log("replaced")
} }
id: "pageStack" id: "pageStack"

View File

@ -3,10 +3,11 @@ import "../base" as Base
Base.HLabel { Base.HLabel {
text: date_time.toLocaleDateString() text: date_time.toLocaleDateString()
width: rootCol.width width: messageDelegate.width
horizontalAlignment: Text.AlignHCenter horizontalAlignment: Text.AlignHCenter
topPadding: rootCol.isFirstMessage ? 0 : rootCol.standardSpacing topPadding: messageDelegate.isFirstMessage ?
bottomPadding: rootCol.standardSpacing 0 : messageDelegate.standardSpacing
bottomPadding: messageDelegate.standardSpacing
font.pixelSize: normalSize * 1.1 font.pixelSize: normalSize * 1.1
color: "darkolivegreen" color: "darkolivegreen"
} }

View File

@ -2,9 +2,10 @@ import QtQuick 2.7
import QtQuick.Controls 2.0 import QtQuick.Controls 2.0
import QtQuick.Layouts 1.4 import QtQuick.Layouts 1.4
import "../base" as Base import "../base" as Base
import "utils.js" as ChatJS
Column { Column {
id: "rootCol" id: "messageDelegate"
function mins_between(date1, date2) { function mins_between(date1, date2) {
return Math.round((((date2 - date1) % 86400000) % 3600000) / 60000) return Math.round((((date2 - date1) % 86400000) % 3600000) / 60000)
@ -12,9 +13,14 @@ Column {
function is_message(type_) { return type_.startsWith("RoomMessage") } function is_message(type_) { return type_.startsWith("RoomMessage") }
readonly property var previousItem: function get_previous_item() {
index < messageListView.model.count - 1 ? return index < messageListView.model.count - 1 ?
messageListView.model.get(index + 1) : null messageListView.model.get(index + 1) : null
}
property var previousItem: get_previous_item()
signal reloadPreviousItem()
onReloadPreviousItem: previousItem = get_previous_item()
readonly property bool isMessage: is_message(type) readonly property bool isMessage: is_message(type)
@ -27,10 +33,10 @@ Column {
readonly property bool isOwn: readonly property bool isOwn:
chatPage.user_id === dict.sender chatPage.user_id === dict.sender
readonly property bool isFirstMessage: ! previousItem readonly property bool isFirstEvent: type == "RoomCreateEvent"
readonly property bool combine: readonly property bool combine:
! isFirstMessage && previousItem &&
! talkBreak && ! talkBreak &&
! dayBreak && ! dayBreak &&
is_message(previousItem.type) === isMessage && is_message(previousItem.type) === isMessage &&
@ -38,11 +44,12 @@ Column {
mins_between(previousItem.date_time, date_time) <= 5 mins_between(previousItem.date_time, date_time) <= 5
readonly property bool dayBreak: readonly property bool dayBreak:
isFirstMessage || isFirstEvent ||
previousItem &&
date_time.getDay() != previousItem.date_time.getDay() date_time.getDay() != previousItem.date_time.getDay()
readonly property bool talkBreak: readonly property bool talkBreak:
! isFirstMessage && previousItem &&
! dayBreak && ! dayBreak &&
mins_between(previousItem.date_time, date_time) >= 20 mins_between(previousItem.date_time, date_time) >= 20
@ -51,9 +58,15 @@ Column {
property int horizontalPadding: 7 property int horizontalPadding: 7
property int verticalPadding: 5 property int verticalPadding: 5
ListView.onAdd: {
var next_delegate = messageListView.contentItem.children[index]
if (next_delegate) { next_delegate.reloadPreviousItem() }
}
width: parent.width width: parent.width
topPadding: topPadding:
! previousItem ? 0 : isFirstEvent ? 0 :
talkBreak ? standardSpacing * 3 : talkBreak ? standardSpacing * 3 :
combine ? standardSpacing / 4 : combine ? standardSpacing / 4 :
standardSpacing standardSpacing