mirror of
https://github.com/vector-im/element-web.git
synced 2024-11-16 21:24:59 +08:00
Use a Map instead of Object to preserve failure ordering
This commit is contained in:
parent
f08274585e
commit
f22f2d7bd6
@ -129,17 +129,18 @@ export default class DecryptionFailureTracker {
|
|||||||
|
|
||||||
// Only track one failure per event
|
// Only track one failure per event
|
||||||
const dedupedFailuresMap = failuresGivenGrace.reduce(
|
const dedupedFailuresMap = failuresGivenGrace.reduce(
|
||||||
(result, failure) => {
|
(map, failure) => {
|
||||||
if (!this.trackedEventHashMap[eventIdHash(failure.failedEventId)]) {
|
if (!this.trackedEventHashMap[eventIdHash(failure.failedEventId)]) {
|
||||||
return {...result, [failure.failedEventId]: failure};
|
return map.set(failure.failedEventId, failure);
|
||||||
} else {
|
} else {
|
||||||
return result;
|
return map;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{},
|
// Use a map to preseve key ordering
|
||||||
|
new Map(),
|
||||||
);
|
);
|
||||||
|
|
||||||
const trackedEventIds = Object.keys(dedupedFailuresMap);
|
const trackedEventIds = [...dedupedFailuresMap.keys()];
|
||||||
|
|
||||||
this.trackedEventHashMap = trackedEventIds.reduce(
|
this.trackedEventHashMap = trackedEventIds.reduce(
|
||||||
(result, eventId) => ({...result, [eventIdHash(eventId)]: true}),
|
(result, eventId) => ({...result, [eventIdHash(eventId)]: true}),
|
||||||
@ -148,7 +149,7 @@ export default class DecryptionFailureTracker {
|
|||||||
|
|
||||||
this.saveTrackedEventHashMap();
|
this.saveTrackedEventHashMap();
|
||||||
|
|
||||||
const dedupedFailures = trackedEventIds.map((k) => dedupedFailuresMap[k]);
|
const dedupedFailures = dedupedFailuresMap.values();
|
||||||
|
|
||||||
this.failuresToTrack = [...this.failuresToTrack, ...dedupedFailures];
|
this.failuresToTrack = [...this.failuresToTrack, ...dedupedFailures];
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user