about summary refs log tree commit diff
path: root/app/models
diff options
context:
space:
mode:
authoraschmitz <aschmitz@lardbucket.org>2017-11-09 08:41:10 -0600
committeraschmitz <aschmitz@lardbucket.org>2017-11-09 08:41:10 -0600
commit49445150202f0bdaae942b9ae1ba44802a1c22e9 (patch)
tree5d305bb395d7e61ec6b2f0e4b48229ebf216be8d /app/models
parent870d71b78be74b7fab4892a79a87aff39b1e2726 (diff)
"Show reblogs" per-follower UI/database changes
TODO:

* Tests (particularly for FollowRequests).
* Anything to respect the setting when putting reblogs in timelines.
Diffstat (limited to 'app/models')
-rw-r--r--app/models/concerns/account_interactions.rb23
-rw-r--r--app/models/follow.rb1
-rw-r--r--app/models/follow_request.rb3
3 files changed, 22 insertions, 5 deletions
diff --git a/app/models/concerns/account_interactions.rb b/app/models/concerns/account_interactions.rb
index 0afdebf89..088fef4da 100644
--- a/app/models/concerns/account_interactions.rb
+++ b/app/models/concerns/account_interactions.rb
@@ -5,7 +5,11 @@ module AccountInteractions
 
   class_methods do
     def following_map(target_account_ids, account_id)
-      follow_mapping(Follow.where(target_account_id: target_account_ids, account_id: account_id), :target_account_id)
+      Follow.where(target_account_id: target_account_ids, account_id: account_id).each_with_object({}) do |follow, mapping|
+        mapping[follow.target_account_id] = {
+          reblogs: follow.show_reblogs?
+        }
+      end
     end
 
     def followed_by_map(target_account_ids, account_id)
@@ -25,7 +29,11 @@ module AccountInteractions
     end
 
     def requested_map(target_account_ids, account_id)
-      follow_mapping(FollowRequest.where(target_account_id: target_account_ids, account_id: account_id), :target_account_id)
+      FollowRequest.where(target_account_id: target_account_ids, account_id: account_id).each_with_object({}) do |follow_request, mapping|
+        mapping[follow_request.target_account_id] = {
+          reblogs: follow_request.show_reblogs?
+        }
+      end
     end
 
     def domain_blocking_map(target_account_ids, account_id)
@@ -66,8 +74,15 @@ module AccountInteractions
     has_many :domain_blocks, class_name: 'AccountDomainBlock', dependent: :destroy
   end
 
-  def follow!(other_account)
-    active_relationships.find_or_create_by!(target_account: other_account)
+  def follow!(other_account, reblogs: nil)
+    reblogs = true if reblogs.nil?
+    rel = active_relationships.create_with(show_reblogs: reblogs).find_or_create_by!(target_account: other_account)
+    if rel.show_reblogs != reblogs
+      rel.show_reblogs = reblogs
+      rel.save!
+    end
+    
+    rel
   end
 
   def block!(other_account)
diff --git a/app/models/follow.rb b/app/models/follow.rb
index 667720a88..a8ddcb7f0 100644
--- a/app/models/follow.rb
+++ b/app/models/follow.rb
@@ -8,6 +8,7 @@
 #  account_id        :integer          not null
 #  id                :integer          not null, primary key
 #  target_account_id :integer          not null
+#  show_reblogs      :boolean          default(TRUE), not null
 #
 
 class Follow < ApplicationRecord
diff --git a/app/models/follow_request.rb b/app/models/follow_request.rb
index 60036d903..0608ffabc 100644
--- a/app/models/follow_request.rb
+++ b/app/models/follow_request.rb
@@ -8,6 +8,7 @@
 #  account_id        :integer          not null
 #  id                :integer          not null, primary key
 #  target_account_id :integer          not null
+#  show_reblogs      :boolean          default(TRUE), not null
 #
 
 class FollowRequest < ApplicationRecord
@@ -21,7 +22,7 @@ class FollowRequest < ApplicationRecord
   validates :account_id, uniqueness: { scope: :target_account_id }
 
   def authorize!
-    account.follow!(target_account)
+    account.follow!(target_account, reblogs: reblogs)
     MergeWorker.perform_async(target_account.id, account.id)
 
     destroy!