[Client] Minor olm fixes

This commit is contained in:
Christian Pauly 2020-02-18 11:49:02 +01:00
parent b530eb2781
commit 974d507292
2 changed files with 16 additions and 4 deletions

View file

@ -1552,7 +1552,13 @@ class Client {
if (existingSessions != null) {
for (olm.Session session in existingSessions) {
if ((type == 0 && session.matches_inbound(body) == 1) || type == 1) {
plaintext = session.decrypt(type, body);
try {
plaintext = session.decrypt(type, body);
storeOlmSession(senderKey, session);
break;
} catch (_) {
plaintext = null;
}
}
}
}
@ -1565,8 +1571,8 @@ class Client {
newSession.create_inbound_from(_olmAccount, senderKey, body);
_olmAccount.remove_one_time_keys(newSession);
storeAPI?.storeClient();
storeOlmSession(senderKey, newSession);
plaintext = newSession.decrypt(type, body);
storeOlmSession(senderKey, newSession);
}
final Map<String, dynamic> plainContent = json.decode(plaintext);
if (plainContent.containsKey("sender") &&
@ -1597,6 +1603,8 @@ class Client {
if (!_olmSessions.containsKey(curve25519IdentityKey)) {
_olmSessions[curve25519IdentityKey] = [];
}
_olmSessions[curve25519IdentityKey]
.removeWhere((olm.Session s) => s.session_id() == session.session_id());
_olmSessions[curve25519IdentityKey].add(session);
Map<String, List<String>> pickleMap = {};
for (var entry in olmSessions.entries) {

View file

@ -505,7 +505,9 @@ class Room {
Future<String> sendEvent(Map<String, dynamic> content,
{String txid, Event inReplyTo}) async {
final String type = "m.room.message";
final String sendType = this.encrypted ? "m.room.encrypted" : type;
final String sendType = (this.encrypted && client.encryptionEnabled)
? "m.room.encrypted"
: type;
// Create new transaction id
String messageID;
@ -555,7 +557,9 @@ class Room {
final Map<String, dynamic> response = await client.jsonRequest(
type: HTTPType.PUT,
action: "/client/r0/rooms/${id}/send/$sendType/$messageID",
data: await encryptGroupMessagePayload(content));
data: client.encryptionEnabled
? await encryptGroupMessagePayload(content)
: content);
final String res = response["event_id"];
eventUpdate.content["status"] = 1;
eventUpdate.content["unsigned"] = {"transaction_id": messageID};