also load session keys when requesting history
This commit is contained in:
parent
9971e7377e
commit
03beffbb46
|
@ -1024,58 +1024,61 @@ class Room {
|
||||||
if (onHistoryReceived != null) onHistoryReceived();
|
if (onHistoryReceived != null) onHistoryReceived();
|
||||||
prev_batch = resp['end'];
|
prev_batch = resp['end'];
|
||||||
|
|
||||||
final dbActions = <Future<dynamic> Function()>[];
|
final loadFn = () async {
|
||||||
if (client.database != null) {
|
if (!(resp['chunk'] is List<dynamic> &&
|
||||||
dbActions.add(
|
resp['chunk'].length > 0 &&
|
||||||
() => client.database.setRoomPrevBatch(prev_batch, client.id, id));
|
resp['end'] is String)) return;
|
||||||
}
|
|
||||||
|
|
||||||
if (!(resp['chunk'] is List<dynamic> &&
|
if (resp['state'] is List<dynamic>) {
|
||||||
resp['chunk'].length > 0 &&
|
for (final state in resp['state']) {
|
||||||
resp['end'] is String)) return;
|
var eventUpdate = EventUpdate(
|
||||||
|
type: 'state',
|
||||||
if (resp['state'] is List<dynamic>) {
|
roomID: id,
|
||||||
for (final state in resp['state']) {
|
eventType: state['type'],
|
||||||
var eventUpdate = EventUpdate(
|
content: state,
|
||||||
type: 'state',
|
sortOrder: oldSortOrder,
|
||||||
roomID: id,
|
).decrypt(this);
|
||||||
eventType: state['type'],
|
if (eventUpdate.eventType == 'm.room.encrypted' &&
|
||||||
content: state,
|
client.database != null) {
|
||||||
sortOrder: oldSortOrder,
|
await loadInboundGroupSessionKey(
|
||||||
).decrypt(this);
|
state['content']['session_id'], state['content']['sender_key']);
|
||||||
client.onEvent.add(eventUpdate);
|
eventUpdate = eventUpdate.decrypt(this);
|
||||||
if (client.database != null) {
|
}
|
||||||
dbActions.add(
|
client.onEvent.add(eventUpdate);
|
||||||
() => client.database.storeEventUpdate(client.id, eventUpdate));
|
await client.database?.storeEventUpdate(client.id, eventUpdate);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
List<dynamic> history = resp['chunk'];
|
List<dynamic> history = resp['chunk'];
|
||||||
for (final hist in history) {
|
for (final hist in history) {
|
||||||
var eventUpdate = EventUpdate(
|
var eventUpdate = EventUpdate(
|
||||||
type: 'history',
|
type: 'history',
|
||||||
roomID: id,
|
roomID: id,
|
||||||
eventType: hist['type'],
|
eventType: hist['type'],
|
||||||
content: hist,
|
content: hist,
|
||||||
sortOrder: oldSortOrder,
|
sortOrder: oldSortOrder,
|
||||||
).decrypt(this);
|
).decrypt(this);
|
||||||
client.onEvent.add(eventUpdate);
|
if (eventUpdate.eventType == 'm.room.encrypted' &&
|
||||||
if (client.database != null) {
|
client.database != null) {
|
||||||
dbActions.add(
|
await loadInboundGroupSessionKey(
|
||||||
() => client.database.storeEventUpdate(client.id, eventUpdate));
|
hist['content']['session_id'], hist['content']['sender_key']);
|
||||||
|
eventUpdate = eventUpdate.decrypt(this);
|
||||||
|
}
|
||||||
|
client.onEvent.add(eventUpdate);
|
||||||
|
await client.database?.storeEventUpdate(client.id, eventUpdate);
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
if (client.database != null) {
|
if (client.database != null) {
|
||||||
dbActions.add(
|
await client.database?.transaction(() async {
|
||||||
() => client.database.setRoomPrevBatch(resp['end'], client.id, id));
|
await client.database.setRoomPrevBatch(prev_batch, client.id, id);
|
||||||
|
await loadFn();
|
||||||
|
await client.database.setRoomPrevBatch(resp['end'], client.id, id);
|
||||||
|
await updateSortOrder();
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
await loadFn();
|
||||||
}
|
}
|
||||||
await client.database?.transaction(() async {
|
|
||||||
for (final f in dbActions) {
|
|
||||||
await f();
|
|
||||||
}
|
|
||||||
await updateSortOrder();
|
|
||||||
});
|
|
||||||
client.onRoomUpdate.add(
|
client.onRoomUpdate.add(
|
||||||
RoomUpdate(
|
RoomUpdate(
|
||||||
id: id,
|
id: id,
|
||||||
|
|
Loading…
Reference in a new issue