fix: Last message set incorrectly on all session key received
This fixes a bug that the last message was sent incorrectly when a session key received for example from the key backup. It may fix several issues like the last message is set as a very old one or the last message is not decrypted.
This commit is contained in:
parent
3fb134dfb2
commit
05c945b042
|
|
@ -190,20 +190,21 @@ class KeyManager {
|
|||
event.content['session_id'] == sessionId) {
|
||||
final decrypted = encryption.decryptRoomEventSync(roomId, event);
|
||||
if (decrypted.type != EventTypes.Encrypted) {
|
||||
// Remove this from the state to make sure it does not appear as last event
|
||||
room.states.remove(EventTypes.Encrypted);
|
||||
// Set the decrypted event as last event by adding it to the state
|
||||
room.setState(decrypted);
|
||||
room.states[decrypted.type] = {'': decrypted};
|
||||
// Also store in database
|
||||
final database = client.database;
|
||||
if (database != null) {
|
||||
await database.transaction(() async {
|
||||
await database.storeEventUpdate(
|
||||
EventUpdate(
|
||||
roomID: room.id,
|
||||
type: EventUpdateType.state,
|
||||
content: decrypted.toJson(),
|
||||
),
|
||||
client);
|
||||
});
|
||||
await database.storeEventUpdate(
|
||||
EventUpdate(
|
||||
roomID: room.id,
|
||||
type: EventUpdateType.state,
|
||||
content: decrypted.toJson(),
|
||||
),
|
||||
client,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -872,8 +872,11 @@ class Client extends MatrixApi {
|
|||
// Try to decrypt encrypted events but don't update the database.
|
||||
if (leftRoom.encrypted && leftRoom.client.encryptionEnabled) {
|
||||
if (timeline.events[i].type == EventTypes.Encrypted) {
|
||||
timeline.events[i] = await leftRoom.client.encryption!
|
||||
.decryptRoomEvent(leftRoom.id, timeline.events[i]);
|
||||
timeline.events[i] =
|
||||
await leftRoom.client.encryption!.decryptRoomEvent(
|
||||
leftRoom.id,
|
||||
timeline.events[i],
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1322,7 +1322,10 @@ class Room {
|
|||
for (var i = 0; i < events.length; i++) {
|
||||
if (events[i].type == EventTypes.Encrypted &&
|
||||
events[i].content['can_request_session'] == true) {
|
||||
events[i] = await client.encryption!.decryptRoomEvent(id, events[i]);
|
||||
events[i] = await client.encryption!.decryptRoomEvent(
|
||||
id,
|
||||
events[i],
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1414,8 +1417,11 @@ class Room {
|
|||
for (var i = 0; i < chunk.events.length; i++) {
|
||||
if (chunk.events[i].content['can_request_session'] == true) {
|
||||
chunk.events[i] = await client.encryption!.decryptRoomEvent(
|
||||
id, chunk.events[i],
|
||||
store: !isArchived);
|
||||
id,
|
||||
chunk.events[i],
|
||||
store: !isArchived,
|
||||
updateType: EventUpdateType.history,
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
@ -1632,8 +1638,10 @@ class Room {
|
|||
final event = Event.fromMatrixEvent(matrixEvent, this);
|
||||
if (event.type == EventTypes.Encrypted && client.encryptionEnabled) {
|
||||
// attempt decryption
|
||||
return await client.encryption
|
||||
?.decryptRoomEvent(id, event, store: false);
|
||||
return await client.encryption?.decryptRoomEvent(
|
||||
id,
|
||||
event,
|
||||
);
|
||||
}
|
||||
return event;
|
||||
} on MatrixException catch (err) {
|
||||
|
|
|
|||
|
|
@ -227,8 +227,10 @@ class Timeline {
|
|||
if (room.encrypted && room.client.encryptionEnabled) {
|
||||
for (var i = 0; i < newEvents.length; i++) {
|
||||
if (newEvents[i].type == EventTypes.Encrypted) {
|
||||
newEvents[i] = await room.client.encryption!
|
||||
.decryptRoomEvent(room.id, newEvents[i]);
|
||||
newEvents[i] = await room.client.encryption!.decryptRoomEvent(
|
||||
room.id,
|
||||
newEvents[i],
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -314,8 +316,12 @@ class Timeline {
|
|||
if (events[i].type == EventTypes.Encrypted &&
|
||||
events[i].messageType == MessageTypes.BadEncrypted &&
|
||||
events[i].content['session_id'] == sessionId) {
|
||||
events[i] = await encryption.decryptRoomEvent(room.id, events[i],
|
||||
store: true);
|
||||
events[i] = await encryption.decryptRoomEvent(
|
||||
room.id,
|
||||
events[i],
|
||||
store: true,
|
||||
updateType: EventUpdateType.history,
|
||||
);
|
||||
onChange?.call(i);
|
||||
if (events[i].type != EventTypes.Encrypted) {
|
||||
decryptAtLeastOneEvent = true;
|
||||
|
|
|
|||
Loading…
Reference in New Issue