mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-26 21:18:48 +03:00
parent
ec63a4fbf7
commit
67458dd2f8
2 changed files with 23 additions and 11 deletions
|
@ -46,6 +46,14 @@ private:
|
||||||
std::function<void()> fn_;
|
std::function<void()> fn_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct DecryptionResult
|
||||||
|
{
|
||||||
|
//! The decrypted content as a normal plaintext event.
|
||||||
|
utils::TimelineEvent event;
|
||||||
|
//! Whether or not the decryption was successful.
|
||||||
|
bool isDecrypted = false;
|
||||||
|
};
|
||||||
|
|
||||||
class FloatingButton;
|
class FloatingButton;
|
||||||
struct DescInfo;
|
struct DescInfo;
|
||||||
|
|
||||||
|
@ -192,7 +200,7 @@ private:
|
||||||
|
|
||||||
QWidget *relativeWidget(TimelineItem *item, int dt) const;
|
QWidget *relativeWidget(TimelineItem *item, int dt) const;
|
||||||
|
|
||||||
TimelineEvent parseEncryptedEvent(
|
DecryptionResult parseEncryptedEvent(
|
||||||
const mtx::events::EncryptedEvent<mtx::events::msg::Encrypted> &e);
|
const mtx::events::EncryptedEvent<mtx::events::msg::Encrypted> &e);
|
||||||
|
|
||||||
void handleClaimedKeys(std::shared_ptr<StateKeeper> keeper,
|
void handleClaimedKeys(std::shared_ptr<StateKeeper> keeper,
|
||||||
|
|
|
@ -280,15 +280,19 @@ TimelineView::parseMessageEvent(const mtx::events::collections::TimelineEvents &
|
||||||
return processMessageEvent<Sticker, StickerItem>(mpark::get<Sticker>(event),
|
return processMessageEvent<Sticker, StickerItem>(mpark::get<Sticker>(event),
|
||||||
direction);
|
direction);
|
||||||
} else if (mpark::holds_alternative<EncryptedEvent<msg::Encrypted>>(event)) {
|
} else if (mpark::holds_alternative<EncryptedEvent<msg::Encrypted>>(event)) {
|
||||||
auto decrypted =
|
auto res = parseEncryptedEvent(mpark::get<EncryptedEvent<msg::Encrypted>>(event));
|
||||||
parseEncryptedEvent(mpark::get<EncryptedEvent<msg::Encrypted>>(event));
|
auto item = parseMessageEvent(res.event, direction);
|
||||||
return parseMessageEvent(decrypted, direction);
|
|
||||||
|
if (item != nullptr && res.isDecrypted)
|
||||||
|
item->markReceived(true);
|
||||||
|
|
||||||
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
TimelineEvent
|
DecryptionResult
|
||||||
TimelineView::parseEncryptedEvent(const mtx::events::EncryptedEvent<mtx::events::msg::Encrypted> &e)
|
TimelineView::parseEncryptedEvent(const mtx::events::EncryptedEvent<mtx::events::msg::Encrypted> &e)
|
||||||
{
|
{
|
||||||
MegolmSessionIndex index;
|
MegolmSessionIndex index;
|
||||||
|
@ -309,12 +313,12 @@ TimelineView::parseEncryptedEvent(const mtx::events::EncryptedEvent<mtx::events:
|
||||||
index.session_id,
|
index.session_id,
|
||||||
e.sender);
|
e.sender);
|
||||||
// TODO: request megolm session_id & session_key from the sender.
|
// TODO: request megolm session_id & session_key from the sender.
|
||||||
return dummy;
|
return {dummy, false};
|
||||||
}
|
}
|
||||||
} catch (const lmdb::error &e) {
|
} catch (const lmdb::error &e) {
|
||||||
nhlog::db()->critical("failed to check megolm session's existence: {}", e.what());
|
nhlog::db()->critical("failed to check megolm session's existence: {}", e.what());
|
||||||
dummy.content.body = "-- Decryption Error (failed to communicate with DB) --";
|
dummy.content.body = "-- Decryption Error (failed to communicate with DB) --";
|
||||||
return dummy;
|
return {dummy, false};
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string msg_str;
|
std::string msg_str;
|
||||||
|
@ -330,7 +334,7 @@ TimelineView::parseEncryptedEvent(const mtx::events::EncryptedEvent<mtx::events:
|
||||||
e.what());
|
e.what());
|
||||||
dummy.content.body =
|
dummy.content.body =
|
||||||
"-- Decryption Error (failed to retrieve megolm keys from db) --";
|
"-- Decryption Error (failed to retrieve megolm keys from db) --";
|
||||||
return dummy;
|
return {dummy, false};
|
||||||
} catch (const mtx::crypto::olm_exception &e) {
|
} catch (const mtx::crypto::olm_exception &e) {
|
||||||
nhlog::crypto()->critical("failed to decrypt message with index ({}, {}, {}): {}",
|
nhlog::crypto()->critical("failed to decrypt message with index ({}, {}, {}): {}",
|
||||||
index.room_id,
|
index.room_id,
|
||||||
|
@ -338,7 +342,7 @@ TimelineView::parseEncryptedEvent(const mtx::events::EncryptedEvent<mtx::events:
|
||||||
index.sender_key,
|
index.sender_key,
|
||||||
e.what());
|
e.what());
|
||||||
dummy.content.body = "-- Decryption Error (" + std::string(e.what()) + ") --";
|
dummy.content.body = "-- Decryption Error (" + std::string(e.what()) + ") --";
|
||||||
return dummy;
|
return {dummy, false};
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add missing fields for the event.
|
// Add missing fields for the event.
|
||||||
|
@ -358,10 +362,10 @@ TimelineView::parseEncryptedEvent(const mtx::events::EncryptedEvent<mtx::events:
|
||||||
mtx::responses::utils::parse_timeline_events(event_array, events);
|
mtx::responses::utils::parse_timeline_events(event_array, events);
|
||||||
|
|
||||||
if (events.size() == 1)
|
if (events.size() == 1)
|
||||||
return events.at(0);
|
return {events.at(0), true};
|
||||||
|
|
||||||
dummy.content.body = "-- Encrypted Event (Unknown event type) --";
|
dummy.content.body = "-- Encrypted Event (Unknown event type) --";
|
||||||
return dummy;
|
return {dummy, false};
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
Loading…
Reference in a new issue