Parse display name from user ID.
Clicking "In Reply To" now switches to the event if possible.
This commit is contained in:
parent
d1186ea810
commit
1c499ddb90
|
@ -98,7 +98,7 @@ ColumnLayout {
|
||||||
|
|
||||||
id: contentLabel
|
id: contentLabel
|
||||||
|
|
||||||
text: "<style>a{color: white;} .user-pill{color: white}</style>" + display
|
text: "<style>a{color: white;} .user-pill{}</style>" + display
|
||||||
|
|
||||||
color: "white"
|
color: "white"
|
||||||
|
|
||||||
|
@ -111,7 +111,17 @@ ColumnLayout {
|
||||||
selectionColor: "white"
|
selectionColor: "white"
|
||||||
textFormat: Text.RichText
|
textFormat: Text.RichText
|
||||||
|
|
||||||
onLinkActivated: Qt.openUrlExternally(link)
|
onLinkActivated: {
|
||||||
|
if (link.startsWith("https://matrix.to/")) {
|
||||||
|
var result = link.replace(/\?.*/, "").match("https://matrix.to/#/(!.*:.*)/(\\$.*:.*)")
|
||||||
|
if (result.length < 3) return
|
||||||
|
if (result[1] != currentRoom.id) return
|
||||||
|
if (!result[2]) return
|
||||||
|
goToEvent(result[2])
|
||||||
|
} else {
|
||||||
|
Qt.openUrlExternally(link)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
MouseArea {
|
MouseArea {
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
|
|
14
src/utils.h
14
src/utils.h
|
@ -2,6 +2,7 @@
|
||||||
#define Utils_H
|
#define Utils_H
|
||||||
|
|
||||||
#include "room.h"
|
#include "room.h"
|
||||||
|
#include "user.h"
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QRegExp>
|
#include <QRegExp>
|
||||||
|
@ -32,11 +33,18 @@ QString eventToString(const BaseEventT& evt,
|
||||||
if (prettyPrint && e.hasTextContent() &&
|
if (prettyPrint && e.hasTextContent() &&
|
||||||
e.mimeType().name() != "text/plain") {
|
e.mimeType().name() != "text/plain") {
|
||||||
static const QRegExp userPillRegExp(
|
static const QRegExp userPillRegExp(
|
||||||
"<a href=\"https://matrix.to/#/@.*:.*\">(.*)</a>");
|
"<a href=\"https://matrix.to/#/(@.*:.*)\">.*</a>");
|
||||||
QString formattedStr(
|
QString formattedStr(
|
||||||
static_cast<const TextContent*>(e.content())->body);
|
static_cast<const TextContent*>(e.content())->body);
|
||||||
formattedStr.replace(userPillRegExp,
|
int pos = 0;
|
||||||
"<b class=\"user-pill\">\\1</b>");
|
while ((pos = userPillRegExp.indexIn(formattedStr, pos)) != -1) {
|
||||||
|
QString userId = userPillRegExp.cap(1);
|
||||||
|
formattedStr.remove(pos, userPillRegExp.matchedLength());
|
||||||
|
formattedStr.insert(pos, "<b class=\"user-pill\">" +
|
||||||
|
room->user(userId)->displayname() +
|
||||||
|
"</b>");
|
||||||
|
pos += userPillRegExp.matchedLength();
|
||||||
|
}
|
||||||
return formattedStr;
|
return formattedStr;
|
||||||
}
|
}
|
||||||
if (e.hasFileContent()) {
|
if (e.hasFileContent()) {
|
||||||
|
|
Loading…
Reference in New Issue