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;
}
const data = Utils.getLinkDataForStatusLinks(link)
if (data && data.callback) {
return data.callback()
}
appMain.openLink(link)
}

View File

@ -113,31 +113,9 @@ Column {
}
fetched = true
if (link.includes(Constants.deepLinkPrefix) || link.includes(Constants.joinStatusLink)) {
// Parse link to know what to show
// TODO put it in another function?
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
}
const data = Utils.getLinkDataForStatusLinks(link)
if (data) {
linkData = data
return unfurledLinkComponent
}

View File

@ -289,6 +289,35 @@ QtObject {
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) {
return /(!|\@|#|\$|%|\^|&|\*|\(|\)|_|\+|\||-|=|\\|{|}|[|]|"|;|'|<|>|\?|,|\.|\/)/.test(c)
}