Replace QRegExp with QRegularExpression.

Fix timeline viewport saving.
Fix invitation dialog. #124
This commit is contained in:
Black Hat 2018-11-29 10:41:38 +08:00
parent e7b2698521
commit 5192a91391
6 changed files with 48 additions and 31 deletions

View File

@ -160,7 +160,7 @@ ColumnLayout {
id: contentLabel
text: "<style>a{color: white;} .user-pill{}</style>" + (replyEventId ? display.replace(/<mx-reply>.*<\/mx-reply>/g, "") : display)
text: "<style>a{color: white;} .user-pill{}</style>" + display
color: "white"

View File

@ -854,11 +854,30 @@ Rectangle {
title: "Action Required"
modal: true
standardButtons: Dialog.Ok | Dialog.Cancel
contentItem: Label { text: "Accept this invitation?" }
onAccepted: currentRoom.acceptInvitation()
onRejected: currentRoom.forget()
footer: DialogButtonBox {
Button {
text: "Accept"
flat: true
onClicked: currentRoom.acceptInvitation()
}
Button {
text: "Reject"
flat: true
onClicked: currentRoom.forget()
}
Button {
text: "Reject"
flat: true
onClicked: inviteDialog.close()
}
}
}
}

View File

@ -115,8 +115,6 @@ Item {
currentRoom.getPreviousContent(20);
}
onMovementEnded: currentRoom.saveViewport(sortedMessageEventModel.mapToSource(indexAt(contentX, contentY)), sortedMessageEventModel.mapToSource(largestVisibleIndex))
displaced: Transition {
NumberAnimation {
property: "y"; duration: 200
@ -126,6 +124,7 @@ Item {
delegate: ColumnLayout {
width: parent.width
implicitHeight: 32
id: delegateColumn
@ -330,13 +329,14 @@ Item {
function goToEvent(eventID) {
var index = messageEventModel.eventIDToIndex(eventID)
if (index === -1) return
messageListView.currentIndex = -1
messageListView.currentIndex = sortedMessageEventModel.mapFromSource(index)
// messageListView.currentIndex = sortedMessageEventModel.mapFromSource(index)
messageListView.positionViewAtIndex(sortedMessageEventModel.mapFromSource(index), ListView.Contain)
}
function saveReadMarker(room) {
var readMarker = sortedMessageEventModel.get(messageListView.largestVisibleIndex).eventId
if (!readMarker) return
room.readMarkerEventId = readMarker
currentRoom.saveViewport(sortedMessageEventModel.mapToSource(messageListView.indexAt(messageListView.contentX, messageListView.contentY)), sortedMessageEventModel.mapToSource(messageListView.largestVisibleIndex))
}
}

View File

@ -9,7 +9,6 @@
#include <events/roommemberevent.h>
#include <events/simplestateevents.h>
#include <QRegExp>
#include <QtCore/QDebug>
#include <QtQml> // for qmlRegisterType()
@ -265,9 +264,7 @@ QVariant MessageEventModel::data(const QModelIndex &idx, int role) const {
}
if (role == MessageRole) {
static const QRegExp rmReplyRegExp("^> <@.*:.*> .*\n\n(.*)");
return utils::eventToString(evt, m_currentRoom)
.replace(rmReplyRegExp, "\\1");
return utils::removeReply(utils::eventToString(evt, m_currentRoom));
}
if (role == Qt::ToolTipRole) {

View File

@ -6,3 +6,10 @@ QString utils::removeReply(const QString& text) {
result.remove(utils::removeReplyRegex);
return result;
}
QString utils::cleanHTML(const QString& text, QMatrixClient::Room* room) {
QString result(text);
result.replace(codePillRegExp, "<i>\\1</i>");
result.replace(userPillRegExp, "<b>\\1</b>");
return result;
}

View File

@ -5,7 +5,7 @@
#include "user.h"
#include <QObject>
#include <QRegExp>
#include <QRegularExpression>
#include <QString>
#include <events/redactionevent.h>
@ -14,10 +14,18 @@
#include <events/simplestateevents.h>
namespace utils {
const QRegExp removeReplyRegex{"> <.*>.*\\n\\n"};
const QRegExp removeRichReplyRegex{"<mx-reply>.*</mx-reply>"};
static const QRegularExpression removeReplyRegex{
"> <.*?>.*?\\n\\n", QRegularExpression::DotMatchesEverythingOption};
static const QRegularExpression removeRichReplyRegex{
"<mx-reply>.*?</mx-reply>", QRegularExpression::DotMatchesEverythingOption};
static const QRegularExpression codePillRegExp{
"<pre>(.*?)</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, QMatrixClient::Room* room);
template <typename BaseEventT>
QString eventToString(const BaseEventT& evt,
@ -33,22 +41,8 @@ QString eventToString(const BaseEventT& evt,
if (prettyPrint && e.hasTextContent() &&
e.mimeType().name() != "text/plain") {
static const QRegExp userPillRegExp(
"<a href=\"https://matrix.to/#/(@.*:.*)\">.*</a>");
QString formattedStr(
static_cast<const TextContent*>(e.content())->body);
int pos = 0;
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();
}
static const QRegExp codePillRegExp("<pre>(.*)</pre>");
formattedStr.replace(codePillRegExp, "<i>\\1</i>");
return formattedStr;
return cleanHTML(static_cast<const TextContent*>(e.content())->body,
room);
}
if (e.hasFileContent()) {
auto fileCaption = e.content()->fileInfo()->originalName;