diff options
-rw-r--r-- | src/Cache.cpp | 24 | ||||
-rw-r--r-- | src/Cache.h | 2 | ||||
-rw-r--r-- | src/Cache_p.h | 1 | ||||
-rw-r--r-- | src/ChatPage.cpp | 4 | ||||
-rw-r--r-- | src/TextInputWidget.cpp | 2 | ||||
-rw-r--r-- | src/TextInputWidget.h | 1 | ||||
-rw-r--r-- | src/timeline/TimelineModel.cpp | 6 |
7 files changed, 40 insertions, 0 deletions
diff --git a/src/Cache.cpp b/src/Cache.cpp index b7a25343..63f6e426 100644 --- a/src/Cache.cpp +++ b/src/Cache.cpp @@ -373,6 +373,25 @@ Cache::updateOutboundMegolmSession(const std::string &room_id, int message_index } void +Cache::dropOutboundMegolmSession(const std::string &room_id) +{ + using namespace mtx::crypto; + + if (!outboundMegolmSessionExists(room_id)) + return; + + { + std::unique_lock<std::mutex> lock(session_storage.group_outbound_mtx); + session_storage.group_outbound_session_data.erase(room_id); + session_storage.group_outbound_sessions.erase(room_id); + + auto txn = lmdb::txn::begin(env_); + lmdb::dbi_del(txn, outboundMegolmSessionDb_, lmdb::val(room_id), nullptr); + txn.commit(); + } +} + +void Cache::saveOutboundMegolmSession(const std::string &room_id, const OutboundGroupSessionData &data, mtx::crypto::OutboundGroupSessionPtr session) @@ -3889,6 +3908,11 @@ updateOutboundMegolmSession(const std::string &room_id, int message_index) { instance_->updateOutboundMegolmSession(room_id, message_index); } +void +dropOutboundMegolmSession(const std::string &room_id) +{ + instance_->dropOutboundMegolmSession(room_id); +} void importSessionKeys(const mtx::crypto::ExportedSessionKeys &keys) diff --git a/src/Cache.h b/src/Cache.h index edad5993..fca80145 100644 --- a/src/Cache.h +++ b/src/Cache.h @@ -271,6 +271,8 @@ bool outboundMegolmSessionExists(const std::string &room_id) noexcept; void updateOutboundMegolmSession(const std::string &room_id, int message_index); +void +dropOutboundMegolmSession(const std::string &room_id); void importSessionKeys(const mtx::crypto::ExportedSessionKeys &keys); diff --git a/src/Cache_p.h b/src/Cache_p.h index 034c6d76..b37eae58 100644 --- a/src/Cache_p.h +++ b/src/Cache_p.h @@ -251,6 +251,7 @@ public: OutboundGroupSessionDataRef getOutboundMegolmSession(const std::string &room_id); bool outboundMegolmSessionExists(const std::string &room_id) noexcept; void updateOutboundMegolmSession(const std::string &room_id, int message_index); + void dropOutboundMegolmSession(const std::string &room_id); void importSessionKeys(const mtx::crypto::ExportedSessionKeys &keys); mtx::crypto::ExportedSessionKeys exportSessionKeys(); diff --git a/src/ChatPage.cpp b/src/ChatPage.cpp index 6abe4078..87b4c277 100644 --- a/src/ChatPage.cpp +++ b/src/ChatPage.cpp @@ -168,6 +168,10 @@ ChatPage::ChatPage(QSharedPointer<UserSettings> userSettings, QWidget *parent) view_manager_, &TimelineViewManager::clearCurrentRoomTimeline); + connect(text_input_, &TextInputWidget::rotateMegolmSession, this, [this]() { + cache::dropOutboundMegolmSession(current_room_.toStdString()); + }); + connect( new QShortcut(QKeySequence("Ctrl+Down"), this), &QShortcut::activated, this, [this]() { if (isVisible()) diff --git a/src/TextInputWidget.cpp b/src/TextInputWidget.cpp index 4a25c4cf..d1be7fb4 100644 --- a/src/TextInputWidget.cpp +++ b/src/TextInputWidget.cpp @@ -709,6 +709,8 @@ TextInputWidget::command(QString command, QString args) emit sendTextMessage("ノ┬─┬ノ ︵ ( \\o°o)\\"); } else if (command == "clear-timeline") { emit clearRoomTimeline(); + } else if (command == "rotate-megolm-session") { + emit rotateMegolmSession(); } } diff --git a/src/TextInputWidget.h b/src/TextInputWidget.h index 3aa05c39..092e0ff2 100644 --- a/src/TextInputWidget.h +++ b/src/TextInputWidget.h @@ -186,6 +186,7 @@ signals: void sendBanRoomRequest(const QString &userid, const QString &reason); void sendUnbanRoomRequest(const QString &userid, const QString &reason); void changeRoomNick(const QString &displayname); + void rotateMegolmSession(); void startedTyping(); void stoppedTyping(); diff --git a/src/timeline/TimelineModel.cpp b/src/timeline/TimelineModel.cpp index af26a543..5e8952fc 100644 --- a/src/timeline/TimelineModel.cpp +++ b/src/timeline/TimelineModel.cpp @@ -1120,6 +1120,12 @@ TimelineModel::handleClaimedKeys( nhlog::net()->debug("{} : \n {}", device_id, rd.second.dump(2)); + if (rd.second.empty() || !rd.second.begin()->contains("key")) { + nhlog::net()->warn("Skipping device {} as it has no key.", + device_id); + continue; + } + // TODO: Verify signatures auto otk = rd.second.begin()->at("key"); |