Skip to content

Commit

Permalink
Merge pull request #1001 from matrix-org/hs/recursive-tombstone-fixes
Browse files Browse the repository at this point in the history
Tombstone bugfixes
  • Loading branch information
turt2live authored Jul 29, 2019
2 parents 6cca73b + c9bf61c commit 9a8af05
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -2369,6 +2369,7 @@ MatrixClient.prototype.getRoomUpgradeHistory = function(roomId, verifyLinks=fals
while (tombstoneEvent) {
const refRoom = this.getRoom(tombstoneEvent.getContent()['replacement_room']);
if (!refRoom) break; // end of the chain
if (refRoom.roomId === currentRoom.roomId) break; // Tombstone is referencing it's own room

if (verifyLinks) {
createEvent = refRoom.currentState.getStateEvents("m.room.create", "");
Expand All @@ -2380,6 +2381,12 @@ MatrixClient.prototype.getRoomUpgradeHistory = function(roomId, verifyLinks=fals

// Push to the end because we're looking forwards
upgradeHistory.push(refRoom);
const roomIds = new Set(upgradeHistory.map((ref) => ref.roomId));
if (roomIds.size < upgradeHistory.length) {
// The last room added to the list introduced a previous roomId
// To avoid recursion, return the last rooms - 1
return upgradeHistory.slice(0, upgradeHistory.length - 1);
}

// Set the current room to the reference room so we know where we're at
currentRoom = refRoom;
Expand Down

0 comments on commit 9a8af05

Please sign in to comment.