]> cat aescling's git repositories - mastodon.git/commitdiff
Add handler for salmons of undoing favourites
authorEugen Rochko <eugen@zeonfederated.com>
Sun, 12 Feb 2017 18:50:18 +0000 (19:50 +0100)
committerEugen Rochko <eugen@zeonfederated.com>
Sun, 12 Feb 2017 18:50:18 +0000 (19:50 +0100)
app/services/process_interaction_service.rb

index 8420ca35193c605edfbc235527f8effcf8fecf0b..c74ff9e22f3447b9e567bff541428b55de388207 100644 (file)
@@ -39,6 +39,8 @@ class ProcessInteractionService < BaseService
         unfollow!(account, target_account)
       when :favorite
         favourite!(xml, account)
+      when :unfavorite
+        unfavourite!(xml, account)
       when :post
         add_post!(body, account) if mentions_account?(xml, target_account)
       when :share
@@ -121,6 +123,12 @@ class ProcessInteractionService < BaseService
     NotifyService.new.call(current_status.account, favourite)
   end
 
+  def unfavourite!(xml, from_account)
+    current_status = status(xml)
+    favourite = current_status.favourites.where(account: from_account).first
+    favourite&.destroy
+  end
+
   def add_post!(body, account)
     process_feed_service.call(body, account)
   end