mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2024-12-23 03:25:12 +01:00
Keep room key with earliest index
This commit is contained in:
parent
9fad5b3b29
commit
a2f8731a23
@ -138,12 +138,23 @@ export class Decryption {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: compare first_known_index to see which session to keep
|
|
||||||
const hasSession = await txn.inboundGroupSessions.has(roomId, senderKey, sessionId);
|
|
||||||
if (!hasSession) {
|
|
||||||
const session = new this._olm.InboundGroupSession();
|
const session = new this._olm.InboundGroupSession();
|
||||||
try {
|
try {
|
||||||
session.create(sessionKey);
|
session.create(sessionKey);
|
||||||
|
|
||||||
|
let incomingSessionIsBetter = true;
|
||||||
|
const existingSessionEntry = await txn.inboundGroupSessions.get(roomId, senderKey, sessionId);
|
||||||
|
if (existingSessionEntry) {
|
||||||
|
const existingSession = new this._olm.InboundGroupSession();
|
||||||
|
try {
|
||||||
|
existingSession.unpickle(this._pickleKey, existingSessionEntry.session);
|
||||||
|
incomingSessionIsBetter = session.first_known_index() < existingSession.first_known_index();
|
||||||
|
} finally {
|
||||||
|
existingSession.free();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (incomingSessionIsBetter) {
|
||||||
const sessionEntry = {
|
const sessionEntry = {
|
||||||
roomId,
|
roomId,
|
||||||
senderKey,
|
senderKey,
|
||||||
@ -153,10 +164,10 @@ export class Decryption {
|
|||||||
};
|
};
|
||||||
txn.inboundGroupSessions.set(sessionEntry);
|
txn.inboundGroupSessions.set(sessionEntry);
|
||||||
newSessions.push(sessionEntry);
|
newSessions.push(sessionEntry);
|
||||||
|
}
|
||||||
} finally {
|
} finally {
|
||||||
session.free();
|
session.free();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
// this will be passed to the Room in notifyRoomKeys
|
// this will be passed to the Room in notifyRoomKeys
|
||||||
|
Loading…
Reference in New Issue
Block a user