about summary refs log tree commit diff
path: root/app
diff options
context:
space:
mode:
authorFire Demon <firedemon@creature.cafe>2020-09-20 22:52:50 -0500
committerFire Demon <firedemon@creature.cafe>2020-09-20 23:07:30 -0500
commit64694de343737360e797a92a0a6c0e88695facda (patch)
treee31a8d7eb5cb909be89df96e8185b20183ed5a22 /app
parente3cb18ba7520997a0f605c7f90db258ccccd5e33 (diff)
Monsterfork v1-style curated Federated timeline
Diffstat (limited to 'app')
-rw-r--r--app/controllers/api/v1/statuses/bookmarks_controller.rb6
-rw-r--r--app/models/public_feed.rb7
-rw-r--r--app/models/status.rb10
-rw-r--r--app/services/fan_out_on_write_service.rb37
-rw-r--r--app/services/favourite_service.rb6
-rw-r--r--app/services/reblog_service.rb6
6 files changed, 46 insertions, 26 deletions
diff --git a/app/controllers/api/v1/statuses/bookmarks_controller.rb b/app/controllers/api/v1/statuses/bookmarks_controller.rb
index 19963c002..1bf698a78 100644
--- a/app/controllers/api/v1/statuses/bookmarks_controller.rb
+++ b/app/controllers/api/v1/statuses/bookmarks_controller.rb
@@ -9,6 +9,7 @@ class Api::V1::Statuses::BookmarksController < Api::BaseController
 
   def create
     current_account.bookmarks.find_or_create_by!(account: current_account, status: @status)
+    curate! unless @status.curated? || !@status.published?
     render json: @status, serializer: REST::StatusSerializer
   end
 
@@ -37,4 +38,9 @@ class Api::V1::Statuses::BookmarksController < Api::BaseController
   rescue Mastodon::NotPermittedError
     not_found
   end
+
+  def curate!
+    @status.curate!
+    DistributionWorker.perform_async(@status.id)
+  end
 end
diff --git a/app/models/public_feed.rb b/app/models/public_feed.rb
index 2839da5cb..afde8aa65 100644
--- a/app/models/public_feed.rb
+++ b/app/models/public_feed.rb
@@ -26,7 +26,8 @@ class PublicFeed < Feed
     scope.merge!(without_replies_scope) unless with_replies?
     scope.merge!(without_reblogs_scope) unless with_reblogs?
     scope.merge!(local_only_scope) if local_only?
-    scope.merge!(remote_only_scope) if remote_only?
+    #scope.merge!(remote_only_scope) if remote_only?
+    scope.merge!(curated_scope) unless remote_only?
     scope.merge!(account_filters_scope) if account?
     scope.merge!(media_only_scope) if media_only?
 
@@ -79,6 +80,10 @@ class PublicFeed < Feed
     Status.remote
   end
 
+  def curated_scope
+    Status.curated
+  end
+
   def without_replies_scope
     Status.without_replies
   end
diff --git a/app/models/status.rb b/app/models/status.rb
index c79cbeaf9..ba8b4ff2b 100644
--- a/app/models/status.rb
+++ b/app/models/status.rb
@@ -35,6 +35,7 @@
 #  expires_at             :datetime
 #  publish_at             :datetime
 #  originally_local_only  :boolean          default(FALSE), not null
+#  curated                :boolean          default(FALSE), not null
 #
 
 # rubocop:disable Metrics/ClassLength
@@ -142,6 +143,7 @@ class Status < ApplicationRecord
   scope :replies, -> { where(reply: true) }
   scope :expired, -> { published.where('statuses.expires_at IS NOT NULL AND statuses.expires_at < ?', Time.now.utc) }
   scope :ready_to_publish, -> { unpublished.where('statuses.publish_at IS NOT NULL AND statuses.publish_at < ?', Time.now.utc) }
+  scope :curated, -> { where(curated: true) }
 
   scope :not_hidden_by_account, ->(account) do
     left_outer_joins(:mutes, :conversation_mute).where('(status_mutes.account_id IS NULL OR status_mutes.account_id != ?) AND (conversation_mutes.account_id IS NULL OR conversation_mutes.account_id != ?)', account.id, account.id)
@@ -308,6 +310,14 @@ class Status < ApplicationRecord
     update_status_stat!(key => [public_send(key) - 1, 0].max)
   end
 
+  def curate!
+    update_column(:curated, true) if public_visibility? && !curated
+  end
+
+  def uncurate!
+    update_column(:curated, false) if curated
+  end
+
   def notify=(value)
     Redis.current.set("status:#{id}:notify", value ? 1 : 0, ex: 1.hour)
     @notify = value
