From 3c5c3d163c43f02a02eed00ea73434f5bc339357 Mon Sep 17 00:00:00 2001 From: Roland Pallai Date: Mon, 17 Apr 2023 08:35:14 +0200 Subject: [PATCH] Apply suggestions from code review Co-authored-by: Alexey Rusakov --- client/chatroomwidget.cpp | 20 +++++++++----------- client/models/messageeventmodel.cpp | 16 ++++++++-------- client/models/messageeventmodel.h | 2 +- 3 files changed, 18 insertions(+), 20 deletions(-) diff --git a/client/chatroomwidget.cpp b/client/chatroomwidget.cpp index d14bd1b5..ab07f40c 100644 --- a/client/chatroomwidget.cpp +++ b/client/chatroomwidget.cpp @@ -426,7 +426,7 @@ void ChatRoomWidget::sendMessage() } void ChatRoomWidget::sendMessageFromFragment(const QTextDocumentFragment& text, - enum TextFormat textFormat) + TextFormat textFormat) { const auto& plainText = text.toPlainText(); const auto& htmlText = @@ -450,14 +450,12 @@ void ChatRoomWidget::sendMessageFromFragment(const QTextDocumentFragment& text, auto eventRelation = EventRelation::replace( referencedEventIndex().data(MessageEventModel::EventIdRole).toString() ); - EventContent::TextContent* textContent; - if (htmlText.contains(MarkupRE)) { - textContent = new EventContent::TextContent(htmlText, - QStringLiteral("text/html"), eventRelation); - } else { - textContent = new EventContent::TextContent("", - QStringLiteral("text/plain"), eventRelation); - } + auto* textContent = + htmlText.contains(MarkupRE) + ? new EventContent::TextContent(htmlText, + QStringLiteral("text/html"), eventRelation) + : new EventContent::TextContent(QString(), + QStringLiteral("text/plain"), eventRelation); auto roomMessageEvent = new RoomMessageEvent(plainText, MessageEventType::Text, textContent); currentRoom()->postEvent(roomMessageEvent); @@ -778,7 +776,7 @@ bool ChatRoomWidget::setReferringMode(const int newMode, const QString& eventId, const char* icon_name) { Q_ASSERT( newMode == Replying || newMode == Editing ); - // Actually, we could let the user to refer to pending events too but in + // Actually, we could let the user refer to pending events too but in // this case we would need a universal pointer instead of event id. Now the // user cannot start to edit a pending message which might be annoying if // transactions are acknowledged slowly. @@ -876,7 +874,7 @@ void ChatRoomWidget::edit(const QString& eventId) } auto htmlText = referencedEventIndex() - .data(MessageEventModel::NudeRichBodyRole) + .data(MessageEventModel::BareRichBodyRole) .toString(); m_chatEdit->clear(); // We can never be sure which input format was used to build this message. diff --git a/client/models/messageeventmodel.cpp b/client/models/messageeventmodel.cpp index c8e23ab4..9667451f 100644 --- a/client/models/messageeventmodel.cpp +++ b/client/models/messageeventmodel.cpp @@ -49,7 +49,7 @@ QHash MessageEventModel::roleNames() const roles.insert(EventResolvedTypeRole, "eventResolvedType"); roles.insert(RefRole, "refId"); roles.insert(ReactionsRole, "reactions"); - roles.insert(NudeRichBodyRole, "nudeRichBody"); + roles.insert(BareRichBodyRole, "bareRichBody"); roles.insert(QuotationRole, "quotation"); roles.insert(HtmlQuotationRole, "htmlQuotation"); return roles; @@ -908,7 +908,7 @@ QVariant MessageEventModel::data(const QModelIndex& idx, int role) const evt, [](const RoomCreateEvent& e) { return e.predecessor().roomId; }, [](const RoomTombstoneEvent& e) { return e.successorRoomId(); }); - if (role == NudeRichBodyRole) + if (role == BareRichBodyRole) { auto e = eventCast(&evt); if (!e || !e->hasTextContent()) @@ -919,7 +919,7 @@ QVariant MessageEventModel::data(const QModelIndex& idx, int role) const QRegularExpression::DotMatchesEverythingOption }; static const QRegularExpression quoteLines("> .*(?:\n|$)"); - QString nudeBody; + QString bareBody; if (e->mimeType().name() != "text/plain") { // Naïvely assume that it's HTML auto htmlBody = @@ -927,13 +927,13 @@ QVariant MessageEventModel::data(const QModelIndex& idx, int role) const auto [cleanHtml, errorPos, errorString] = HtmlFilter::fromMatrixHtml(htmlBody.remove(quoteBlock), m_currentRoom); if (errorPos == -1) { - nudeBody = cleanHtml; + bareBody = cleanHtml; } } - if (nudeBody.isEmpty()) { - nudeBody = m_currentRoom->prettyPrint(e->plainBody().remove(quoteLines)); + if (bareBody.isEmpty()) { + bareBody = m_currentRoom->prettyPrint(e->plainBody().remove(quoteLines)); } - return nudeBody; + return bareBody; } if (role == QuotationRole) @@ -959,7 +959,7 @@ QVariant MessageEventModel::data(const QModelIndex& idx, int role) const { if (isPending) return QString(); // Cannot construct event link with unknown eventId - QString quotation = data(idx, NudeRichBodyRole).toString(); + QString quotation = data(idx, BareRichBodyRole).toString(); if (quotation.isEmpty()) return QString(); const auto authorUser = m_currentRoom->user(evt.senderId()); diff --git a/client/models/messageeventmodel.h b/client/models/messageeventmodel.h index eb895a2b..7801b938 100644 --- a/client/models/messageeventmodel.h +++ b/client/models/messageeventmodel.h @@ -34,7 +34,7 @@ class MessageEventModel: public QAbstractListModel RefRole, ReactionsRole, EventResolvedTypeRole, - NudeRichBodyRole, + BareRichBodyRole, QuotationRole, HtmlQuotationRole, };