about summary refs log tree commit diff
path: root/app/controllers/stream_entries_controller.rb
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2016-03-06 12:51:55 +0100
committerEugen Rochko <eugen@zeonfederated.com>2016-03-06 12:51:55 +0100
commitc605b828b53165cb0161a1885e03202013b63f52 (patch)
treea667e98afc79ca3eaa49f46955529f4dc5f2f101 /app/controllers/stream_entries_controller.rb
parentaab330eb2d39711e19753e89ba7ff67521929cf0 (diff)
Adding routes to follow, unfollow, favourite and reblog (locally known models)
Diffstat (limited to 'app/controllers/stream_entries_controller.rb')
-rw-r--r--app/controllers/stream_entries_controller.rb16
1 files changed, 16 insertions, 0 deletions
diff --git a/app/controllers/stream_entries_controller.rb b/app/controllers/stream_entries_controller.rb
index cbf7bfdff..293cc6d81 100644
--- a/app/controllers/stream_entries_controller.rb
+++ b/app/controllers/stream_entries_controller.rb
@@ -3,6 +3,8 @@ class StreamEntriesController < ApplicationController
 
   before_action :set_account
   before_action :set_stream_entry
+  before_action :authenticate_user!, only: [:reblog, :favourite]
+  before_action :only_statuses!, only: [:reblog, :favourite]
 
   def show
     @type = @stream_entry.activity_type.downcase
@@ -13,6 +15,16 @@ class StreamEntriesController < ApplicationController
     end
   end
 
+  def reblog
+    ReblogService.new.(current_user.account, @stream_entry.activity)
+    redirect_to root_path
+  end
+
+  def favourite
+    FavouriteService.new.(current_user.account, @stream_entry.activity)
+    redirect_to root_path
+  end
+
   private
 
   def set_account
@@ -22,4 +34,8 @@ class StreamEntriesController < ApplicationController
   def set_stream_entry
     @stream_entry = @account.stream_entries.find(params[:id])
   end
+
+  def only_statuses!
+    redirect_to root_url unless @stream_entry.activity_type == 'Status'
+  end
 end