2016-02-22 15:00:20 +00:00
|
|
|
class ProcessInteractionService
|
|
|
|
def call(envelope, target_account)
|
|
|
|
body = salmon.unpack(envelope)
|
|
|
|
xml = Nokogiri::XML(body)
|
|
|
|
|
2016-02-23 18:17:37 +00:00
|
|
|
return if !involves_target_account(xml, target_account) || xml.at_xpath('//xmlns:author/xmlns:name').nil? || xml.at_xpath('//xmlns:author/xmlns:uri').nil?
|
2016-02-22 15:00:20 +00:00
|
|
|
|
2016-02-23 18:17:37 +00:00
|
|
|
username = xml.at_xpath('//xmlns:author/xmlns:name').content
|
|
|
|
url = xml.at_xpath('//xmlns:author/xmlns:uri').content
|
2016-02-22 15:00:20 +00:00
|
|
|
domain = Addressable::URI.parse(url).host
|
|
|
|
account = Account.find_by(username: username, domain: domain)
|
|
|
|
|
|
|
|
if account.nil?
|
|
|
|
account = follow_remote_account_service.("acct:#{username}@#{domain}")
|
|
|
|
end
|
|
|
|
|
|
|
|
if salmon.verify(envelope, account.keypair)
|
|
|
|
verb = xml.at_path('//activity:verb').content
|
|
|
|
|
|
|
|
case verb
|
|
|
|
when 'http://activitystrea.ms/schema/1.0/follow', 'follow'
|
|
|
|
account.follow!(target_account)
|
|
|
|
when 'http://activitystrea.ms/schema/1.0/unfollow', 'unfollow'
|
|
|
|
account.unfollow!(target_account)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2016-02-22 18:11:07 +00:00
|
|
|
def involves_target_account(target_account)
|
2016-02-23 12:08:01 +00:00
|
|
|
# todo
|
2016-02-22 18:11:07 +00:00
|
|
|
end
|
|
|
|
|
2016-02-22 15:00:20 +00:00
|
|
|
def salmon
|
|
|
|
OStatus2::Salmon.new
|
|
|
|
end
|
|
|
|
|
|
|
|
def follow_remote_account_service
|
|
|
|
FollowRemoteAccountService.new
|
|
|
|
end
|
|
|
|
end
|