Skip to content

Commit

Permalink
Change detailed status child ordering to sort self-replies on top (ma…
Browse files Browse the repository at this point in the history
  • Loading branch information
ClearlyClaire authored and umonaca committed Aug 30, 2019
1 parent 8fa30df commit fceb276
Showing 1 changed file with 27 additions and 17 deletions.
44 changes: 27 additions & 17 deletions app/javascript/mastodon/features/status/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,28 +84,38 @@ const makeMapStateToProps = () => {
const getDescendantsIds = createSelector([
(_, { id }) => id,
state => state.getIn(['contexts', 'replies']),
], (statusId, contextReplies) => {
let descendantsIds = Immutable.List();
descendantsIds = descendantsIds.withMutations(mutable => {
const ids = [statusId];
state => state.get('statuses'),
], (statusId, contextReplies, statuses) => {
let descendantsIds = [];
const ids = [statusId];

while (ids.length > 0) {
let id = ids.shift();
const replies = contextReplies.get(id);
while (ids.length > 0) {
let id = ids.shift();
const replies = contextReplies.get(id);

if (statusId !== id) {
mutable.push(id);
}
if (statusId !== id) {
descendantsIds.push(id);
}

if (replies) {
replies.reverse().forEach(reply => {
ids.unshift(reply);
});
}
if (replies) {
replies.reverse().forEach(reply => {
ids.unshift(reply);
});
}
});
}

let insertAt = descendantsIds.findIndex((id) => statuses.get(id).get('in_reply_to_account_id') !== statuses.get(id).get('account'));
if (insertAt !== -1) {
descendantsIds.forEach((id, idx) => {
if (idx > insertAt && statuses.get(id).get('in_reply_to_account_id') === statuses.get(id).get('account')) {
descendantsIds.splice(idx, 1);
descendantsIds.splice(insertAt, 0, id);
insertAt += 1;
}
});
}

return descendantsIds;
return Immutable.List(descendantsIds);
});

const mapStateToProps = (state, props) => {
Expand Down

0 comments on commit fceb276

Please sign in to comment.