~cellsoftware/telegram-app/autopilotTest-4

« back to all changes in this revision

Viewing changes to telegram/app/qml/components/MessagesListItem.qml

  • Committer: Paz Chauhan
  • Date: 2016-11-10 14:49:57 UTC
  • mfrom: (243.2.2 telegram-app)
  • Revision ID: paz.chauhan@cellsoftware.co.uk-20161110144957-0kexnmggnkfh0sau
conflicts resolved

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
 
37
37
    property Message message
38
38
    property string messageText: message.message
 
39
    property string messageHtmlText: parseText(message.message)
39
40
    property User user: telegramObject.user(message.fromId)
40
41
    property User fwdUser: telegramObject.user(message.fwdFromId)
41
42
 
42
43
    property bool sent: message.sent
43
44
    property bool uploading: message.upload.fileId !== 0
44
45
 
45
 
    property variant messageLinks: Tools.stringLinks(message.message)
46
 
    property bool hasLink: messageLinks.length !== 0
 
46
    property bool hasLink: htmlHasLinks(messageHtmlText)
47
47
    property bool allowLoadLinks: telegram.userData.isLoadLink(user.id)
48
48
 
49
49
    property alias maximumMediaHeight: message_media.maximumMediaHeight
63
63
    signal messageFocusRequest(int msgId);
64
64
    signal previewRequest(int type, string path)
65
65
 
 
66
    // Taken from messaging-app
 
67
    function parseText(text) {
 
68
        var phoneExp = /(\+?([0-9]+[ ]?)?\(?([0-9]+)\)?[-. ]?([0-9]+)[-. ]?([0-9]+)[-. ]?([0-9]+))/img;
 
69
        // remove html tags
 
70
        text = text.replace(/</g,'&lt;').replace(/>/g,'<tt>&gt;</tt>');
 
71
        // replace line breaks
 
72
        text = text.replace(/(\n)+/g, '<br />');
 
73
        // check for links
 
74
        var htmlText = BaLinkify.linkify(text);
 
75
        if (htmlText !== text) {
 
76
            return htmlText;
 
77
        }
 
78
        // linkify phone numbers if no web links were found
 
79
        return text.replace(phoneExp, '<a href="tel:///$1">$1</a>');
 
80
    }
 
81
 
 
82
    function htmlHasLinks(html) {
 
83
        return html.indexOf('<a href="') !== -1;
 
84
    }
 
85
 
66
86
//    Connections {
67
87
//        target: telegram.userData
68
88
//        onLoadLinkChanged: {
263
283
                        horizontalAlignment: Text.AlignLeft
264
284
                        wrapMode: Text.WrapAtWordBoundaryOrAnywhere
265
285
                        textFormat: Text.RichText
266
 
                        text: messageText // emojis.textToEmojiText(messageText)
 
286
                        text: message_item.messageHtmlText // emojis.textToEmojiText(message_item.messageHtmlText)
267
287
 
268
288
                        onLinkActivated: {
269
289
                            if (link.slice(0,6) == "tag://") {
274
294
                        }
275
295
 
276
296
                        property real htmlWidth: Cutegram.htmlWidth(text)
277
 
                        property string messageText: {
278
 
                            return message_text.parseText(message.message)
279
 
                        }
280
297
                    }
281
298
 
282
299
                    MessageStatus {