Fix messages and non-messages getting combined

This commit is contained in:
miruka 2019-07-02 23:32:39 -04:00
parent f0c5afe8c7
commit c8347647b9

View File

@ -9,9 +9,16 @@ Column {
return Math.round((((date2 - date1) % 86400000) % 3600000) / 60000) return Math.round((((date2 - date1) % 86400000) % 3600000) / 60000)
} }
function getPreviousItem() { function getPreviousItem(nth) {
return index < roomEventListView.model.count - 1 ? // Remember, index 0 = newest bottomest message
roomEventListView.model.get(index + 1) : null nth = nth || 1
return model.index + nth - 1 < roomEventListView.model.count - 1 ?
roomEventListView.model.get(index + nth) : null
}
function isMessage(item) {
item = item || model
return /^RoomMessage($|[A-Z])/.test(item.eventType)
} }
property var previousItem: getPreviousItem() property var previousItem: getPreviousItem()
@ -20,17 +27,18 @@ Column {
property var senderInfo: null property var senderInfo: null
Component.onCompleted: Component.onCompleted:
senderInfo = models.users.getUser(chatPage.userId, senderId) senderInfo = models.users.getUser(chatPage.userId, model.senderId)
readonly property bool isOwn: chatPage.userId === senderId readonly property bool isOwn: chatPage.userId === model.senderId
readonly property bool isFirstEvent: model.event_type == "RoomCreateEvent" readonly property bool isFirstEvent: model.eventType == "RoomCreateEvent"
readonly property bool combine: readonly property bool combine:
previousItem && previousItem &&
isMessage(previousItem) == isMessage(model) &&
! talkBreak && ! talkBreak &&
! dayBreak && ! dayBreak &&
previousItem.senderId === senderId && previousItem.senderId === model.senderId &&
minsBetween(previousItem.date, model.date) <= 5 minsBetween(previousItem.date, model.date) <= 5
readonly property bool dayBreak: readonly property bool dayBreak: