0
0
Fork 0

Stop trying to shoehorn all Salmon updates into the poor database-connected

StreamEntry model. Simply render Salmon slaps as they are needed
This commit is contained in:
Eugen Rochko 2017-02-12 00:48:53 +01:00
parent 94d2182717
commit 0518492158
22 changed files with 304 additions and 266 deletions

View file

@ -2,27 +2,10 @@
class Block < ApplicationRecord
include Paginable
include Streamable
belongs_to :account
belongs_to :target_account, class_name: 'Account'
validates :account, :target_account, presence: true
validates :account_id, uniqueness: { scope: :target_account_id }
def verb
destroyed? ? :unblock : :block
end
def target
target_account
end
def hidden?
true
end
def title
destroyed? ? "#{account.acct} is no longer blocking #{target_account.acct}" : "#{account.acct} blocked #{target_account.acct}"
end
end

View file

@ -2,7 +2,6 @@
class Favourite < ApplicationRecord
include Paginable
include Streamable
belongs_to :account, inverse_of: :favourites
belongs_to :status, inverse_of: :favourites
@ -11,26 +10,6 @@ class Favourite < ApplicationRecord
validates :status_id, uniqueness: { scope: :account_id }
def verb
destroyed? ? :unfavorite : :favorite
end
def title
destroyed? ? "#{account.acct} no longer favourites a status by #{status.account.acct}" : "#{account.acct} favourited a status by #{status.account.acct}"
end
def thread
status
end
def target
thread
end
def hidden?
status.private_visibility?
end
before_validation do
self.status = status.reblog if status.reblog?
end

View file

@ -2,7 +2,6 @@
class Follow < ApplicationRecord
include Paginable
include Streamable
belongs_to :account
belongs_to :target_account, class_name: 'Account'
@ -11,16 +10,4 @@ class Follow < ApplicationRecord
validates :account, :target_account, presence: true
validates :account_id, uniqueness: { scope: :target_account_id }
def verb
destroyed? ? :unfollow : :follow
end
def target
target_account
end
def title
destroyed? ? "#{account.acct} is no longer following #{target_account.acct}" : "#{account.acct} started following #{target_account.acct}"
end
end

View file

@ -2,7 +2,6 @@
class FollowRequest < ApplicationRecord
include Paginable
include Streamable
belongs_to :account
belongs_to :target_account, class_name: 'Account'
@ -13,9 +12,6 @@ class FollowRequest < ApplicationRecord
validates :account_id, uniqueness: { scope: :target_account_id }
def authorize!
@verb = :authorize
@target = clone.freeze
account.follow!(target_account)
MergeWorker.perform_async(target_account.id, account.id)
@ -23,44 +19,6 @@ class FollowRequest < ApplicationRecord
end
def reject!
@verb = :reject
@target = clone.freeze
destroy!
end
def verb
destroyed? ? (@verb || :delete) : :request_friend
end
def target
if destroyed? && @verb
@target
else
target_account
end
end
def hidden?
true
end
def needs_stream_entry?
true
end
def title
if destroyed?
case @verb
when :authorize
"#{target_account.acct} authorized #{account.acct}'s request to follow"
when :reject
"#{target_account.acct} rejected #{account.acct}'s request to follow"
else
"#{account.acct} withdrew the request to follow #{target_account.acct}"
end
else
"#{account.acct} requested to follow #{target_account.acct}"
end
end
end

View file

@ -6,17 +6,13 @@ class StreamEntry < ApplicationRecord
belongs_to :account, inverse_of: :stream_entries
belongs_to :activity, polymorphic: true
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 :block, foreign_type: 'Block', foreign_key: 'activity_id'
belongs_to :follow_request, foreign_type: 'FollowRequest', foreign_key: 'activity_id'
belongs_to :status, foreign_type: 'Status', foreign_key: 'activity_id', inverse_of: :stream_entry
validates :account, :activity, presence: true
STATUS_INCLUDES = [:account, :stream_entry, :media_attachments, :tags, mentions: :account, reblog: [:stream_entry, :account, mentions: :account], thread: [:stream_entry, :account]].freeze
scope :with_includes, -> { includes(:account, status: STATUS_INCLUDES, favourite: [:account, :stream_entry, status: STATUS_INCLUDES], follow: [:target_account, :stream_entry]) }
scope :with_includes, -> { includes(:account, status: STATUS_INCLUDES) }
def object_type
if orphaned?