diff --git a/resources/qml/TimelineView.qml b/resources/qml/TimelineView.qml index 051ea915..35dcae03 100644 --- a/resources/qml/TimelineView.qml +++ b/resources/qml/TimelineView.qml @@ -199,6 +199,7 @@ Rectangle { } MenuItem { text: qsTr("Redact message") + onTriggered: chat.model.redactEvent(model.id) } MenuItem { visible: model.type == MtxEvent.ImageMessage || model.type == MtxEvent.VideoMessage || model.type == MtxEvent.AudioMessage || model.type == MtxEvent.FileMessage diff --git a/src/ChatPage.cpp b/src/ChatPage.cpp index e5d4c9be..b8f312ac 100644 --- a/src/ChatPage.cpp +++ b/src/ChatPage.cpp @@ -115,11 +115,6 @@ ChatPage::ChatPage(QSharedPointer userSettings, QWidget *parent) contentLayout_->addWidget(top_bar_); contentLayout_->addWidget(view_manager_->getWidget()); - connect(this, - &ChatPage::removeTimelineEvent, - view_manager_, - &TimelineViewManager::removeTimelineEvent); - // Splitter splitter->addWidget(sideBar_); splitter->addWidget(content_); diff --git a/src/ChatPage.h b/src/ChatPage.h index e41ae1ae..1898f1a7 100644 --- a/src/ChatPage.h +++ b/src/ChatPage.h @@ -125,8 +125,6 @@ signals: void showUserSettingsPage(); void showOverlayProgressBar(); - void removeTimelineEvent(const QString &room_id, const QString &event_id); - void ownProfileOk(); void setUserDisplayName(const QString &name); void setUserAvatar(const QString &avatar); diff --git a/src/timeline2/TimelineModel.cpp b/src/timeline2/TimelineModel.cpp index b702686e..f9a8358f 100644 --- a/src/timeline2/TimelineModel.cpp +++ b/src/timeline2/TimelineModel.cpp @@ -321,6 +321,9 @@ TimelineModel::TimelineModel(QString room_id, QObject *parent) emit dataChanged(index(idx, 0), index(idx, 0)); }); + connect(this, &TimelineModel::redactionFailed, this, [](const QString &msg) { + emit ChatPage::instance()->showNotification(msg); + }); } QHash @@ -745,6 +748,25 @@ TimelineModel::readReceiptsAction(QString id) const MainWindow::instance()->openReadReceiptsDialog(id); } +void +TimelineModel::redactEvent(QString id) +{ + if (!id.isEmpty()) + http::client()->redact_event( + room_id_.toStdString(), + id.toStdString(), + [this, id](const mtx::responses::EventId &, mtx::http::RequestErr err) { + if (err) { + emit redactionFailed( + tr("Message redaction failed: %1") + .arg(QString::fromStdString(err->matrix_error.error))); + return; + } + + emit eventRedacted(id); + }); +} + int TimelineModel::idToIndex(QString id) const { diff --git a/src/timeline2/TimelineModel.h b/src/timeline2/TimelineModel.h index e10a0b6e..ffe5aecb 100644 --- a/src/timeline2/TimelineModel.h +++ b/src/timeline2/TimelineModel.h @@ -149,6 +149,7 @@ public: Q_INVOKABLE void viewRawMessage(QString id) const; Q_INVOKABLE void replyAction(QString id); Q_INVOKABLE void readReceiptsAction(QString id) const; + Q_INVOKABLE void redactEvent(QString id); Q_INVOKABLE int idToIndex(QString id) const; Q_INVOKABLE QString indexToId(int index) const; @@ -175,6 +176,8 @@ signals: void messageFailed(QString txn_id); void messageSent(QString txn_id, QString event_id); void currentIndexChanged(int index); + void redactionFailed(QString id); + void eventRedacted(QString id); private: DecryptionResult decryptEvent( diff --git a/src/timeline2/TimelineViewManager.h b/src/timeline2/TimelineViewManager.h index 9fcbc2f8..38d68f16 100644 --- a/src/timeline2/TimelineViewManager.h +++ b/src/timeline2/TimelineViewManager.h @@ -66,7 +66,6 @@ signals: public slots: void updateReadReceipts(const QString &room_id, const std::vector &event_ids); - void removeTimelineEvent(const QString &room_id, const QString &event_id) {} void initWithMessages(const std::map &msgs); void setHistoryView(const QString &room_id);