summary refs log tree commit diff
path: root/src/timeline/EventStore.cpp
diff options
context:
space:
mode:
authorChethan2k1 <40890937+Chethan2k1@users.noreply.github.com>2020-09-04 12:02:24 +0530
committerChethan2k1 <40890937+Chethan2k1@users.noreply.github.com>2020-09-04 12:02:24 +0530
commite8eeb480d51b6fc60c9807dd92195e9068582592 (patch)
treee9c707bbbbd62c528339b8104ec456c3473f11c9 /src/timeline/EventStore.cpp
parentMerge branch 'master' into device-verification (diff)
downloadnheko-e8eeb480d51b6fc60c9807dd92195e9068582592.tar.xz
Fix Wrong Emojis Issue in Room Verification
Diffstat (limited to 'src/timeline/EventStore.cpp')
-rw-r--r--src/timeline/EventStore.cpp221
1 files changed, 123 insertions, 98 deletions
diff --git a/src/timeline/EventStore.cpp b/src/timeline/EventStore.cpp

index bfc16a02..e5eaefb8 100644 --- a/src/timeline/EventStore.cpp +++ b/src/timeline/EventStore.cpp
@@ -32,38 +32,40 @@ EventStore::EventStore(std::string room_id, QObject *) this->last = range->last; } - connect(this, - &EventStore::eventFetched, - this, - [this](std::string id, - std::string relatedTo, - mtx::events::collections::TimelineEvents timeline) { - cache::client()->storeEvent(room_id_, id, {timeline}); + connect( + this, + &EventStore::eventFetched, + this, + [this](std::string id, + std::string relatedTo, + mtx::events::collections::TimelineEvents timeline) { + cache::client()->storeEvent(room_id_, id, {timeline}); - if (!relatedTo.empty()) { - auto idx = idToIndex(relatedTo); - if (idx) - emit dataChanged(*idx, *idx); - } - }, - Qt::QueuedConnection); + if (!relatedTo.empty()) { + auto idx = idToIndex(relatedTo); + if (idx) + emit dataChanged(*idx, *idx); + } + }, + Qt::QueuedConnection); - connect(this, - &EventStore::oldMessagesRetrieved, - this, - [this](const mtx::responses::Messages &res) { - uint64_t newFirst = cache::client()->saveOldMessages(room_id_, res); - if (newFirst == first && !res.chunk.empty()) - fetchMore(); - else { - emit beginInsertRows(toExternalIdx(newFirst), - toExternalIdx(this->first - 1)); - this->first = newFirst; - emit endInsertRows(); - emit fetchedMore(); - } - }, - Qt::QueuedConnection); + connect( + this, + &EventStore::oldMessagesRetrieved, + this, + [this](const mtx::responses::Messages &res) { + uint64_t newFirst = cache::client()->saveOldMessages(room_id_, res); + if (newFirst == first) + fetchMore(); + else { + emit beginInsertRows(toExternalIdx(newFirst), + toExternalIdx(this->first - 1)); + this->first = newFirst; + emit endInsertRows(); + emit fetchedMore(); + } + }, + Qt::QueuedConnection); connect(this, &EventStore::processPending, this, [this]() { if (!current_txn.empty()) { @@ -128,46 +130,48 @@ EventStore::EventStore(std::string room_id, QObject *) event->data); }); - connect(this, - &EventStore::messageFailed, - this, - [this](std::string txn_id) { - if (current_txn == txn_id) { - current_txn_error_count++; - if (current_txn_error_count > 10) { - nhlog::ui()->debug("failing txn id '{}'", txn_id); - cache::client()->removePendingStatus(room_id_, txn_id); - current_txn_error_count = 0; - } - } - QTimer::singleShot(1000, this, [this]() { - nhlog::ui()->debug("timeout"); - this->current_txn = ""; - emit processPending(); - }); - }, - Qt::QueuedConnection); + connect( + this, + &EventStore::messageFailed, + this, + [this](std::string txn_id) { + if (current_txn == txn_id) { + current_txn_error_count++; + if (current_txn_error_count > 10) { + nhlog::ui()->debug("failing txn id '{}'", txn_id); + cache::client()->removePendingStatus(room_id_, txn_id); + current_txn_error_count = 0; + } + } + QTimer::singleShot(1000, this, [this]() { + nhlog::ui()->debug("timeout"); + this->current_txn = ""; + emit processPending(); + }); + }, + Qt::QueuedConnection); - connect(this, - &EventStore::messageSent, - this, - [this](std::string txn_id, std::string event_id) { - nhlog::ui()->debug("sent {}", txn_id); + connect( + this, + &EventStore::messageSent, + this, + [this](std::string txn_id, std::string event_id) { + nhlog::ui()->debug("sent {}", txn_id); - http::client()->read_event( - room_id_, event_id, [this, event_id](mtx::http::RequestErr err) { - if (err) { - nhlog::net()->warn( - "failed to read_event ({}, {})", room_id_, event_id); - } - }); + http::client()->read_event( + room_id_, event_id, [this, event_id](mtx::http::RequestErr err) { + if (err) { + nhlog::net()->warn( + "failed to read_event ({}, {})", room_id_, event_id); + } + }); - cache::client()->removePendingStatus(room_id_, txn_id); - this->current_txn = ""; - this->current_txn_error_count = 0; - emit processPending(); - }, - Qt::QueuedConnection); + cache::client()->removePendingStatus(room_id_, txn_id); + this->current_txn = ""; + this->current_txn_error_count = 0; + emit processPending(); + }, + Qt::QueuedConnection); } void @@ -280,50 +284,77 @@ EventStore::handleSync(const mtx::responses::Timeline &events) if (auto encrypted = std::get_if<mtx::events::EncryptedEvent<mtx::events::msg::Encrypted>>( &event)) { - auto event = decryptEvent({room_id_, encrypted->event_id}, *encrypted); + auto d_event = decryptEvent({room_id_, encrypted->event_id}, *encrypted); if (std::visit( [](auto e) { return (e.sender != utils::localUser().toStdString()); }, - *event)) { - if (auto msg = std::get_if<mtx::events::RoomEvent< - mtx::events::msg::KeyVerificationRequest>>(event)) { + *d_event)) { + if (std::get_if<mtx::events::RoomEvent< + mtx::events::msg::KeyVerificationRequest>>(d_event)) { + auto msg = std::get_if<mtx::events::RoomEvent< + mtx::events::msg::KeyVerificationRequest>>(d_event); last_verification_request_event = *msg; - } else if (auto msg = std::get_if<mtx::events::RoomEvent< - mtx::events::msg::KeyVerificationCancel>>(event)) { + continue; + } else if (std::get_if<mtx::events::RoomEvent< + mtx::events::msg::KeyVerificationCancel>>(d_event)) { + auto msg = std::get_if<mtx::events::RoomEvent< + mtx::events::msg::KeyVerificationCancel>>(d_event); last_verification_cancel_event = *msg; ChatPage::instance()->recievedDeviceVerificationCancel( msg->content); - } else if (auto msg = std::get_if<mtx::events::RoomEvent< - mtx::events::msg::KeyVerificationAccept>>(event)) { + continue; + } else if (std::get_if<mtx::events::RoomEvent< + mtx::events::msg::KeyVerificationAccept>>(d_event)) { + auto msg = std::get_if<mtx::events::RoomEvent< + mtx::events::msg::KeyVerificationAccept>>(d_event); ChatPage::instance()->recievedDeviceVerificationAccept( msg->content); - } else if (auto msg = std::get_if<mtx::events::RoomEvent< - mtx::events::msg::KeyVerificationKey>>(event)) { + continue; + } else if (std::get_if<mtx::events::RoomEvent< + mtx::events::msg::KeyVerificationKey>>(d_event)) { + auto msg = std::get_if<mtx::events::RoomEvent< + mtx::events::msg::KeyVerificationKey>>(d_event); ChatPage::instance()->recievedDeviceVerificationKey( msg->content); - } else if (auto msg = std::get_if<mtx::events::RoomEvent< - mtx::events::msg::KeyVerificationMac>>(event)) { + continue; + } else if (std::get_if<mtx::events::RoomEvent< + mtx::events::msg::KeyVerificationMac>>(d_event)) { + auto msg = std::get_if<mtx::events::RoomEvent< + mtx::events::msg::KeyVerificationMac>>(d_event); ChatPage::instance()->recievedDeviceVerificationMac( msg->content); - } else if (auto msg = std::get_if<mtx::events::RoomEvent< - mtx::events::msg::KeyVerificationReady>>(event)) { + continue; + } else if (std::get_if<mtx::events::RoomEvent< + mtx::events::msg::KeyVerificationReady>>(d_event)) { + auto msg = std::get_if<mtx::events::RoomEvent< + mtx::events::msg::KeyVerificationReady>>(d_event); ChatPage::instance()->recievedDeviceVerificationReady( msg->content); - } else if (auto msg = std::get_if<mtx::events::RoomEvent< - mtx::events::msg::KeyVerificationDone>>(event)) { + continue; + } else if (std::get_if<mtx::events::RoomEvent< + mtx::events::msg::KeyVerificationDone>>(d_event)) { + auto msg = std::get_if<mtx::events::RoomEvent< + mtx::events::msg::KeyVerificationDone>>(d_event); ChatPage::instance()->recievedDeviceVerificationDone( msg->content); - } else if (auto msg = std::get_if<mtx::events::RoomEvent< - mtx::events::msg::KeyVerificationStart>>(event)) { + continue; + } else if (std::get_if<mtx::events::RoomEvent< + mtx::events::msg::KeyVerificationStart>>(d_event)) { + auto msg = std::get_if<mtx::events::RoomEvent< + mtx::events::msg::KeyVerificationStart>>(d_event); ChatPage::instance()->recievedDeviceVerificationStart( msg->content, msg->sender); + continue; + } + } else { + // only the key.verification.ready sent by localuser's other device + // is of significance as it is used for detecting accepted request + if (std::get_if<mtx::events::RoomEvent< + mtx::events::msg::KeyVerificationReady>>(d_event)) { + auto msg = std::get_if<mtx::events::RoomEvent< + mtx::events::msg::KeyVerificationReady>>(d_event); + ChatPage::instance()->recievedDeviceVerificationReady( + msg->content); } - } - // only the key.verification.ready sent by localuser's other device is of - // significance as it is used for detecting accepted request - if (auto msg = std::get_if< - mtx::events::RoomEvent<mtx::events::msg::KeyVerificationReady>>( - event)) { - ChatPage::instance()->recievedDeviceVerificationReady(msg->content); } } } @@ -614,12 +645,6 @@ EventStore::decryptEvent(const IdIndex &idx, return asCacheEntry(std::move(temp_events[0])); } - dummy.content.body = tr("-- Encrypted Event (Unknown event type) --", - "Placeholder, when the message was decrypted, but we " - "couldn't parse it, because " - "Nheko/mtxclient don't support that event type yet.") - .toStdString(); - return asCacheEntry(std::move(dummy)); auto encInfo = mtx::accessors::file(decryptionResult.event.value()); if (encInfo) emit newEncryptedImage(encInfo.value());