Skip to content

Commit fceb276

Browse files
ClearlyClaireumonaca
authored andcommitted
Change detailed status child ordering to sort self-replies on top (mastodon#11686)
Fixes mastodon#11679
1 parent 8fa30df commit fceb276

1 file changed

Lines changed: 27 additions & 17 deletions

File tree

  • app/javascript/mastodon/features/status

app/javascript/mastodon/features/status/index.js

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -84,28 +84,38 @@ const makeMapStateToProps = () => {
8484
const getDescendantsIds = createSelector([
8585
(_, { id }) => id,
8686
state => state.getIn(['contexts', 'replies']),
87-
], (statusId, contextReplies) => {
88-
let descendantsIds = Immutable.List();
89-
descendantsIds = descendantsIds.withMutations(mutable => {
90-
const ids = [statusId];
87+
state => state.get('statuses'),
88+
], (statusId, contextReplies, statuses) => {
89+
let descendantsIds = [];
90+
const ids = [statusId];
9191

92-
while (ids.length > 0) {
93-
let id = ids.shift();
94-
const replies = contextReplies.get(id);
92+
while (ids.length > 0) {
93+
let id = ids.shift();
94+
const replies = contextReplies.get(id);
9595

96-
if (statusId !== id) {
97-
mutable.push(id);
98-
}
96+
if (statusId !== id) {
97+
descendantsIds.push(id);
98+
}
9999

100-
if (replies) {
101-
replies.reverse().forEach(reply => {
102-
ids.unshift(reply);
103-
});
104-
}
100+
if (replies) {
101+
replies.reverse().forEach(reply => {
102+
ids.unshift(reply);
103+
});
105104
}
106-
});
105+
}
106+
107+
let insertAt = descendantsIds.findIndex((id) => statuses.get(id).get('in_reply_to_account_id') !== statuses.get(id).get('account'));
108+
if (insertAt !== -1) {
109+
descendantsIds.forEach((id, idx) => {
110+
if (idx > insertAt && statuses.get(id).get('in_reply_to_account_id') === statuses.get(id).get('account')) {
111+
descendantsIds.splice(idx, 1);
112+
descendantsIds.splice(insertAt, 0, id);
113+
insertAt += 1;
114+
}
115+
});
116+
}
107117

108-
return descendantsIds;
118+
return Immutable.List(descendantsIds);
109119
});
110120

111121
const mapStateToProps = (state, props) => {

0 commit comments

Comments
 (0)