Fix redaction of edited messages
This commit is contained in:
parent
b3ff70fee9
commit
c4c13a1da9
@ -447,7 +447,8 @@ EventStore::edits(const std::string &event_id)
|
|||||||
auto event_ids = cache::client()->relatedEvents(room_id_, event_id);
|
auto event_ids = cache::client()->relatedEvents(room_id_, event_id);
|
||||||
|
|
||||||
auto original_event = get(event_id, "", false, false);
|
auto original_event = get(event_id, "", false, false);
|
||||||
if (!original_event)
|
if (!original_event ||
|
||||||
|
std::holds_alternative<mtx::events::RoomEvent<mtx::events::msg::Redacted>>(*original_event))
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
auto original_sender = mtx::accessors::sender(*original_event);
|
auto original_sender = mtx::accessors::sender(*original_event);
|
||||||
|
@ -77,6 +77,7 @@ public:
|
|||||||
mtx::events::collections::TimelineEvents *get(int idx, bool decrypt = true);
|
mtx::events::collections::TimelineEvents *get(int idx, bool decrypt = true);
|
||||||
|
|
||||||
QVariantList reactions(const std::string &event_id);
|
QVariantList reactions(const std::string &event_id);
|
||||||
|
std::vector<mtx::events::collections::TimelineEvents> edits(const std::string &event_id);
|
||||||
olm::DecryptionErrorCode decryptionError(std::string id);
|
olm::DecryptionErrorCode decryptionError(std::string id);
|
||||||
void requestSession(const mtx::events::EncryptedEvent<mtx::events::msg::Encrypted> &ev,
|
void requestSession(const mtx::events::EncryptedEvent<mtx::events::msg::Encrypted> &ev,
|
||||||
bool manual);
|
bool manual);
|
||||||
@ -120,7 +121,6 @@ public slots:
|
|||||||
void enableKeyRequests(bool suppressKeyRequests_);
|
void enableKeyRequests(bool suppressKeyRequests_);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<mtx::events::collections::TimelineEvents> edits(const std::string &event_id);
|
|
||||||
olm::DecryptionResult *decryptEvent(
|
olm::DecryptionResult *decryptEvent(
|
||||||
const IdIndex &idx,
|
const IdIndex &idx,
|
||||||
const mtx::events::EncryptedEvent<mtx::events::msg::Encrypted> &e);
|
const mtx::events::EncryptedEvent<mtx::events::msg::Encrypted> &e);
|
||||||
|
@ -344,6 +344,19 @@ TimelineModel::TimelineModel(TimelineViewManager *manager, QString room_id, QObj
|
|||||||
[](const QString &msg) { emit ChatPage::instance()->showNotification(msg); },
|
[](const QString &msg) { emit ChatPage::instance()->showNotification(msg); },
|
||||||
Qt::QueuedConnection);
|
Qt::QueuedConnection);
|
||||||
|
|
||||||
|
connect(this, &TimelineModel::dataAtIdChanged, this, [this](QString id) {
|
||||||
|
relatedEventCacheBuster++;
|
||||||
|
|
||||||
|
auto idx = idToIndex(id);
|
||||||
|
if (idx != -1) {
|
||||||
|
auto pos = index(idx);
|
||||||
|
nhlog::ui()->debug("data changed at {}", id.toStdString());
|
||||||
|
emit dataChanged(pos, pos);
|
||||||
|
} else {
|
||||||
|
nhlog::ui()->debug("id not found {}", id.toStdString());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
connect(this,
|
connect(this,
|
||||||
&TimelineModel::newMessageToSend,
|
&TimelineModel::newMessageToSend,
|
||||||
this,
|
this,
|
||||||
@ -1095,7 +1108,8 @@ TimelineModel::showReadReceipts(QString id)
|
|||||||
void
|
void
|
||||||
TimelineModel::redactEvent(QString id)
|
TimelineModel::redactEvent(QString id)
|
||||||
{
|
{
|
||||||
if (!id.isEmpty())
|
if (!id.isEmpty()) {
|
||||||
|
auto edits = events.edits(id.toStdString());
|
||||||
http::client()->redact_event(
|
http::client()->redact_event(
|
||||||
room_id_.toStdString(),
|
room_id_.toStdString(),
|
||||||
id.toStdString(),
|
id.toStdString(),
|
||||||
@ -1106,8 +1120,26 @@ TimelineModel::redactEvent(QString id)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
emit eventRedacted(id);
|
emit dataAtIdChanged(id);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// redact all edits to prevent leaks
|
||||||
|
for (const auto &e : edits) {
|
||||||
|
auto id_ = mtx::accessors::event_id(e);
|
||||||
|
http::client()->redact_event(
|
||||||
|
room_id_.toStdString(),
|
||||||
|
id_,
|
||||||
|
[this, id, 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 dataAtIdChanged(id);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
@ -367,9 +367,9 @@ private slots:
|
|||||||
void scrollTimerEvent();
|
void scrollTimerEvent();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
void dataAtIdChanged(QString id);
|
||||||
void currentIndexChanged(int index);
|
void currentIndexChanged(int index);
|
||||||
void redactionFailed(QString id);
|
void redactionFailed(QString id);
|
||||||
void eventRedacted(QString id);
|
|
||||||
void mediaCached(QString mxcUrl, QString cacheUrl);
|
void mediaCached(QString mxcUrl, QString cacheUrl);
|
||||||
void newEncryptedImage(mtx::crypto::EncryptedFile encryptionInfo);
|
void newEncryptedImage(mtx::crypto::EncryptedFile encryptionInfo);
|
||||||
void typingUsersChanged(std::vector<QString> users);
|
void typingUsersChanged(std::vector<QString> users);
|
||||||
|
Loading…
Reference in New Issue
Block a user