Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
nheko
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Nheko Reborn
nheko
Commits
a70044e6
Commit
a70044e6
authored
4 years ago
by
Nicolas Werner
Browse files
Options
Downloads
Patches
Plain Diff
Cache decrypted events
parent
c739a042
No related branches found
Branches containing commit
No related tags found
Tags containing commit
Loading
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/timeline/TimelineModel.cpp
+24
-2
24 additions, 2 deletions
src/timeline/TimelineModel.cpp
with
24 additions
and
2 deletions
src/timeline/TimelineModel.cpp
+
24
−
2
View file @
a70044e6
...
@@ -4,6 +4,7 @@
...
@@ -4,6 +4,7 @@
#include
<thread>
#include
<thread>
#include
<type_traits>
#include
<type_traits>
#include
<QCache>
#include
<QFileDialog>
#include
<QFileDialog>
#include
<QMimeDatabase>
#include
<QMimeDatabase>
#include
<QRegularExpression>
#include
<QRegularExpression>
...
@@ -22,6 +23,14 @@
...
@@ -22,6 +23,14 @@
Q_DECLARE_METATYPE
(
QModelIndex
)
Q_DECLARE_METATYPE
(
QModelIndex
)
namespace
std
{
inline
uint
qHash
(
const
std
::
string
&
key
,
uint
seed
=
0
)
{
return
qHash
(
QByteArray
::
fromRawData
(
key
.
data
(),
key
.
length
()),
seed
);
}
}
namespace
{
namespace
{
struct
RoomEventType
struct
RoomEventType
{
{
...
@@ -705,6 +714,11 @@ TimelineModel::openUserProfile(QString userid) const
...
@@ -705,6 +714,11 @@ TimelineModel::openUserProfile(QString userid) const
DecryptionResult
DecryptionResult
TimelineModel
::
decryptEvent
(
const
mtx
::
events
::
EncryptedEvent
<
mtx
::
events
::
msg
::
Encrypted
>
&
e
)
const
TimelineModel
::
decryptEvent
(
const
mtx
::
events
::
EncryptedEvent
<
mtx
::
events
::
msg
::
Encrypted
>
&
e
)
const
{
{
static
QCache
<
std
::
string
,
DecryptionResult
>
decryptedEvents
{
300
};
if
(
auto
cachedEvent
=
decryptedEvents
.
object
(
e
.
event_id
))
return
*
cachedEvent
;
MegolmSessionIndex
index
;
MegolmSessionIndex
index
;
index
.
room_id
=
room_id_
.
toStdString
();
index
.
room_id
=
room_id_
.
toStdString
();
index
.
session_id
=
e
.
content
.
session_id
;
index
.
session_id
=
e
.
content
.
session_id
;
...
@@ -726,6 +740,8 @@ TimelineModel::decryptEvent(const mtx::events::EncryptedEvent<mtx::events::msg::
...
@@ -726,6 +740,8 @@ TimelineModel::decryptEvent(const mtx::events::EncryptedEvent<mtx::events::msg::
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.
decryptedEvents
.
insert
(
dummy
.
event_id
,
new
DecryptionResult
{
dummy
,
false
},
1
);
return
{
dummy
,
false
};
return
{
dummy
,
false
};
}
}
}
catch
(
const
lmdb
::
error
&
e
)
{
}
catch
(
const
lmdb
::
error
&
e
)
{
...
@@ -734,6 +750,7 @@ TimelineModel::decryptEvent(const mtx::events::EncryptedEvent<mtx::events::msg::
...
@@ -734,6 +750,7 @@ TimelineModel::decryptEvent(const mtx::events::EncryptedEvent<mtx::events::msg::
"Placeholder, when the message can't be decrypted, because "
"Placeholder, when the message can't be decrypted, because "
"the DB access failed when trying to lookup the session."
)
"the DB access failed when trying to lookup the session."
)
.
toStdString
();
.
toStdString
();
decryptedEvents
.
insert
(
dummy
.
event_id
,
new
DecryptionResult
{
dummy
,
false
},
1
);
return
{
dummy
,
false
};
return
{
dummy
,
false
};
}
}
...
@@ -753,6 +770,7 @@ TimelineModel::decryptEvent(const mtx::events::EncryptedEvent<mtx::events::msg::
...
@@ -753,6 +770,7 @@ TimelineModel::decryptEvent(const mtx::events::EncryptedEvent<mtx::events::msg::
"Placeholder, when the message can't be decrypted, because the DB access "
"Placeholder, when the message can't be decrypted, because the DB access "
"failed."
)
"failed."
)
.
toStdString
();
.
toStdString
();
decryptedEvents
.
insert
(
dummy
.
event_id
,
new
DecryptionResult
{
dummy
,
false
},
1
);
return
{
dummy
,
false
};
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 ({}, {}, {}): {}"
,
...
@@ -766,6 +784,7 @@ TimelineModel::decryptEvent(const mtx::events::EncryptedEvent<mtx::events::msg::
...
@@ -766,6 +784,7 @@ TimelineModel::decryptEvent(const mtx::events::EncryptedEvent<mtx::events::msg::
"decrytion returned an error, which is passed ad %1."
)
"decrytion returned an error, which is passed ad %1."
)
.
arg
(
e
.
what
())
.
arg
(
e
.
what
())
.
toStdString
();
.
toStdString
();
decryptedEvents
.
insert
(
dummy
.
event_id
,
new
DecryptionResult
{
dummy
,
false
},
1
);
return
{
dummy
,
false
};
return
{
dummy
,
false
};
}
}
...
@@ -786,14 +805,17 @@ TimelineModel::decryptEvent(const mtx::events::EncryptedEvent<mtx::events::msg::
...
@@ -786,14 +805,17 @@ TimelineModel::decryptEvent(const mtx::events::EncryptedEvent<mtx::events::msg::
std
::
vector
<
mtx
::
events
::
collections
::
TimelineEvents
>
temp_events
;
std
::
vector
<
mtx
::
events
::
collections
::
TimelineEvents
>
temp_events
;
mtx
::
responses
::
utils
::
parse_timeline_events
(
event_array
,
temp_events
);
mtx
::
responses
::
utils
::
parse_timeline_events
(
event_array
,
temp_events
);
if
(
temp_events
.
size
()
==
1
)
if
(
temp_events
.
size
()
==
1
)
{
return
{
temp_events
.
at
(
0
),
true
};
decryptedEvents
.
insert
(
e
.
event_id
,
new
DecryptionResult
{
temp_events
[
0
],
true
},
1
);
return
{
temp_events
[
0
],
true
};
}
dummy
.
content
.
body
=
dummy
.
content
.
body
=
tr
(
"-- Encrypted Event (Unknown event type) --"
,
tr
(
"-- Encrypted Event (Unknown event type) --"
,
"Placeholder, when the message was decrypted, but we couldn't parse it, because "
"Placeholder, when the message was decrypted, but we couldn't parse it, because "
"Nheko/mtxclient don't support that event type yet."
)
"Nheko/mtxclient don't support that event type yet."
)
.
toStdString
();
.
toStdString
();
decryptedEvents
.
insert
(
dummy
.
event_id
,
new
DecryptionResult
{
dummy
,
false
},
1
);
return
{
dummy
,
false
};
return
{
dummy
,
false
};
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment