aboutsummaryrefslogtreecommitdiff
path: root/qml/ChatPage.qml
diff options
context:
space:
mode:
authorlink2xt <link2xt@testrun.org>2021-10-02 23:30:45 +0000
committerlink2xt <link2xt@testrun.org>2021-10-02 23:30:45 +0000
commit2936a854df9f1a1202fda08cd71773a95c727603 (patch)
tree063e23801381e88d4b421884168c9e199166896c /qml/ChatPage.qml
parent40092aa096bac7e279eb5a4cc97758bac484236c (diff)
downloadkdeltachat-2936a854df9f1a1202fda08cd71773a95c727603.tar.gz
kdeltachat-2936a854df9f1a1202fda08cd71773a95c727603.zip
Fix QML code style
Mostly qmlformat, also rename root "id"s.
Diffstat (limited to 'qml/ChatPage.qml')
-rw-r--r--qml/ChatPage.qml94
1 files changed, 42 insertions, 52 deletions
diff --git a/qml/ChatPage.qml b/qml/ChatPage.qml
index a0541cc..63e3dae 100644
--- a/qml/ChatPage.qml
+++ b/qml/ChatPage.qml
@@ -1,51 +1,46 @@
+import DeltaChat 1.0
+import QtQml.Models 2.1
import QtQuick 2.12
import QtQuick.Controls 2.12
import QtQuick.Layouts 1.12
-import QtQml.Models 2.1
import org.kde.kirigami 2.12 as Kirigami
-import DeltaChat 1.0
-
Kirigami.ScrollablePage {
- id: chatPage
-
- title: chat ? chat.name : qsTr("Chat")
+ id: root
required property DcContext context
required property DcAccountsEventEmitter eventEmitter
-
required property var chatId
property DcChat chat: context.getChat(chatId)
function updateMessagelist() {
// Reverse message list, because it is laid out from bottom to top.
- let messagelist = context.getMsgIdList(chatId).reverse()
-
+ let messagelist = context.getMsgIdList(chatId).reverse();
for (let i = 0; i < messagelist.length; i++) {
- const msgId = messagelist[i]
-
+ const msgId = messagelist[i];
const item = {
- msgId: msgId
- }
-
+ "msgId": msgId
+ };
let j;
for (j = i; j < messagelistModel.count; j++) {
if (messagelistModel.get(j).msgId == msgId) {
- messagelistModel.move(j, i, 1)
- messagelistModel.set(i, item)
- break
+ messagelistModel.move(j, i, 1);
+ messagelistModel.set(i, item);
+ break;
}
}
+ if (j == messagelistModel.count)
+ messagelistModel.insert(i, item);
- if (j == messagelistModel.count) {
- messagelistModel.insert(i, item)
- }
}
+ if (messagelistModel.count > messagelist.length)
+ messagelistModel.remove(messagelist.length, messagelistModel.count - messagelist.length);
- if (messagelistModel.count > messagelist.length) {
- messagelistModel.remove(messagelist.length,
- messagelistModel.count - messagelist.length)
- }
+ }
+
+ title: chat ? chat.name : qsTr("Chat")
+ Component.onCompleted: {
+ root.updateMessagelist();
}
ListModel {
@@ -53,35 +48,26 @@ Kirigami.ScrollablePage {
}
Connections {
- target: chatPage.eventEmitter
-
function onChatModified() {
- console.log("CHAT MODIFIED!")
- chatPage.chat = context.getChat(chatId)
+ console.log("CHAT MODIFIED!");
+ root.chat = context.getChat(chatId);
}
+
function onIncomingMessage(accountId, chatId, msgId) {
- console.log("Incoming message for chat " + chatId)
+ console.log("Incoming message for chat " + chatId);
+ if (chatId == root.chatId)
+ root.updateMessagelist();
- if (chatId == chatPage.chatId) {
- chatPage.updateMessagelist()
- }
}
+
function onMessagesChanged(accountId, chatId, msgId) {
- console.log("Messages changed for chat " + chatId)
+ console.log("Messages changed for chat " + chatId);
+ if (chatId == root.chatId || chatId == 0)
+ root.updateMessagelist();
- if (chatId == chatPage.chatId || chatId == 0) {
- chatPage.updateMessagelist()
- }
}
- }
-
- Component.onCompleted: {
- chatPage.updateMessagelist()
- }
- background: Rectangle {
- color: Kirigami.Theme.alternateBackgroundColor
- anchors.fill: parent
+ target: root.eventEmitter
}
ListView {
@@ -89,9 +75,7 @@ Kirigami.ScrollablePage {
anchors.fill: parent
spacing: Kirigami.Units.largeSpacing
-
model: messagelistModel
-
/*
* Messages are laid out bottom to top, because their height
* is not known in advance.
@@ -104,17 +88,23 @@ Kirigami.ScrollablePage {
verticalLayoutDirection: ListView.BottomToTop
delegate: Message {
- message: chatPage.context.getMessage(msgId)
- context: chatPage.context
+ message: root.context.getMessage(msgId)
+ context: root.context
width: ListView.view.width
}
+
}
- footer: ComposePane {
- context: chatPage.context
- chatId: chatPage.chatId
- chat: chatPage.chat
+ background: Rectangle {
+ color: Kirigami.Theme.alternateBackgroundColor
+ anchors.fill: parent
+ }
+ footer: ComposePane {
+ context: root.context
+ chatId: root.chatId
+ chat: root.chat
Layout.fillWidth: true
}
+
}