aboutsummaryrefslogtreecommitdiff
path: root/lib/room.cpp
diff options
context:
space:
mode:
authorAlexey Rusakov <Kitsune-Ral@users.sf.net>2022-06-23 08:34:53 +0200
committerAlexey Rusakov <Kitsune-Ral@users.sf.net>2022-06-23 18:37:08 +0200
commit143ac38aabab90b40fbe73b489b91fb159e66b6b (patch)
tree4781d895b1b5c0fe42dc50a104fa7b752db7489e /lib/room.cpp
parent19746de7426aeb67eb90e8c48448356691e270b0 (diff)
downloadlibquotient-143ac38aabab90b40fbe73b489b91fb159e66b6b.tar.gz
libquotient-143ac38aabab90b40fbe73b489b91fb159e66b6b.zip
Streamline Room::P::shouldRotateMegolmSession()
Now there's only 1 instead of 5 lookups of the same EncryptionEvent, and the code is shorter.
Diffstat (limited to 'lib/room.cpp')
-rw-r--r--lib/room.cpp30
1 files changed, 10 insertions, 20 deletions
diff --git a/lib/room.cpp b/lib/room.cpp
index 2d4cfeb4..35a89cc6 100644
--- a/lib/room.cpp
+++ b/lib/room.cpp
@@ -411,10 +411,17 @@ public:
bool shouldRotateMegolmSession() const
{
- if (!q->usesEncryption()) {
+ const auto* encryptionConfig = currentState.get<EncryptionEvent>();
+ if (!encryptionConfig || !encryptionConfig->useEncryption())
return false;
- }
- return currentOutboundMegolmSession->messageCount() >= rotationMessageCount() || currentOutboundMegolmSession->creationTime().addMSecs(rotationInterval()) < QDateTime::currentDateTime();
+
+ const auto rotationInterval = encryptionConfig->rotationPeriodMs();
+ const auto rotationMessageCount = encryptionConfig->rotationPeriodMsgs();
+ return currentOutboundMegolmSession->messageCount()
+ >= rotationMessageCount
+ || currentOutboundMegolmSession->creationTime().addMSecs(
+ rotationInterval)
+ < QDateTime::currentDateTime();
}
bool hasValidMegolmSession() const
@@ -425,23 +432,6 @@ public:
return currentOutboundMegolmSession != nullptr;
}
- /// Time in milliseconds after which the outgoing megolmsession should be replaced
- unsigned int rotationInterval() const
- {
- if (!q->usesEncryption()) {
- return 0;
- }
- return q->getCurrentState<EncryptionEvent>()->rotationPeriodMs();
- }
-
- // Number of messages sent by this user after which the outgoing megolm session should be replaced
- int rotationMessageCount() const
- {
- if (!q->usesEncryption()) {
- return 0;
- }
- return q->getCurrentState<EncryptionEvent>()->rotationPeriodMsgs();
- }
void createMegolmSession() {
qCDebug(E2EE) << "Creating new outbound megolm session for room "
<< q->objectName();