about summary refs log tree commit diff
path: root/app/models
diff options
context:
space:
mode:
Diffstat (limited to 'app/models')
-rw-r--r--app/models/block.rb1
-rw-r--r--app/models/favourite.rb4
-rw-r--r--app/models/follow_request.rb4
-rw-r--r--app/models/notification.rb18
-rw-r--r--app/models/remote_follow.rb13
-rw-r--r--app/models/status.rb19
-rw-r--r--app/models/user.rb2
7 files changed, 50 insertions, 11 deletions
diff --git a/app/models/block.rb b/app/models/block.rb
index ad225d180..c2067c5b8 100644
--- a/app/models/block.rb
+++ b/app/models/block.rb
@@ -1,6 +1,7 @@
 # frozen_string_literal: true
 
 class Block < ApplicationRecord
+  include Paginable
   include Streamable
 
   belongs_to :account
diff --git a/app/models/favourite.rb b/app/models/favourite.rb
index 2fc3d18cd..147105e48 100644
--- a/app/models/favourite.rb
+++ b/app/models/favourite.rb
@@ -29,6 +29,10 @@ class Favourite < ApplicationRecord
     thread
   end
 
+  def hidden?
+    status.private_visibility?
+  end
+
   before_validation do
     self.status = status.reblog if status.reblog?
   end
diff --git a/app/models/follow_request.rb b/app/models/follow_request.rb
index 132316fb4..8eef3abf4 100644
--- a/app/models/follow_request.rb
+++ b/app/models/follow_request.rb
@@ -1,9 +1,13 @@
 # frozen_string_literal: true
 
 class FollowRequest < ApplicationRecord
+  include Paginable
+
   belongs_to :account
   belongs_to :target_account, class_name: 'Account'
 
+  has_one :notification, as: :activity, dependent: :destroy
+
   validates :account, :target_account, presence: true
   validates :account_id, uniqueness: { scope: :target_account_id }
 
diff --git a/app/models/notification.rb b/app/models/notification.rb
index 9d076ad41..c0b5c45a8 100644
--- a/app/models/notification.rb
+++ b/app/models/notification.rb
@@ -8,16 +8,18 @@ class Notification < ApplicationRecord
   belongs_to :from_account, class_name: 'Account'
   belongs_to :activity, polymorphic: true
 
-  belongs_to :mention,   foreign_type: 'Mention',   foreign_key: 'activity_id'
-  belongs_to :status,    foreign_type: 'Status',    foreign_key: 'activity_id'
-  belongs_to :follow,    foreign_type: 'Follow',    foreign_key: 'activity_id'
-  belongs_to :favourite, foreign_type: 'Favourite', foreign_key: 'activity_id'
+  belongs_to :mention,        foreign_type: 'Mention',       foreign_key: 'activity_id'
+  belongs_to :status,         foreign_type: 'Status',        foreign_key: 'activity_id'
+  belongs_to :follow,         foreign_type: 'Follow',        foreign_key: 'activity_id'
+  belongs_to :follow_request, foreign_type: 'FollowRequest', foreign_key: 'activity_id'
+  belongs_to :favourite,      foreign_type: 'Favourite',     foreign_key: 'activity_id'
 
   validates :account_id, uniqueness: { scope: [:activity_type, :activity_id] }
 
   STATUS_INCLUDES = [:account, :stream_entry, :media_attachments, :tags, mentions: :account, reblog: [:stream_entry, :account, :media_attachments, :tags, mentions: :account]].freeze
 
   scope :cache_ids, -> { select(:id, :updated_at, :activity_type, :activity_id) }
+  scope :browserable, -> { where.not(activity_type: ['FollowRequest']) }
 
   cache_associated :from_account, status: STATUS_INCLUDES, mention: [status: STATUS_INCLUDES], favourite: [:account, status: STATUS_INCLUDES], follow: :account
 
@@ -30,7 +32,7 @@ class Notification < ApplicationRecord
     when 'Status'
       :reblog
     else
-      activity_type.downcase.to_sym
+      activity_type.underscore.to_sym
     end
   end
 
@@ -43,6 +45,10 @@ class Notification < ApplicationRecord
     end
   end
 
+  def browserable?
+    type != :follow_request
+  end
+
   class << self
     def reload_stale_associations!(cached_items)
       account_ids = cached_items.map(&:from_account_id).uniq
@@ -61,7 +67,7 @@ class Notification < ApplicationRecord
 
   def set_from_account
     case activity_type
-    when 'Status', 'Follow', 'Favourite'
+    when 'Status', 'Follow', 'Favourite', 'FollowRequest'
       self.from_account_id = activity(false)&.account_id
     when 'Mention'
       self.from_account_id = activity(false)&.status&.account_id
diff --git a/app/models/remote_follow.rb b/app/models/remote_follow.rb
new file mode 100644
index 000000000..13281a4fc
--- /dev/null
+++ b/app/models/remote_follow.rb
@@ -0,0 +1,13 @@
+# frozen_string_literal: true
+
+class RemoteFollow
+  include ActiveModel::Validations
+
+  attr_accessor :acct
+
+  validates :acct, presence: true
+
+  def initialize(attrs = {})
+    @acct = attrs[:acct]
+  end
+end
diff --git a/app/models/status.rb b/app/models/status.rb
index dc7fc60d7..bc595c93b 100644
--- a/app/models/status.rb
+++ b/app/models/status.rb
@@ -8,6 +8,7 @@ class Status < ApplicationRecord
   enum visibility: [:public, :unlisted, :private], _suffix: :visibility
 
   belongs_to :account, inverse_of: :statuses
+  belongs_to :in_reply_to_account, foreign_key: 'in_reply_to_account_id', class_name: 'Account'
 
   belongs_to :thread, foreign_key: 'in_reply_to_id', class_name: 'Status', inverse_of: :replies
   belongs_to :reblog, foreign_key: 'reblog_of_id', class_name: 'Status', inverse_of: :reblogs, touch: true
@@ -31,7 +32,6 @@ class Status < ApplicationRecord
 
   scope :remote, -> { where.not(uri: nil) }
   scope :local, -> { where(uri: nil) }
-  scope :permitted_for, ->(target_account, account) { account&.id == target_account.id || account&.following?(target_account) ? where('1=1') : where.not(visibility: :private) }
 
   cache_associated :account, :media_attachments, :tags, :stream_entry, mentions: :account, reblog: [:account, :stream_entry, :tags, :media_attachments, mentions: :account], thread: :account
 
@@ -72,7 +72,7 @@ class Status < ApplicationRecord
   end
 
   def permitted?(other_account = nil)
-    private_visibility? ? (account.id == other_account&.id || other_account&.following?(account)) : true
+    private_visibility? ? (account.id == other_account&.id || other_account&.following?(account)) : other_account.nil? || !account.blocking?(other_account)
   end
 
   def ancestors(account = nil)
@@ -145,6 +145,16 @@ class Status < ApplicationRecord
       end
     end
 
+    def permitted_for(target_account, account)
+      if account&.id == target_account.id || account&.following?(target_account)
+        where('1 = 1')
+      elsif !account.nil? && target_account.blocking?(account)
+        where('1 = 0')
+      else
+        where.not(visibility: :private)
+      end
+    end
+
     private
 
     def filter_timeline(query, account)
@@ -161,8 +171,9 @@ class Status < ApplicationRecord
 
   before_validation do
     text.strip!
-    self.reblog = reblog.reblog if reblog? && reblog.reblog?
-    self.in_reply_to_account_id = thread.account_id if reply?
+
+    self.reblog                 = reblog.reblog if reblog? && reblog.reblog?
+    self.in_reply_to_account_id = (thread.account_id == account_id && thread.reply? ? thread.in_reply_to_account_id : thread.account_id) if reply?
     self.visibility             = (account.locked? ? :private : :public) if visibility.nil?
   end
 
diff --git a/app/models/user.rb b/app/models/user.rb
index 3fc028a6a..d5a52da06 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -15,7 +15,7 @@ class User < ApplicationRecord
   scope :admins,   -> { where(admin: true) }
 
   has_settings do |s|
-    s.key :notification_emails, defaults: { follow: false, reblog: false, favourite: false, mention: false }
+    s.key :notification_emails, defaults: { follow: false, reblog: false, favourite: false, mention: false, follow_request: true }
     s.key :interactions, defaults: { must_be_follower: false, must_be_following: false }
   end