1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-11-28 05:03:59 +03:00

Tweak duplicateStrategy code to reduce diff

This commit is contained in:
Richard van der Hoff
2016-01-15 13:23:51 +00:00
parent 706966ffe9
commit e68ab7d54a

View File

@@ -541,33 +541,31 @@ Room.prototype.addEvents = function(events, duplicateStrategy) {
// N.B. account_data is added directly by /sync to avoid // N.B. account_data is added directly by /sync to avoid
// having to maintain an event.isAccountData() here // having to maintain an event.isAccountData() here
else { else {
if (duplicateStrategy) { var timeline = this._eventIdToTimeline[events[i].getId()];
if (timeline && duplicateStrategy) {
// is there a duplicate? // is there a duplicate?
var shouldIgnore = false; var shouldIgnore = false;
var timeline = this._eventIdToTimeline[events[i].getId()]; var tlEvents = timeline.getEvents();
if (timeline) { for (var j = 0; j < tlEvents.length; j++) {
var tlEvents = timeline.getEvents(); if (tlEvents[j].getId() === events[i].getId()) {
for (var j = 0; j < tlEvents.length; j++) { if (duplicateStrategy === "replace") {
if (tlEvents[j].getId() === events[i].getId()) { // still need to set the right metadata on this event
if (duplicateStrategy === "replace") { setEventMetadata(
// still need to set the right metadata on this event events[i],
setEventMetadata( timeline.getState(false),
events[i], false
timeline.getState(false), );
false
);
if (!tlEvents[j].encryptedType) { if (!tlEvents[j].encryptedType) {
tlEvents[j] = events[i]; tlEvents[j] = events[i];
}
// skip the insert so we don't add this event twice.
// Don't break in case we replace multiple events.
shouldIgnore = true;
}
else if (duplicateStrategy === "ignore") {
shouldIgnore = true;
break; // stop searching, we're skipping the insert
} }
// skip the insert so we don't add this event twice.
// Don't break in case we replace multiple events.
shouldIgnore = true;
}
else if (duplicateStrategy === "ignore") {
shouldIgnore = true;
break; // stop searching, we're skipping the insert
} }
} }
} }