2019-07-02 08:10:25 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class HomeFeed < Feed
|
|
|
|
def initialize(account)
|
|
|
|
@type = :home
|
|
|
|
@id = account.id
|
|
|
|
@account = account
|
|
|
|
end
|
|
|
|
|
2021-01-22 04:34:14 +00:00
|
|
|
def get(limit = 20, max_id = nil, since_id = nil, min_id = nil)
|
2021-01-03 05:38:23 +00:00
|
|
|
# if redis.exists?("account:#{@account.id}:regeneration")
|
|
|
|
from_database(limit, max_id, since_id, min_id)
|
|
|
|
# else
|
|
|
|
# super
|
|
|
|
# end
|
2019-07-02 08:10:25 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def from_database(limit, max_id, since_id, min_id)
|
2021-01-22 04:34:14 +00:00
|
|
|
pagination_max = ""
|
|
|
|
pagination_min = ""
|
|
|
|
pagination_max = "and s.id < #{max_id}" unless max_id.nil?
|
|
|
|
pagination_min = "and s.id > #{min_id}" unless min_id.nil?
|
|
|
|
Status.find_by_sql "
|
|
|
|
select st.* from (
|
|
|
|
select s.*
|
|
|
|
from statuses s
|
2021-01-22 05:06:14 +00:00
|
|
|
left join statuses reblog
|
|
|
|
on s.reblog_of_id = reblog.id
|
2021-01-22 04:34:14 +00:00
|
|
|
where
|
|
|
|
s.created_at > NOW() - INTERVAL '7 days'
|
|
|
|
and s.reply is false
|
|
|
|
and (
|
|
|
|
s.account_id = #{@id}
|
|
|
|
or s.account_id in (select target_account_id from follows where account_id = #{@id})
|
|
|
|
)
|
|
|
|
and s.account_id not in (select target_account_id from mutes where account_id = #{@id})
|
2021-01-23 08:13:47 +00:00
|
|
|
and (reblog.id is null or reblog.account_id not in (select target_account_id from mutes where account_id = #{@id}))
|
|
|
|
and (reblog.id is null or reblog.account_id not in (select target_account_id from blocks where account_id = #{@id}))
|
2021-01-22 04:34:14 +00:00
|
|
|
#{pagination_max}
|
|
|
|
#{pagination_min}
|
|
|
|
order by s.created_at desc
|
|
|
|
limit #{limit}
|
|
|
|
) st
|
2021-01-22 05:09:26 +00:00
|
|
|
left join statuses rb
|
|
|
|
on st.reblog_of_id = rb.id
|
2021-01-22 04:34:14 +00:00
|
|
|
left join custom_filters cf
|
2021-01-22 05:09:26 +00:00
|
|
|
on cf.account_id = #{@id} and (
|
|
|
|
st.text like '%' || cf.phrase || '%'
|
|
|
|
or rb.text like '%' || cf.phrase || '%')
|
2021-01-22 05:17:25 +00:00
|
|
|
where cf.id is null or st.account_id = #{@id}
|
2021-01-22 04:34:14 +00:00
|
|
|
"
|
|
|
|
# .reject { |status| FeedManager.instance.filter?(:home, status, @account.id) }
|
|
|
|
# Status.as_home_timeline(@account)
|
|
|
|
# .paginate_by_id(limit, max_id: max_id, since_id: since_id, min_id: min_id)
|
2019-07-02 08:10:25 +01:00
|
|
|
end
|
|
|
|
end
|