~nicohman/signal-rs

ref: 5084c926fb753fdc6dda5f3cc2c8af2df5f1190b signal-rs/qml/messages/MessageUI.qml -rw-r--r-- 9.0 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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
import QtQuick 2.15
import QtQuick.Controls 2.5
import QtQuick.Layouts 1.15
import org.kde.kirigami 2.13 as Kirigami
import SignalUI 0.1

ItemDelegate {
    id: message
    x: 5
    height: rectangle.height + Kirigami.Units.gridUnit + emojiListView.height //+ emojiListView.anchors.topMargin
    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: Math.min(27 * Kirigami.Units.gridUnit, chatHistory.width - (Kirigami.Units.gridUnit ) * 2)
    width: parent ? parent.width : 0
    property ListModel attachmentModel: ListModel {
    }
    property ListModel reactionModel : ListModel {
    }
    Component.onCompleted : {
        if (message.message.attachment && message.message.attachment !== "[]") {
            var attachments  = JSON.parse(new String(message.message.attachment));
            if (attachments && attachments.length) {
                attachments.forEach(function(at) {
                    message.attachmentModel.append(at);
                });
            }
        }
        if (message.message.reactions && message.message.reactions !== "[]") {
            var reactions = JSON.parse(new String(message.message.reactions));
            if (reactions && reactions.length) {
                reactions.forEach(function(r) {
                    message.reactionModel.append(r);
                });
            }
        }
    }
    Row {
        id: row
        x: 0
        y: 0
        Layout.topMargin: 0
        anchors.fill: parent
        anchors.bottomMargin: 0
        layoutDirection: message.message.outgoing ? Qt.RightToLeft : Qt.LeftToRight
        Layout.rightMargin: 5
        Rectangle {
            Kirigami.Theme.colorSet:  message.message.outgoing ? Kirigami.Theme.Complementary : Kirigami.Theme.View  
            MouseArea {
                anchors.fill: parent
                acceptedButtons: Qt.RightButton
                onClicked : {
                    if (mouse.button === Qt.RightButton) {
                        msgRightClick.popup();
                    }
                }
                Menu {
                    id: msgRightClick
                    MenuItem {
                        onClicked: {
                            SignalUI.del_message(signalState.current, message.message.sent_at);
                        }
                        text: "Delete"
                    }
                    MenuItem {
                        onClicked: {
                            messageInfo.showMessage(message.message.chat_id, message.message.sent_at);
                        }
                        text: "More Info"
                    }
                }
            }
            id: rectangle
            width: Math.max(
                           textLabel.width,
                           dateLabel.implicitWidth, attachmentList.implicitWidth, dynName.implicitWidth) + 10
            height: textLabel.implicitHeight + textLabel.anchors.topMargin + 15
                    + dateLabel.implicitHeight + atRow.implicitHeight + dynName.implicitHeight + dynName.anchors.topMargin + attachmentList.anchors.topMargin + dateLabel.anchors.topMargin 
            color:  Kirigami.Theme.alternateBackgroundColor
            radius: 10
            anchors.top: parent.top
            anchors.topMargin: 10
            anchors.leftMargin: 5
            anchors.rightMargin: 5
            ColumnLayout {
                Row {
                    leftPadding: 5
                    TextEdit {
                        textFormat: Text.RichText
                        Kirigami.Theme.inherit: true
                        selectByMouse: !Kirigami.Settings.isMobile
                        readOnly: true
                        MouseArea {
                            anchors.fill: parent
                            cursorShape: parent.hoveredLink ? Qt.PointingHandCursor : Qt.IBeamCursor
                            acceptedButtons: Qt.NoButton
                        }
                        onLinkActivated: {
                            console.log("Opening link " + link);
                            Qt.openUrlExternally(link);
                        }
                    	color:  Kirigami.Theme.textColor
                        font.pixelSize: Qt.application.font.pixelSize
                        font.bold: false
                        id: textLabel
                        width: message.oneLine ? textLabel.implicitWidth : message.maxDelegateWidth
                        text: {
                            var regex = new RegExp("http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+");
                            return message.message.message.toString().replace(regex, "<a href=\"$&\">$&</a>");
                        }
                        wrapMode: Text.WordWrap
                    }
                }
                Row {
                    topPadding: {
                       return message.attachmentModel.count === 0 ? 0 : 5;
                    }
                    Layout.leftMargin: {
                       return message.attachmentModel.count === 0 ? 0 : 5;
                    }
                    id: atRow
                    ListView {
                    	id:attachmentList
                        model: message.attachmentModel
                        delegate: ItemDelegate {
                            id: atDel
                            Component.onCompleted: {
                                switch (CType) {
                                    case 2:
                                        var obj = msgimgover.createObject(atRow, {filePath: File});
                                        if (obj.width > rectangle.width) {
                                            rectangle.width = obj.width + 10;
                                        }
                                        break;
                                    default:
                                        var obj = Qt.createQmlObject('import QtQuick 2.15; import QtQuick.Controls 2.5; Label { text: "Can\'t display attachment"}', atDel, "defaultDel");
                                        attachmentList.height += obj.implicitHeight;
                                        break;
                                }
                            }
                        }
                    }
                }
                Row {
                	id: dynName
                	leftPadding: 5
                	Label {
                		text: SignalUI.resolve_name(message.message.source)
                		visible: signalState.currentIsGroup
                	}
                }
                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);
                            }
                        }
                    }
                }
                Row {
                    Layout.topMargin: -10
                    leftPadding: 5
                    height: emojiListView.implicitHeight
                    ListView {
                        id: emojiListView
                        orientation: ListView.Horizontal
                        model: message.reactionModel
                        delegate: ItemDelegate {
                            height:emojLab.implicitWidth
                            width: emojLab.implicitHeight
                             Rectangle {
                                anchors.fill: parent
                                Kirigami.Theme.colorSet: Kirigami.Theme.Complementary
                                Kirigami.Theme.inherit: false
                                radius: 50
                                color: Kirigami.Theme.alternateBackgroundColor
                                Label { 
                                    anchors.verticalCenter: parent.verticalCenter
                                    anchors.horizontalCenter: parent.horizontalCenter
                                    id: emojLab
                                    text: emoji
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}