diff --git a/app/services/fan_out_on_write_service.rb b/app/services/fan_out_on_write_service.rb
index 5b5d2c0a1..1fa8b2520 100644
--- a/app/services/fan_out_on_write_service.rb
+++ b/app/services/fan_out_on_write_service.rb
@@ -22,23 +22,18 @@ class FanOutOnWriteService < BaseService
     end
 
     return if status.account.silenced?
+    return if status.reblog? && !Setting.show_reblogs_in_public_timelines
 
-    render_anonymous_payload(status.proper)
-    deliver_to_hashtags(status)
-
-    if status.reblog?
-      if status.local? && status.reblog.public_visibility? && !status.reblog.account.silenced?
-        deliver_to_public(status.reblog)
-        deliver_to_media(status.reblog) if status.reblog.media_attachments.any?
-      end
-      return
+    if status.distributable?
+      render_anonymous_payload(status)
+      deliver_to_hashtags(status)
     end
 
-    deliver_to_hashtags(status) if status.distributable?
-    return if !status.public_visibility? || (status.reply? && status.in_reply_to_account_id != status.account_id)
+    return unless status.public_visibility?
+    return if status.reply? && status.in_reply_to_account_id != status.account_id && !Setting.show_replies_in_public_timelines
 
-    deliver_to_media(status, true) if status.media_attachments.any?
-    deliver_to_public(status, true)
+    deliver_to_public(status)
+    deliver_to_media(status) if status.media_attachments.any?
   end
 
   private
@@ -93,26 +88,18 @@ class FanOutOnWriteService < BaseService
     end
   end
 
-  def deliver_to_public(status, tavern = false)
-    key = "timeline:public:#{status.id}"
-    return if Redis.current.get(key)
-
+  def deliver_to_public(status)
     Rails.logger.debug "Delivering status #{status.id} to public timeline"
 
-    Redis.current.set(key, 1, ex: 2.hours)
-
-    Redis.current.publish('timeline:public', @payload) if status.local? || !tavern
+    Redis.current.publish('timeline:public', @payload) if status.curated?
     Redis.current.publish('timeline:public:local', @payload) if status.local?
     Redis.current.publish('timeline:public:remote', @payload)
   end
 
-  def deliver_to_media(status, tavern = false)
-    key = "timeline:public:#{status.id}"
-    return if Redis.current.get(key)
-
+  def deliver_to_media(status)
     Rails.logger.debug "Delivering status #{status.id} to media timeline"
 
-    Redis.current.publish('timeline:public:media', @payload) if status.local? || !tavern
+    Redis.current.publish('timeline:public:media', @payload) if status.curated?
     Redis.current.publish('timeline:public:local:media', @payload) if status.local?
     Redis.current.publish('timeline:public:remote:media', @payload)
   end
diff --git a/app/services/favourite_service.rb b/app/services/favourite_service.rb
index 02b26458a..af08f5267 100644
--- a/app/services/favourite_service.rb
+++ b/app/services/favourite_service.rb
@@ -16,6 +16,7 @@ class FavouriteService < BaseService
     return favourite unless favourite.nil?
 
     favourite = Favourite.create!(account: account, status: status)
+    curate!(status) unless status.curated? || !status.published?
 
     create_notification(favourite)
     bump_potential_friendship(account, status)
@@ -44,4 +45,9 @@ class FavouriteService < BaseService
   def build_json(favourite)
     Oj.dump(serialize_payload(favourite, ActivityPub::LikeSerializer))
   end
+
+  def curate!(status)
+    status.curate!
+    DistributionWorker.perform_async(status.id)
+  end
 end
diff --git a/app/services/reblog_service.rb b/app/services/reblog_service.rb
index ddd22e379..86b37560a 100644
--- a/app/services/reblog_service.rb
+++ b/app/services/reblog_service.rb
@@ -29,6 +29,7 @@ class ReblogService < BaseService
     end
 
     reblog = account.statuses.create!(reblog: reblogged_status, text: '', visibility: visibility, rate_limit: options[:with_rate_limit], sensitive: true, spoiler_text: options[:spoiler_text] || '', published: true)
+    curate!(reblogged_status) unless reblogged_status.curated? || !reblogged_status.published?
 
     DistributionWorker.perform_async(reblog.id)
     ActivityPub::DistributionWorker.perform_async(reblog.id) unless reblogged_status.local_only?
@@ -62,4 +63,9 @@ class ReblogService < BaseService
   def build_json(reblog)
     Oj.dump(serialize_payload(ActivityPub::ActivityPresenter.from_status(reblog, embed: false), ActivityPub::ActivitySerializer, signer: reblog.account, target_domain: reblog.account.domain))
   end
+
+  def curate!(status)
+    status.curate!
+    DistributionWorker.perform_async(status.id)
+  end
 end