mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-22 11:00: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_;
|
||||
};
|
||||
|
||||
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;
|
||||
struct DescInfo;
|
||||
|
||||
|
@ -192,7 +200,7 @@ private:
|
|||
|
||||
QWidget *relativeWidget(TimelineItem *item, int dt) const;
|
||||
|
||||
TimelineEvent parseEncryptedEvent(
|
||||
DecryptionResult parseEncryptedEvent(
|
||||
const mtx::events::EncryptedEvent<mtx::events::msg::Encrypted> &e);
|
||||
|
||||
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),
|
||||
direction);
|
||||
} else if (mpark::holds_alternative<EncryptedEvent<msg::Encrypted>>(event)) {
|
||||
auto decrypted =
|
||||
parseEncryptedEvent(mpark::get<EncryptedEvent<msg::Encrypted>>(event));
|
||||
return parseMessageEvent(decrypted, direction);
|
||||
auto res = parseEncryptedEvent(mpark::get<EncryptedEvent<msg::Encrypted>>(event));
|
||||
auto item = parseMessageEvent(res.event, direction);
|
||||
|
||||
if (item != nullptr && res.isDecrypted)
|
||||
item->markReceived(true);
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
TimelineEvent
|
||||
DecryptionResult
|
||||
TimelineView::parseEncryptedEvent(const mtx::events::EncryptedEvent<mtx::events::msg::Encrypted> &e)
|
||||
{
|
||||
MegolmSessionIndex index;
|
||||
|
@ -309,12 +313,12 @@ TimelineView::parseEncryptedEvent(const mtx::events::EncryptedEvent<mtx::events:
|
|||
index.session_id,
|
||||
e.sender);
|
||||
// TODO: request megolm session_id & session_key from the sender.
|
||||
return dummy;
|
||||
return {dummy, false};
|
||||
}
|
||||
} catch (const lmdb::error &e) {
|
||||
nhlog::db()->critical("failed to check megolm session's existence: {}", e.what());
|
||||
dummy.content.body = "-- Decryption Error (failed to communicate with DB) --";
|
||||
return dummy;
|
||||
return {dummy, false};
|
||||
}
|
||||
|
||||
std::string msg_str;
|
||||
|
@ -330,7 +334,7 @@ TimelineView::parseEncryptedEvent(const mtx::events::EncryptedEvent<mtx::events:
|
|||
e.what());
|
||||
dummy.content.body =
|
||||
"-- Decryption Error (failed to retrieve megolm keys from db) --";
|
||||
return dummy;
|
||||
return {dummy, false};
|
||||
} catch (const mtx::crypto::olm_exception &e) {
|
||||
nhlog::crypto()->critical("failed to decrypt message with index ({}, {}, {}): {}",
|
||||
index.room_id,
|
||||
|
@ -338,7 +342,7 @@ TimelineView::parseEncryptedEvent(const mtx::events::EncryptedEvent<mtx::events:
|
|||
index.sender_key,
|
||||
e.what());
|
||||
dummy.content.body = "-- Decryption Error (" + std::string(e.what()) + ") --";
|
||||
return dummy;
|
||||
return {dummy, false};
|
||||
}
|
||||
|
||||
// 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);
|
||||
|
||||
if (events.size() == 1)
|
||||
return events.at(0);
|
||||
return {events.at(0), true};
|
||||
|
||||
dummy.content.body = "-- Encrypted Event (Unknown event type) --";
|
||||
return dummy;
|
||||
return {dummy, false};
|
||||
}
|
||||
|
||||
void
|
||||
|
|
Loading…
Reference in a new issue