Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Merge pull request #2872 from matrix-org/travis/breadcrumbs/upgrades
Browse files Browse the repository at this point in the history
Use the most recent version of the room in breadcrumbs
  • Loading branch information
turt2live authored Apr 5, 2019
2 parents a109e06 + 68fc04d commit 98b35d1
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions src/components/views/rooms/RoomBreadcrumbs.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ export default class RoomBreadcrumbs extends React.Component {
const rooms = this.state.rooms.slice();

if (rooms.length) {
const {room, animated} = rooms[0];
if (!animated) {
rooms[0] = {room, animated: true};
const roomModel = rooms[0];
if (!roomModel.animated) {
roomModel.animated = true;
setTimeout(() => this.setState({rooms}), 0);
}
}
Expand Down Expand Up @@ -158,16 +158,31 @@ export default class RoomBreadcrumbs extends React.Component {
}

_appendRoomId(roomId) {
const room = MatrixClientPeg.get().getRoom(roomId);
if (!room) {
return;
}
let room = MatrixClientPeg.get().getRoom(roomId);
if (!room) return;

const rooms = this.state.rooms.slice();

// If the room is upgraded, use that room instead. We'll also splice out
// any children of the room.
const history = MatrixClientPeg.get().getRoomUpgradeHistory(roomId);
if (history.length > 1) {
room = history[history.length - 1]; // Last room is most recent

// Take out any room that isn't the most recent room
for (let i = 0; i < history.length - 1; i++) {
const idx = rooms.findIndex((r) => r.room.roomId === history[i].roomId);
if (idx !== -1) rooms.splice(idx, 1);
}
}

const existingIdx = rooms.findIndex((r) => r.room.roomId === room.roomId);
if (existingIdx !== -1) {
rooms.splice(existingIdx, 1);
}

rooms.splice(0, 0, {room, animated: false});

if (rooms.length > MAX_ROOMS) {
rooms.splice(MAX_ROOMS, rooms.length - MAX_ROOMS);
}
Expand Down

0 comments on commit 98b35d1

Please sign in to comment.