social_stream-ostatus 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,3 @@
1
+ Contact.class_eval do
2
+ include SocialStream::Ostatus::Models::Contact
3
+ end
@@ -34,6 +34,7 @@ module SocialStream
34
34
  autoload :Activity, 'social_stream/ostatus/models/activity'
35
35
  autoload :Actor, 'social_stream/ostatus/models/actor'
36
36
  autoload :Audience, 'social_stream/ostatus/models/audience'
37
+ autoload :Contact, 'social_stream/ostatus/models/contact'
37
38
  autoload :Tie, 'social_stream/ostatus/models/tie'
38
39
 
39
40
  module Object
@@ -21,8 +21,10 @@ module SocialStream
21
21
  # FIXME: should not use to_sym
22
22
  # https://github.com/shf/proudhon/issues/7
23
23
  case entry.verb.to_sym
24
- when :follow
25
- Tie.from_entry! entry, receiver
24
+ when :follow, :subscribe, :join
25
+ Tie.create_from_entry! entry, receiver
26
+ when :unsubscribe, :leave, 'http://ostatus.org/schema/1.0/unfollow'
27
+ Tie.destroy_from_entry! entry, receiver
26
28
  else
27
29
  # :post is the default verb
28
30
  r = record_from_entry! entry, receiver
@@ -0,0 +1,64 @@
1
+ module SocialStream
2
+ module Ostatus
3
+ module Models
4
+ module Contact
5
+ extend ActiveSupport::Concern
6
+
7
+ included do
8
+ # FIXME: hack, this overwrites base definition, see there
9
+ # for the reasons related to after_destroy callbacks
10
+ alias_method_chain :unset_follow_action, :salmon
11
+ end
12
+
13
+ module ClassMethods
14
+ # Find contact from OStatus entry
15
+ def from_entry! entry, receiver
16
+ # Sender must be remote
17
+ sender = RemoteSubject.find_or_create_by_webfinger_uri! entry.author.uri
18
+
19
+ contact = sender.contact_to!(receiver)
20
+
21
+ # FIXME: hack
22
+ contact.user_author = sender
23
+
24
+ contact
25
+ end
26
+ end
27
+
28
+ # Send Salmon notification
29
+ #
30
+ # FIXME DRY with activity.rb
31
+ def unset_follow_action_with_salmon(relation)
32
+ unset_follow_action_without_salmon(relation)
33
+
34
+ return if sender.subject_type == "RemoteSubject" ||
35
+ receiver.subject_type != "RemoteSubject"
36
+
37
+ title = I18n.t "activity.stream.title.unfollow",
38
+ author: sender_subject.name,
39
+ activity_object: receiver_subject.name
40
+
41
+ entry =
42
+ Proudhon::Entry.new id: "tag:#{ SocialStream::Ostatus.activity_feed_host },2005:contact-destroy-#{ id }",
43
+ title: title,
44
+ content: title,
45
+ verb: 'http://ostatus.org/schema/1.0/unfollow',
46
+ author: Proudhon::Author.new(name: sender.name,
47
+ uri: sender.webfinger_uri)
48
+ salmon = entry.to_salmon
49
+
50
+ if SocialStream::Ostatus.debug_requests
51
+ logger.info entry.to_xml
52
+ end
53
+
54
+ # FIXME: Rails 4 queues
55
+ Thread.new do
56
+ salmon.deliver receiver_subject.salmon_url, sender.rsa_key
57
+
58
+ ActiveRecord::Base.connection.close
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
@@ -6,16 +6,17 @@ module SocialStream
6
6
 
7
7
  module ClassMethods
8
8
  # Create a new {Tie} from OStatus entry
9
- def from_entry! entry, receiver
10
- # Sender must be remote
11
- sender = RemoteSubject.find_or_create_by_webfinger_uri! entry.author.uri
9
+ def create_from_entry! entry, receiver
10
+ contact = ::Contact.from_entry! entry, receiver
11
+
12
+ contact.relation_ids = [::Relation::Public.instance.id]
13
+ end
12
14
 
