Adding a block model and filter mentions from blocked users (fix #60)
This commit is contained in:
parent
a488b05726
commit
9d59d7b463
11 changed files with 55 additions and 12 deletions
|
@ -10,7 +10,7 @@ class ApplicationController < ActionController::Base
|
|||
rescue_from ActionController::RoutingError, with: :not_found
|
||||
rescue_from ActiveRecord::RecordNotFound, with: :not_found
|
||||
|
||||
before_action :store_current_location, :unless => :devise_controller?
|
||||
before_action :store_current_location, unless: :devise_controller?
|
||||
|
||||
def raise_not_found
|
||||
raise ActionController::RoutingError, "No route matches #{params[:unmatched_route]}"
|
||||
|
|
|
@ -40,13 +40,13 @@ class FeedManager
|
|||
end
|
||||
|
||||
# Filter status out of the home feed if it is a reply to someone the user doesn't follow
|
||||
def filter_from_home?(status, follower)
|
||||
def filter_from_home?(status, receiver)
|
||||
replied_to_user = status.reply? ? status.thread.account : nil
|
||||
(status.reply? && !(follower.id == replied_to_user.id || replied_to_user.id == status.account_id || follower.following?(replied_to_user)))
|
||||
(status.reply? && !(receiver.id == replied_to_user.id || replied_to_user.id == status.account_id || receiver.following?(replied_to_user)))
|
||||
end
|
||||
|
||||
def filter_from_mentions?(status, follower)
|
||||
false
|
||||
def filter_from_mentions?(status, receiver)
|
||||
receiver.blocking?(status.account) || (status.reblog? && receiver.blocking?(status.reblog.account))
|
||||
end
|
||||
|
||||
def inline_render(target_account, status)
|
||||
|
|
|
@ -33,8 +33,12 @@ class Account < ApplicationRecord
|
|||
has_many :active_relationships, class_name: 'Follow', foreign_key: 'account_id', dependent: :destroy
|
||||
has_many :passive_relationships, class_name: 'Follow', foreign_key: 'target_account_id', dependent: :destroy
|
||||
|
||||
has_many :following, through: :active_relationships, source: :target_account
|
||||
has_many :followers, through: :passive_relationships, source: :account
|
||||
has_many :following, -> { order('follows.created_at desc') }, through: :active_relationships, source: :target_account
|
||||
has_many :followers, -> { order('follows.created_at desc') }, through: :passive_relationships, source: :account
|
||||
|
||||
# Block relationships
|
||||
has_many :block_relationships, class_name: 'Block', foreign_key: 'account_id', dependent: :destroy
|
||||
has_many :blocking, -> { order('blocks.created_at desc') }, through: :block_relationships, source: :target_account
|
||||
|
||||
has_many :media_attachments, dependent: :destroy
|
||||
|
||||
|
@ -57,6 +61,10 @@ class Account < ApplicationRecord
|
|||
following.include?(other_account)
|
||||
end
|
||||
|
||||
def blocking?(other_account)
|
||||
blocking.include?(other_account)
|
||||
end
|
||||
|
||||
def local?
|
||||
domain.nil?
|
||||
end
|
||||
|
|
7
app/models/block.rb
Normal file
7
app/models/block.rb
Normal file
|
@ -0,0 +1,7 @@
|
|||
class Block < ApplicationRecord
|
||||
belongs_to :account
|
||||
belongs_to :target_account, class_name: 'Account'
|
||||
|
||||
validates :account, :target_account, presence: true
|
||||
validates :account_id, uniqueness: { scope: :target_account_id }
|
||||
end
|
|
@ -47,7 +47,7 @@ class StreamEntry < ApplicationRecord
|
|||
end
|
||||
|
||||
def mentions
|
||||
activity.respond_to?(:mentions) ? activity.mentions.map { |x| x.account } : []
|
||||
activity.respond_to?(:mentions) ? activity.mentions.map(&:account) : []
|
||||
end
|
||||
|
||||
def activity
|
||||
|
|
|
@ -7,7 +7,7 @@ class PrecomputeFeedService < BaseService
|
|||
instant_return = []
|
||||
|
||||
Status.send("as_#{type}_timeline", account).order('created_at desc').limit(FeedManager::MAX_ITEMS).find_each do |status|
|
||||
next FeedManager.instance.filter?(type, status, account)
|
||||
next if FeedManager.instance.filter?(type, status, account)
|
||||
redis.zadd(FeedManager.instance.key(type, account.id), status.id, status.id)
|
||||
instant_return << status unless instant_return.size > limit
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue