Commit b81aa575 authored by Jeffrey Phillips Freeman's avatar Jeffrey Phillips Freeman 💥
Browse files

Temporary fix for streaming error.

parent 399db3f2
......@@ -25,24 +25,47 @@ class Api::V1::Timelines::PublicController < Api::BaseController
cache_collection(public_statuses, Status)
end
# TODO: uncomment and fix below code and comment out the two public_* methods below this.
# This version is the improved version from fedibird but causes an Invalid token error on streaming when used.
# Once this code is uncommented then as_public_timeline can be removed from app/models/status.rb as well.
#
# def public_statuses
# public_feed.get(
# limit_param(DEFAULT_STATUSES_LIMIT),
# params[:max_id],
# params[:since_id],
# params[:min_id]
# )
# end
# def public_feed
# PublicFeed.new(
# current_account,
# local: truthy_param?(:local),
# remote: truthy_param?(:remote),
# domain: params[:domain],
# only_media: truthy_param?(:only_media),
# application: doorkeeper_token&.application
# )
# end
def public_statuses
public_feed.get(
statuses = public_timeline_statuses.paginate_by_id(
limit_param(DEFAULT_STATUSES_LIMIT),
params[:max_id],
params[:since_id],
params[:min_id]
params_slice(:max_id, :since_id, :min_id)
)
if truthy_param?(:only_media)
# `SELECT DISTINCT id, updated_at` is too slow, so pluck ids at first, and then select id, updated_at with ids.
status_ids = statuses.joins(:media_attachments).distinct(:id).pluck(:id)
statuses.where(id: status_ids)
else
statuses
end
end
def public_feed
PublicFeed.new(
current_account,
local: truthy_param?(:local),
remote: truthy_param?(:remote),
domain: params[:domain],
only_media: truthy_param?(:only_media),
application: doorkeeper_token&.application
)
def public_timeline_statuses
Status.as_public_timeline(current_account, truthy_param?(:remote) ? :remote : truthy_param?(:local))
end
def insert_pagination_headers
......
......@@ -359,6 +359,12 @@ class Status < ApplicationRecord
%w(text/plain text/markdown)
end
def as_public_timeline(account = nil, local_only = false)
query = timeline_scope(local_only).without_replies
apply_timeline_filters(query, account, [:local, true].include?(local_only))
end
def favourites_map(status_ids, account_id)
Favourite.select('status_id').where(status_id: status_ids).where(account_id: account_id).each_with_object({}) { |f, h| h[f.status_id] = true }
end
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment