From 02fcd0e7cf731d42a46935fe8e7ec2387d579a50 Mon Sep 17 00:00:00 2001 From: MTRNord Date: Thu, 23 Dec 2021 02:33:46 +0100 Subject: [PATCH 1/4] Apply (selective) Clang-tidy and clazy suggestions on TimelineModel --- src/timeline/TimelineModel.cpp | 59 +++++++++++++++++----------------- src/timeline/TimelineModel.h | 48 +++++++++++++-------------- 2 files changed, 53 insertions(+), 54 deletions(-) diff --git a/src/timeline/TimelineModel.cpp b/src/timeline/TimelineModel.cpp index b9941dfa..3fe52553 100644 --- a/src/timeline/TimelineModel.cpp +++ b/src/timeline/TimelineModel.cpp @@ -15,7 +15,6 @@ #include #include #include -#include #include #include @@ -330,7 +329,7 @@ qml_mtx_events::fromRoomEventType(qml_mtx_events::EventType t) }; } -TimelineModel::TimelineModel(TimelineViewManager *manager, QString room_id, QObject *parent) +TimelineModel::TimelineModel(TimelineViewManager *manager, const QString &room_id, QObject *parent) : QAbstractListModel(parent) , events(room_id.toStdString(), this) , room_id_(room_id) @@ -355,7 +354,7 @@ TimelineModel::TimelineModel(TimelineViewManager *manager, QString room_id, QObj [](const QString &msg) { emit ChatPage::instance()->showNotification(msg); }, Qt::QueuedConnection); - connect(this, &TimelineModel::dataAtIdChanged, this, [this](QString id) { + connect(this, &TimelineModel::dataAtIdChanged, this, [this](const QString &id) { relatedEventCacheBuster++; auto idx = idToIndex(id); @@ -404,7 +403,7 @@ TimelineModel::TimelineModel(TimelineViewManager *manager, QString room_id, QObj connect(&events, &EventStore::startDMVerification, this, - [this](mtx::events::RoomEvent msg) { + [this](const mtx::events::RoomEvent &msg) { ChatPage::instance()->receivedRoomDeviceVerificationRequest(msg, this); }); connect(&events, &EventStore::updateFlowEventId, this, [this](std::string event_id) { @@ -414,7 +413,7 @@ TimelineModel::TimelineModel(TimelineViewManager *manager, QString room_id, QObj // When a message is sent, check if the current edit/reply relates to that message, // and update the event_id so that it points to the sent message and not the pending one. connect( - &events, &EventStore::messageSent, this, [this](std::string txn_id, std::string event_id) { + &events, &EventStore::messageSent, this, [this](const std::string &txn_id, const std::string &event_id) { if (edit_.toStdString() == txn_id) { edit_ = QString::fromStdString(event_id); emit editChanged(edit_); @@ -486,7 +485,7 @@ TimelineModel::rowCount(const QModelIndex &parent) const } QVariantMap -TimelineModel::getDump(QString eventId, QString relatedTo) const +TimelineModel::getDump(const QString &eventId, const QString &relatedTo) const { if (auto event = events.get(eventId.toStdString(), relatedTo.toStdString())) return data(*event, Dump).toMap(); @@ -747,7 +746,7 @@ TimelineModel::data(const QModelIndex &index, int role) const } QVariant -TimelineModel::dataById(QString id, int role, QString relatedTo) +TimelineModel::dataById(const QString &id, int role, const QString &relatedTo) { if (auto event = events.get(id.toStdString(), relatedTo.toStdString())) return data(*event, role); @@ -1054,7 +1053,7 @@ TimelineModel::formatDateSeparator(QDate date) const } void -TimelineModel::viewRawMessage(QString id) +TimelineModel::viewRawMessage(const QString &id) { auto e = events.get(id.toStdString(), "", false); if (!e) @@ -1064,7 +1063,7 @@ TimelineModel::viewRawMessage(QString id) } void -TimelineModel::forwardMessage(QString eventId, QString roomId) +TimelineModel::forwardMessage(const QString & eventId, QString roomId) { auto e = events.get(eventId.toStdString(), ""); if (!e) @@ -1099,7 +1098,7 @@ TimelineModel::replyAction(QString id) } void -TimelineModel::unpin(QString id) +TimelineModel::unpin(const QString &id) { auto pinned = cache::client()->getStateEvent(room_id_.toStdString()); @@ -1129,7 +1128,7 @@ TimelineModel::unpin(QString id) } void -TimelineModel::pin(QString id) +TimelineModel::pin(const QString &id) { auto pinned = cache::client()->getStateEvent(room_id_.toStdString()); @@ -1159,7 +1158,7 @@ TimelineModel::editAction(QString id) } RelatedInfo -TimelineModel::relatedInfo(QString id) +TimelineModel::relatedInfo(const QString &id) { auto event = events.get(id.toStdString(), ""); if (!event) @@ -1175,7 +1174,7 @@ TimelineModel::showReadReceipts(QString id) } void -TimelineModel::redactEvent(QString id) +TimelineModel::redactEvent(const QString &id) { if (!id.isEmpty()) { auto edits = events.edits(id.toStdString()); @@ -1212,7 +1211,7 @@ TimelineModel::redactEvent(QString id) } int -TimelineModel::idToIndex(QString id) const +TimelineModel::idToIndex(const QString &id) const { if (id.isEmpty()) return -1; @@ -1427,11 +1426,11 @@ void TimelineModel::openMedia(QString eventId) { cacheMedia(eventId, - [](QString filename) { QDesktopServices::openUrl(QUrl::fromLocalFile(filename)); }); + [](const QString &filename) { QDesktopServices::openUrl(QUrl::fromLocalFile(filename)); }); } bool -TimelineModel::saveMedia(QString eventId) const +TimelineModel::saveMedia(const QString &eventId) const { mtx::events::collections::TimelineEvents *event = events.get(eventId.toStdString(), ""); if (!event) @@ -1505,7 +1504,7 @@ TimelineModel::saveMedia(QString eventId) const } void -TimelineModel::cacheMedia(QString eventId, std::function callback) +TimelineModel::cacheMedia(const QString &eventId, const std::function &callback) { mtx::events::collections::TimelineEvents *event = events.get(eventId.toStdString(), ""); if (!event) @@ -1594,7 +1593,7 @@ TimelineModel::cacheMedia(QString eventId, std::function ca } void -TimelineModel::cacheMedia(QString eventId) +TimelineModel::cacheMedia(const QString &eventId) { cacheMedia(eventId, NULL); } @@ -1650,7 +1649,7 @@ TimelineModel::scrollTimerEvent() } void -TimelineModel::requestKeyForEvent(QString id) +TimelineModel::requestKeyForEvent(const QString &id) { auto encrypted_event = events.get(id.toStdString(), "", false); if (encrypted_event) { @@ -1661,7 +1660,7 @@ TimelineModel::requestKeyForEvent(QString id) } void -TimelineModel::copyLinkToEvent(QString eventId) const +TimelineModel::copyLinkToEvent(const QString &eventId) const { QStringList vias; @@ -1755,7 +1754,7 @@ TimelineModel::formatTypingUsers(const std::vector &users, QColor bg) } QString -TimelineModel::formatJoinRuleEvent(QString id) +TimelineModel::formatJoinRuleEvent(const QString &id) { mtx::events::collections::TimelineEvents *e = events.get(id.toStdString(), ""); if (!e) @@ -1793,7 +1792,7 @@ TimelineModel::formatJoinRuleEvent(QString id) } QString -TimelineModel::formatGuestAccessEvent(QString id) +TimelineModel::formatGuestAccessEvent(const QString &id) { mtx::events::collections::TimelineEvents *e = events.get(id.toStdString(), ""); if (!e) @@ -1817,7 +1816,7 @@ TimelineModel::formatGuestAccessEvent(QString id) } QString -TimelineModel::formatHistoryVisibilityEvent(QString id) +TimelineModel::formatHistoryVisibilityEvent(const QString &id) { mtx::events::collections::TimelineEvents *e = events.get(id.toStdString(), ""); if (!e) @@ -1849,7 +1848,7 @@ TimelineModel::formatHistoryVisibilityEvent(QString id) } QString -TimelineModel::formatPowerLevelEvent(QString id) +TimelineModel::formatPowerLevelEvent(const QString &id) { mtx::events::collections::TimelineEvents *e = events.get(id.toStdString(), ""); if (!e) @@ -1867,7 +1866,7 @@ TimelineModel::formatPowerLevelEvent(QString id) } QVariantMap -TimelineModel::formatRedactedEvent(QString id) +TimelineModel::formatRedactedEvent(const QString &id) { QVariantMap pair{{"first", ""}, {"second", ""}}; mtx::events::collections::TimelineEvents *e = events.get(id.toStdString(), ""); @@ -1905,7 +1904,7 @@ TimelineModel::formatRedactedEvent(QString id) } void -TimelineModel::acceptKnock(QString id) +TimelineModel::acceptKnock(const QString &id) { mtx::events::collections::TimelineEvents *e = events.get(id.toStdString(), ""); if (!e) @@ -1929,7 +1928,7 @@ TimelineModel::acceptKnock(QString id) } bool -TimelineModel::showAcceptKnockButton(QString id) +TimelineModel::showAcceptKnockButton(const QString &id) { mtx::events::collections::TimelineEvents *e = events.get(id.toStdString(), ""); if (!e) @@ -1950,7 +1949,7 @@ TimelineModel::showAcceptKnockButton(QString id) } QString -TimelineModel::formatMemberEvent(QString id) +TimelineModel::formatMemberEvent(const QString &id) { mtx::events::collections::TimelineEvents *e = events.get(id.toStdString(), ""); if (!e) @@ -2054,7 +2053,7 @@ TimelineModel::formatMemberEvent(QString id) } void -TimelineModel::setEdit(QString newEdit) +TimelineModel::setEdit(const QString &newEdit) { if (newEdit.isEmpty()) { resetEdit(); @@ -2213,7 +2212,7 @@ TimelineModel::directChatOtherUserId() const { if (roomMemberCount() < 3) { QString id; - for (auto member : cache::getMembers(room_id_.toStdString())) + for (const auto &member : cache::getMembers(room_id_.toStdString())) if (member.user_id != UserSettings::instance()->userId()) id = member.user_id; return id; diff --git a/src/timeline/TimelineModel.h b/src/timeline/TimelineModel.h index a06d4063..4d6f7015 100644 --- a/src/timeline/TimelineModel.h +++ b/src/timeline/TimelineModel.h @@ -189,7 +189,7 @@ class TimelineModel : public QAbstractListModel public: explicit TimelineModel(TimelineViewManager *manager, - QString room_id, + const QString& room_id, QObject *parent = nullptr); enum Roles @@ -237,7 +237,7 @@ public: int rowCount(const QModelIndex &parent = QModelIndex()) const override; QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; QVariant data(const mtx::events::collections::TimelineEvents &event, int role) const; - Q_INVOKABLE QVariant dataById(QString id, int role, QString relatedTo); + Q_INVOKABLE QVariant dataById(const QString &id, int role, const QString &relatedTo); bool canFetchMore(const QModelIndex &) const override; void fetchMore(const QModelIndex &) override; @@ -246,40 +246,40 @@ public: Q_INVOKABLE QString avatarUrl(QString id) const; Q_INVOKABLE QString formatDateSeparator(QDate date) const; Q_INVOKABLE QString formatTypingUsers(const std::vector &users, QColor bg); - Q_INVOKABLE bool showAcceptKnockButton(QString id); - Q_INVOKABLE void acceptKnock(QString id); - Q_INVOKABLE QString formatMemberEvent(QString id); - Q_INVOKABLE QString formatJoinRuleEvent(QString id); - Q_INVOKABLE QString formatHistoryVisibilityEvent(QString id); - Q_INVOKABLE QString formatGuestAccessEvent(QString id); - Q_INVOKABLE QString formatPowerLevelEvent(QString id); - Q_INVOKABLE QVariantMap formatRedactedEvent(QString id); + Q_INVOKABLE bool showAcceptKnockButton(const QString &id); + Q_INVOKABLE void acceptKnock(const QString &id); + Q_INVOKABLE QString formatMemberEvent(const QString &id); + Q_INVOKABLE QString formatJoinRuleEvent(const QString &id); + Q_INVOKABLE QString formatHistoryVisibilityEvent(const QString &id); + Q_INVOKABLE QString formatGuestAccessEvent(const QString &id); + Q_INVOKABLE QString formatPowerLevelEvent(const QString &id); + Q_INVOKABLE QVariantMap formatRedactedEvent(const QString &id); - Q_INVOKABLE void viewRawMessage(QString id); - Q_INVOKABLE void forwardMessage(QString eventId, QString roomId); + Q_INVOKABLE void viewRawMessage(const QString &id); + Q_INVOKABLE void forwardMessage(const QString &eventId, QString roomId); Q_INVOKABLE void viewDecryptedRawMessage(QString id); Q_INVOKABLE void openUserProfile(QString userid); Q_INVOKABLE void editAction(QString id); Q_INVOKABLE void replyAction(QString id); - Q_INVOKABLE void unpin(QString id); - Q_INVOKABLE void pin(QString id); + Q_INVOKABLE void unpin(const QString &id); + Q_INVOKABLE void pin(const QString &id); Q_INVOKABLE void showReadReceipts(QString id); - Q_INVOKABLE void redactEvent(QString id); - Q_INVOKABLE int idToIndex(QString id) const; + Q_INVOKABLE void redactEvent(const QString &id); + Q_INVOKABLE int idToIndex(const QString &id) const; Q_INVOKABLE QString indexToId(int index) const; Q_INVOKABLE void openMedia(QString eventId); - Q_INVOKABLE void cacheMedia(QString eventId); - Q_INVOKABLE bool saveMedia(QString eventId) const; + Q_INVOKABLE void cacheMedia(const QString &eventId); + Q_INVOKABLE bool saveMedia(const QString &eventId) const; Q_INVOKABLE void showEvent(QString eventId); - Q_INVOKABLE void copyLinkToEvent(QString eventId) const; - void cacheMedia(QString eventId, std::function callback); + Q_INVOKABLE void copyLinkToEvent(const QString &eventId) const; + void cacheMedia(const QString &eventId, const std::function &callback); Q_INVOKABLE void sendReset() { beginResetModel(); endResetModel(); } - Q_INVOKABLE void requestKeyForEvent(QString id); + Q_INVOKABLE void requestKeyForEvent(const QString &id); std::vector<::Reaction> reactions(const std::string &event_id) { @@ -296,7 +296,7 @@ public: void syncState(const mtx::responses::State &state); template void sendMessageEvent(const T &content, mtx::events::EventType eventType); - RelatedInfo relatedInfo(QString id); + RelatedInfo relatedInfo(const QString &id); DescInfo lastMessage() const { return lastMessage_; } bool isSpace() const { return isSpace_; } @@ -320,7 +320,7 @@ public slots: int currentIndex() const { return idToIndex(currentId); } void eventShown(); void markEventsAsRead(const std::vector &event_ids); - QVariantMap getDump(QString eventId, QString relatedTo) const; + QVariantMap getDump(const QString &eventId, const QString &relatedTo) const; void updateTypingUsers(const std::vector &users) { if (this->typingUsers_ != users) { @@ -349,7 +349,7 @@ public slots: } } QString edit() const { return edit_; } - void setEdit(QString newEdit); + void setEdit(const QString &newEdit); void resetEdit(); void setDecryptDescription(bool decrypt) { decryptDescription = decrypt; } void clearTimeline() { events.clearTimeline(); } From a872bdf8c5dc17f901cc9f553d4ff2539f0334f6 Mon Sep 17 00:00:00 2001 From: MTRNord Date: Thu, 23 Dec 2021 02:46:33 +0100 Subject: [PATCH 2/4] Apply (selective) Clang-tidy move and some new detected const pointer suggestions on TimelineModel --- src/timeline/TimelineModel.cpp | 15 ++++++++------- src/timeline/TimelineModel.h | 8 ++++---- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/timeline/TimelineModel.cpp b/src/timeline/TimelineModel.cpp index 3fe52553..543d2c84 100644 --- a/src/timeline/TimelineModel.cpp +++ b/src/timeline/TimelineModel.cpp @@ -17,6 +17,7 @@ #include #include #include +#include #include "Cache_p.h" #include "ChatPage.h" @@ -407,7 +408,7 @@ TimelineModel::TimelineModel(TimelineViewManager *manager, const QString &room_i ChatPage::instance()->receivedRoomDeviceVerificationRequest(msg, this); }); connect(&events, &EventStore::updateFlowEventId, this, [this](std::string event_id) { - this->updateFlowEventId(event_id); + this->updateFlowEventId(std::move(event_id)); }); // When a message is sent, check if the current edit/reply relates to that message, @@ -1069,11 +1070,11 @@ TimelineModel::forwardMessage(const QString & eventId, QString roomId) if (!e) return; - emit forwardToRoom(e, roomId); + emit forwardToRoom(e, std::move(roomId)); } void -TimelineModel::viewDecryptedRawMessage(QString id) +TimelineModel::viewDecryptedRawMessage(const QString &id) { auto e = events.get(id.toStdString(), ""); if (!e) @@ -1086,7 +1087,7 @@ TimelineModel::viewDecryptedRawMessage(QString id) void TimelineModel::openUserProfile(QString userid) { - UserProfile *userProfile = new UserProfile(room_id_, userid, manager_, this); + UserProfile *userProfile = new UserProfile(room_id_, std::move(userid), manager_, this); connect(this, &TimelineModel::roomAvatarUrlChanged, userProfile, &UserProfile::updateAvatarUrl); emit manager_->openProfile(userProfile); } @@ -1094,7 +1095,7 @@ TimelineModel::openUserProfile(QString userid) void TimelineModel::replyAction(QString id) { - setReply(id); + setReply(std::move(id)); } void @@ -1423,7 +1424,7 @@ TimelineModel::addPendingMessage(mtx::events::collections::TimelineEvents event) } void -TimelineModel::openMedia(QString eventId) +TimelineModel::openMedia(const QString &eventId) { cacheMedia(eventId, [](const QString &filename) { QDesktopServices::openUrl(QUrl::fromLocalFile(filename)); }); @@ -1700,7 +1701,7 @@ TimelineModel::copyLinkToEvent(const QString &eventId) const } QString -TimelineModel::formatTypingUsers(const std::vector &users, QColor bg) +TimelineModel::formatTypingUsers(const std::vector &users, const QColor &bg) { QString temp = tr("%1 and %2 are typing.", diff --git a/src/timeline/TimelineModel.h b/src/timeline/TimelineModel.h index 4d6f7015..f9f11009 100644 --- a/src/timeline/TimelineModel.h +++ b/src/timeline/TimelineModel.h @@ -245,7 +245,7 @@ public: Q_INVOKABLE QString displayName(QString id) const; Q_INVOKABLE QString avatarUrl(QString id) const; Q_INVOKABLE QString formatDateSeparator(QDate date) const; - Q_INVOKABLE QString formatTypingUsers(const std::vector &users, QColor bg); + Q_INVOKABLE QString formatTypingUsers(const std::vector &users, const QColor &bg); Q_INVOKABLE bool showAcceptKnockButton(const QString &id); Q_INVOKABLE void acceptKnock(const QString &id); Q_INVOKABLE QString formatMemberEvent(const QString &id); @@ -257,7 +257,7 @@ public: Q_INVOKABLE void viewRawMessage(const QString &id); Q_INVOKABLE void forwardMessage(const QString &eventId, QString roomId); - Q_INVOKABLE void viewDecryptedRawMessage(QString id); + Q_INVOKABLE void viewDecryptedRawMessage(const QString &id); Q_INVOKABLE void openUserProfile(QString userid); Q_INVOKABLE void editAction(QString id); Q_INVOKABLE void replyAction(QString id); @@ -267,7 +267,7 @@ public: Q_INVOKABLE void redactEvent(const QString &id); Q_INVOKABLE int idToIndex(const QString &id) const; Q_INVOKABLE QString indexToId(int index) const; - Q_INVOKABLE void openMedia(QString eventId); + Q_INVOKABLE void openMedia(const QString &eventId); Q_INVOKABLE void cacheMedia(const QString &eventId); Q_INVOKABLE bool saveMedia(const QString &eventId) const; Q_INVOKABLE void showEvent(QString eventId); @@ -331,7 +331,7 @@ public slots: std::vector typingUsers() const { return typingUsers_; } bool paginationInProgress() const { return m_paginationInProgress; } QString reply() const { return reply_; } - void setReply(QString newReply) + void setReply(const QString &newReply) { if (edit_.startsWith('m')) return; From 049613211a1269db8e4bcd13cde52595e60b981a Mon Sep 17 00:00:00 2001 From: MTRNord Date: Thu, 23 Dec 2021 02:55:25 +0100 Subject: [PATCH 3/4] Apply (selective) Clang-tidy const function and new const pointer suggestions on TimelineModel --- src/timeline/TimelineModel.cpp | 8 ++++---- src/timeline/TimelineModel.h | 10 +++++----- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/timeline/TimelineModel.cpp b/src/timeline/TimelineModel.cpp index 543d2c84..0447a56a 100644 --- a/src/timeline/TimelineModel.cpp +++ b/src/timeline/TimelineModel.cpp @@ -1027,13 +1027,13 @@ TimelineModel::readEvent(const std::string &id) } QString -TimelineModel::displayName(QString id) const +TimelineModel::displayName(const QString &id) const { return cache::displayName(room_id_, id).toHtmlEscaped(); } QString -TimelineModel::avatarUrl(QString id) const +TimelineModel::avatarUrl(const QString &id) const { return cache::avatarUrl(room_id_, id); } @@ -1093,9 +1093,9 @@ TimelineModel::openUserProfile(QString userid) } void -TimelineModel::replyAction(QString id) +TimelineModel::replyAction(const QString &id) { - setReply(std::move(id)); + setReply(id); } void diff --git a/src/timeline/TimelineModel.h b/src/timeline/TimelineModel.h index f9f11009..9ee78831 100644 --- a/src/timeline/TimelineModel.h +++ b/src/timeline/TimelineModel.h @@ -242,8 +242,8 @@ public: bool canFetchMore(const QModelIndex &) const override; void fetchMore(const QModelIndex &) override; - Q_INVOKABLE QString displayName(QString id) const; - Q_INVOKABLE QString avatarUrl(QString id) const; + Q_INVOKABLE QString displayName(const QString &id) const; + Q_INVOKABLE QString avatarUrl(const QString &id) const; Q_INVOKABLE QString formatDateSeparator(QDate date) const; Q_INVOKABLE QString formatTypingUsers(const std::vector &users, const QColor &bg); Q_INVOKABLE bool showAcceptKnockButton(const QString &id); @@ -260,7 +260,7 @@ public: Q_INVOKABLE void viewDecryptedRawMessage(const QString &id); Q_INVOKABLE void openUserProfile(QString userid); Q_INVOKABLE void editAction(QString id); - Q_INVOKABLE void replyAction(QString id); + Q_INVOKABLE void replyAction(const QString &id); Q_INVOKABLE void unpin(const QString &id); Q_INVOKABLE void pin(const QString &id); Q_INVOKABLE void showReadReceipts(QString id); @@ -367,8 +367,8 @@ public slots: QString roomAvatarUrl() const; QString roomId() const { return room_id_; } - bool hasMentions() { return highlight_count > 0; } - int notificationCount() { return notification_count; } + bool hasMentions() const { return highlight_count > 0; } + int notificationCount() const { return notification_count; } QString scrollTarget() const; From 7b2f7e65fd1bd0ceda02f3e0bb06b435ae37dfd6 Mon Sep 17 00:00:00 2001 From: MTRNord Date: Mon, 27 Dec 2021 20:49:27 +0100 Subject: [PATCH 4/4] Run linter --- src/timeline/TimelineModel.cpp | 34 +++++++++++++++++++--------------- src/timeline/TimelineModel.h | 5 +++-- 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/src/timeline/TimelineModel.cpp b/src/timeline/TimelineModel.cpp index 0447a56a..781f028e 100644 --- a/src/timeline/TimelineModel.cpp +++ b/src/timeline/TimelineModel.cpp @@ -413,17 +413,19 @@ TimelineModel::TimelineModel(TimelineViewManager *manager, const QString &room_i // When a message is sent, check if the current edit/reply relates to that message, // and update the event_id so that it points to the sent message and not the pending one. - connect( - &events, &EventStore::messageSent, this, [this](const std::string &txn_id, const std::string &event_id) { - if (edit_.toStdString() == txn_id) { - edit_ = QString::fromStdString(event_id); - emit editChanged(edit_); - } - if (reply_.toStdString() == txn_id) { - reply_ = QString::fromStdString(event_id); - emit replyChanged(reply_); - } - }); + connect(&events, + &EventStore::messageSent, + this, + [this](const std::string &txn_id, const std::string &event_id) { + if (edit_.toStdString() == txn_id) { + edit_ = QString::fromStdString(event_id); + emit editChanged(edit_); + } + if (reply_.toStdString() == txn_id) { + reply_ = QString::fromStdString(event_id); + emit replyChanged(reply_); + } + }); connect( manager_, &TimelineViewManager::initialSyncChanged, &events, &EventStore::enableKeyRequests); @@ -1064,7 +1066,7 @@ TimelineModel::viewRawMessage(const QString &id) } void -TimelineModel::forwardMessage(const QString & eventId, QString roomId) +TimelineModel::forwardMessage(const QString &eventId, QString roomId) { auto e = events.get(eventId.toStdString(), ""); if (!e) @@ -1426,8 +1428,9 @@ TimelineModel::addPendingMessage(mtx::events::collections::TimelineEvents event) void TimelineModel::openMedia(const QString &eventId) { - cacheMedia(eventId, - [](const QString &filename) { QDesktopServices::openUrl(QUrl::fromLocalFile(filename)); }); + cacheMedia(eventId, [](const QString &filename) { + QDesktopServices::openUrl(QUrl::fromLocalFile(filename)); + }); } bool @@ -1505,7 +1508,8 @@ TimelineModel::saveMedia(const QString &eventId) const } void -TimelineModel::cacheMedia(const QString &eventId, const std::function &callback) +TimelineModel::cacheMedia(const QString &eventId, + const std::function &callback) { mtx::events::collections::TimelineEvents *event = events.get(eventId.toStdString(), ""); if (!event) diff --git a/src/timeline/TimelineModel.h b/src/timeline/TimelineModel.h index 9ee78831..bbc1e5ef 100644 --- a/src/timeline/TimelineModel.h +++ b/src/timeline/TimelineModel.h @@ -189,7 +189,7 @@ class TimelineModel : public QAbstractListModel public: explicit TimelineModel(TimelineViewManager *manager, - const QString& room_id, + const QString &room_id, QObject *parent = nullptr); enum Roles @@ -272,7 +272,8 @@ public: Q_INVOKABLE bool saveMedia(const QString &eventId) const; Q_INVOKABLE void showEvent(QString eventId); Q_INVOKABLE void copyLinkToEvent(const QString &eventId) const; - void cacheMedia(const QString &eventId, const std::function &callback); + void + cacheMedia(const QString &eventId, const std::function &callback); Q_INVOKABLE void sendReset() { beginResetModel();