From abfd0c107c8003ba06a118625c49d22df553696f Mon Sep 17 00:00:00 2001 From: Fire Demon Date: Fri, 14 Aug 2020 02:41:44 -0500 Subject: [Command Tags] Add #!notify toggle to allow toggling whether or not a post should be locally delivered to timelines/notifications --- app/services/fan_out_on_write_service.rb | 2 +- app/services/post_status_service.rb | 3 +++ app/services/process_mentions_service.rb | 2 +- app/services/update_status_service.rb | 2 ++ 4 files changed, 7 insertions(+), 2 deletions(-) (limited to 'app/services') diff --git a/app/services/fan_out_on_write_service.rb b/app/services/fan_out_on_write_service.rb index 6102ed1e5..1e12def33 100644 --- a/app/services/fan_out_on_write_service.rb +++ b/app/services/fan_out_on_write_service.rb @@ -92,7 +92,7 @@ class FanOutOnWriteService < BaseService Rails.logger.debug "Delivering status #{status.id} to public timeline" - Redis.current.set(key, true, ex: 6.hours) + Redis.current.set(key, 1, ex: 6.hours) Redis.current.publish('timeline:public', @payload) if status.local? diff --git a/app/services/post_status_service.rb b/app/services/post_status_service.rb index 82588d254..c6a983001 100644 --- a/app/services/post_status_service.rb +++ b/app/services/post_status_service.rb @@ -27,6 +27,7 @@ class PostStatusService < BaseService # @option [Enumerable] :mentions Optional array of Mentions to include # @option [Enumerable] :tags Option array of tag names to include # @option [Boolean] :publish If true, status will be published + # @option [Boolean] :notify If false, status will not be delivered to local timelines or mentions # @return [Status] def call(account, options = {}) @account = account @@ -91,6 +92,8 @@ class PostStatusService < BaseService @status = @account.statuses.create!(status_attributes) end + @status.notify = @options[:notify] if @options[:notify].present? + process_command_tags_service.call(@account, @status) process_hashtags_service.call(@status, nil, @tag_names) process_mentions_service.call(@status, mentions: @mentions, deliver: @options[:publish]) diff --git a/app/services/process_mentions_service.rb b/app/services/process_mentions_service.rb index 3752cebb9..fea00ef4f 100644 --- a/app/services/process_mentions_service.rb +++ b/app/services/process_mentions_service.rb @@ -31,7 +31,7 @@ class ProcessMentionsService < BaseService mentioned_account = mention.account if mentioned_account.local? - LocalNotificationWorker.perform_async(mentioned_account.id, mention.id, mention.class.name) unless mention.silent? + LocalNotificationWorker.perform_async(mentioned_account.id, mention.id, mention.class.name) unless !@status.notify? || mention.silent? elsif mentioned_account.activitypub? && !@status.local_only? ActivityPub::DeliveryWorker.perform_async(activitypub_json(mentioned_account.domain), mention.status.account_id, mentioned_account.inbox_url) end diff --git a/app/services/update_status_service.rb b/app/services/update_status_service.rb index 05586aa1b..327cc74ea 100644 --- a/app/services/update_status_service.rb +++ b/app/services/update_status_service.rb @@ -147,6 +147,8 @@ class UpdateStatusService < BaseService ActivityPub::DistributionWorker.perform_async(@status.id) if @status.local? && !@status.local_only? + return unless @status.notify? + mentions = @status.active_mentions.includes(:account).where(id: @new_mention_ids, accounts: { domain: nil }) mentions.each { |mention| LocalNotificationWorker.perform_async(mention.account.id, mention.id, mention.class.name) } end -- cgit