diff options
author | Eugen Rochko <eugen@zeonfederated.com> | 2016-02-22 16:00:20 +0100 |
---|---|---|
committer | Eugen Rochko <eugen@zeonfederated.com> | 2016-02-22 16:00:20 +0100 |
commit | 709c6685a90bb819696566cc9e42e587546d72dc (patch) | |
tree | 272783009e0a0c8b13b8003dc4bc4e58f3b0b84b /app/services/process_interaction_service.rb | |
parent | 9c4856bdb11fc9311ab30a97224cee3dfaec492f (diff) |
Made some progress
Diffstat (limited to 'app/services/process_interaction_service.rb')
-rw-r--r-- | app/services/process_interaction_service.rb | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/app/services/process_interaction_service.rb b/app/services/process_interaction_service.rb new file mode 100644 index 000000000..8262ead8f --- /dev/null +++ b/app/services/process_interaction_service.rb @@ -0,0 +1,38 @@ +class ProcessInteractionService + def call(envelope, target_account) + body = salmon.unpack(envelope) + xml = Nokogiri::XML(body) + + return if xml.at_xpath('//author/name').nil? || xml.at_xpath('//author/uri').nil? + + username = xml.at_xpath('//author/name').content + url = xml.at_xpath('//author/uri').content + 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 + + def salmon + OStatus2::Salmon.new + end + + def follow_remote_account_service + FollowRemoteAccountService.new + end +end |