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])
chat.positionViewAtIndex(chat.model.idToIndex(match[2]), ListView.Contain)
}
else timelineManager.openLink(link)
else TimelineManager.openLink(link)
}
MouseArea
{

View File

@ -139,7 +139,8 @@ Cache::Cache(const QString &userId, QObject *parent)
, localUserId_{userId}
{
setup();
connect(this,
connect(
this,
&Cache::updateUserCacheFlag,
this,
[this](const std::string &user_id) {
@ -152,7 +153,8 @@ Cache::Cache(const QString &userId, QObject *parent)
}
},
Qt::QueuedConnection);
connect(this,
connect(
this,
&Cache::deleteLeftUsers,
this,
[this](const std::string &user_id) { deleteUserCache(user_id); },

View File

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

View File

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

View File

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

View File

@ -32,7 +32,8 @@ EventStore::EventStore(std::string room_id, QObject *)
this->last = range->last;
}
connect(this,
connect(
this,
&EventStore::eventFetched,
this,
[this](std::string id,
@ -48,12 +49,13 @@ EventStore::EventStore(std::string room_id, QObject *)
},
Qt::QueuedConnection);
connect(this,
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())
if (newFirst == first)
fetchMore();
else {
emit beginInsertRows(toExternalIdx(newFirst),
@ -128,7 +130,8 @@ EventStore::EventStore(std::string room_id, QObject *)
event->data);
});
connect(this,
connect(
this,
&EventStore::messageFailed,
this,
[this](std::string txn_id) {
@ -148,7 +151,8 @@ EventStore::EventStore(std::string room_id, QObject *)
},
Qt::QueuedConnection);
connect(this,
connect(
this,
&EventStore::messageSent,
this,
[this](std::string txn_id, std::string event_id) {
@ -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());

View File

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

View File

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