Adding routes to follow, unfollow, favourite and reblog (locally known models)
This commit is contained in:
parent
aab330eb2d
commit
c605b828b5
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
class FavouriteService < BaseService
|
||||
# Favourite a status and notify remote user
|
||||
# @param [Account] account
|
||||
# @param [Status] status
|
||||
# @return [Favourite]
|
||||
def call(account, status)
|
||||
favourite = Favourite.create!(account: account, status: status)
|
||||
account.ping!(account_url(account, format: 'atom'), [Rails.configuration.x.hub_url])
|
||||
return favourite if status.local?
|
||||
send_interaction_service.(favourite.stream_entry, status.account)
|
||||
favourite
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def send_interaction_service
|
||||
@send_interaction_service ||= SendInteractionService.new
|
||||
end
|
||||
end
|
|
@ -9,7 +9,17 @@ Rails.application.routes.draw do
|
|||
}
|
||||
|
||||
resources :accounts, path: 'users', only: [:show], param: :username do
|
||||
resources :stream_entries, path: 'updates', only: [:show]
|
||||
member do
|
||||
post :follow
|
||||
post :unfollow
|
||||
end
|
||||
|
||||
resources :stream_entries, path: 'updates', only: [:show] do
|
||||
member do
|
||||
post :reblog
|
||||
post :favourite
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
namespace :api do
|
||||
|
|
Loading…
Reference in New Issue