forked from mystiq/hydrogen-web
log redaction during sync
This commit is contained in:
parent
8a8c5569dc
commit
f271517446
3 changed files with 13 additions and 11 deletions
|
@ -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 entries = [];
|
||||||
const updatedEntries = [];
|
const updatedEntries = [];
|
||||||
// events is in reverse chronological order for backwards pagination,
|
// events is in reverse chronological order for backwards pagination,
|
||||||
|
@ -123,12 +123,12 @@ export class GapWriter {
|
||||||
txn.timelineEvents.insert(eventStorageEntry);
|
txn.timelineEvents.insert(eventStorageEntry);
|
||||||
const eventEntry = new EventEntry(eventStorageEntry, this._fragmentIdComparer);
|
const eventEntry = new EventEntry(eventStorageEntry, this._fragmentIdComparer);
|
||||||
directionalAppend(entries, eventEntry, direction);
|
directionalAppend(entries, eventEntry, direction);
|
||||||
const updatedRelationTargetEntry = await this._relationWriter.writeRelation(eventEntry);
|
const updatedRelationTargetEntry = await this._relationWriter.writeRelation(eventEntry, txn, log);
|
||||||
if (updatedRelationTargetEntry) {
|
if (updatedRelationTargetEntry) {
|
||||||
updatedEntries.push(updatedRelationTargetEntry);
|
updatedEntries.push(updatedRelationTargetEntry);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return entries;
|
return {entries, updatedEntries};
|
||||||
}
|
}
|
||||||
|
|
||||||
_findMember(userId, state, events, index, direction) {
|
_findMember(userId, state, events, index, direction) {
|
||||||
|
@ -246,7 +246,7 @@ export class GapWriter {
|
||||||
end = null;
|
end = null;
|
||||||
}
|
}
|
||||||
// create entries for all events in chunk, add them to entries
|
// 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);
|
const fragments = await this._updateFragments(fragmentEntry, neighbourFragmentEntry, end, entries, txn);
|
||||||
|
|
||||||
return {entries, updatedEntries, fragments};
|
return {entries, updatedEntries, fragments};
|
||||||
|
|
|
@ -24,11 +24,11 @@ export class RelationWriter {
|
||||||
}
|
}
|
||||||
|
|
||||||
// this needs to happen again after decryption too for edits
|
// this needs to happen again after decryption too for edits
|
||||||
async writeRelation(sourceEntry, txn) {
|
async writeRelation(sourceEntry, txn, log) {
|
||||||
if (sourceEntry.relatedEventId) {
|
if (sourceEntry.relatedEventId) {
|
||||||
const target = await txn.timelineEvents.getByEventId(this._roomId, sourceEntry.relatedEventId);
|
const target = await txn.timelineEvents.getByEventId(this._roomId, sourceEntry.relatedEventId);
|
||||||
if (target) {
|
if (target) {
|
||||||
if (this._applyRelation(sourceEntry, target)) {
|
if (this._applyRelation(sourceEntry, target, log)) {
|
||||||
txn.timelineEvents.update(target);
|
txn.timelineEvents.update(target);
|
||||||
return new EventEntry(target, this._fragmentIdComparer);
|
return new EventEntry(target, this._fragmentIdComparer);
|
||||||
}
|
}
|
||||||
|
@ -37,15 +37,17 @@ export class RelationWriter {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
_applyRelation(sourceEntry, target) {
|
_applyRelation(sourceEntry, target, log) {
|
||||||
if (sourceEntry.eventType === REDACTION_TYPE) {
|
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 {
|
} else {
|
||||||
return false;
|
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?
|
// 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"
|
// 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)
|
// reactions are the only thing that comes to mind, but we don't encrypt those (for now)
|
||||||
|
|
|
@ -174,7 +174,7 @@ export class SyncWriter {
|
||||||
txn.timelineEvents.insert(storageEntry);
|
txn.timelineEvents.insert(storageEntry);
|
||||||
const entry = new EventEntry(storageEntry, this._fragmentIdComparer);
|
const entry = new EventEntry(storageEntry, this._fragmentIdComparer);
|
||||||
entries.push(entry);
|
entries.push(entry);
|
||||||
const updatedRelationTargetEntry = await this._relationWriter.writeRelation(entry);
|
const updatedRelationTargetEntry = await this._relationWriter.writeRelation(entry, txn, log);
|
||||||
if (updatedRelationTargetEntry) {
|
if (updatedRelationTargetEntry) {
|
||||||
updatedEntries.push(updatedRelationTargetEntry);
|
updatedEntries.push(updatedRelationTargetEntry);
|
||||||
}
|
}
|
||||||
|
@ -246,7 +246,7 @@ export class SyncWriter {
|
||||||
// members are available in the transaction
|
// members are available in the transaction
|
||||||
await this._writeStateEvents(roomResponse, memberChanges, timeline?.limited, txn, log);
|
await this._writeStateEvents(roomResponse, memberChanges, timeline?.limited, txn, log);
|
||||||
const {currentKey, entries, updatedEntries} =
|
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);
|
log.set("memberChanges", memberChanges.size);
|
||||||
return {entries, updatedEntries, newLiveKey: currentKey, memberChanges};
|
return {entries, updatedEntries, newLiveKey: currentKey, memberChanges};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue