2019-07-13 19:39:01 +10:00
|
|
|
import QtQuick 2.12
|
2019-04-29 05:18:36 +10:00
|
|
|
import "../../Base"
|
2019-07-20 13:07:26 +10:00
|
|
|
import "../../utils.js" as Utils
|
2019-03-22 14:28:14 +11:00
|
|
|
|
2019-08-28 12:46:31 +10:00
|
|
|
Rectangle {
|
2019-07-14 10:15:20 +10:00
|
|
|
property alias listView: eventList
|
2019-07-07 07:29:32 +10:00
|
|
|
|
2019-07-14 10:15:20 +10:00
|
|
|
color: theme.chat.eventList.background
|
2019-04-29 01:01:38 +10:00
|
|
|
|
2019-08-31 01:17:13 +10:00
|
|
|
HSelectableLabelContainer {
|
|
|
|
id: selectableLabelContainer
|
|
|
|
anchors.fill: parent
|
|
|
|
reversed: eventList.verticalLayoutDirection == ListView.BottomToTop
|
|
|
|
|
|
|
|
onDragPositionChanged: {
|
2019-09-01 19:19:41 +10:00
|
|
|
let left = dragPoint.pressedButtons & Qt.LeftButton
|
|
|
|
let vel = dragPoint.velocity.y
|
2019-09-01 19:16:47 +10:00
|
|
|
|
2019-08-31 01:17:13 +10:00
|
|
|
let boost = 20 * (
|
|
|
|
dragPosition.y < 50 ?
|
|
|
|
-dragPosition.y : -(height - dragPosition.y)
|
2019-07-20 13:07:26 +10:00
|
|
|
)
|
2019-08-31 01:17:13 +10:00
|
|
|
|
|
|
|
dragFlicker.speed =
|
2019-09-01 19:19:41 +10:00
|
|
|
dragPosition.x == 0 && dragPosition.y == 0 ? 0 :
|
|
|
|
left && vel && dragPosition.y < 50 ? 1000 + boost:
|
|
|
|
left && vel && dragPosition.y > height - 50 ? -1000 + -boost :
|
2019-08-31 01:17:13 +10:00
|
|
|
0
|
2019-07-20 13:07:26 +10:00
|
|
|
}
|
|
|
|
|
2019-09-01 13:58:51 +10:00
|
|
|
|
2019-08-31 01:17:13 +10:00
|
|
|
Timer {
|
|
|
|
id: dragFlicker
|
|
|
|
interval: 100
|
|
|
|
running: speed != 0
|
|
|
|
repeat: true
|
|
|
|
|
|
|
|
onTriggered: {
|
|
|
|
if (eventList.verticalOvershoot != 0) return
|
|
|
|
if (speed < 0 && eventList.atYEnd) return
|
|
|
|
if (eventList.atYBeggining) {
|
|
|
|
if (bouncedStart) { return } else { bouncedStart = true }
|
|
|
|
}
|
|
|
|
|
|
|
|
eventList.flick(0, speed * acceleration)
|
|
|
|
acceleration = Math.min(8, acceleration * 1.05)
|
|
|
|
}
|
|
|
|
onRunningChanged: if (! running) {
|
|
|
|
acceleration = 1.0
|
|
|
|
bouncedStart = false
|
|
|
|
eventList.cancelFlick()
|
|
|
|
eventList.returnToBounds()
|
|
|
|
}
|
2019-07-20 13:07:26 +10:00
|
|
|
|
2019-08-31 01:17:13 +10:00
|
|
|
property real speed: 0.0
|
|
|
|
property real acceleration: 1.0
|
|
|
|
property bool bouncedStart: false
|
2019-07-20 13:07:26 +10:00
|
|
|
}
|
|
|
|
|
2019-08-31 01:17:13 +10:00
|
|
|
HListView {
|
|
|
|
id: eventList
|
|
|
|
clip: true
|
|
|
|
enableFlicking: false
|
2019-08-31 00:33:17 +10:00
|
|
|
|
2019-08-31 01:17:13 +10:00
|
|
|
anchors.fill: parent
|
|
|
|
anchors.leftMargin: theme.spacing
|
|
|
|
anchors.rightMargin: theme.spacing
|
2019-07-20 13:07:26 +10:00
|
|
|
|
2019-08-31 01:17:13 +10:00
|
|
|
topMargin: theme.spacing
|
|
|
|
bottomMargin: theme.spacing
|
|
|
|
verticalLayoutDirection: ListView.BottomToTop
|
2019-07-20 13:07:26 +10:00
|
|
|
|
2019-08-31 01:17:13 +10:00
|
|
|
// Keep x scroll pages cached, to limit images having to be
|
|
|
|
// reloaded from network.
|
|
|
|
cacheBuffer: height * 4
|
2019-07-03 03:59:52 +10:00
|
|
|
|
2019-08-31 01:17:13 +10:00
|
|
|
onYPosChanged:
|
|
|
|
if (canLoad && yPos < 0.1) Qt.callLater(loadPastEvents)
|
2019-07-18 20:23:31 +10:00
|
|
|
|
2019-08-31 01:17:13 +10:00
|
|
|
// When an invited room becomes joined, we should now be able to
|
|
|
|
// fetch past events.
|
|
|
|
onInviterChanged: canLoad = true
|
2019-07-03 03:59:52 +10:00
|
|
|
|
2019-08-31 01:17:13 +10:00
|
|
|
Component.onCompleted: shortcuts.flickTarget = eventList
|
|
|
|
|
|
|
|
|
|
|
|
property string inviter: chatPage.roomInfo.inviter || ""
|
|
|
|
property real yPos: visibleArea.yPosition
|
|
|
|
property bool canLoad: true
|
|
|
|
|
|
|
|
property bool ownEventsOnRight:
|
|
|
|
width < theme.chat.eventList.ownEventsOnRightUnderWidth
|
|
|
|
|
|
|
|
|
|
|
|
function canCombine(item, itemAfter) {
|
|
|
|
if (! item || ! itemAfter) return false
|
|
|
|
|
|
|
|
return Boolean(
|
|
|
|
! canTalkBreak(item, itemAfter) &&
|
|
|
|
! canDayBreak(item, itemAfter) &&
|
|
|
|
item.sender_id === itemAfter.sender_id &&
|
|
|
|
Utils.minutesBetween(item.date, itemAfter.date) <= 5
|
2019-08-20 03:14:25 +10:00
|
|
|
)
|
|
|
|
}
|
2019-08-16 01:46:40 +10:00
|
|
|
|
2019-08-31 01:17:13 +10:00
|
|
|
function canTalkBreak(item, itemAfter) {
|
|
|
|
if (! item || ! itemAfter) return false
|
|
|
|
|
|
|
|
return Boolean(
|
|
|
|
! canDayBreak(item, itemAfter) &&
|
|
|
|
Utils.minutesBetween(item.date, itemAfter.date) >= 20
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
function canDayBreak(item, itemAfter) {
|
|
|
|
if (itemAfter && itemAfter.event_type == "RoomCreateEvent")
|
|
|
|
return true
|
|
|
|
|
|
|
|
if (! item || ! itemAfter || ! item.date || ! itemAfter.date)
|
|
|
|
return false
|
|
|
|
|
|
|
|
return item.date.getDate() != itemAfter.date.getDate()
|
|
|
|
}
|
|
|
|
|
|
|
|
function loadPastEvents() {
|
|
|
|
// try/catch blocks to hide pyotherside error when the
|
|
|
|
// component is destroyed but func is still running
|
|
|
|
|
|
|
|
try {
|
|
|
|
eventList.canLoad = false
|
|
|
|
|
|
|
|
py.callClientCoro(
|
|
|
|
chatPage.userId, "load_past_events", [chatPage.roomId],
|
|
|
|
moreToLoad => {
|
|
|
|
try {
|
|
|
|
eventList.canLoad = moreToLoad
|
|
|
|
} catch (err) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
} catch (err) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
model: HListModel {
|
|
|
|
keyField: "client_id"
|
|
|
|
source: modelSources[[
|
|
|
|
"Event", chatPage.userId, chatPage.roomId
|
|
|
|
]] || []
|
|
|
|
}
|
|
|
|
|
|
|
|
delegate: EventDelegate {}
|
|
|
|
}
|
2019-03-22 14:28:14 +11:00
|
|
|
}
|
2019-04-23 01:31:06 +10:00
|
|
|
|
2019-05-03 04:20:21 +10:00
|
|
|
HNoticePage {
|
2019-08-16 01:56:28 +10:00
|
|
|
text: qsTr("No messages visible yet.")
|
2019-04-29 04:20:30 +10:00
|
|
|
|
2019-07-14 10:15:20 +10:00
|
|
|
visible: eventList.model.count < 1
|
2019-05-03 04:20:21 +10:00
|
|
|
anchors.fill: parent
|
2019-04-23 01:31:06 +10:00
|
|
|
}
|
2019-03-22 14:28:14 +11:00
|
|
|
}
|