Fix line strike.
Fix code block wrapping. Fix replyModel being garbage collected. Reply message in RoomPanelInput is richtext now.
This commit is contained in:
@@ -285,12 +285,11 @@ QVariant MessageEventModel::data(const QModelIndex& idx, int role) const {
|
||||
const auto& evt = isPending ? **pendingIt : **timelineIt;
|
||||
|
||||
if (role == Qt::DisplayRole) {
|
||||
return utils::cleanHTML(
|
||||
utils::removeReply(m_currentRoom->eventToString(evt, Qt::RichText)));
|
||||
return m_currentRoom->eventToString(evt, Qt::RichText);
|
||||
}
|
||||
|
||||
if (role == MessageRole) {
|
||||
return utils::removeReply(m_currentRoom->eventToString(evt));
|
||||
return m_currentRoom->eventToString(evt);
|
||||
}
|
||||
|
||||
if (role == Qt::ToolTipRole) {
|
||||
@@ -443,8 +442,7 @@ QVariant MessageEventModel::data(const QModelIndex& idx, int role) const {
|
||||
|
||||
return QVariantMap{
|
||||
{"eventId", replyEventId},
|
||||
{"display", utils::cleanHTML(utils::removeReply(
|
||||
m_currentRoom->eventToString(replyEvt, Qt::RichText)))},
|
||||
{"display", m_currentRoom->eventToString(replyEvt, Qt::RichText)},
|
||||
{"author",
|
||||
QVariant::fromValue(m_currentRoom->user(replyEvt.senderId()))}};
|
||||
}
|
||||
|
||||
@@ -118,7 +118,7 @@ QString SpectralRoom::lastEvent() const {
|
||||
|
||||
return user(evt->senderId())->displayname() +
|
||||
(evt->isStateEvent() ? " " : ": ") +
|
||||
utils::removeReply(eventToString(*evt));
|
||||
eventToString(*evt);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
@@ -230,18 +230,27 @@ QString SpectralRoom::avatarMediaId() const {
|
||||
}
|
||||
|
||||
QString SpectralRoom::eventToString(const RoomEvent& evt,
|
||||
Qt::TextFormat format) const {
|
||||
Qt::TextFormat format, bool removeReply) const {
|
||||
const bool prettyPrint = (format == Qt::RichText);
|
||||
|
||||
using namespace QMatrixClient;
|
||||
return visit(
|
||||
evt,
|
||||
[prettyPrint](const RoomMessageEvent& e) {
|
||||
[prettyPrint, removeReply](const RoomMessageEvent& e) {
|
||||
using namespace MessageEventContent;
|
||||
|
||||
if (prettyPrint && e.hasTextContent() &&
|
||||
e.mimeType().name() != "text/plain")
|
||||
return static_cast<const TextContent*>(e.content())->body;
|
||||
e.mimeType().name() != "text/plain") {
|
||||
auto htmlBody = static_cast<const TextContent*>(e.content())->body;
|
||||
if (removeReply) {
|
||||
htmlBody.remove(utils::removeRichReplyRegex);
|
||||
}
|
||||
htmlBody.replace(utils::userPillRegExp, "<b>\\1</b>");
|
||||
htmlBody.replace(utils::strikethroughRegExp, "<s>\\1</s>");
|
||||
htmlBody.push_front("<style>pre {white-space: pre-wrap}</style>");
|
||||
return htmlBody;
|
||||
}
|
||||
|
||||
if (e.hasFileContent()) {
|
||||
auto fileCaption =
|
||||
e.content()->fileInfo()->originalName.toHtmlEscaped();
|
||||
@@ -252,8 +261,18 @@ QString SpectralRoom::eventToString(const RoomEvent& evt,
|
||||
}
|
||||
return !fileCaption.isEmpty() ? fileCaption : tr("a file");
|
||||
}
|
||||
return prettyPrint ? QMatrixClient::prettyPrint(e.plainBody())
|
||||
: e.plainBody();
|
||||
|
||||
if (prettyPrint) {
|
||||
auto plainBody = e.plainBody();
|
||||
if (removeReply) {
|
||||
return plainBody.remove(utils::removeReplyRegex);
|
||||
}
|
||||
return QMatrixClient::prettyPrint(plainBody);
|
||||
}
|
||||
if (removeReply) {
|
||||
return e.plainBody().remove(utils::removeReplyRegex);
|
||||
}
|
||||
return e.plainBody();
|
||||
},
|
||||
[this](const RoomMemberEvent& e) {
|
||||
// FIXME: Rewind to the name that was at the time of this event
|
||||
@@ -478,7 +497,7 @@ void SpectralRoom::postPlainMessage(const QString& text,
|
||||
replyEventId +
|
||||
"\">In reply to</a> <a href=\"https://matrix.to/#/" +
|
||||
replyEvt.senderId() + "\">" + replyEvt.senderId() + "</a><br>" +
|
||||
utils::removeReply(eventToString(replyEvt, Qt::RichText)) +
|
||||
eventToString(replyEvt, Qt::RichText) +
|
||||
"</blockquote></mx-reply>" + text.toHtmlEscaped()}};
|
||||
postJson("m.room.message", json);
|
||||
|
||||
@@ -513,7 +532,7 @@ void SpectralRoom::postHtmlMessage(const QString& text,
|
||||
replyEventId +
|
||||
"\">In reply to</a> <a href=\"https://matrix.to/#/" +
|
||||
replyEvt.senderId() + "\">" + replyEvt.senderId() + "</a><br>" +
|
||||
utils::removeReply(eventToString(replyEvt, Qt::RichText)) +
|
||||
eventToString(replyEvt, Qt::RichText) +
|
||||
"</blockquote></mx-reply>" + html}};
|
||||
postJson("m.room.message", json);
|
||||
|
||||
|
||||
@@ -70,7 +70,7 @@ class SpectralRoom : public Room {
|
||||
QString avatarMediaId() const;
|
||||
|
||||
QString eventToString(const RoomEvent& evt,
|
||||
Qt::TextFormat format = Qt::PlainText) const;
|
||||
Qt::TextFormat format = Qt::PlainText, bool removeReply = true) const;
|
||||
|
||||
private:
|
||||
QString m_cachedInput;
|
||||
|
||||
@@ -1,15 +1 @@
|
||||
#include "utils.h"
|
||||
|
||||
QString utils::removeReply(const QString& text) {
|
||||
QString result(text);
|
||||
result.remove(utils::removeRichReplyRegex);
|
||||
result.remove(utils::removeReplyRegex);
|
||||
return result;
|
||||
}
|
||||
|
||||
QString utils::cleanHTML(const QString& text) {
|
||||
QString result(text);
|
||||
result.replace(codePillRegExp, "<i>\\1</i>");
|
||||
result.replace(userPillRegExp, "<b>\\1</b>");
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -19,13 +19,12 @@ static const QRegularExpression removeReplyRegex{
|
||||
static const QRegularExpression removeRichReplyRegex{
|
||||
"<mx-reply>.*?</mx-reply>", QRegularExpression::DotMatchesEverythingOption};
|
||||
static const QRegularExpression codePillRegExp{
|
||||
"<pre>(.*?)</pre>", QRegularExpression::DotMatchesEverythingOption};
|
||||
"<pre><code[^>]*>(.*?)</code></pre>", QRegularExpression::DotMatchesEverythingOption};
|
||||
static const QRegularExpression userPillRegExp{
|
||||
"<a href=\"https://matrix.to/#/@.*?:.*?\">(.*?)</a>",
|
||||
QRegularExpression::DotMatchesEverythingOption};
|
||||
|
||||
QString removeReply(const QString& text);
|
||||
QString cleanHTML(const QString& text);
|
||||
static const QRegularExpression strikethroughRegExp{
|
||||
"<del>(.*?)</del>", QRegularExpression::DotMatchesEverythingOption};
|
||||
} // namespace utils
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user