feat: show unfurled link for status chats in 1:1

This commit is contained in:
Jonathan Rainville 2021-02-25 14:32:39 -05:00 committed by Iuri Matias
parent c86f67b9f1
commit 35688e9740
5 changed files with 52 additions and 4 deletions

View File

@ -224,6 +224,10 @@ proc toTextItem*(jsonText: JsonNode): TextItem =
destination: jsonText{"destination"}.getStr,
children: @[]
)
if (result.literal.startsWith("statusim://")):
result.textType = "link"
# TODO isolate the link only
result.destination = result.literal
if jsonText.hasKey("children") and jsonText["children"].kind != JNull:
for child in jsonText["children"]:
@ -276,7 +280,7 @@ proc toMessage*(jsonMsg: JsonNode, pk: string): Message =
message.parsedText.add(text.toTextItem)
message.linkUrls = concat(message.parsedText.map(t => t.children.filter(c => c.textType == "link")))
.filter(t => t.destination.startsWith("http"))
.filter(t => t.destination.startsWith("http") or t.destination.startsWith("statusim://"))
.map(t => t.destination)
.join(" ")

View File

@ -112,6 +112,35 @@ Column {
return
}
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
}
return unfurledLinkComponent
}
return chatsModel.getLinkPreviewData(link, root.uuid)
}
// setting the height to 0 allows the "enable link" dialog to
@ -120,6 +149,7 @@ Column {
this.height = 0
return undefined
}
Component.onCompleted: {
// putting this is onCompleted prevents automatic binding, where
// QML warns of a binding loop detected
@ -198,7 +228,13 @@ Column {
anchors.right: linkImage.right
anchors.bottom: linkSite.bottom
cursorShape: Qt.PointingHandCursor
onClicked: appMain.openLink(linkData.address)
onClicked: {
if (!!linkData.callback) {
return linkData.callback()
}
appMain.openLink(linkData.address)
}
}
}
}

BIN
ui/app/img/status.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.3 KiB

View File

@ -121,4 +121,7 @@ QtObject {
readonly property int browserEthereumExplorerBlockchair: 3
readonly property int repeatHeaderInterval: 2
readonly property string deepLinkPrefix: 'statusim://'
readonly property string joinStatusLink: 'join.status.im'
}

View File

@ -83,7 +83,7 @@ QtObject {
function linkifyAndXSS(inputText) {
//URLs starting with http://, https://, or ftp://
var replacePattern1 = /(\b(https?|ftp):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/gim;
var replacePattern1 = /(\b(https?|ftp|statusim):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/gim;
var replacedText = inputText.replace(replacePattern1, "<a href='$1'>$1</a>");
//URLs starting with "www." (without // before it, or it'd re-link the ones done above).
@ -365,7 +365,12 @@ QtObject {
function getHostname(url) {
const rgx = /\:\/\/(?:[a-zA-Z0-9\-]*\.{1,}){1,}[a-zA-Z0-9]*/i
const matches = rgx.exec(url)
if (!matches || !matches.length) return ""
if (!matches || !matches.length) {
if (url.includes(Constants.deepLinkPrefix)) {
return Constants.deepLinkPrefix
}
return ""
}
return matches[0].substring(3)
}