Browse Source

Fix for single status pages

closed-social-glitch-2
Eugen Rochko 7 years ago
parent
commit
762157ee4e
4 changed files with 26 additions and 4 deletions
  1. +2
    -2
      app/controllers/accounts_controller.rb
  2. +14
    -0
      app/controllers/stream_entries_controller.rb
  3. +8
    -0
      app/models/status.rb
  4. +2
    -2
      app/views/stream_entries/_status.html.haml

+ 2
- 2
app/controllers/accounts_controller.rb View File

@ -11,8 +11,8 @@ class AccountsController < ApplicationController
if user_signed_in?
status_ids = @statuses.collect { |s| [s.id, s.reblog_of_id] }.flatten.uniq
@favourited = Favourite.where(status_id: status_ids).where(account_id: current_user.account_id).map { |f| [f.status_id, true] }.to_h
@reblogged = Status.where(reblog_of_id: status_ids).where(account_id: current_user.account_id).map { |s| [s.reblog_of_id, true] }.to_h
@favourited = Status.favourites_map(status_ids, current_user.account_id)
@reblogged = Status.reblogs_map(status_ids, current_user.account_id)
else
@favourited = {}
@reblogged = {}

+ 14
- 0
app/controllers/stream_entries_controller.rb View File

@ -7,6 +7,20 @@ class StreamEntriesController < ApplicationController
def show
@type = @stream_entry.activity_type.downcase
if @stream_entry.activity_type == 'Status'
@ancestors = @stream_entry.activity.ancestors.with_includes.with_counters
@descendants = @stream_entry.activity.descendants.with_includes.with_counters
if user_signed_in?
status_ids = [@stream_entry.activity_id] + @ancestors.map { |s| s.id } + @descendants.map { |s| s.id }
@favourited = Status.favourites_map(status_ids, current_user.account_id)
@reblogged = Status.reblogs_map(status_ids, current_user.account_id)
else
@favourited = {}
@reblogged = {}
end
end
respond_to do |format|
format.html
format.atom

+ 8
- 0
app/models/status.rb View File

@ -75,4 +75,12 @@ class Status < ApplicationRecord
def self.as_mentions_timeline(account)
self.where(id: Mention.where(account: account).pluck(:status_id)).with_includes.with_counters
end
def self.favourites_map(status_ids, account_id)
Favourite.where(status_id: status_ids).where(account_id: account_id).map { |f| [f.status_id, true] }.to_h
end
def self.reblogs_map(status_ids, account_id)
self.where(reblog_of_id: status_ids).where(account_id: account_id).map { |s| [s.reblog_of_id, true] }.to_h
end
end

+ 2
- 2
app/views/stream_entries/_status.html.haml View File

@ -4,7 +4,7 @@
- centered = include_threads && !is_predecessor && !is_successor
- if status.reply? && include_threads
- status.ancestors.with_includes.with_counters.each do |status|
- @ancestors.each do |status|
= render partial: 'status', locals: { status: status, is_predecessor: true }
.entry{ class: entry_classes(status, is_predecessor, is_successor, include_threads) }
@ -43,5 +43,5 @@
%li.transparent-background= link_to '', media.file.url, style: "background-image: url(#{media.file.url(:small)})", target: '_blank'
- if include_threads
- status.descendants.with_includes.with_counters.each do |status|
- @descendants.each do |status|
= render partial: 'status', locals: { status: status, is_successor: true }

Loading…
Cancel
Save