2
* Copyright 2012-2016 Canonical Ltd.
4
* This file is part of messaging-app.
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.
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.
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/>.
20
import Ubuntu.Components 1.3
21
import Ubuntu.Contacts 0.1
22
import Ubuntu.History 0.1
26
objectName: "messageDelegate"
28
// To be used by actions
29
property int _index: index
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
38
function deleteMessage()
40
eventModel.removeEvents([messageData.properties]);
43
function forwardMessage()
46
var items = [{"text": textMessage, "url":""}]
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")) {
58
item["url"] = "file://" + attachment.filePath
62
transfer["items"] = items
63
properties["sharedAttachmentsTransfer"] = transfer
65
mainView.showMessagesView(properties)
68
function copyMessage()
70
Clipboard.push(messageText)
71
application.showNotificationMessage(i18n.tr("Text message copied to clipboard"), "edit-copy")
74
function resendMessage()
76
var newAttachments = []
77
for (var i = 0; i < attachments.length; i++) {
79
var item = attachments[i]
80
// we dont include smil files. they will be auto generated
81
if (item.contentType.toLowerCase() === "application/smil") {
84
// text messages will be sent as textMessage. skip it
85
// to avoid duplication
86
if (item.contentType.toLowerCase() === "text/plain") {
89
attachment.push(item.attachmentId)
90
attachment.push(item.contentType)
91
attachment.push(item.filePath)
92
newAttachments.push(attachment)
95
messages.validator.validateMessageAndSend(textMessage, messages.participantIds, newAttachments, {"x-canonical-tmp-files": true}, [messageDelegate.deleteMessage])
98
width: messageList.width
99
height: label.contentHeight
100
divider.visible: false
101
contentItem.clip: false
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
118
return account.selfContactId
127
text: "<font color=\"%1\">[%2]</font>\t%3"
128
.arg(incoming ? "green" : "blue")
130
.arg(messageDelegate.messageText)
131
font.bold: (messages.chatType === HistoryThreadModel.ChatTypeRoom) &&
132
messageDelegate.incoming &&
133
(_accountRegex && text.match(_accountRegex))
134
wrapMode: Text.WordWrap
137
//highlightColor: "transparent"
139
leadingActions: ListItemActions {
143
text: i18n.tr("Delete")
144
onTriggered: deleteMessage()
147
delegate: Rectangle {
148
width: height + units.gu(4.5)
149
color: UbuntuColors.red
151
name: action.iconName
155
anchors.centerIn: parent
160
trailingActions: ListItemActions {
166
text: i18n.tr("Retry")
167
visible: messageData.textMessageStatus === HistoryThreadModel.MessageStatusPermanentlyFailed
168
onTriggered: messageDelegate.resendMessage()
173
iconName: "edit-copy"
174
text: i18n.tr("Copy")
175
visible: messageText !== ""
176
onTriggered: messageDelegate.copyMessage()
181
iconName: "mail-forward"
182
text: i18n.tr("Forward")
183
onTriggered: messageDelegate.forwardMessage()
189
text: i18n.tr("Info")
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)
205
Component.onCompleted: {
206
if (messageData.newEvent) {
207
messages.markThreadAsRead();