about summary refs log tree commit diff
path: root/app/models
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2016-10-03 17:11:54 +0200
committerEugen Rochko <eugen@zeonfederated.com>2016-10-03 17:12:13 +0200
commit9d59d7b463e7f31ceedf27775a7ee3e8e071b4a1 (patch)
tree6623a9795e3b6fc755b11caa132211f56acfed32 /app/models
parenta488b05726b2e93b5f66e93ef700a6bc32a3a029 (diff)
Adding a block model and filter mentions from blocked users (fix #60)
Diffstat (limited to 'app/models')
-rw-r--r--app/models/account.rb12
-rw-r--r--app/models/block.rb7
-rw-r--r--app/models/stream_entry.rb2
3 files changed, 18 insertions, 3 deletions
diff --git a/app/models/account.rb b/app/models/account.rb
index 2fbd5a655..518b55f19 100644
--- a/app/models/account.rb
+++ b/app/models/account.rb
@@ -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
diff --git a/app/models/block.rb b/app/models/block.rb
new file mode 100644
index 000000000..418afdbdf
--- /dev/null
+++ b/app/models/block.rb
@@ -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
diff --git a/app/models/stream_entry.rb b/app/models/stream_entry.rb
index 261ecda53..0df7ece60 100644
--- a/app/models/stream_entry.rb
+++ b/app/models/stream_entry.rb
@@ -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