|
|
@ -32,38 +32,40 @@ EventStore::EventStore(std::string room_id, QObject *) |
|
|
|
this->last = range->last; |
|
|
|
this->last = range->last; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
connect(this, |
|
|
|
connect( |
|
|
|
&EventStore::eventFetched, |
|
|
|
this, |
|
|
|
this, |
|
|
|
&EventStore::eventFetched, |
|
|
|
[this](std::string id, |
|
|
|
this, |
|
|
|
std::string relatedTo, |
|
|
|
[this](std::string id, |
|
|
|
mtx::events::collections::TimelineEvents timeline) { |
|
|
|
std::string relatedTo, |
|
|
|
cache::client()->storeEvent(room_id_, id, {timeline}); |
|
|
|
mtx::events::collections::TimelineEvents timeline) { |
|
|
|
|
|
|
|
cache::client()->storeEvent(room_id_, id, {timeline}); |
|
|
|
if (!relatedTo.empty()) { |
|
|
|
|
|
|
|
auto idx = idToIndex(relatedTo); |
|
|
|
if (!relatedTo.empty()) { |
|
|
|
if (idx) |
|
|
|
auto idx = idToIndex(relatedTo); |
|
|
|
emit dataChanged(*idx, *idx); |
|
|
|
if (idx) |
|
|
|
} |
|
|
|
emit dataChanged(*idx, *idx); |
|
|
|
}, |
|
|
|
} |
|
|
|
Qt::QueuedConnection); |
|
|
|
}, |
|
|
|
|
|
|
|
Qt::QueuedConnection); |
|
|
|
connect(this, |
|
|
|
|
|
|
|
&EventStore::oldMessagesRetrieved, |
|
|
|
connect( |
|
|
|
this, |
|
|
|
this, |
|
|
|
[this](const mtx::responses::Messages &res) { |
|
|
|
&EventStore::oldMessagesRetrieved, |
|
|
|
uint64_t newFirst = cache::client()->saveOldMessages(room_id_, res); |
|
|
|
this, |
|
|
|
if (newFirst == first && !res.chunk.empty()) |
|
|
|
[this](const mtx::responses::Messages &res) { |
|
|
|
fetchMore(); |
|
|
|
uint64_t newFirst = cache::client()->saveOldMessages(room_id_, res); |
|
|
|
else { |
|
|
|
if (newFirst == first) |
|
|
|
emit beginInsertRows(toExternalIdx(newFirst), |
|
|
|
fetchMore(); |
|
|
|
toExternalIdx(this->first - 1)); |
|
|
|
else { |
|
|
|
this->first = newFirst; |
|
|
|
emit beginInsertRows(toExternalIdx(newFirst), |
|
|
|
emit endInsertRows(); |
|
|
|
toExternalIdx(this->first - 1)); |
|
|
|
emit fetchedMore(); |
|
|
|
this->first = newFirst; |
|
|
|
} |
|
|
|
emit endInsertRows(); |
|
|
|
}, |
|
|
|
emit fetchedMore(); |
|
|
|
Qt::QueuedConnection); |
|
|
|
} |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
Qt::QueuedConnection); |
|
|
|
|
|
|
|
|
|
|
|
connect(this, &EventStore::processPending, this, [this]() { |
|
|
|
connect(this, &EventStore::processPending, this, [this]() { |
|
|
|
if (!current_txn.empty()) { |
|
|
|
if (!current_txn.empty()) { |
|
|
@ -128,46 +130,48 @@ EventStore::EventStore(std::string room_id, QObject *) |
|
|
|
event->data); |
|
|
|
event->data); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
connect(this, |
|
|
|
connect( |
|
|
|
&EventStore::messageFailed, |
|
|
|
this, |
|
|
|
this, |
|
|
|
&EventStore::messageFailed, |
|
|
|
[this](std::string txn_id) { |
|
|
|
this, |
|
|
|
if (current_txn == txn_id) { |
|
|
|
[this](std::string txn_id) { |
|
|
|
current_txn_error_count++; |
|
|
|
if (current_txn == txn_id) { |
|
|
|
if (current_txn_error_count > 10) { |
|
|
|
current_txn_error_count++; |
|
|
|
nhlog::ui()->debug("failing txn id '{}'", txn_id); |
|
|
|
if (current_txn_error_count > 10) { |
|
|
|
cache::client()->removePendingStatus(room_id_, txn_id); |
|
|
|
nhlog::ui()->debug("failing txn id '{}'", txn_id); |
|
|
|
current_txn_error_count = 0; |
|
|
|
cache::client()->removePendingStatus(room_id_, txn_id); |
|
|
|
} |
|
|
|
current_txn_error_count = 0; |
|
|
|
} |
|
|
|
} |
|
|
|
QTimer::singleShot(1000, this, [this]() { |
|
|
|
} |
|
|
|
nhlog::ui()->debug("timeout"); |
|
|
|
QTimer::singleShot(1000, this, [this]() { |
|
|
|
this->current_txn = ""; |
|
|
|
nhlog::ui()->debug("timeout"); |
|
|
|
emit processPending(); |
|
|
|
this->current_txn = ""; |
|
|
|
}); |
|
|
|
emit processPending(); |
|
|
|
}, |
|
|
|
}); |
|
|
|
Qt::QueuedConnection); |
|
|
|
}, |
|
|
|
|
|
|
|
Qt::QueuedConnection); |
|
|
|
connect(this, |
|
|
|
|
|
|
|
&EventStore::messageSent, |
|
|
|
connect( |
|
|
|
this, |
|
|
|
this, |
|
|
|
[this](std::string txn_id, std::string event_id) { |
|
|
|
&EventStore::messageSent, |
|
|
|
nhlog::ui()->debug("sent {}", txn_id); |
|
|
|
this, |
|
|
|
|
|
|
|
[this](std::string txn_id, std::string event_id) { |
|
|
|
http::client()->read_event( |
|
|
|
nhlog::ui()->debug("sent {}", txn_id); |
|
|
|
room_id_, event_id, [this, event_id](mtx::http::RequestErr err) { |
|
|
|
|
|
|
|
if (err) { |
|
|
|
http::client()->read_event( |
|
|
|
nhlog::net()->warn( |
|
|
|
room_id_, event_id, [this, event_id](mtx::http::RequestErr err) { |
|
|
|
"failed to read_event ({}, {})", room_id_, event_id); |
|
|
|
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; |
|
|
|
cache::client()->removePendingStatus(room_id_, txn_id); |
|
|
|
emit processPending(); |
|
|
|
this->current_txn = ""; |
|
|
|
}, |
|
|
|
this->current_txn_error_count = 0; |
|
|
|
Qt::QueuedConnection); |
|
|
|
emit processPending(); |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
Qt::QueuedConnection); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void |
|
|
|
void |
|
|
@ -280,50 +284,77 @@ EventStore::handleSync(const mtx::responses::Timeline &events) |
|
|
|
if (auto encrypted = |
|
|
|
if (auto encrypted = |
|
|
|
std::get_if<mtx::events::EncryptedEvent<mtx::events::msg::Encrypted>>( |
|
|
|
std::get_if<mtx::events::EncryptedEvent<mtx::events::msg::Encrypted>>( |
|
|
|
&event)) { |
|
|
|
&event)) { |
|
|
|
auto event = decryptEvent({room_id_, encrypted->event_id}, *encrypted); |
|
|
|
auto d_event = decryptEvent({room_id_, encrypted->event_id}, *encrypted); |
|
|
|
if (std::visit( |
|
|
|
if (std::visit( |
|
|
|
[](auto e) { return (e.sender != utils::localUser().toStdString()); }, |
|
|
|
[](auto e) { return (e.sender != utils::localUser().toStdString()); }, |
|
|
|
*event)) { |
|
|
|
*d_event)) { |
|
|
|
if (auto msg = std::get_if<mtx::events::RoomEvent< |
|
|
|
if (std::get_if<mtx::events::RoomEvent< |
|
|
|
mtx::events::msg::KeyVerificationRequest>>(event)) { |
|
|
|
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; |
|
|
|
last_verification_request_event = *msg; |
|
|
|
} else if (auto msg = std::get_if<mtx::events::RoomEvent< |
|
|
|
continue; |
|
|
|
mtx::events::msg::KeyVerificationCancel>>(event)) { |
|
|
|
} 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; |
|
|
|
last_verification_cancel_event = *msg; |
|
|
|
ChatPage::instance()->recievedDeviceVerificationCancel( |
|
|
|
ChatPage::instance()->recievedDeviceVerificationCancel( |
|
|
|
msg->content); |
|
|
|
msg->content); |
|
|
|
} else if (auto msg = std::get_if<mtx::events::RoomEvent< |
|
|
|
continue; |
|
|
|
mtx::events::msg::KeyVerificationAccept>>(event)) { |
|
|
|
} 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( |
|
|
|
ChatPage::instance()->recievedDeviceVerificationAccept( |
|
|
|
msg->content); |
|
|
|
msg->content); |
|
|
|
} else if (auto msg = std::get_if<mtx::events::RoomEvent< |
|
|
|
continue; |
|
|
|
mtx::events::msg::KeyVerificationKey>>(event)) { |
|
|
|
} 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( |
|
|
|
ChatPage::instance()->recievedDeviceVerificationKey( |
|
|
|
msg->content); |
|
|
|
msg->content); |
|
|
|
} else if (auto msg = std::get_if<mtx::events::RoomEvent< |
|
|
|
continue; |
|
|
|
mtx::events::msg::KeyVerificationMac>>(event)) { |
|
|
|
} 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( |
|
|
|
ChatPage::instance()->recievedDeviceVerificationMac( |
|
|
|
msg->content); |
|
|
|
msg->content); |
|
|
|
} else if (auto msg = std::get_if<mtx::events::RoomEvent< |
|
|
|
continue; |
|
|
|
mtx::events::msg::KeyVerificationReady>>(event)) { |
|
|
|
} 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( |
|
|
|
ChatPage::instance()->recievedDeviceVerificationReady( |
|
|
|
msg->content); |
|
|
|
msg->content); |
|
|
|
} else if (auto msg = std::get_if<mtx::events::RoomEvent< |
|
|
|
continue; |
|
|
|
mtx::events::msg::KeyVerificationDone>>(event)) { |
|
|
|
} 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( |
|
|
|
ChatPage::instance()->recievedDeviceVerificationDone( |
|
|
|
msg->content); |
|
|
|
msg->content); |
|
|
|
} else if (auto msg = std::get_if<mtx::events::RoomEvent< |
|
|
|
continue; |
|
|
|
mtx::events::msg::KeyVerificationStart>>(event)) { |
|
|
|
} 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( |
|
|
|
ChatPage::instance()->recievedDeviceVerificationStart( |
|
|
|
msg->content, msg->sender); |
|
|
|
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])); |
|
|
|
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()); |
|
|
|
auto encInfo = mtx::accessors::file(decryptionResult.event.value()); |
|
|
|
if (encInfo) |
|
|
|
if (encInfo) |
|
|
|
emit newEncryptedImage(encInfo.value()); |
|
|
|
emit newEncryptedImage(encInfo.value()); |
|
|
|