Mastodonを読む/フォロー時の処理その2(サーバ側)
をテンプレートにして作成
[
トップ
] [
新規
|
一覧
|
単語検索
|
最終更新
|
ヘルプ
]
開始行:
[[Mastodonを読む]]
#contents
*はじめに [#h2593682]
前回は、クライアント(画面)でフォローボタンを押したとき...
*app/controllers/api/v1/accounts_controller.rb [#i70dad46]
フォローボタンが押されると、サーバ側の「/api/v1/accounts/...
#code(Ruby){{
def follow
FollowService.new.call(current_user.account, @account...
set_relationship
render :relationship
end
}}
@accountはbefore_actionを使用して設定されています。
#code(Ruby){{
before_action :set_account, except: [:verify_credential...
def set_account
@account = Account.find(params[:id])
end
}}
**app/models/account.rb [#hc93614e]
Accountのacctはインスタンスも含めてアカウントを識別するた...
#code(Ruby){{
def local?
domain.nil?
end
def acct
local? ? username : "#{username}@#{domain}"
end
}}
さて、ここで気づくことがあります。上のコードを考えると、...
では、どうやって別インスタンスのアカウント情報を取ってく...
*app/services/follow_service.rb [#c74027ee]
#code(Ruby){{
class FollowService < BaseService
include StreamEntryRenderer
# Follow a remote user, notify remote user about the fo...
# @param [Account] source_account From which to follow
# @param [String] uri User URI to follow in the form of...
def call(source_account, uri)
target_account = FollowRemoteAccountService.new.call(...
raise ActiveRecord::RecordNotFound if target_account....
raise Mastodon::NotPermittedError if target_account....
if target_account.locked?
request_follow(source_account, target_account)
else
direct_follow(source_account, target_account)
end
end
}}
FollowRemoteAccountServiceはaccountsテーブルにアカウント...
といいつつ一言だけ。WebFingerでは特定のURLにアクセスする...
以下のURLへのアクセスが行われ、情報が返されるようです。
#code(Ruby){{
get '.well-known/webfinger', to: 'well_known/webfinger#...
}}
さて、話を戻して、鍵付きかどうかで処理が分かれていますが...
#code(Ruby){{
def direct_follow(source_account, target_account)
follow = source_account.follow!(target_account)
if target_account.local?
NotifyService.new.call(target_account, follow)
else
Pubsubhubbub::SubscribeWorker.perform_async(target_...
NotificationWorker.perform_async(build_follow_xml(f...
AfterRemoteFollowWorker.perform_async(follow.id)
end
MergeWorker.perform_async(target_account.id, source_a...
follow
end
}}
フォロー処理を行った後、ローカルアカウントなのかリモート...
:NotifyService|メールの送信、Redisへの書き込み(ストリー...
:Pubsubhubbub::SubscribeWorker|[[OStatus2>https://github....
:NotificationWorker|Salmon経由でフォローを通知。受け取っ...
:AfterRemoteFollowWorker|よくわからない。時間差で相手が鍵...
:MergeWorker|フォローしたアカウントのトゥートを自分のホー...
*おわりに [#f32beb41]
今回はフォロー時のサーバ側の処理について見てきました。リ...
終了行:
[[Mastodonを読む]]
#contents
*はじめに [#h2593682]
前回は、クライアント(画面)でフォローボタンを押したとき...
*app/controllers/api/v1/accounts_controller.rb [#i70dad46]
フォローボタンが押されると、サーバ側の「/api/v1/accounts/...
#code(Ruby){{
def follow
FollowService.new.call(current_user.account, @account...
set_relationship
render :relationship
end
}}
@accountはbefore_actionを使用して設定されています。
#code(Ruby){{
before_action :set_account, except: [:verify_credential...
def set_account
@account = Account.find(params[:id])
end
}}
**app/models/account.rb [#hc93614e]
Accountのacctはインスタンスも含めてアカウントを識別するた...
#code(Ruby){{
def local?
domain.nil?
end
def acct
local? ? username : "#{username}@#{domain}"
end
}}
さて、ここで気づくことがあります。上のコードを考えると、...
では、どうやって別インスタンスのアカウント情報を取ってく...
*app/services/follow_service.rb [#c74027ee]
#code(Ruby){{
class FollowService < BaseService
include StreamEntryRenderer
# Follow a remote user, notify remote user about the fo...
# @param [Account] source_account From which to follow
# @param [String] uri User URI to follow in the form of...
def call(source_account, uri)
target_account = FollowRemoteAccountService.new.call(...
raise ActiveRecord::RecordNotFound if target_account....
raise Mastodon::NotPermittedError if target_account....
if target_account.locked?
request_follow(source_account, target_account)
else
direct_follow(source_account, target_account)
end
end
}}
FollowRemoteAccountServiceはaccountsテーブルにアカウント...
といいつつ一言だけ。WebFingerでは特定のURLにアクセスする...
以下のURLへのアクセスが行われ、情報が返されるようです。
#code(Ruby){{
get '.well-known/webfinger', to: 'well_known/webfinger#...
}}
さて、話を戻して、鍵付きかどうかで処理が分かれていますが...
#code(Ruby){{
def direct_follow(source_account, target_account)
follow = source_account.follow!(target_account)
if target_account.local?
NotifyService.new.call(target_account, follow)
else
Pubsubhubbub::SubscribeWorker.perform_async(target_...
NotificationWorker.perform_async(build_follow_xml(f...
AfterRemoteFollowWorker.perform_async(follow.id)
end
MergeWorker.perform_async(target_account.id, source_a...
follow
end
}}
フォロー処理を行った後、ローカルアカウントなのかリモート...
:NotifyService|メールの送信、Redisへの書き込み(ストリー...
:Pubsubhubbub::SubscribeWorker|[[OStatus2>https://github....
:NotificationWorker|Salmon経由でフォローを通知。受け取っ...
:AfterRemoteFollowWorker|よくわからない。時間差で相手が鍵...
:MergeWorker|フォローしたアカウントのトゥートを自分のホー...
*おわりに [#f32beb41]
今回はフォロー時のサーバ側の処理について見てきました。リ...
ページ名: