about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2017-06-08 15:07:39 +0200
committerGitHub <noreply@github.com>2017-06-08 15:07:39 +0200
commitb87eb8ea146a54fcfd2533f47622070d0f30a9fa (patch)
tree40aea8cfa0bd2a61cbf4c1a11884d3c7148e59da
parent8902e265b4efea68cafef790ee0e2870f62985cd (diff)
Fix #3378 - If favourite/reblog already exists, return it instead of failing (#3641)
-rw-r--r--app/services/favourite_service.rb4
-rw-r--r--app/services/reblog_service.rb4
2 files changed, 8 insertions, 0 deletions
diff --git a/app/services/favourite_service.rb b/app/services/favourite_service.rb
index f27145c96..90267af33 100644
--- a/app/services/favourite_service.rb
+++ b/app/services/favourite_service.rb
@@ -10,6 +10,10 @@ class FavouriteService < BaseService
   def call(account, status)
     authorize_with account, status, :show?
 
+    favourite = Favourite.find_by(account: account, status: status)
+
+    return favourite unless favourite.nil?
+
     favourite = Favourite.create!(account: account, status: status)
 
     if status.local?
diff --git a/app/services/reblog_service.rb b/app/services/reblog_service.rb
index a3636a283..ba24b1f9d 100644
--- a/app/services/reblog_service.rb
+++ b/app/services/reblog_service.rb
@@ -13,6 +13,10 @@ class ReblogService < BaseService
 
     authorize_with account, reblogged_status, :reblog?
 
+    reblog = account.statuses.find_by(reblog: reblogged_status)
+
+    return reblog unless reblog.nil?
+
     reblog = account.statuses.create!(reblog: reblogged_status, text: '')
 
     DistributionWorker.perform_async(reblog.id)