~phablet-team/messaging-app/select-part-of-message

« back to all changes in this revision

Viewing changes to src/qml/RegularMessageDelegate_irc.qml

  • Committer: Tiago Salem Herrmann
  • Date: 2017-02-08 21:04:29 UTC
  • mfrom: (639.12.11 sort-thread)
  • Revision ID: tiago.herrmann@canonical.com-20170208210429-kk2s6v6jbxj8qnmr
merge parent

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright 2012-2016 Canonical Ltd.
 
3
 *
 
4
 * This file is part of messaging-app.
 
5
 *
 
6
 * messaging-app is free software; you can redistribute it and/or modify
 
7
 * it under the terms of the GNU General Public License as published by
 
8
 * the Free Software Foundation; version 3.
 
9
 *
 
10
 * messaging-app is distributed in the hope that it will be useful,
 
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 * GNU General Public License for more details.
 
14
 *
 
15
 * You should have received a copy of the GNU General Public License
 
16
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
17
 */
 
18
 
 
19
import QtQuick 2.2
 
20
import Ubuntu.Components 1.3
 
21
import Ubuntu.Contacts 0.1
 
22
import Ubuntu.History 0.1
 
23
 
 
24
ListItem {
 
25
    id: messageDelegate
 
26
    objectName: "messageDelegate"
 
27
 
 
28
    // To be used by actions
 
29
    property int _index: index
 
30
 
 
31
    property var messageData: null
 
32
    property string messageText: messageData ? messageData.textMessage : ""
 
33
    property bool incoming: (messageData && messageData.senderId !== "self")
 
34
    property string accountLabel: ""
 
35
    property var account: null
 
36
    property var _accountRegex: account && (account.selfContactId != "") ? new RegExp('\\b' + account.selfContactId + '\\b', 'g') : null
 
37
 
 
38
    function deleteMessage()
 
39
    {
 
40
        eventModel.removeEvents([messageData.properties]);
 
41
    }
 
42
 
 
43
    function forwardMessage()
 
44
    {
 
45
        var properties = {}
 
46
        var items = [{"text": textMessage, "url":""}]
 
47
        emptyStack()
 
48
        var transfer = {}
 
49
 
 
50
        for (var i = 0; i < dataAttachments.length; i++) {
 
51
            var attachment = dataAttachments[i].data
 
52
            var item = {"text":"", "url":""}
 
53
            var contentType = application.fileMimeType(String(attachment.filePath))
 
54
            // we dont include smil files. they will be auto generated
 
55
            if (startsWith(contentType.toLowerCase(), "application/smil")) {
 
56
                continue
 
57
            }
 
58
            item["url"] = "file://" + attachment.filePath
 
59
            items.push(item)
 
60
        }
 
61
 
 
62
        transfer["items"] = items
 
63
        properties["sharedAttachmentsTransfer"] = transfer
 
64
 
 
65
        mainView.showMessagesView(properties)
 
66
    }
 
67
 
 
68
    function copyMessage()
 
69
    {
 
70
        Clipboard.push(messageText)
 
71
        application.showNotificationMessage(i18n.tr("Text message copied to clipboard"), "edit-copy")
 
72
    }
 
73
 
 
74
    function resendMessage()
 
75
    {
 
76
        var newAttachments = []
 
77
        for (var i = 0; i < attachments.length; i++) {
 
78
            var attachment = []
 
79
            var item = attachments[i]
 
80
            // we dont include smil files. they will be auto generated
 
81
            if (item.contentType.toLowerCase() === "application/smil") {
 
82
                continue
 
83
            }
 
84
            // text messages will be sent as textMessage. skip it
 
85
            // to avoid duplication
 
86
            if (item.contentType.toLowerCase() === "text/plain") {
 
87
                continue
 
88
            }
 
89
            attachment.push(item.attachmentId)
 
90
            attachment.push(item.contentType)
 
91
            attachment.push(item.filePath)
 
92
            newAttachments.push(attachment)
 
93
        }
 
94
 
 
95
        messages.validator.validateMessageAndSend(textMessage, messages.participantIds, newAttachments, {"x-canonical-tmp-files": true}, [messageDelegate.deleteMessage])
 
96
    }
 
97
 
 
98
    width: messageList.width
 
99
    height: label.contentHeight
 
100
    divider.visible: false
 
101
    contentItem.clip: false
 
102
 
 
103
    Label {
 
104
        id: label
 
105
 
 
106
        property string sender: {
 
107
            if (messages.chatType == HistoryThreadModel.ChatTypeRoom || messageData.participants.length > 1) {
 
108
                if (messageData.sender && incoming) {
 
109
                    if (messageData.sender.alias !== undefined && messageData.sender.alias !== "") {
 
110
                        return messageData.sender.alias
 
111
                    } else if (messageData.sender.identifier !== undefined && messageData.sender.identifier !== "") {
 
112
                        return messageData.sender.identifier
 
113
                    } else if (messageData.senderId !== "") {
 
114
                        return messageData.senderId
 
115
                    }
 
116
                }
 
117
            }
 
118
            return account.selfContactId
 
119
        }
 
120
 
 
121
 
 
122
        anchors {
 
123
            left: parent.left
 
124
            right: parent.right
 
125
            margins: units.gu(1)
 
126
        }
 
127
        text: "<font color=\"%1\">[%2]</font>\t%3"
 
128
            .arg(incoming ? "green" : "blue")
 
129
            .arg(sender)
 
130
            .arg(messageDelegate.messageText)
 
131
        font.bold: (messages.chatType === HistoryThreadModel.ChatTypeRoom) &&
 
132
                   messageDelegate.incoming &&
 
133
                   (_accountRegex && text.match(_accountRegex))
 
134
        wrapMode: Text.WordWrap
 
135
    }
 
136
 
 
137
    //highlightColor: "transparent"
 
138
 
 
139
    leadingActions: ListItemActions {
 
140
        actions: [
 
141
            Action {
 
142
                iconName: "delete"
 
143
                text: i18n.tr("Delete")
 
144
                onTriggered: deleteMessage()
 
145
            }
 
146
        ]
 
147
        delegate: Rectangle {
 
148
            width: height + units.gu(4.5)
 
149
            color: UbuntuColors.red
 
150
            Icon {
 
151
                name: action.iconName
 
152
                width: units.gu(3)
 
153
                height: width
 
154
                color: "white"
 
155
                anchors.centerIn: parent
 
156
            }
 
157
        }
 
158
    }
 
159
 
 
160
    trailingActions: ListItemActions {
 
161
        actions: [
 
162
            Action {
 
163
                id: retryAction
 
164
 
 
165
                iconName: "reload"
 
166
                text: i18n.tr("Retry")
 
167
                visible: messageData.textMessageStatus === HistoryThreadModel.MessageStatusPermanentlyFailed
 
168
                onTriggered: messageDelegate.resendMessage()
 
169
            },
 
170
            Action {
 
171
                id: copyAction
 
172
 
 
173
                iconName: "edit-copy"
 
174
                text: i18n.tr("Copy")
 
175
                visible: messageText !== ""
 
176
                onTriggered: messageDelegate.copyMessage()
 
177
            },
 
178
            Action {
 
179
                id: forwardAction
 
180
 
 
181
                iconName: "mail-forward"
 
182
                text: i18n.tr("Forward")
 
183
                onTriggered: messageDelegate.forwardMessage()
 
184
            },
 
185
            Action {
 
186
                id: infoAction
 
187
 
 
188
                iconName: "info"
 
189
                text: i18n.tr("Info")
 
190
                onTriggered: {
 
191
                    var messageType = attachments.length > 0 ? i18n.tr("MMS") : i18n.tr("SMS")
 
192
                    var messageInfo = {"type": messageType,
 
193
                                       "senderId": messageData.senderId,
 
194
                                       "sender": messageData.sender,
 
195
                                       "timestamp": messageData.timestamp,
 
196
                                       "textReadTimestamp": messageData.textReadTimestamp,
 
197
                                       "status": messageData.textMessageStatus,
 
198
                                       "participants": messages.participants}
 
199
                    messageInfoDialog.showMessageInfo(messageInfo)
 
200
                }
 
201
            }
 
202
        ]
 
203
    }
 
204
 
 
205
    Component.onCompleted: {
 
206
        if (messageData.newEvent) {
 
207
            messages.markThreadAsRead();
 
208
        }
 
209
    }
 
210
}