From c605b828b53165cb0161a1885e03202013b63f52 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Sun, 6 Mar 2016 12:51:55 +0100 Subject: Adding routes to follow, unfollow, favourite and reblog (locally known models) --- app/controllers/accounts_controller.rb | 11 +++++++++++ app/controllers/stream_entries_controller.rb | 16 ++++++++++++++++ 2 files changed, 27 insertions(+) (limited to 'app/controllers') diff --git a/app/controllers/accounts_controller.rb b/app/controllers/accounts_controller.rb index 156926927..9e2e160b2 100644 --- a/app/controllers/accounts_controller.rb +++ b/app/controllers/accounts_controller.rb @@ -3,6 +3,7 @@ class AccountsController < ApplicationController before_action :set_account before_action :set_webfinger_header + before_action :authenticate_user!, only: [:follow, :unfollow] def show @statuses = @account.statuses.order('id desc').includes(thread: [:account], reblog: [:account], stream_entry: []) @@ -13,6 +14,16 @@ class AccountsController < ApplicationController end end + def follow + current_user.account.follow!(@account) + redirect_to root_path + end + + def unfollow + current_user.account.unfollow!(@account) + redirect_to root_path + end + private def set_account 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 -- cgit