Replace QRegExp with QRegularExpression.
Fix timeline viewport saving. Fix invitation dialog. #124
This commit is contained in:
parent
e7b2698521
commit
5192a91391
|
@ -160,7 +160,7 @@ ColumnLayout {
|
||||||
|
|
||||||
id: contentLabel
|
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"
|
color: "white"
|
||||||
|
|
||||||
|
|
|
@ -854,11 +854,30 @@ Rectangle {
|
||||||
|
|
||||||
title: "Action Required"
|
title: "Action Required"
|
||||||
modal: true
|
modal: true
|
||||||
standardButtons: Dialog.Ok | Dialog.Cancel
|
|
||||||
|
|
||||||
contentItem: Label { text: "Accept this invitation?" }
|
contentItem: Label { text: "Accept this invitation?" }
|
||||||
|
|
||||||
onAccepted: currentRoom.acceptInvitation()
|
footer: DialogButtonBox {
|
||||||
onRejected: currentRoom.forget()
|
Button {
|
||||||
|
text: "Accept"
|
||||||
|
flat: true
|
||||||
|
|
||||||
|
onClicked: currentRoom.acceptInvitation()
|
||||||
|
}
|
||||||
|
|
||||||
|
Button {
|
||||||
|
text: "Reject"
|
||||||
|
flat: true
|
||||||
|
|
||||||
|
onClicked: currentRoom.forget()
|
||||||
|
}
|
||||||
|
|
||||||
|
Button {
|
||||||
|
text: "Reject"
|
||||||
|
flat: true
|
||||||
|
|
||||||
|
onClicked: inviteDialog.close()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -115,8 +115,6 @@ Item {
|
||||||
currentRoom.getPreviousContent(20);
|
currentRoom.getPreviousContent(20);
|
||||||
}
|
}
|
||||||
|
|
||||||
onMovementEnded: currentRoom.saveViewport(sortedMessageEventModel.mapToSource(indexAt(contentX, contentY)), sortedMessageEventModel.mapToSource(largestVisibleIndex))
|
|
||||||
|
|
||||||
displaced: Transition {
|
displaced: Transition {
|
||||||
NumberAnimation {
|
NumberAnimation {
|
||||||
property: "y"; duration: 200
|
property: "y"; duration: 200
|
||||||
|
@ -126,6 +124,7 @@ Item {
|
||||||
|
|
||||||
delegate: ColumnLayout {
|
delegate: ColumnLayout {
|
||||||
width: parent.width
|
width: parent.width
|
||||||
|
implicitHeight: 32
|
||||||
|
|
||||||
id: delegateColumn
|
id: delegateColumn
|
||||||
|
|
||||||
|
@ -330,13 +329,14 @@ Item {
|
||||||
function goToEvent(eventID) {
|
function goToEvent(eventID) {
|
||||||
var index = messageEventModel.eventIDToIndex(eventID)
|
var index = messageEventModel.eventIDToIndex(eventID)
|
||||||
if (index === -1) return
|
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) {
|
function saveReadMarker(room) {
|
||||||
var readMarker = sortedMessageEventModel.get(messageListView.largestVisibleIndex).eventId
|
var readMarker = sortedMessageEventModel.get(messageListView.largestVisibleIndex).eventId
|
||||||
if (!readMarker) return
|
if (!readMarker) return
|
||||||
room.readMarkerEventId = readMarker
|
room.readMarkerEventId = readMarker
|
||||||
|
currentRoom.saveViewport(sortedMessageEventModel.mapToSource(messageListView.indexAt(messageListView.contentX, messageListView.contentY)), sortedMessageEventModel.mapToSource(messageListView.largestVisibleIndex))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,6 @@
|
||||||
#include <events/roommemberevent.h>
|
#include <events/roommemberevent.h>
|
||||||
#include <events/simplestateevents.h>
|
#include <events/simplestateevents.h>
|
||||||
|
|
||||||
#include <QRegExp>
|
|
||||||
#include <QtCore/QDebug>
|
#include <QtCore/QDebug>
|
||||||
#include <QtQml> // for qmlRegisterType()
|
#include <QtQml> // for qmlRegisterType()
|
||||||
|
|
||||||
|
@ -265,9 +264,7 @@ QVariant MessageEventModel::data(const QModelIndex &idx, int role) const {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (role == MessageRole) {
|
if (role == MessageRole) {
|
||||||
static const QRegExp rmReplyRegExp("^> <@.*:.*> .*\n\n(.*)");
|
return utils::removeReply(utils::eventToString(evt, m_currentRoom));
|
||||||
return utils::eventToString(evt, m_currentRoom)
|
|
||||||
.replace(rmReplyRegExp, "\\1");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (role == Qt::ToolTipRole) {
|
if (role == Qt::ToolTipRole) {
|
||||||
|
|
|
@ -6,3 +6,10 @@ QString utils::removeReply(const QString& text) {
|
||||||
result.remove(utils::removeReplyRegex);
|
result.remove(utils::removeReplyRegex);
|
||||||
return result;
|
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;
|
||||||
|
}
|
||||||
|
|
32
src/utils.h
32
src/utils.h
|
@ -5,7 +5,7 @@
|
||||||
#include "user.h"
|
#include "user.h"
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QRegExp>
|
#include <QRegularExpression>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
|
||||||
#include <events/redactionevent.h>
|
#include <events/redactionevent.h>
|
||||||
|
@ -14,10 +14,18 @@
|
||||||
#include <events/simplestateevents.h>
|
#include <events/simplestateevents.h>
|
||||||
|
|
||||||
namespace utils {
|
namespace utils {
|
||||||
const QRegExp removeReplyRegex{"> <.*>.*\\n\\n"};
|
static const QRegularExpression removeReplyRegex{
|
||||||
const QRegExp removeRichReplyRegex{"<mx-reply>.*</mx-reply>"};
|
"> <.*?>.*?\\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 removeReply(const QString& text);
|
||||||
|
QString cleanHTML(const QString& text, QMatrixClient::Room* room);
|
||||||
|
|
||||||
template <typename BaseEventT>
|
template <typename BaseEventT>
|
||||||
QString eventToString(const BaseEventT& evt,
|
QString eventToString(const BaseEventT& evt,
|
||||||
|
@ -33,22 +41,8 @@ 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(
|
return cleanHTML(static_cast<const TextContent*>(e.content())->body,
|
||||||
"<a href=\"https://matrix.to/#/(@.*:.*)\">.*</a>");
|
room);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
if (e.hasFileContent()) {
|
if (e.hasFileContent()) {
|
||||||
auto fileCaption = e.content()->fileInfo()->originalName;
|
auto fileCaption = e.content()->fileInfo()->originalName;
|
||||||
|
|
Loading…
Reference in New Issue