|
@ -8,7 +8,7 @@ module StatusThreadingConcern |
|
|
end |
|
|
end |
|
|
|
|
|
|
|
|
def descendants(limit, account = nil, max_child_id = nil, since_child_id = nil, depth = nil) |
|
|
def descendants(limit, account = nil, max_child_id = nil, since_child_id = nil, depth = nil) |
|
|
find_statuses_from_tree_path(descendant_ids(limit, max_child_id, since_child_id, depth), account) |
|
|
|
|
|
|
|
|
find_statuses_from_tree_path(descendant_ids(limit, max_child_id, since_child_id, depth), account, promote: true) |
|
|
end |
|
|
end |
|
|
|
|
|
|
|
|
private |
|
|
private |
|
@ -76,7 +76,7 @@ module StatusThreadingConcern |
|
|
descendants_with_self - [self] |
|
|
descendants_with_self - [self] |
|
|
end |
|
|
end |
|
|
|
|
|
|
|
|
def find_statuses_from_tree_path(ids, account) |
|
|
|
|
|
|
|
|
def find_statuses_from_tree_path(ids, account, promote: false) |
|
|
statuses = statuses_with_accounts(ids).to_a |
|
|
statuses = statuses_with_accounts(ids).to_a |
|
|
account_ids = statuses.map(&:account_id).uniq |
|
|
account_ids = statuses.map(&:account_id).uniq |
|
|
domains = statuses.map(&:account_domain).compact.uniq |
|
|
domains = statuses.map(&:account_domain).compact.uniq |
|
@ -86,6 +86,28 @@ module StatusThreadingConcern |
|
|
|
|
|
|
|
|
# Order ancestors/descendants by tree path |
|
|
# Order ancestors/descendants by tree path |
|
|
statuses.sort_by! { |status| ids.index(status.id) } |
|
|
statuses.sort_by! { |status| ids.index(status.id) } |
|
|
|
|
|
|
|
|
|
|
|
# Bring self-replies to the top |
|
|
|
|
|
if promote |
|
|
|
|
|
promote_by!(statuses) { |status| status.in_reply_to_account_id == status.account_id } |
|
|
|
|
|
else |
|
|
|
|
|
statuses |
|
|
|
|
|
end |
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
def promote_by!(arr) |
|
|
|
|
|
insert_at = arr.find_index { |item| !yield(item) } |
|
|
|
|
|
|
|
|
|
|
|
return arr if insert_at.nil? |
|
|
|
|
|
|
|
|
|
|
|
arr.each_with_index do |item, index| |
|
|
|
|
|
next if index <= insert_at || !yield(item) |
|
|
|
|
|
|
|
|
|
|
|
arr.insert(insert_at, arr.delete_at(index)) |
|
|
|
|
|
insert_at += 1 |
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
arr |
|
|
end |
|
|
end |
|
|
|
|
|
|
|
|
def relations_map_for_account(account, account_ids, domains) |
|
|
def relations_map_for_account(account, account_ids, domains) |
|
|