mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-22 11:00:48 +03:00
Fix double href links on username pills
This commit is contained in:
parent
896fe069b6
commit
a21db789e7
3 changed files with 59 additions and 9 deletions
|
@ -3,10 +3,13 @@
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QDesktopWidget>
|
#include <QDesktopWidget>
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
|
#include <QXmlStreamReader>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
#include <boost/variant.hpp>
|
#include <boost/variant.hpp>
|
||||||
|
|
||||||
|
#include "Config.h"
|
||||||
|
|
||||||
using TimelineEvent = mtx::events::collections::TimelineEvents;
|
using TimelineEvent = mtx::events::collections::TimelineEvents;
|
||||||
|
|
||||||
QString
|
QString
|
||||||
|
@ -276,3 +279,51 @@ utils::humanReadableFingerprint(const QString &ed25519)
|
||||||
}
|
}
|
||||||
return fingerprintList.join(" ");
|
return fingerprintList.join(" ");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString
|
||||||
|
utils::linkifyMessage(const QString &body)
|
||||||
|
{
|
||||||
|
QXmlStreamReader xml{"<html>" + body + "</html>"};
|
||||||
|
|
||||||
|
QString textString;
|
||||||
|
while (!xml.atEnd() && !xml.hasError()) {
|
||||||
|
auto t = xml.readNext();
|
||||||
|
|
||||||
|
switch (t) {
|
||||||
|
case QXmlStreamReader::Characters: {
|
||||||
|
auto text = xml.text().toString();
|
||||||
|
text.replace(conf::strings::url_regex, conf::strings::url_html);
|
||||||
|
|
||||||
|
textString += text;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case QXmlStreamReader::StartDocument:
|
||||||
|
case QXmlStreamReader::EndDocument:
|
||||||
|
break;
|
||||||
|
case QXmlStreamReader::StartElement: {
|
||||||
|
if (xml.name() == "html")
|
||||||
|
break;
|
||||||
|
|
||||||
|
textString += "<" + xml.name() + ">";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case QXmlStreamReader::EndElement: {
|
||||||
|
if (xml.name() == "html")
|
||||||
|
break;
|
||||||
|
|
||||||
|
textString += "</" + xml.name() + ">";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default: {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (xml.hasError()) {
|
||||||
|
// qWarning() << "error while parsing xml";
|
||||||
|
return body;
|
||||||
|
}
|
||||||
|
|
||||||
|
return textString;
|
||||||
|
}
|
||||||
|
|
|
@ -201,7 +201,7 @@ humanReadableFingerprint(const QString &ed25519);
|
||||||
//! If the `format` of the message is not supported we fallback to `body`.
|
//! If the `format` of the message is not supported we fallback to `body`.
|
||||||
template<typename RoomMessageT>
|
template<typename RoomMessageT>
|
||||||
QString
|
QString
|
||||||
get_message_body(const RoomMessageT &event)
|
getMessageBody(const RoomMessageT &event)
|
||||||
{
|
{
|
||||||
if (event.content.format.empty())
|
if (event.content.format.empty())
|
||||||
return QString::fromStdString(event.content.body);
|
return QString::fromStdString(event.content.body);
|
||||||
|
@ -211,4 +211,8 @@ get_message_body(const RoomMessageT &event)
|
||||||
|
|
||||||
return QString::fromStdString(event.content.formatted_body);
|
return QString::fromStdString(event.content.formatted_body);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//! Replace raw URLs in text with HTML link tags.
|
||||||
|
QString
|
||||||
|
linkifyMessage(const QString &body);
|
||||||
}
|
}
|
||||||
|
|
|
@ -437,7 +437,7 @@ TimelineItem::TimelineItem(const mtx::events::RoomEvent<mtx::events::msg::Notice
|
||||||
const auto sender = QString::fromStdString(event.sender);
|
const auto sender = QString::fromStdString(event.sender);
|
||||||
const auto timestamp = QDateTime::fromMSecsSinceEpoch(event.origin_server_ts);
|
const auto timestamp = QDateTime::fromMSecsSinceEpoch(event.origin_server_ts);
|
||||||
|
|
||||||
auto formatted_body = utils::get_message_body(event).trimmed();
|
auto formatted_body = utils::linkifyMessage(utils::getMessageBody(event).trimmed());
|
||||||
auto body = QString::fromStdString(event.content.body).trimmed();
|
auto body = QString::fromStdString(event.content.body).trimmed();
|
||||||
|
|
||||||
descriptionMsg_ = {Cache::displayName(room_id_, sender),
|
descriptionMsg_ = {Cache::displayName(room_id_, sender),
|
||||||
|
@ -448,7 +448,6 @@ TimelineItem::TimelineItem(const mtx::events::RoomEvent<mtx::events::msg::Notice
|
||||||
|
|
||||||
generateTimestamp(timestamp);
|
generateTimestamp(timestamp);
|
||||||
|
|
||||||
formatted_body.replace(conf::strings::url_regex, conf::strings::url_html);
|
|
||||||
formatted_body = "<i>" + formatted_body + "</i>";
|
formatted_body = "<i>" + formatted_body + "</i>";
|
||||||
|
|
||||||
if (with_sender) {
|
if (with_sender) {
|
||||||
|
@ -485,7 +484,7 @@ TimelineItem::TimelineItem(const mtx::events::RoomEvent<mtx::events::msg::Emote>
|
||||||
event_id_ = QString::fromStdString(event.event_id);
|
event_id_ = QString::fromStdString(event.event_id);
|
||||||
const auto sender = QString::fromStdString(event.sender);
|
const auto sender = QString::fromStdString(event.sender);
|
||||||
|
|
||||||
auto formatted_body = utils::get_message_body(event).trimmed();
|
auto formatted_body = utils::linkifyMessage(utils::getMessageBody(event).trimmed());
|
||||||
auto body = QString::fromStdString(event.content.body).trimmed();
|
auto body = QString::fromStdString(event.content.body).trimmed();
|
||||||
|
|
||||||
auto timestamp = QDateTime::fromMSecsSinceEpoch(event.origin_server_ts);
|
auto timestamp = QDateTime::fromMSecsSinceEpoch(event.origin_server_ts);
|
||||||
|
@ -494,8 +493,6 @@ TimelineItem::TimelineItem(const mtx::events::RoomEvent<mtx::events::msg::Emote>
|
||||||
|
|
||||||
descriptionMsg_ = {"", sender, emoteMsg, utils::descriptiveTime(timestamp), timestamp};
|
descriptionMsg_ = {"", sender, emoteMsg, utils::descriptiveTime(timestamp), timestamp};
|
||||||
|
|
||||||
formatted_body.replace(conf::strings::url_regex, conf::strings::url_html);
|
|
||||||
|
|
||||||
generateTimestamp(timestamp);
|
generateTimestamp(timestamp);
|
||||||
|
|
||||||
if (with_sender) {
|
if (with_sender) {
|
||||||
|
@ -530,14 +527,12 @@ TimelineItem::TimelineItem(const mtx::events::RoomEvent<mtx::events::msg::Text>
|
||||||
event_id_ = QString::fromStdString(event.event_id);
|
event_id_ = QString::fromStdString(event.event_id);
|
||||||
const auto sender = QString::fromStdString(event.sender);
|
const auto sender = QString::fromStdString(event.sender);
|
||||||
|
|
||||||
auto formatted_body = utils::get_message_body(event).trimmed();
|
auto formatted_body = utils::linkifyMessage(utils::getMessageBody(event).trimmed());
|
||||||
auto body = QString::fromStdString(event.content.body).trimmed();
|
auto body = QString::fromStdString(event.content.body).trimmed();
|
||||||
|
|
||||||
auto timestamp = QDateTime::fromMSecsSinceEpoch(event.origin_server_ts);
|
auto timestamp = QDateTime::fromMSecsSinceEpoch(event.origin_server_ts);
|
||||||
auto displayName = Cache::displayName(room_id_, sender);
|
auto displayName = Cache::displayName(room_id_, sender);
|
||||||
|
|
||||||
formatted_body.replace(conf::strings::url_regex, conf::strings::url_html);
|
|
||||||
|
|
||||||
QSettings settings;
|
QSettings settings;
|
||||||
descriptionMsg_ = {sender == settings.value("auth/user_id") ? "You" : displayName,
|
descriptionMsg_ = {sender == settings.value("auth/user_id") ? "You" : displayName,
|
||||||
sender,
|
sender,
|
||||||
|
|
Loading…
Reference in a new issue