~nicohman/signal-rs

ref: 5084c926fb753fdc6dda5f3cc2c8af2df5f1190b signal-rs/qml/messages/ChatHistory.qml -rw-r--r-- 3.5 KiB
5084c926 — nicohman Make SignalUI a singleton and add application icon 4 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import QtQuick 2.0
import QtQuick.Controls 2.5
import QtQuick.Layouts 1.15
import QtQuick.Dialogs 1.3
import org.kde.kirigami 2.13 as Kirigami
import SignalUI 0.1

Kirigami.ScrollablePage {
    //anchors.fill: stackView
    id: chatHistory
    property var msgImgComponent: Qt.createComponent(Qt.resolvedUrl("MessageImage.qml"))
    objectName: "chatHistory"
    title: signalState.currentName
    actions.main: Kirigami.Action {
        id: editContactAction
        icon.name: "document-edit"
        text: "Edit Chat"
        onTriggered: {
            if (signalState.currentIsGroup) {
                signalState.editGroup(signalState.currentChat.tel);
                signalState.openView("editGroup");
            } else {
                signalState.openView("editContact");
            }
        }
    }
    function sendMessage() {
        console.log("Sending "+ msgTextInput.text +" to "+signalState.current);
        if (signalState.currentIsGroup) {
            SignalUI.send_group_message(signalState.current, msgTextInput.text, "");
        } else {
            SignalUI.send_message(signalState.current, msgTextInput.text, "");
        }
        msgTextInput.text = "";
    }
    Connections {
        target: SignalUI
        function onChats_changed () {
            signalState.setCurrent(signalState.current);
        }
    }
    FileDialog {
        id: fd
        title: "Upload an attachment"
        selectExisting: true
        selectFolder: false
        selectMultiple: false
        onAccepted: {
            var path = fd.fileUrl.toString().replace("file://", "");
            if (signalState.currentIsGroup) {
            SignalUI.send_group_message(signalState.current, msgTextInput.text, path);

                } else {


            SignalUI.send_message(signalState.current, msgTextInput.text, path);
        }
        }
    }
           ListView {
            verticalLayoutDirection: ListView.BottomToTop
                anchors.fill: parent
            Layout.topMargin: 10
            highlight: Rectangle {
                color: "transparent"
            }
            Component.onCompleted: {
                chatView.positionViewAtEnd()
            }
            id: chatView
            x: 0
            y: 0
            Layout.fillWidth: true
            //Layout.maximumHeight:window.height - window.header.height - sendButton.height - msgTextInput.height
            Layout.fillHeight: true
            Layout.rightMargin: 5
            delegate:
                MessageUI {
                    outgoing: outgoing
                    message: model
                }
            model: SignalUI.messages
        }

    footer:         Row {
            Layout.fillWidth: true
            TextField {
                placeholderText: "Write a message"
                id: msgTextInput
                width: parent.width - addAttachmentButton.width - sendButton.width
                onAccepted: {
                    chatHistory.sendMessage();
                }
            }
            Button {
                id: addAttachmentButton
                icon.name: "edit-add"
                display:AbstractButton.IconOnly
                onClicked: {
                    fd.visible = true;
                }
            }
            Button {
                id: sendButton
                icon.name: "document-send"
                display:AbstractButton.IconOnly
               action: Kirigami.Action {
                onTriggered: {
                    chatHistory.sendMessage();
                }
               }
            }
        }
}