feat: intercept clicks on messages links as well

This commit is contained in:
Jonathan Rainville 2021-02-25 14:41:40 -05:00 committed by Iuri Matias
parent 35688e9740
commit c5241e2bf4
3 changed files with 38 additions and 25 deletions

View File

@ -55,6 +55,12 @@ Item {
return; return;
} }
const data = Utils.getLinkDataForStatusLinks(link)
if (data && data.callback) {
return data.callback()
}
appMain.openLink(link) appMain.openLink(link)
} }

View File

@ -113,31 +113,9 @@ Column {
} }
fetched = true fetched = true
if (link.includes(Constants.deepLinkPrefix) || link.includes(Constants.joinStatusLink)) { const data = Utils.getLinkDataForStatusLinks(link)
// Parse link to know what to show if (data) {
// TODO put it in another function? linkData = data
let title = "Status"
let callback = function () {}
// Link to send a direct message
let index = link.indexOf("/u/")
if (index > -1) {
const pk = link.substring(index + 3)
title = qsTr("Start a 1 on 1 chat with %1").arg(utilsModel.generateAlias(pk))
callback = function () {
chatsModel.joinChat(pk, Constants.chatTypeOneToOne);
}
}
linkData = {
site: qsTr("Status app link"),
title: title,
thumbnailUrl: "../../../../img/status.png",
contentType: "",
height: 0,
width: 0,
callback: callback
}
return unfurledLinkComponent return unfurledLinkComponent
} }

View File

@ -289,6 +289,35 @@ QtObject {
return (/( |\t|\n|\r)/.test(c)) return (/( |\t|\n|\r)/.test(c))
} }
function getLinkDataForStatusLinks(link) {
if (!link.includes(Constants.deepLinkPrefix) && !link.includes(Constants.joinStatusLink)) {
return
}
let title = "Status"
let callback = function () {}
// Link to send a direct message
let index = link.indexOf("/u/")
if (index > -1) {
const pk = link.substring(index + 3)
title = qsTr("Start a 1 on 1 chat with %1").arg(utilsModel.generateAlias(pk))
callback = function () {
chatsModel.joinChat(pk, Constants.chatTypeOneToOne);
}
}
return {
site: qsTr("Status app link"),
title: title,
thumbnailUrl: "../../../../img/status.png",
contentType: "",
height: 0,
width: 0,
callback: callback
}
}
function isPunct(c) { function isPunct(c) {
return /(!|\@|#|\$|%|\^|&|\*|\(|\)|_|\+|\||-|=|\\|{|}|[|]|"|;|'|<|>|\?|,|\.|\/)/.test(c) return /(!|\@|#|\$|%|\^|&|\*|\(|\)|_|\+|\||-|=|\\|{|}|[|]|"|;|'|<|>|\?|,|\.|\/)/.test(c)
} }