Ancestors and descendants of statuses

pull/69/head
Eugen Rochko 2016-03-21 11:43:21 +01:00
parent 7e00a21ea6
commit 35aafdba96
3 changed files with 12 additions and 3 deletions

View File

@ -76,6 +76,14 @@ class Status < ActiveRecord::Base
m m
end end
def ancestors
Status.where(id: Status.find_by_sql(['WITH RECURSIVE search_tree(id, in_reply_to_id, path) AS (SELECT id, in_reply_to_id, ARRAY[id] FROM statuses WHERE id = ? UNION ALL SELECT statuses.id, statuses.in_reply_to_id, path || statuses.id FROM search_tree JOIN statuses ON statuses.id = search_tree.in_reply_to_id WHERE NOT statuses.id = ANY(path)) SELECT id FROM search_tree ORDER BY path DESC', self.id]) - [self])
end
def descendants
Status.where(id: Status.find_by_sql(['WITH RECURSIVE search_tree(id, path) AS (SELECT id, ARRAY[id] FROM statuses WHERE id = ? UNION ALL SELECT statuses.id, path || statuses.id FROM search_tree JOIN statuses ON statuses.in_reply_to_id = search_tree.id WHERE NOT statuses.id = ANY(path)) SELECT id FROM search_tree ORDER BY path', self.id]) - [self])
end
after_create do after_create do
self.account.stream_entries.create!(activity: self) self.account.stream_entries.create!(activity: self)
end end

View File

@ -1,5 +1,6 @@
- if status.reply? && include_threads - if status.reply? && include_threads
= render partial: 'status', locals: { status: status.thread, include_threads: false, is_predecessor: true, is_successor: false } - status.ancestors.with_includes.with_counters.each do |status|
= render partial: 'status', locals: { status: status, include_threads: false, is_predecessor: true, is_successor: false }
.entry{ class: entry_classes(status, is_predecessor, is_successor, include_threads) } .entry{ class: entry_classes(status, is_predecessor, is_successor, include_threads) }
- if status.reblog? - if status.reblog?
@ -32,5 +33,5 @@
= status.reblog? ? (status.reblog.local? ? linkify(status.reblog) : status.reblog.content.html_safe) : (status.local? ? linkify(status) : status.content.html_safe) = status.reblog? ? (status.reblog.local? ? linkify(status.reblog) : status.reblog.content.html_safe) : (status.local? ? linkify(status) : status.content.html_safe)
- if include_threads - if include_threads
- status.replies.each do |status| - status.descendants.with_includes.with_counters.each do |status|
= render partial: 'status', locals: { status: status, include_threads: false, is_successor: true, is_predecessor: false } = render partial: 'status', locals: { status: status, include_threads: false, is_successor: true, is_predecessor: false }

View File

@ -5,7 +5,7 @@ RSpec.describe Api::SubscriptionsController, type: :controller do
describe 'GET #show' do describe 'GET #show' do
before do before do
get :show, id: account.id, 'hub.topic': 'topic_url', 'hub.verify_token': 123, 'hub.challenge': '456' get :show, :id => account.id, 'hub.topic' => 'topic_url', 'hub.verify_token' => 123, 'hub.challenge' => '456'
end end
it 'returns http success' do it 'returns http success' do