about summary refs log tree commit diff
path: root/app/services
diff options
context:
space:
mode:
Diffstat (limited to 'app/services')
-rw-r--r--app/services/fan_out_on_write_service.rb12
-rw-r--r--app/services/follow_service.rb2
-rw-r--r--app/services/notify_service.rb5
-rw-r--r--app/services/search_service.rb2
-rw-r--r--app/services/send_push_notification_service.rb28
-rw-r--r--app/services/warm_cache_service.rb8
6 files changed, 20 insertions, 37 deletions
diff --git a/app/services/fan_out_on_write_service.rb b/app/services/fan_out_on_write_service.rb
index 13aad4632..71f6cbca1 100644
--- a/app/services/fan_out_on_write_service.rb
+++ b/app/services/fan_out_on_write_service.rb
@@ -34,13 +34,21 @@ class FanOutOnWriteService < BaseService
 
   def deliver_to_hashtags(status)
     Rails.logger.debug "Delivering status #{status.id} to hashtags"
+
+    payload = FeedManager.instance.inline_render(nil, 'api/v1/statuses/show', status)
+
     status.tags.find_each do |tag|
-      FeedManager.instance.broadcast("hashtag:#{tag.name}", event: 'update', payload: FeedManager.instance.inline_render(nil, 'api/v1/statuses/show', status))
+      FeedManager.instance.broadcast("hashtag:#{tag.name}", event: 'update', payload: payload)
+      FeedManager.instance.broadcast("hashtag:#{tag.name}:local", event: 'update', payload: payload) if status.account.local?
     end
   end
 
   def deliver_to_public(status)
     Rails.logger.debug "Delivering status #{status.id} to public timeline"
-    FeedManager.instance.broadcast(:public, event: 'update', payload: FeedManager.instance.inline_render(nil, 'api/v1/statuses/show', status))
+
+    payload = FeedManager.instance.inline_render(nil, 'api/v1/statuses/show', status)
+
+    FeedManager.instance.broadcast(:public, event: 'update', payload: payload)
+    FeedManager.instance.broadcast('public:local', event: 'update', payload: payload) if status.account.local?
   end
 end
diff --git a/app/services/follow_service.rb b/app/services/follow_service.rb
index 87c16a621..9f34cb6ac 100644
--- a/app/services/follow_service.rb
+++ b/app/services/follow_service.rb
@@ -8,7 +8,7 @@ class FollowService < BaseService
     target_account = follow_remote_account_service.call(uri)
 
     raise ActiveRecord::RecordNotFound if target_account.nil? || target_account.id == source_account.id || target_account.suspended?
-    raise Mastodon::NotPermitted       if target_account.blocking?(source_account)
+    raise Mastodon::NotPermitted       if target_account.blocking?(source_account) || source_account.blocking?(target_account)
 
     if target_account.locked?
       request_follow(source_account, target_account)
diff --git a/app/services/notify_service.rb b/app/services/notify_service.rb
index 0cc3cd618..942cd9d21 100644
--- a/app/services/notify_service.rb
+++ b/app/services/notify_service.rb
@@ -10,7 +10,6 @@ class NotifyService < BaseService
 
     create_notification
     send_email if email_enabled?
-    send_push_notification
   rescue ActiveRecord::RecordInvalid
     return
   end
@@ -58,10 +57,6 @@ class NotifyService < BaseService
     NotificationMailer.send(@notification.type, @recipient, @notification).deliver_later
   end
 
-  def send_push_notification
-    PushNotificationWorker.perform_async(@notification.id)
-  end
-
   def email_enabled?
     @recipient.user.settings.notification_emails[@notification.type]
   end
diff --git a/app/services/search_service.rb b/app/services/search_service.rb
index e9a27f136..04de8a134 100644
--- a/app/services/search_service.rb
+++ b/app/services/search_service.rb
@@ -17,7 +17,7 @@ class SearchService < BaseService
     results = results.limit(limit).to_a
     results = [exact_match] + results.reject { |a| a.id == exact_match.id } if exact_match
 
-    if resolve && results.empty? && !domain.nil?
+    if resolve && !exact_match && !domain.nil?
       results = [FollowRemoteAccountService.new.call("#{username}@#{domain}")]
     end
 
diff --git a/app/services/send_push_notification_service.rb b/app/services/send_push_notification_service.rb
deleted file mode 100644
index 526ae20cb..000000000
--- a/app/services/send_push_notification_service.rb
+++ /dev/null
@@ -1,28 +0,0 @@
-# frozen_string_literal: true
-
-class SendPushNotificationService < BaseService
-  def call(notification)
-    return if ENV['FCM_API_KEY'].blank?
-
-    devices = Device.where(account: notification.account).pluck(:registration_id)
-    fcm     = FCM.new(ENV['FCM_API_KEY'])
-
-    response = fcm.send(devices, data: { notification_id: notification.id }, collapse_key: :notifications, priority: :high)
-    handle_response(response)
-  end
-
-  private
-
-  def handle_response(response)
-    update_canonical_ids(response[:canonical_ids]) if response[:canonical_ids]
-    remove_bad_ids(response[:not_registered_ids])  if response[:not_registered_ids]
-  end
-
-  def update_canonical_ids(ids)
-    ids.each { |pair| Device.find_by(registration_id: pair[:old]).update(registration_id: pair[:new]) }
-  end
-
-  def remove_bad_ids(bad_ids)
-    Device.where(registration_id: bad_ids).delete_all unless bad_ids.empty?
-  end
-end
diff --git a/app/services/warm_cache_service.rb b/app/services/warm_cache_service.rb
new file mode 100644
index 000000000..091a471ff
--- /dev/null
+++ b/app/services/warm_cache_service.rb
@@ -0,0 +1,8 @@
+# frozen_string_literal: true
+
+class WarmCacheService < BaseService
+  def call(cacheable)
+    full_item = cacheable.class.where(id: cacheable.id).with_includes.first
+    Rails.cache.write(cacheable.cache_key, full_item)
+  end
+end