~nicohman/signal-rs

ref: 0dda6ee3b1035fc46c4f26a945876f1f3062cb3d signal-rs/qml/MessageUI.qml -rw-r--r-- 5.6 KiB
0dda6ee3nicohman Add sending group messages 9 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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
import QtQuick 2.15
import QtQuick.Controls 2.5
import QtQuick.Layouts 1.15

ItemDelegate {
    id: message
    x: 5
    height: rectangle.height + 5
    property string messagetext: "Lorem ipsum"
    property bool outgoing: true
    property var message: null
    property bool group: false
    property int oneLineWidth: textLabel.implicitWidth
    property bool oneLine: oneLineWidth <= maxDelegateWidth
    readonly property int maxDelegateWidth: 27 * 8
    width: parent.width
    property ListModel attachmentModel: ListModel {
    }
    Component.onCompleted : {
        if (message.message.attachment && message.message.attachment !== "[]") {
            var attachments  = JSON.parse(new String(message.message.attachment));
            attachments.forEach(function(at) {
                message.attachmentModel.append(at);
            });
        }
    }
    Row {
        id: row
        x: 0
        y: 0
        anchors.fill: parent
        anchors.bottomMargin: 0
        anchors.topMargin: 0
        anchors.horizontalCenterOffset: 0
        layoutDirection: message.message.outgoing ? Qt.RightToLeft : Qt.LeftToRight
        Layout.rightMargin: 5
        Rectangle {
            MouseArea {
                anchors.fill: parent
                acceptedButtons: Qt.RightButton
                onClicked : {
                    if (mouse.button === Qt.RightButton) {
                        msgRightClick.popup();
                    }
                }
                Menu {
                    id: msgRightClick
                    MenuItem {
                        onClicked: {
                            console.log(signalState.currentChat.tel);
                            signal.del_message(signalState.currentChat.tel, message.message.sent_at);
                            console.log("Delete")
                        }
                        text: "Delete"
                    }
                }
            }
            id: rectangle
            width: Math.min(
                       message.maxDelegateWidth, Math.max(
                           message.oneLine ? message.oneLineWidth : textLabel.implicitWidth,
                           dateLabel.implicitWidth, attachmentList.implicitWidth, dynName.implicitWidth)) + 10
            height: textLabel.implicitHeight + textLabel.anchors.topMargin + 5
                    + dateLabel.implicitHeight + attachmentList.implicitHeight + dynName.implicitHeight + dynName.anchors.topMargin +attachmentList.anchors.topMargin
            color: theme.highlight//"#6393e0"
            radius: 10
            anchors.top: parent.top
            anchors.topMargin: 10
            anchors.leftMargin: 5
            anchors.rightMargin: 5
            ColumnLayout {
                Row {
                    leftPadding: 5
                    Label {
                    	color: theme.highlightedText
                        font.pixelSize: Qt.application.font.pixelSize
                        //minimumPointSize: 10
                        font.bold: false
                        id: textLabel
                        width: message.oneLine ? textLabel.implicitWidth : message.maxDelegateWidth
                        text: message.message.message
                        wrapMode: Text.Wrap
                    }
                }
                ListView {
                	id:attachmentList
                    model: message.attachmentModel
                    delegate: Row {
                        id: atDel
                        Component.onCompleted: {
                            switch (CType) {
                                case 2:
                                    var obj = Qt.createQmlObject(`import QtQuick 2.15; Image { width: 350\nfillMode: Image.PreserveAspectFit\nsource: "file://${File}"}`,atDel,  "imageDel");
                                    rectangle.height += obj.implicitHeight;
                                    break;
                                default:
                                    var obj = Qt.createQmlObject('import QtQuick 2.15; Text { text: "Can\'t display"}', atDel, "defaultDel");
                                    rectangle.height += obj.implicitHeight;
                                    break;
                            }
                        }
                    }
                }
                Row {
                	id: dynName
                	leftPadding: 5
                	Label {
                		color: theme.highlightedText
                		text: signalState.contact(message.message.source).Name || message.message.source
                		visible: signalState.currentChat.is_group
                	}
                }
                Row {
                    leftPadding: 5
                    Label {
                        color: theme.highlightedText
                        Layout.leftMargin: 5
                        id: dateLabel
                        text: {
                            var now = new Date();
                            var dateobj = new Date(message.message.sent_at);
                            if (dateobj.getDate() === now.getDate()
                                    && dateobj.getMonth() === now.getMonth()) {
                                return dateobj.toLocaleTimeString(
                                            Qt.locale("en_US"), Locale.ShortFormat);
                            } else {
                                return dateobj.toLocaleDateString(
                                            Qt.locale("en_US"),
                                            Locale.ShortFormat);
                            }
                        }
                    }
                }
            }
        }
    }
}