log redaction during sync

This commit is contained in:
Bruno Windels 2021-05-20 15:02:14 +02:00
parent 8a8c5569dc
commit f271517446
3 changed files with 13 additions and 11 deletions

View file

@ -105,7 +105,7 @@ export class GapWriter {
}
}
async _storeEvents(events, startKey, direction, state, txn) {
async _storeEvents(events, startKey, direction, state, txn, log) {
const entries = [];
const updatedEntries = [];
// events is in reverse chronological order for backwards pagination,
@ -123,12 +123,12 @@ export class GapWriter {
txn.timelineEvents.insert(eventStorageEntry);
const eventEntry = new EventEntry(eventStorageEntry, this._fragmentIdComparer);
directionalAppend(entries, eventEntry, direction);
const updatedRelationTargetEntry = await this._relationWriter.writeRelation(eventEntry);
const updatedRelationTargetEntry = await this._relationWriter.writeRelation(eventEntry, txn, log);
if (updatedRelationTargetEntry) {
updatedEntries.push(updatedRelationTargetEntry);
}
}
return entries;
return {entries, updatedEntries};
}
_findMember(userId, state, events, index, direction) {
@ -246,7 +246,7 @@ export class GapWriter {
end = null;
}
// create entries for all events in chunk, add them to entries
const {entries, updatedEntries} = await this._storeEvents(nonOverlappingEvents, lastKey, direction, state, txn);
const {entries, updatedEntries} = await this._storeEvents(nonOverlappingEvents, lastKey, direction, state, txn, log);
const fragments = await this._updateFragments(fragmentEntry, neighbourFragmentEntry, end, entries, txn);
return {entries, updatedEntries, fragments};

View file

@ -24,11 +24,11 @@ export class RelationWriter {
}
// this needs to happen again after decryption too for edits
async writeRelation(sourceEntry, txn) {
async writeRelation(sourceEntry, txn, log) {
if (sourceEntry.relatedEventId) {
const target = await txn.timelineEvents.getByEventId(this._roomId, sourceEntry.relatedEventId);
if (target) {
if (this._applyRelation(sourceEntry, target)) {
if (this._applyRelation(sourceEntry, target, log)) {
txn.timelineEvents.update(target);
return new EventEntry(target, this._fragmentIdComparer);
}
@ -37,15 +37,17 @@ export class RelationWriter {
return;
}
_applyRelation(sourceEntry, target) {
_applyRelation(sourceEntry, target, log) {
if (sourceEntry.eventType === REDACTION_TYPE) {
return this._applyRedaction(sourceEntry.event, target.event);
return log.wrap("redact", log => this._applyRedaction(sourceEntry.event, target.event, log));
} else {
return false;
}
}
_applyRedaction(redactionEvent, targetEvent) {
_applyRedaction(redactionEvent, targetEvent, log) {
log.set("redactionId", redactionEvent.event_id);
log.set("id", targetEvent.event_id);
// TODO: should we make efforts to preserve the decrypted event type?
// probably ok not to, as we'll show whatever is deleted as "deleted message"
// reactions are the only thing that comes to mind, but we don't encrypt those (for now)

View file

@ -174,7 +174,7 @@ export class SyncWriter {
txn.timelineEvents.insert(storageEntry);
const entry = new EventEntry(storageEntry, this._fragmentIdComparer);
entries.push(entry);
const updatedRelationTargetEntry = await this._relationWriter.writeRelation(entry);
const updatedRelationTargetEntry = await this._relationWriter.writeRelation(entry, txn, log);
if (updatedRelationTargetEntry) {
updatedEntries.push(updatedRelationTargetEntry);
}
@ -246,7 +246,7 @@ export class SyncWriter {
// members are available in the transaction
await this._writeStateEvents(roomResponse, memberChanges, timeline?.limited, txn, log);
const {currentKey, entries, updatedEntries} =
await this._writeTimeline(entries, updatedEntries, timeline, this._lastLiveKey, memberChanges, txn, log);
await this._writeTimeline(timeline, this._lastLiveKey, memberChanges, txn, log);
log.set("memberChanges", memberChanges.size);
return {entries, updatedEntries, newLiveKey: currentKey, memberChanges};
}