Merge lp:~d.filoni/telegram-app/bug1564823 into lp:telegram-app

Proposed by Devid Antonio Filoni
Status: Merged
Approved by: Jin
Approved revision: 244
Merged at revision: 244
Proposed branch: lp:~d.filoni/telegram-app/bug1564823
Merge into: lp:telegram-app
Diff against target: 88 lines (+23/-21)
1 file modified
telegram/app/qml/components/MessagesListItem.qml (+23/-21)
To merge this branch: bzr merge lp:~d.filoni/telegram-app/bug1564823
Reviewer Review Type Date Requested Status
Jin (community) Approve
Review via email: mp+309800@code.launchpad.net

Description of the change

This MR fixes bug #1564823 : AsemanTools::stringLinks doesn't recognize all TLDs so a message is not shown if it contains a link with an unknown TLD (for example: .de). As parseText() is already used to replace plain links with HTML code, this branch recognize if a message has links searching for HTML code in parsed text message.
Tested on mako ;)

To post a comment you must log in.
Revision history for this message
Jin (jindallo) wrote :

Hello @Devid,

Code looks good,
I will approve after verification done,
please wait for my feedback.

Revision history for this message
Jin (jindallo) wrote :

Verified pass locally,
I approve.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'telegram/app/qml/components/MessagesListItem.qml'
2--- telegram/app/qml/components/MessagesListItem.qml 2016-09-28 18:34:44 +0000
3+++ telegram/app/qml/components/MessagesListItem.qml 2016-11-01 21:19:24 +0000
4@@ -36,14 +36,14 @@
5
6 property Message message
7 property string messageText: message.message
8+ property string messageHtmlText: parseText(message.message)
9 property User user: telegramObject.user(message.fromId)
10 property User fwdUser: telegramObject.user(message.fwdFromId)
11
12 property bool sent: message.sent
13 property bool uploading: message.upload.fileId !== 0
14
15- property variant messageLinks: Tools.stringLinks(message.message)
16- property bool hasLink: messageLinks.length !== 0
17+ property bool hasLink: htmlHasLinks(messageHtmlText)
18 property bool allowLoadLinks: telegram.userData.isLoadLink(user.id)
19
20 property alias maximumMediaHeight: message_media.maximumMediaHeight
21@@ -63,6 +63,26 @@
22 signal messageFocusRequest(int msgId);
23 signal previewRequest(int type, string path)
24
25+ // Taken from messaging-app
26+ function parseText(text) {
27+ var phoneExp = /(\+?([0-9]+[ ]?)?\(?([0-9]+)\)?[-. ]?([0-9]+)[-. ]?([0-9]+)[-. ]?([0-9]+))/img;
28+ // remove html tags
29+ text = text.replace(/</g,'&lt;').replace(/>/g,'<tt>&gt;</tt>');
30+ // replace line breaks
31+ text = text.replace(/(\n)+/g, '<br />');
32+ // check for links
33+ var htmlText = BaLinkify.linkify(text);
34+ if (htmlText !== text) {
35+ return htmlText;
36+ }
37+ // linkify phone numbers if no web links were found
38+ return text.replace(phoneExp, '<a href="tel:///$1">$1</a>');
39+ }
40+
41+ function htmlHasLinks(html) {
42+ return html.indexOf('<a href="') !== -1;
43+ }
44+
45 // Connections {
46 // target: telegram.userData
47 // onLoadLinkChanged: {
48@@ -248,21 +268,6 @@
49
50 Label {
51 id: message_text
52- // Taken from messaging-app
53- function parseText(text) {
54- var phoneExp = /(\+?([0-9]+[ ]?)?\(?([0-9]+)\)?[-. ]?([0-9]+)[-. ]?([0-9]+)[-. ]?([0-9]+))/img;
55- // remove html tags
56- text = text.replace(/</g,'&lt;').replace(/>/g,'<tt>&gt;</tt>');
57- // replace line breaks
58- text = text.replace(/(\n)+/g, '<br />');
59- // check for links
60- var htmlText = BaLinkify.linkify(text);
61- if (htmlText !== text) {
62- return htmlText;
63- }
64- // linkify phone numbers if no web links were found
65- return text.replace(phoneExp, '<a href="tel:///$1">$1</a>');
66- }
67
68 anchors {
69 top: parent.top
70@@ -276,7 +281,7 @@
71 horizontalAlignment: Text.AlignLeft
72 wrapMode: Text.WrapAtWordBoundaryOrAnywhere
73 textFormat: Text.RichText
74- text: messageText // emojis.textToEmojiText(messageText)
75+ text: message_item.messageHtmlText // emojis.textToEmojiText(message_item.messageHtmlText)
76
77 onLinkActivated: {
78 if (link.slice(0,6) == "tag://") {
79@@ -287,9 +292,6 @@
80 }
81
82 property real htmlWidth: Cutegram.htmlWidth(text)
83- property string messageText: {
84- return message_text.parseText(message.message)
85- }
86 }
87
88 MessageStatus {

Subscribers

People subscribed via source and target branches

to status/vote changes: