141 lines
4.4 KiB
QML
141 lines
4.4 KiB
QML
import QtGraphicalEffects 1.0
|
|
import QtQuick 2.7
|
|
import QtQuick.Controls 2.4
|
|
import QtQuick.Controls.Material 2.0
|
|
import QtQuick.Layouts 1.3
|
|
|
|
import "../opaque" as Opaque
|
|
import "../opaque/controls" as Awesome
|
|
import "../opaque/fonts/Twemoji.js" as T
|
|
import "../utils.js" as Utils
|
|
import "../widgets" as W
|
|
import "../opaque/theme"
|
|
|
|
W.Overlay {
|
|
property bool loading
|
|
|
|
//horizontalPadding: 15 * gcd.themeScale
|
|
|
|
Connections {
|
|
target: mm
|
|
onRowsInserted: {
|
|
if (messagesListView.atYEnd) thymer.running = true
|
|
|
|
//todo: this won't fire for non-active convos
|
|
windowItem.alert(0)
|
|
if (gcd.os == "android" && windowItem.activeFocusItem == null) {
|
|
androidCwtchActivity.notification = "New Content"
|
|
}
|
|
}
|
|
}
|
|
|
|
// onRowsInserted is firing after the model is updated but before the delegate is inflated
|
|
// causing positionViewAtEnd() to scroll to "just above the last message"
|
|
// so we use this timer to delay scrolling by a few milliseconds
|
|
Timer {
|
|
id: thymer
|
|
interval: 30
|
|
onTriggered: {
|
|
thymer.running = false
|
|
messagesListView.positionViewAtEnd()
|
|
}
|
|
}
|
|
|
|
contentItem: ListView {
|
|
id: messagesListView
|
|
|
|
Layout.fillWidth: true
|
|
|
|
width: parent.width
|
|
model: mm
|
|
spacing: 6
|
|
|
|
clip: true
|
|
ScrollBar.vertical: Opaque.ScrollBar {}
|
|
maximumFlickVelocity: 1250
|
|
|
|
section.delegate: sectionHeading
|
|
section.property: "Day"
|
|
|
|
|
|
delegate: W.Message {
|
|
handle: PeerID
|
|
from: PeerID
|
|
displayName: mm.getNick(PeerID)
|
|
message: JSON.parse(RawMessage).d
|
|
rawMessage: RawMessage
|
|
image: mm.getImage(PeerID)
|
|
messageID: Signature
|
|
fromMe: PeerID == gcd.selectedProfile
|
|
timestamp: parseInt(Timestamp)
|
|
ackd: Acknowledged
|
|
error: Error
|
|
calendarEvent: PeerID == "calendar"
|
|
// listview doesnt do anchors right
|
|
// https://stackoverflow.com/questions/31381997/why-does-anchors-fill-does-not-work-in-a-qml-listviews-delegates-subviews-and/31382307
|
|
width: messagesListView.width
|
|
}
|
|
|
|
Component {
|
|
id: sectionHeading
|
|
Rectangle {// ⟵ outer rect because anchors._Margin isnt supported here
|
|
// with qt 5.15+ this↓ can be changed to...
|
|
// required property string section
|
|
property string txt: section
|
|
color: Theme.backgroundMainColor
|
|
width: parent.width
|
|
height: texmet.height + 6 + 12 * gcd.themeScale
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
|
|
|
|
Rectangle {
|
|
opacity: 1
|
|
width: texmet.width + radius * 4 + 6
|
|
height: texmet.height + 6
|
|
color: Theme.messageFromOtherBackgroundColor
|
|
radius: texmet.height / 2
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
|
|
|
|
Text {
|
|
id: txtDate
|
|
// ... and this can be changed to
|
|
// text: parent.parent.section
|
|
text: parent.parent.txt
|
|
font.pixelSize: Theme.chatSize * gcd.themeScale
|
|
color: Theme.messageFromOtherTextColor
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
}
|
|
|
|
TextMetrics {
|
|
id: texmet
|
|
text: txtDate.text
|
|
font.pixelSize: Theme.chatSize * gcd.themeScale
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
Connections {
|
|
target: gcd
|
|
|
|
onClearMessages: function() {
|
|
messagesListView.model = null
|
|
messagesListView.model = mm
|
|
messagesListView.positionViewAtEnd()
|
|
thymer.running = true
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
onSendClicked: function(messageText) {
|
|
var msg = JSON.stringify({"o":1, "d":messageText.replace(/\[\:newline\:\]/g,"\n")})
|
|
gcd.sendMessage(msg)
|
|
}
|
|
}
|
|
|
|
|