13
- contact = sender.contact_to!(receiver)
15
+ # Remove all {Tie} from OStatus entry
16
+ def destroy_from_entry! entry, receiver
17
+ contact = ::Contact.from_entry! entry, receiver
14
18
 
15
- # FIXME: hack
16
- contact.user_author = sender
17
-
18
- contact.relation_ids = [::Relation::Public.instance.id]
19
+ contact.relation_ids = []
19
20
  end
20
21
  end
21
22
  end
@@ -1,5 +1,5 @@
1
1
  module SocialStream
2
2
  module Ostatus
3
- VERSION = "0.1.0".freeze
3
+ VERSION = "0.2.0".freeze
4
4
  end
5
5
  end
@@ -12,8 +12,8 @@ Gem::Specification.new do |s|
12
12
  s.files = `git ls-files`.split("\n")
13
13
 
14
14
  # Gem dependencies
15
- s.add_runtime_dependency('social_stream-base', '~> 0.23.0')
16
- s.add_runtime_dependency('proudhon','>= 0.3.5')
15
+ s.add_runtime_dependency('social_stream-base', '~> 0.24.0')
16
+ s.add_runtime_dependency('proudhon','>= 0.3.6')
17
17
  s.add_runtime_dependency('nokogiri','> 1.4.4')
18
18
 
19
19
  # Development Gem dependencies
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: social_stream-ostatus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-10-03 00:00:00.000000000 Z
13
+ date: 2012-10-23 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: social_stream-base
@@ -19,7 +19,7 @@ dependencies:
19
19
  requirements:
20
20
  - - ~>
21
21
  - !ruby/object:Gem::Version
22
- version: 0.23.0
22
+ version: 0.24.0
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -27,7 +27,7 @@ dependencies:
27
27
  requirements:
28
28
  - - ~>
29
29
  - !ruby/object:Gem::Version
30
- version: 0.23.0
30
+ version: 0.24.0
31
31
  - !ruby/object:Gem::Dependency
32
32
  name: proudhon
33
33
  requirement: !ruby/object:Gem::Requirement
@@ -35,7 +35,7 @@ dependencies:
35
35
  requirements:
36
36
  - - ! '>='
37
37
  - !ruby/object:Gem::Version
38
- version: 0.3.5
38
+ version: 0.3.6
39
39
  type: :runtime
40
40
  prerelease: false
41
41
  version_requirements: !ruby/object:Gem::Requirement
@@ -43,7 +43,7 @@ dependencies:
43
43
  requirements:
44
44
  - - ! '>='
45
45
  - !ruby/object:Gem::Version
46
- version: 0.3.5
46
+ version: 0.3.6
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: nokogiri
49
49
  requirement: !ruby/object:Gem::Requirement
@@ -164,6 +164,7 @@ files:
164
164
  - app/decorators/social_stream/base/activity_decorator.rb
165
165
  - app/decorators/social_stream/base/actor_decorator.rb
166
166
  - app/decorators/social_stream/base/audience_decorator.rb
167
+ - app/decorators/social_stream/base/contact_decorator.rb
167
168
  - app/decorators/social_stream/base/relation/custom_decorator.rb
168
169
  - app/decorators/social_stream/base/tie_decorator.rb
169
170
  - app/models/actor_key.rb
@@ -184,6 +185,7 @@ files:
184
185
  - lib/social_stream/ostatus/models/activity.rb
185
186
  - lib/social_stream/ostatus/models/actor.rb
186
187
  - lib/social_stream/ostatus/models/audience.rb
188
+ - lib/social_stream/ostatus/models/contact.rb
187
189
  - lib/social_stream/ostatus/models/object.rb
188
190
  - lib/social_stream/ostatus/models/relation/custom.rb
189
191
  - lib/social_stream/ostatus/models/tie.rb
@@ -257,3 +259,4 @@ specification_version: 3
257
259
  summary: Provides a Social Stream node with social network federation support via
258
260
  OStatus protocol
259
261
  test_files: []
262
+ has_rdoc: