Skip to content

Commit 9835e2e

Browse files
authored
Merge pull request element-hq#5759 from vector-im/luke/renumerate-broken-ordered-sublists
Implement renumeration of ordered tags upon collision
2 parents 95c7469 + b0d115a commit 9835e2e

1 file changed

Lines changed: 20 additions & 17 deletions

File tree

‎src/components/structures/RoomSubList.js‎

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -327,43 +327,46 @@ var RoomSubList = React.createClass({
327327
},
328328

329329
calcManualOrderTagData: function(room) {
330-
var index = this.state.sortedList.indexOf(room);
330+
const index = this.state.sortedList.indexOf(room);
331331

332332
// we sort rooms by the lexicographic ordering of the 'order' metadata on their tags.
333333
// for convenience, we calculate this for now a floating point number between 0.0 and 1.0.
334334

335-
var orderA = 0.0; // by default we're next to the beginning of the list
335+
let orderA = 0.0; // by default we're next to the beginning of the list
336336
if (index > 0) {
337-
var prevTag = this.state.sortedList[index - 1].tags[this.props.tagName];
337+
const prevTag = this.state.sortedList[index - 1].tags[this.props.tagName];
338338
if (!prevTag) {
339-
console.error("Previous room in sublist is not tagged to be in this list. This should never happen.")
340-
}
341-
else if (prevTag.order === undefined) {
339+
console.error("Previous room in sublist is not tagged to be in this list. This should never happen.");
340+
} else if (prevTag.order === undefined) {
342341
console.error("Previous room in sublist has no ordering metadata. This should never happen.");
343-
}
344-
else {
342+
} else {
345343
orderA = prevTag.order;
346344
}
347345
}
348346

349-
var orderB = 1.0; // by default we're next to the end of the list too
347+
let orderB = 1.0; // by default we're next to the end of the list too
350348
if (index < this.state.sortedList.length - 1) {
351-
var nextTag = this.state.sortedList[index + 1].tags[this.props.tagName];
349+
const nextTag = this.state.sortedList[index + 1].tags[this.props.tagName];
352350
if (!nextTag) {
353-
console.error("Next room in sublist is not tagged to be in this list. This should never happen.")
354-
}
355-
else if (nextTag.order === undefined) {
351+
console.error("Next room in sublist is not tagged to be in this list. This should never happen.");
352+
} else if (nextTag.order === undefined) {
356353
console.error("Next room in sublist has no ordering metadata. This should never happen.");
357-
}
358-
else {
354+
} else {
359355
orderB = nextTag.order;
360356
}
361357
}
362358

363-
var order = (orderA + orderB) / 2.0;
359+
const order = (orderA + orderB) / 2.0;
360+
364361
if (order === orderA || order === orderB) {
365362
console.error("Cannot describe new list position. This should be incredibly unlikely.");
366-
// TODO: renumber the list
363+
this.state.sortedList.forEach((room, index) => {
364+
MatrixClientPeg.get().setRoomTag(
365+
room.roomId, this.props.tagName,
366+
{order: index / this.state.sortedList.length},
367+
);
368+
});
369+
return index / this.state.sortedList.length;
367370
}
368371

369372
return order;

0 commit comments

Comments
 (0)