Fix Wrong Emojis Issue in Room Verification

This commit is contained in:
Chethan2k1 2020-09-04 12:02:24 +05:30
parent 657f4073e9
commit e8eeb480d5
8 changed files with 185 additions and 152 deletions

View file

@ -19,7 +19,7 @@ TextEdit {
TimelineManager.setHistoryView(match[1]) TimelineManager.setHistoryView(match[1])
chat.positionViewAtIndex(chat.model.idToIndex(match[2]), ListView.Contain) chat.positionViewAtIndex(chat.model.idToIndex(match[2]), ListView.Contain)
} }
else timelineManager.openLink(link) else TimelineManager.openLink(link)
} }
MouseArea MouseArea
{ {

View file

@ -139,24 +139,26 @@ Cache::Cache(const QString &userId, QObject *parent)
, localUserId_{userId} , localUserId_{userId}
{ {
setup(); setup();
connect(this, connect(
&Cache::updateUserCacheFlag, this,
this, &Cache::updateUserCacheFlag,
[this](const std::string &user_id) { this,
std::optional<UserCache> cache_ = getUserCache(user_id); [this](const std::string &user_id) {
if (cache_.has_value()) { std::optional<UserCache> cache_ = getUserCache(user_id);
cache_.value().isUpdated = false; if (cache_.has_value()) {
setUserCache(user_id, cache_.value()); cache_.value().isUpdated = false;
} else { setUserCache(user_id, cache_.value());
setUserCache(user_id, UserCache{}); } else {
} setUserCache(user_id, UserCache{});
}, }
Qt::QueuedConnection); },
connect(this, Qt::QueuedConnection);
&Cache::deleteLeftUsers, connect(
this, this,
[this](const std::string &user_id) { deleteUserCache(user_id); }, &Cache::deleteLeftUsers,
Qt::QueuedConnection); this,
[this](const std::string &user_id) { deleteUserCache(user_id); },
Qt::QueuedConnection);
} }
void void

View file

@ -606,11 +606,12 @@ ChatPage::ChatPage(QSharedPointer<UserSettings> userSettings, QWidget *parent)
connect( connect(
this, &ChatPage::tryInitialSyncCb, this, &ChatPage::tryInitialSync, Qt::QueuedConnection); this, &ChatPage::tryInitialSyncCb, this, &ChatPage::tryInitialSync, Qt::QueuedConnection);
connect(this, &ChatPage::trySyncCb, this, &ChatPage::trySync, Qt::QueuedConnection); connect(this, &ChatPage::trySyncCb, this, &ChatPage::trySync, Qt::QueuedConnection);
connect(this, connect(
&ChatPage::tryDelayedSyncCb, this,
this, &ChatPage::tryDelayedSyncCb,
[this]() { QTimer::singleShot(RETRY_TIMEOUT, this, &ChatPage::trySync); }, this,
Qt::QueuedConnection); [this]() { QTimer::singleShot(RETRY_TIMEOUT, this, &ChatPage::trySync); },
Qt::QueuedConnection);
connect(this, connect(this,
&ChatPage::newSyncResponse, &ChatPage::newSyncResponse,

View file

@ -28,10 +28,10 @@ DeviceVerificationFlow::DeviceVerificationFlow(QObject *,
connect(this->model_, connect(this->model_,
&TimelineModel::updateFlowEventId, &TimelineModel::updateFlowEventId,
this, this,
[this](std::string event_id) { [this](std::string event_id_) {
this->relation.rel_type = mtx::common::RelationType::Reference; this->relation.rel_type = mtx::common::RelationType::Reference;
this->relation.event_id = event_id; this->relation.event_id = event_id_;
this->transaction_id = event_id; this->transaction_id = event_id_;
}); });
} }
@ -60,7 +60,7 @@ DeviceVerificationFlow::DeviceVerificationFlow(QObject *,
msg.hashes.end()) && msg.hashes.end()) &&
(std::find(msg.message_authentication_codes.begin(), (std::find(msg.message_authentication_codes.begin(),
msg.message_authentication_codes.end(), msg.message_authentication_codes.end(),
"hmac-sha256") != msg.message_authentication_codes.end())) { "hkdf-hmac-sha256") != msg.message_authentication_codes.end())) {
if (std::find(msg.short_authentication_string.begin(), if (std::find(msg.short_authentication_string.begin(),
msg.short_authentication_string.end(), msg.short_authentication_string.end(),
mtx::events::msg::SASMethods::Decimal) != mtx::events::msg::SASMethods::Decimal) !=
@ -236,11 +236,15 @@ DeviceVerificationFlow::DeviceVerificationFlow(QObject *,
&ChatPage::recievedDeviceVerificationReady, &ChatPage::recievedDeviceVerificationReady,
this, this,
[this](const mtx::events::msg::KeyVerificationReady &msg) { [this](const mtx::events::msg::KeyVerificationReady &msg) {
if (!sender && msg.from_device != http::client()->device_id()) { if (!sender) {
this->deleteLater(); if (msg.from_device != http::client()->device_id()) {
emit verificationCanceled(); this->deleteLater();
emit verificationCanceled();
}
return; return;
} }
if (msg.transaction_id.has_value()) { if (msg.transaction_id.has_value()) {
if (msg.transaction_id.value() != this->transaction_id) if (msg.transaction_id.value() != this->transaction_id)
return; return;
@ -353,9 +357,9 @@ DeviceVerificationFlow::setMethod(DeviceVerificationFlow::Method method_)
} }
void void
DeviceVerificationFlow::setType(Type type) DeviceVerificationFlow::setType(Type type_)
{ {
this->type = type; this->type = type_;
} }
void void
@ -367,11 +371,11 @@ DeviceVerificationFlow::setSender(bool sender_)
} }
void void
DeviceVerificationFlow::setEventId(std::string event_id) DeviceVerificationFlow::setEventId(std::string event_id_)
{ {
this->relation.rel_type = mtx::common::RelationType::Reference; this->relation.rel_type = mtx::common::RelationType::Reference;
this->relation.event_id = event_id; this->relation.event_id = event_id_;
this->transaction_id = event_id; this->transaction_id = event_id_;
} }
//! accepts a verification //! accepts a verification

View file

@ -10,7 +10,7 @@ class QTimer;
using sas_ptr = std::unique_ptr<mtx::crypto::SAS>; using sas_ptr = std::unique_ptr<mtx::crypto::SAS>;
struct TimelineModel; class TimelineModel;
class DeviceVerificationFlow : public QObject class DeviceVerificationFlow : public QObject
{ {

View file

@ -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()) { if (!relatedTo.empty()) {
auto idx = idToIndex(relatedTo); auto idx = idToIndex(relatedTo);
if (idx) if (idx)
emit dataChanged(*idx, *idx); emit dataChanged(*idx, *idx);
} }
}, },
Qt::QueuedConnection); Qt::QueuedConnection);
connect(this, connect(
&EventStore::oldMessagesRetrieved, this,
this, &EventStore::oldMessagesRetrieved,
[this](const mtx::responses::Messages &res) { this,
uint64_t newFirst = cache::client()->saveOldMessages(room_id_, res); [this](const mtx::responses::Messages &res) {
if (newFirst == first && !res.chunk.empty()) uint64_t newFirst = cache::client()->saveOldMessages(room_id_, res);
fetchMore(); if (newFirst == first)
else { fetchMore();
emit beginInsertRows(toExternalIdx(newFirst), else {
toExternalIdx(this->first - 1)); emit beginInsertRows(toExternalIdx(newFirst),
this->first = newFirst; toExternalIdx(this->first - 1));
emit endInsertRows(); this->first = newFirst;
emit fetchedMore(); 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, connect(
&EventStore::messageSent, this,
this, &EventStore::messageSent,
[this](std::string txn_id, std::string event_id) { this,
nhlog::ui()->debug("sent {}", txn_id); [this](std::string txn_id, std::string event_id) {
nhlog::ui()->debug("sent {}", txn_id);
http::client()->read_event( http::client()->read_event(
room_id_, event_id, [this, event_id](mtx::http::RequestErr err) { room_id_, event_id, [this, event_id](mtx::http::RequestErr err) {
if (err) { if (err) {
nhlog::net()->warn( nhlog::net()->warn(
"failed to read_event ({}, {})", room_id_, event_id); "failed to read_event ({}, {})", room_id_, event_id);
} }
}); });
cache::client()->removePendingStatus(room_id_, txn_id); cache::client()->removePendingStatus(room_id_, txn_id);
this->current_txn = ""; this->current_txn = "";
this->current_txn_error_count = 0; this->current_txn_error_count = 0;
emit processPending(); emit processPending();
}, },
Qt::QueuedConnection); 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());

View file

@ -204,11 +204,12 @@ TimelineModel::TimelineModel(TimelineViewManager *manager, QString room_id, QObj
, room_id_(room_id) , room_id_(room_id)
, manager_(manager) , manager_(manager)
{ {
connect(this, connect(
&TimelineModel::redactionFailed, this,
this, &TimelineModel::redactionFailed,
[](const QString &msg) { emit ChatPage::instance()->showNotification(msg); }, this,
Qt::QueuedConnection); [](const QString &msg) { emit ChatPage::instance()->showNotification(msg); },
Qt::QueuedConnection);
connect(this, connect(this,
&TimelineModel::newMessageToSend, &TimelineModel::newMessageToSend,
@ -217,17 +218,17 @@ TimelineModel::TimelineModel(TimelineViewManager *manager, QString room_id, QObj
Qt::QueuedConnection); Qt::QueuedConnection);
connect(this, &TimelineModel::addPendingMessageToStore, &events, &EventStore::addPending); connect(this, &TimelineModel::addPendingMessageToStore, &events, &EventStore::addPending);
connect(&events, connect(
&EventStore::dataChanged, &events,
this, &EventStore::dataChanged,
[this](int from, int to) { this,
nhlog::ui()->debug("data changed {} to {}", [this](int from, int to) {
events.size() - to - 1, nhlog::ui()->debug(
events.size() - from - 1); "data changed {} to {}", events.size() - to - 1, events.size() - from - 1);
emit dataChanged(index(events.size() - to - 1, 0), emit dataChanged(index(events.size() - to - 1, 0),
index(events.size() - from - 1, 0)); index(events.size() - from - 1, 0));
}, },
Qt::QueuedConnection); Qt::QueuedConnection);
connect(&events, &EventStore::beginInsertRows, this, [this](int from, int to) { connect(&events, &EventStore::beginInsertRows, this, [this](int from, int to) {
int first = events.size() - to; int first = events.size() - to;

View file

@ -59,7 +59,7 @@ public:
connect(this, &DeviceInfoModel::queueReset, this, &DeviceInfoModel::reset); connect(this, &DeviceInfoModel::queueReset, this, &DeviceInfoModel::reset);
}; };
QHash<int, QByteArray> roleNames() const override; QHash<int, QByteArray> roleNames() const override;
int rowCount(const QModelIndex &parent = QModelIndex()) const int rowCount(const QModelIndex &parent = QModelIndex()) const override
{ {
(void)parent; (void)parent;
return (int)deviceList_.size(); return (int)deviceList_.size();