social_stream 0.28.4 → 0.29.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +6 -1
- data/.travis.yml +0 -2
- data/Gemfile +3 -0
- data/base/app/controllers/activities_controller.rb +14 -12
- data/base/app/controllers/api_controller.rb +0 -13
- data/base/app/controllers/frontpage_controller.rb +0 -6
- data/base/app/models/activity.rb +21 -61
- data/base/app/models/actor.rb +4 -8
- data/base/app/models/audience.rb +2 -0
- data/base/app/models/comment.rb +2 -1
- data/base/app/models/group.rb +0 -2
- data/base/app/models/relation/custom.rb +17 -4
- data/base/app/models/relation.rb +5 -1
- data/base/app/models/tie.rb +0 -2
- data/base/app/models/user.rb +0 -2
- data/base/app/views/activities/_options.html.erb +1 -1
- data/base/app/views/activities/index.atom.builder +48 -0
- data/base/app/views/activity_objects/_activity_object.atom.erb +1 -0
- data/base/config/locales/en.yml +8 -0
- data/base/config/locales/es.yml +8 -0
- data/base/config/routes.rb +0 -8
- data/base/lib/rails/social_stream.rb +1 -1
- data/base/lib/social_stream/ability/base.rb +4 -16
- data/base/lib/social_stream/activity_streams/subtype.rb +11 -0
- data/base/lib/social_stream/activity_streams/supertype.rb +12 -0
- data/base/lib/social_stream/activity_streams.rb +39 -0
- data/base/lib/social_stream/base/dependencies.rb +2 -0
- data/base/lib/social_stream/base/engine.rb +6 -0
- data/base/lib/social_stream/base/version.rb +1 -1
- data/base/lib/social_stream/models/object.rb +5 -0
- data/base/lib/social_stream/models/subject.rb +1 -1
- data/base/lib/social_stream/models/subtype.rb +2 -0
- data/base/lib/social_stream/models/supertype.rb +2 -0
- data/base/lib/social_stream-base.rb +5 -0
- data/base/social_stream-base.gemspec +2 -0
- data/base/spec/controllers/activities_controller_spec.rb +18 -0
- data/base/spec/controllers/frontpage_controller_spec.rb +0 -5
- data/base/spec/models/activity_wall_spec.rb +96 -0
- data/base/spec/models/post_authorization_spec.rb +370 -0
- data/base/spec/models/post_spec.rb +0 -2
- data/base/spec/models/relation_spec.rb +22 -0
- data/base/spec/social_stream_activity_streams_spec.rb +16 -0
- data/base/spec/social_stream_spec.rb +1 -1
- data/documents/app/views/common_documents/_document_info.html.erb +2 -2
- data/documents/app/views/common_documents/_index.html.erb +2 -2
- data/documents/lib/social_stream/documents/engine.rb +7 -0
- data/documents/lib/social_stream/documents/version.rb +1 -1
- data/documents/social_stream-documents.gemspec +1 -1
- data/events/app/decorators/social_stream/base/actor_decorator.rb +3 -0
- data/events/app/decorators/social_stream/base/document_decorator.rb +3 -0
- data/events/lib/social_stream/events/engine.rb +2 -10
- data/events/lib/social_stream/events/version.rb +1 -1
- data/events/social_stream-events.gemspec +1 -1
- data/lib/generators/social_stream/install_generator.rb +1 -0
- data/lib/social_stream/version.rb +1 -1
- data/lib/social_stream.rb +7 -6
- data/linkser/lib/social_stream/linkser/engine.rb +3 -0
- data/linkser/lib/social_stream/linkser/version.rb +1 -1
- data/linkser/social_stream-linkser.gemspec +1 -1
- data/ostatus/Gemfile +3 -0
- data/ostatus/MIT-LICENSE +20 -0
- data/ostatus/README.rdoc +26 -0
- data/ostatus/Rakefile +26 -0
- data/{base → ostatus}/app/assets/images/logos/actor/remote_subject.png +0 -0
- data/ostatus/app/assets/images/logos/contact/remote_subject.png +0 -0
- data/ostatus/app/assets/images/logos/original/remote_subject.png +0 -0
- data/ostatus/app/assets/images/logos/profile/remote_subject.png +0 -0
- data/ostatus/app/controllers/host_meta_controller.rb +9 -0
- data/ostatus/app/controllers/pshb_controller.rb +26 -0
- data/ostatus/app/controllers/remote_subjects_controller.rb +19 -0
- data/ostatus/app/controllers/salmon_controller.rb +15 -0
- data/ostatus/app/controllers/subjects_controller.rb +5 -0
- data/ostatus/app/controllers/webfinger_controller.rb +24 -0
- data/ostatus/app/decorators/social_stream/base/activity_decorator.rb +3 -0
- data/ostatus/app/decorators/social_stream/base/actor_decorator.rb +3 -0
- data/ostatus/app/decorators/social_stream/base/audience_decorator.rb +3 -0
- data/ostatus/app/decorators/social_stream/base/relation/custom_decorator.rb +3 -0
- data/ostatus/app/decorators/social_stream/base/tie_decorator.rb +3 -0
- data/ostatus/app/models/actor_key.rb +30 -0
- data/ostatus/app/models/remote_subject.rb +139 -0
- data/ostatus/app/views/remote_subjects/_show.html.erb +6 -0
- data/ostatus/app/views/remote_subjects/show.html.erb +5 -0
- data/ostatus/config/locales/en.yml +34 -0
- data/ostatus/config/routes.rb +13 -0
- data/ostatus/db/migrate/20120905145030_create_social_stream_ostatus.rb +20 -0
- data/ostatus/db/migrate/20120918194708_create_actor_keys.rb +18 -0
- data/ostatus/lib/generators/social_stream/ostatus/install_generator.rb +16 -0
- data/ostatus/lib/generators/social_stream/ostatus/templates/initializer.rb +18 -0
- data/ostatus/lib/social_stream/migrations/ostatus.rb +9 -0
- data/ostatus/lib/social_stream/ostatus/activity_streams.rb +79 -0
- data/ostatus/lib/social_stream/ostatus/controllers/debug_requests.rb +24 -0
- data/ostatus/lib/social_stream/ostatus/engine.rb +21 -0
- data/ostatus/lib/social_stream/ostatus/models/activity.rb +41 -0
- data/ostatus/lib/social_stream/ostatus/models/actor.rb +89 -0
- data/ostatus/lib/social_stream/ostatus/models/audience.rb +19 -0
- data/ostatus/lib/social_stream/ostatus/models/object.rb +28 -0
- data/ostatus/lib/social_stream/ostatus/models/relation/custom.rb +22 -0
- data/ostatus/lib/social_stream/ostatus/models/tie.rb +24 -0
- data/ostatus/lib/social_stream/ostatus/version.rb +5 -0
- data/ostatus/lib/social_stream-ostatus.rb +54 -0
- data/ostatus/social_stream-ostatus.gemspec +28 -0
- data/ostatus/spec/controllers/host_meta_controller_spec.rb +10 -0
- data/ostatus/spec/controllers/remote_subjects_controller_spec.rb +37 -0
- data/ostatus/spec/controllers/webfinger_controller_spec.rb +13 -0
- data/ostatus/spec/dummy/Rakefile +7 -0
- data/ostatus/spec/dummy/app/controllers/application_controller.rb +3 -0
- data/ostatus/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/ostatus/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/ostatus/spec/dummy/config/application.rb +45 -0
- data/ostatus/spec/dummy/config/boot.rb +10 -0
- data/ostatus/spec/dummy/config/database.yml +22 -0
- data/ostatus/spec/dummy/config/environment.rb +5 -0
- data/ostatus/spec/dummy/config/environments/development.rb +26 -0
- data/ostatus/spec/dummy/config/environments/production.rb +49 -0
- data/ostatus/spec/dummy/config/environments/test.rb +35 -0
- data/ostatus/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/ostatus/spec/dummy/config/initializers/inflections.rb +10 -0
- data/ostatus/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/ostatus/spec/dummy/config/initializers/secret_token.rb +7 -0
- data/ostatus/spec/dummy/config/initializers/session_store.rb +8 -0
- data/ostatus/spec/dummy/config/locales/en.yml +5 -0
- data/ostatus/spec/dummy/config/routes.rb +58 -0
- data/ostatus/spec/dummy/config.ru +4 -0
- data/ostatus/spec/dummy/public/404.html +26 -0
- data/ostatus/spec/dummy/public/422.html +26 -0
- data/ostatus/spec/dummy/public/500.html +26 -0
- data/ostatus/spec/dummy/public/favicon.ico +0 -0
- data/ostatus/spec/dummy/public/javascripts/application.js +2 -0
- data/ostatus/spec/dummy/public/javascripts/controls.js +965 -0
- data/ostatus/spec/dummy/public/javascripts/dragdrop.js +974 -0
- data/ostatus/spec/dummy/public/javascripts/effects.js +1123 -0
- data/ostatus/spec/dummy/public/javascripts/prototype.js +6001 -0
- data/ostatus/spec/dummy/public/javascripts/rails.js +191 -0
- data/ostatus/spec/dummy/public/stylesheets/.gitkeep +0 -0
- data/ostatus/spec/dummy/script/rails +6 -0
- data/ostatus/spec/factories/remote_subject.rb +39 -0
- data/ostatus/spec/integration/navigation_spec.rb +9 -0
- data/ostatus/spec/models/actor_key_spec.rb +9 -0
- data/ostatus/spec/models/post_spec.rb +25 -0
- data/ostatus/spec/models/remote_subject_spec.rb +24 -0
- data/ostatus/spec/social_stream_ostatus.spec.rb +9 -0
- data/ostatus/spec/social_stream_ostatus_activity_streams.spec.rb +31 -0
- data/ostatus/spec/spec_helper.rb +33 -0
- data/presence/app/decorators/social_stream/base/models/group_decorator.rb +3 -0
- data/presence/app/decorators/social_stream/base/models/tie_decorator.rb +3 -0
- data/presence/lib/generators/social_stream/presence/install_generator.rb +1 -1
- data/presence/lib/social_stream/presence/engine.rb +0 -12
- data/presence/lib/social_stream/presence/version.rb +1 -1
- data/presence/social_stream-presence.gemspec +1 -1
- data/social_stream.gemspec +6 -5
- data/spec/support/db.rb +1 -1
- metadata +125 -18
- data/base/app/assets/images/logos/actor/remote_user.png +0 -0
- data/base/app/controllers/subjects_controller.rb +0 -7
- data/base/app/views/api/activity_atom_feed.atom.builder +0 -40
- data/base/app/views/frontpage/host_meta.xml.builder +0 -11
- data/base/spec/models/activity_authorization_spec.rb +0 -354
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'openssl'
|
2
|
+
|
3
|
+
# Store OStatus private and public key
|
4
|
+
class ActorKey < ActiveRecord::Base
|
5
|
+
KEY_SIZE = 1024
|
6
|
+
|
7
|
+
belongs_to :actor
|
8
|
+
|
9
|
+
validates_presence_of :key_der
|
10
|
+
|
11
|
+
before_validation :generate_key, on: :create
|
12
|
+
|
13
|
+
def key
|
14
|
+
@key ||=
|
15
|
+
OpenSSL::PKey::RSA.new(key_der)
|
16
|
+
end
|
17
|
+
|
18
|
+
def key= new_key
|
19
|
+
@key = new_key
|
20
|
+
self.key_der = new_key.to_der
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def generate_key
|
26
|
+
return if key_der.present?
|
27
|
+
|
28
|
+
self.key = OpenSSL::PKey::RSA.generate(KEY_SIZE)
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,139 @@
|
|
1
|
+
class RemoteSubject < ActiveRecord::Base
|
2
|
+
include SocialStream::Models::Subject
|
3
|
+
# Create absolute routes
|
4
|
+
include Rails.application.routes.url_helpers
|
5
|
+
|
6
|
+
attr_reader :url_helper
|
7
|
+
attr_accessible :webfinger_id
|
8
|
+
|
9
|
+
# Save webfinger_info hash into the database
|
10
|
+
serialize :webfinger_info
|
11
|
+
|
12
|
+
validates_uniqueness_of :webfinger_id
|
13
|
+
|
14
|
+
before_validation :fill_information,
|
15
|
+
:on => :create
|
16
|
+
|
17
|
+
after_create :subscribe_to_public_feed
|
18
|
+
after_destroy :unsubscribe_to_public_feed
|
19
|
+
|
20
|
+
scope :webfinger_alias, lambda { |uri|
|
21
|
+
where('webfinger_info LIKE ?', "%aliases%#{ uri }%")
|
22
|
+
}
|
23
|
+
|
24
|
+
#validates_format_of :webfinger_slug, :with => Devise.email_regexp, :allow_blank => true
|
25
|
+
|
26
|
+
class << self
|
27
|
+
def find_or_create_by_webfinger_uri!(uri)
|
28
|
+
if uri =~ /^https?:\/\//
|
29
|
+
records = webfinger_alias(uri)
|
30
|
+
|
31
|
+
# SQL scope is not reliable
|
32
|
+
if records.present?
|
33
|
+
return records.find{ |r| r.webfinger_aliases.include?(uri) }
|
34
|
+
end
|
35
|
+
|
36
|
+
# TODO: create by http uri?
|
37
|
+
|
38
|
+
raise ::ActiveRecord::RecordNotFound
|
39
|
+
end
|
40
|
+
|
41
|
+
id = uri.dup
|
42
|
+
|
43
|
+
if id =~ /^acct:/
|
44
|
+
id.gsub!('acct:', '')
|
45
|
+
end
|
46
|
+
|
47
|
+
find_or_create_by_webfinger_id!(id)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
# Return the slug in the webfinger_id
|
52
|
+
def webfinger_slug
|
53
|
+
splitted_webfinger_id.first
|
54
|
+
end
|
55
|
+
|
56
|
+
# Return the origin url in the webfinger_id
|
57
|
+
def webfinger_url
|
58
|
+
splitted_webfinger_id.last
|
59
|
+
end
|
60
|
+
|
61
|
+
# URL of the activity feed from this {RemoteSubject}
|
62
|
+
def public_feed_url
|
63
|
+
webfinger_info[:updates_from]
|
64
|
+
end
|
65
|
+
|
66
|
+
# URL of the Salmon endpoint for this {RemoteSubject}
|
67
|
+
def salmon_url
|
68
|
+
webfinger_info[:salmon]
|
69
|
+
end
|
70
|
+
|
71
|
+
# Webfinger Alias
|
72
|
+
def webfinger_aliases
|
73
|
+
webfinger_info[:aliases]
|
74
|
+
end
|
75
|
+
|
76
|
+
# Fetch the webfinger again
|
77
|
+
def refresh_webfinger!
|
78
|
+
fill_webfinger_info
|
79
|
+
|
80
|
+
save!
|
81
|
+
end
|
82
|
+
|
83
|
+
private
|
84
|
+
|
85
|
+
def splitted_webfinger_id
|
86
|
+
@splitted_webfinger_id ||=
|
87
|
+
webfinger_id.split('@')
|
88
|
+
end
|
89
|
+
|
90
|
+
def fill_information
|
91
|
+
fill_webfinger_info
|
92
|
+
|
93
|
+
self.name = webfinger_id
|
94
|
+
end
|
95
|
+
|
96
|
+
def fill_webfinger_info
|
97
|
+
self.webfinger_info = build_webfinger_info
|
98
|
+
self.rsa_key = finger.magic_key
|
99
|
+
end
|
100
|
+
|
101
|
+
def build_webfinger_info
|
102
|
+
{
|
103
|
+
updates_from: finger.links[:updates_from],
|
104
|
+
salmon: finger.links[:salmon],
|
105
|
+
aliases: finger.alias
|
106
|
+
}
|
107
|
+
end
|
108
|
+
|
109
|
+
def finger
|
110
|
+
@finger ||=
|
111
|
+
fetch_finger
|
112
|
+
end
|
113
|
+
|
114
|
+
def fetch_finger
|
115
|
+
finger =
|
116
|
+
Proudhon::Finger.fetch webfinger_id
|
117
|
+
|
118
|
+
# FIXME custom error
|
119
|
+
raise ::ActiveRecord::RecordNotFound if finger.blank?
|
120
|
+
|
121
|
+
finger
|
122
|
+
end
|
123
|
+
|
124
|
+
def subscribe_to_public_feed
|
125
|
+
return if public_feed_url.blank?
|
126
|
+
|
127
|
+
atom = Proudhon::Atom.from_uri(public_feed_url)
|
128
|
+
|
129
|
+
atom.subscribe(pshb_url(:host => SocialStream::Ostatus.pshb_host))
|
130
|
+
end
|
131
|
+
|
132
|
+
def unsubscribe_to_public_feed
|
133
|
+
return if public_feed_url.blank?
|
134
|
+
|
135
|
+
atom = Proudhon::Atom.from_uri(public_feed_url)
|
136
|
+
|
137
|
+
atom.unsubscribe(pshb_url(:host => SocialStream::Ostatus.pshb_host))
|
138
|
+
end
|
139
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
en:
|
2
|
+
activity:
|
3
|
+
verb:
|
4
|
+
follow:
|
5
|
+
RemoteSubject:
|
6
|
+
title: "%{subject} added %{contact} as contact."
|
7
|
+
message: "%{name} added you as contact."
|
8
|
+
notification:
|
9
|
+
subject: "%{name} added you as contact."
|
10
|
+
body: "%{name} added you as contact."
|
11
|
+
like:
|
12
|
+
RemoteSubject:
|
13
|
+
title: "%{subject} is a fan of %{contact}."
|
14
|
+
message: "%{name} is now your fan."
|
15
|
+
notification:
|
16
|
+
subject: "%{name} is now your fan."
|
17
|
+
body: "%{name} is now your fan."
|
18
|
+
make-friend:
|
19
|
+
RemoteSubject:
|
20
|
+
title: "%{subject} and %{contact} are now connected."
|
21
|
+
message: "%{name} also added you as contact."
|
22
|
+
notification:
|
23
|
+
subject: "%{name} also added you as contact."
|
24
|
+
body: "%{name} also added you as contact."
|
25
|
+
post:
|
26
|
+
RemoteSubject:
|
27
|
+
notification:
|
28
|
+
subject: "%{name} has posted something(%{direct_object}) in your wall"
|
29
|
+
body: "%{name} has posted something(%{direct_object}) in your wall"
|
30
|
+
update:
|
31
|
+
RemoteSubject:
|
32
|
+
notification:
|
33
|
+
subject: "%{name} has updated %{direct_object} in your wall"
|
34
|
+
body: "%{name} has updated something(%{direct_object}) in your wall"
|
@@ -0,0 +1,13 @@
|
|
1
|
+
Rails.application.routes.draw do
|
2
|
+
# Host Meta
|
3
|
+
match '/.well-known/host-meta', :to => HostMetaController.action(:index)
|
4
|
+
|
5
|
+
# Webfinger
|
6
|
+
match '/webfinger' => 'webfinger#index', :as => 'webfinger'
|
7
|
+
|
8
|
+
# PushSubHubBub callback
|
9
|
+
match 'pshb' => 'pshb#index', as: :pshb
|
10
|
+
|
11
|
+
# Salmon callback
|
12
|
+
match 'salmon/:slug' => 'salmon#index', as: :salmon
|
13
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
class CreateSocialStreamOstatus < ActiveRecord::Migration
|
2
|
+
|
3
|
+
def self.up
|
4
|
+
create_table :remote_subjects, :force => true do |t|
|
5
|
+
t.integer :actor_id
|
6
|
+
t.string :webfinger_id
|
7
|
+
t.text :webfinger_info
|
8
|
+
t.timestamps
|
9
|
+
end
|
10
|
+
|
11
|
+
add_index "remote_subjects", "actor_id"
|
12
|
+
add_foreign_key "remote_subjects", "actors", :name => "remote_subjects_on_actor_id"
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.down
|
16
|
+
remove_foreign_key "remote_subjects", :name => "remote_subjects_on_actor_id"
|
17
|
+
drop_table :remote_subjects
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class CreateActorKeys < ActiveRecord::Migration
|
2
|
+
def up
|
3
|
+
create_table :actor_keys do |t|
|
4
|
+
t.integer :actor_id
|
5
|
+
t.binary :key_der
|
6
|
+
|
7
|
+
t.timestamps
|
8
|
+
end
|
9
|
+
|
10
|
+
add_index "actor_keys", "actor_id"
|
11
|
+
add_foreign_key "actor_keys", "actors", :name => "actor_keys_on_actor_id"
|
12
|
+
end
|
13
|
+
|
14
|
+
def down
|
15
|
+
remove_foreign_key "actor_keys", :name => "actor_keys_on_actor_id"
|
16
|
+
drop_table :actor_keys
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
class SocialStream::Ostatus::InstallGenerator < Rails::Generators::Base
|
2
|
+
include Rails::Generators::Migration
|
3
|
+
|
4
|
+
source_root File.expand_path('../templates', __FILE__)
|
5
|
+
|
6
|
+
def create_migration_file
|
7
|
+
require 'rake'
|
8
|
+
Rails.application.load_tasks
|
9
|
+
Rake::Task['railties:install:migrations'].reenable
|
10
|
+
Rake::Task['social_stream_ostatus_engine:install:migrations'].invoke
|
11
|
+
end
|
12
|
+
|
13
|
+
def config_initializer
|
14
|
+
copy_file 'initializer.rb', 'config/initializers/social_stream-ostatus.rb'
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
SocialStream::Ostatus.setup do |config|
|
2
|
+
# Default to the PuSH reference Hub server
|
3
|
+
#
|
4
|
+
# config.hub = 'http://pubsubhubbub.appspot.com'
|
5
|
+
|
6
|
+
# The host where the hub should take the activity feed from
|
7
|
+
#
|
8
|
+
# Local subjects will publish their public activities there
|
9
|
+
config.activity_feed_host = 'localhost:3000'
|
10
|
+
|
11
|
+
# The host where the PuSH should send the callbacks to
|
12
|
+
#
|
13
|
+
# Remote subjects get their local activities updates with the PuSH callback
|
14
|
+
config.pshb_host = 'localhost:3000'
|
15
|
+
|
16
|
+
# Debug OStatus requests
|
17
|
+
# config.debug_requests = true
|
18
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
module SocialStream
|
2
|
+
module Ostatus
|
3
|
+
module ActivityStreams
|
4
|
+
# Parses the body from a {PshbController#index} and dispatches
|
5
|
+
# entries for parsing to {#record_from_entry!}
|
6
|
+
def from_pshb_callback(body)
|
7
|
+
atom = Proudhon::Atom.parse body
|
8
|
+
|
9
|
+
atom.entries.each do |entry|
|
10
|
+
# FIXME: get author from feed
|
11
|
+
# https://github.com/shf/proudhon/issues/8
|
12
|
+
entry.author.uri ||= feed.author.uri
|
13
|
+
|
14
|
+
activity_from_entry! entry
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
# Parses an activity form a PuSH or Salmon notification
|
19
|
+
# Decides what action should be taken from an ActivityStreams entry
|
20
|
+
def activity_from_entry! entry, receiver = nil
|
21
|
+
# FIXME: should not use to_sym
|
22
|
+
# https://github.com/shf/proudhon/issues/7
|
23
|
+
case entry.verb.to_sym
|
24
|
+
when :follow
|
25
|
+
Tie.from_entry! entry, receiver
|
26
|
+
else
|
27
|
+
# :post is the default verb
|
28
|
+
r = record_from_entry! entry, receiver
|
29
|
+
r.post_activity
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
# Redirects parsing to the suitable SocialStream's model
|
34
|
+
def record_from_entry! entry, receiver
|
35
|
+
model!(entry.objtype).from_entry! entry, receiver
|
36
|
+
end
|
37
|
+
|
38
|
+
# Finds or creates a {RemoteSubject} from an ActivityStreams entry
|
39
|
+
#
|
40
|
+
def actor_from_entry! entry
|
41
|
+
webfinger_id = entry.author.uri
|
42
|
+
|
43
|
+
if webfinger_id.blank?
|
44
|
+
raise "Entry author without uri: #{ entry.to_xml }"
|
45
|
+
end
|
46
|
+
|
47
|
+
RemoteSubject.find_or_create_by_webfinger_uri! webfinger_id
|
48
|
+
end
|
49
|
+
|
50
|
+
# Parses the body from a {Salmon#index} and receiving actor
|
51
|
+
def from_salmon_callback(body, receiver)
|
52
|
+
salmon = Proudhon::Salmon.new body
|
53
|
+
|
54
|
+
validate_salmon salmon
|
55
|
+
|
56
|
+
activity_from_entry! salmon.to_entry, receiver
|
57
|
+
end
|
58
|
+
|
59
|
+
def validate_salmon salmon
|
60
|
+
remote_subject = RemoteSubject.find_or_create_by_webfinger_uri!(salmon.to_entry.author.uri)
|
61
|
+
key = remote_subject.rsa_key
|
62
|
+
|
63
|
+
unless salmon.verify(key)
|
64
|
+
raise "Invalid salmon: #{ salmon }"
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
# Translate SocialStream activity verb to Proudhon verb
|
69
|
+
def verb orig
|
70
|
+
case orig
|
71
|
+
when 'make-friend'
|
72
|
+
:follow
|
73
|
+
else
|
74
|
+
orig.to_sym
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module SocialStream
|
2
|
+
module Ostatus
|
3
|
+
module Controllers
|
4
|
+
module DebugRequests
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
included do
|
8
|
+
before_filter :debug_request
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def debug_request
|
14
|
+
return unless SocialStream::Ostatus.debug_requests
|
15
|
+
|
16
|
+
logger.info request.body.read
|
17
|
+
|
18
|
+
# Set StringIO to initial state for the action to get the content
|
19
|
+
request.body.rewind
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|