social_stream 0.0.3 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,10 @@
1
+ class CommentsController < InheritedResources::Base
2
+ respond_to :html, :xml, :js
3
+
4
+ def destroy
5
+ @post_activity = resource.post_activity
6
+
7
+ destroy!
8
+ end
9
+
10
+ end
data/app/models/actor.rb CHANGED
@@ -97,6 +97,11 @@ class Actor < ActiveRecord::Base
97
97
  candidates[rand(candidates.size)]
98
98
  end
99
99
 
100
+ # All the ties this actor has with subject that support activities
101
+ def active_ties_to(subject)
102
+ sent_ties.received_by(subject).active
103
+ end
104
+
100
105
  # The set of activities in the wall of this actor
101
106
  # TODO: authorization
102
107
  def wall
@@ -0,0 +1,3 @@
1
+ class Comment < ActiveRecord::Base
2
+ validates_presence_of :text
3
+ end
@@ -8,6 +8,11 @@
8
8
  # two actors are stronger than others.
9
9
  # When a strong tie is established, ties with weaker relations are establised as well
10
10
  #
11
+ # == Reflexive relations
12
+ # Some relations are set by default for actors with theirselves. This sets some ties
13
+ # for posting in self wall at several visibility levels: only for friends, public and
14
+ # so on
15
+ #
11
16
  # == Inverse relations
12
17
  # A Relation can have its inverse. When a tie is established, an inverse tie will be
13
18
  # established if an inverse relation exists. An example is a relation of friendship,
@@ -20,6 +25,11 @@
20
25
  # sends a friendship_request to B. A is granting the friend relation with B, that is,
21
26
  # friendship_request grants friend relation.
22
27
  #
28
+ # == Active relations
29
+ # Those relations whose ties support activities. The default scope define active
30
+ # relations as those that do not grant other relations, those that are not invitations
31
+ # or requests.
32
+ #
23
33
  class Relation < ActiveRecord::Base
24
34
  has_ancestry
25
35
 
@@ -32,7 +42,9 @@ class Relation < ActiveRecord::Base
32
42
  belongs_to :granted,
33
43
  :class_name => "Relation"
34
44
 
45
+ scope :reflexive, where(:reflexive => true)
35
46
  scope :request, where('relations.granted_id IS NOT NULL')
47
+ scope :active, where(:granted_id => nil)
36
48
 
37
49
  has_many :relation_permissions, :dependent => :destroy
38
50
  has_many :permissions, :through => :relation_permissions
data/app/models/tie.rb CHANGED
@@ -64,6 +64,7 @@ class Tie < ActiveRecord::Base
64
64
  }
65
65
 
66
66
  scope :pending, includes(:relation) & Relation.request
67
+ scope :active, includes(:relation) & Relation.active
67
68
 
68
69
  scope :inverse, lambda { |t|
69
70
  sent_by(t.receiver).
@@ -1,8 +1,10 @@
1
1
  <div class="activity_options">
2
2
  <ul class="activity_options" >
3
3
  <li><div class="post_time_ago"><%= t('time.ago', :time => time_ago_in_words(activity.created_at)) %></div></li>
4
+ <% if activity.is_root? %>
4
5
  <li><div class="verb_comment"> · <%= link_to t('activity.to_comment'), "#", :class => "to_comment" %> </div></li>
6
+ <% end %>
5
7
  <li><div class="verb_like" id="like_<%= dom_id(activity) %>"> · <%= like_activity(activity)%></div></li>
6
- <li><div class="verb_delete"> · <%= link_to t('activity.delete'), activity.direct_object , :confirm => t('activity.confirm_delete'), :method => :delete, :remote => true %> </div></li>
8
+ <li><div class="verb_delete"> · <%= link_to t('activity.delete'), activity.direct_object , :confirm => t('confirm_delete', :scope => activity.direct_object.class.to_s.underscore), :method => :delete, :remote => true %> </div></li>
7
9
  </ul>
8
10
  </div>
@@ -0,0 +1,3 @@
1
+ <div class="activity_comments" id="comments_<%= dom_id(activity) %>">
2
+ <%= render activity.comments %>
3
+ </div>
@@ -1,6 +1,6 @@
1
1
  <div id="activities_header" class="content_size">
2
2
  <%= form_for Post.new(:text => t('activity.input'),
3
- :_activity_tie_id => current_tie.id),
3
+ :_activity_tie_id => current_user.active_ties_to(receiver).first.id),
4
4
  :remote => true do |f| %>
5
5
  <%= f.hidden_field :_activity_tie_id %>
6
6
  <%= f.text_field :text, :id => "input_activities", :size => 85 %>
@@ -18,24 +18,12 @@
18
18
  <%= render :partial => 'activities/activity_options',
19
19
  :locals => { :activity => root_activity } %>
20
20
 
21
- <div class="activity_comments" id="comments_<%= dom_id(root_activity) %>">
22
- <%= render root_activity.comments %>
23
- </div>
21
+ <%= render :partial => 'activities/comments',
22
+ :locals => { :activity => root_activity } %>
23
+
24
+ <%= render :partial => 'comments/new',
25
+ :locals => { :activity => root_activity } %>
24
26
 
25
- <div class="activity_new_comment">
26
- <%= form_for Comment.new(:text => t('comment.input'),
27
- :_activity_tie_id => current_tie.id,
28
- :_activity_parent_id => root_activity.id),
29
- :remote => true do |f| %>
30
- <%= f.hidden_field :_activity_tie_id %>
31
- <%= f.hidden_field :_activity_parent_id %>
32
- <%= f.text_field :text, :class =>"input_new_comments" %>
33
- <div class="activities_comment_btn">
34
- <div class="activities_security"></div>
35
- <%= image_submit_tag "buttons/btn_share.png" %>
36
- </div>
37
- <% end %>
38
- </div>
39
27
  </div>
40
28
  <div class="space_comments"></div>
41
29
  <div class="space_activities">
@@ -14,7 +14,7 @@
14
14
  </span>
15
15
  </div>
16
16
 
17
- <%= render :partial => 'activities/subactivity_options',
17
+ <%= render :partial => 'activities/activity_options',
18
18
  :locals => { :activity => subactivity } %>
19
19
 
20
20
  </div>
@@ -0,0 +1 @@
1
+ <%= comment.text %>
@@ -0,0 +1,15 @@
1
+ <div class="activity_new_comment">
2
+ <%= form_for Comment.new(:text => t('comment.input'),
3
+ :_activity_tie_id =>
4
+ current_user.active_ties_to(activity.receiver).first.id,
5
+ :_activity_parent_id => activity.id),
6
+ :remote => true do |f| %>
7
+ <%= f.hidden_field :_activity_tie_id %>
8
+ <%= f.hidden_field :_activity_parent_id %>
9
+ <%= f.text_field :text, :class =>"input_new_comments" %>
10
+ <div class="activities_comment_btn">
11
+ <div class="activities_security"></div>
12
+ <%= image_submit_tag "buttons/btn_share.png" %>
13
+ </div>
14
+ <% end %>
15
+ </div>
@@ -0,0 +1,4 @@
1
+ //Display the new comment
2
+ $("#comments_activity_<%= @comment.post_activity.parent.id %>").append("<%= escape_javascript(render @comment.post_activity) %>");
3
+ $(".input_new_comments").val("<%= t('comment.input') %>");
4
+ $(".activities_comment_btn").hide();
@@ -0,0 +1,2 @@
1
+ //delete comments
2
+ $("#<%= dom_id(@post_activity) %>").hide();
@@ -5,11 +5,11 @@
5
5
 
6
6
  <div id="wrapper_activities">
7
7
  <div id="wrapper_activities_header">
8
- <div id="activities_title" class="content_size">
9
- <%= image_tag("buttons/btn_activities.png") %> <%=t('activity.other')%>
10
- </div>
8
+ <div id="activities_title" class="content_size">
9
+ <%= image_tag("buttons/btn_activities.png") %> <%=t('activity.other')%>
10
+ </div>
11
11
 
12
- <%= render :partial => 'activities/new' %>
12
+ <%= render :partial => 'activities/new', :locals => { :receiver => current_user } %>
13
13
  </div>
14
14
  <div id="wall">
15
15
  <% if current_user.wall.any? %>
@@ -10,11 +10,14 @@ en:
10
10
  unlike: Already I do not like
11
11
  comment:
12
12
  input: "Write a comment..."
13
+ confirm_delete: "Delete comment?"
13
14
  home:
14
15
  one: "Home"
15
16
  location:
16
17
  message: "You are here > %{location}"
17
18
  message: "Message"
19
+ post:
20
+ confirm_delete: "Delete post?"
18
21
  tie:
19
22
  pending:
20
23
  other: Pending requests
@@ -13,5 +13,5 @@ SocialStream.setup do |config|
13
13
  # Type of activities managed by actors
14
14
  # Remember you must add an "activity_object_id" foreign key column to your migration!
15
15
  #
16
- # config.activity_objects = [ :post ]
16
+ # config.activity_objects = [ :post, :comment ]
17
17
  end
@@ -48,6 +48,15 @@ class CreateSocialStream < ActiveRecord::Migration
48
48
  add_index "actors", ["email"], :name => "index_actors_on_email"
49
49
  add_index "actors", ["permalink"], :name => "index_actors_on_permalink", :unique => true
50
50
 
51
+ create_table "comments", :force => true do |t|
52
+ t.integer "activity_object_id"
53
+ t.text "text"
54
+ t.datetime "updated_at"
55
+ t.datetime "created_at"
56
+ end
57
+
58
+ add_index "comments", ["activity_object_id"], :name => "fk_commets_activity_object"
59
+
51
60
  create_table "permissions", :force => true do |t|
52
61
  t.string "action"
53
62
  t.string "object"
@@ -85,7 +94,7 @@ class CreateSocialStream < ActiveRecord::Migration
85
94
  t.string "ancestry"
86
95
  t.integer "inverse_id"
87
96
  t.integer "granted_id"
88
- t.boolean "default", :default => false
97
+ t.boolean "reflexive", :default => false
89
98
  end
90
99
 
91
100
  add_index "relations", ["ancestry"]
@@ -138,5 +147,19 @@ class CreateSocialStream < ActiveRecord::Migration
138
147
  end
139
148
 
140
149
  def self.down
150
+ drop_table :activities
151
+ drop_table :activity_object_activities
152
+ drop_table :activity_objects
153
+ drop_table :activity_verbs
154
+ drop_table :actors
155
+ drop_table :comments
156
+ drop_table :permissions
157
+ drop_table :posts
158
+ drop_table :_relation_permissions
159
+ drop_table :relations
160
+ drop_table :tags
161
+ drop_table :tags_activity_objects
162
+ drop_table :ties
163
+ drop_table :users
141
164
  end
142
165
  end
@@ -2,28 +2,33 @@
2
2
  #
3
3
  # Define your relations and add SocialStream.seed! to db/seeds.rb
4
4
  #
5
- # Example
6
- # relations:
7
- # user-friend:
8
- # sender_type: User
9
- # receiver_type: User
10
- # name: friend
11
- # permissions:
12
- # - [ create, resources, weak_set ]
13
- # - [ read, resources, group_set ]
14
- # - [ update, resources, weak_set ]
15
- # - [ destroy, resources, weak_set ]
16
- # user-fof:
17
- # sender_type: User
18
- # receiver_type: User
19
- # name: friend_of_friend
20
- # parent: user-friend
21
- # permissions:
22
- # - [ read, resources, group_set ]
23
- # user-public:
24
- # sender_type: User
25
- # receiver_type: User
26
- # name: public
27
- # parent: user-fof
28
- # permissions:
29
- # - [ read, resources, group_set ]
5
+ relations:
6
+ user-friend:
7
+ sender_type: User
8
+ receiver_type: User
9
+ name: friend
10
+ # Friendship is a reciprocal relation
11
+ inverse: user-friend
12
+ # It is set for users by default
13
+ reflexive: true
14
+ permissions:
15
+ - [ create, resources, weak_set ]
16
+ - [ read, resources, group_set ]
17
+ - [ update, resources, weak_set ]
18
+ - [ destroy, resources, weak_set ]
19
+ user-public:
20
+ sender_type: User
21
+ receiver_type: User
22
+ name: public
23
+ # This relation is weaker than user-friend
24
+ parent: user-friend
25
+ # This relation is also reciprocal
26
+ inverse: user-public
27
+ permissions:
28
+ - [ read, resources, group_set ]
29
+ user-friend-request:
30
+ sender_type: User
31
+ receiver_type: User
32
+ name: friendship_request
33
+ # This relation is the request for user-friend
34
+ granted: user-friend
@@ -16,6 +16,7 @@ module SocialStream
16
16
  :permalink, :permalink=,
17
17
  :disabled, :disabled=,
18
18
  :ties, :sent_ties, :received_ties,
19
+ :active_ties_to,
19
20
  :sender_subjects, :receiver_subjects, :suggestion,
20
21
  :wall,
21
22
  :to => :actor!
@@ -24,7 +25,7 @@ module SocialStream
24
25
  scope :with_sent_ties, joins(:actor => :sent_ties)
25
26
  scope :with_received_ties, joins(:actor => :received_ties)
26
27
 
27
- after_create :initialize_default_ties
28
+ after_create :initialize_reflexive_ties
28
29
  end
29
30
 
30
31
  module InstanceMethods
@@ -34,8 +35,8 @@ module SocialStream
34
35
 
35
36
  private
36
37
 
37
- def initialize_default_ties
38
- self.class.relations.where(:default => true).each do |r|
38
+ def initialize_reflexive_ties
39
+ self.class.relations.reflexive.each do |r|
39
40
  Tie.create! :sender => self.actor,
40
41
  :receiver => self.actor,
41
42
  :relation => r
@@ -12,6 +12,8 @@ module ActionDispatch::Routing
12
12
  resources :activities do
13
13
  resource :like
14
14
  end
15
+ resources :posts
16
+ resources :comments
15
17
  end
16
18
  end
17
19
  end
@@ -24,7 +24,7 @@ module SocialStream
24
24
  find_or_create_by_sender_type_and_receiver_type_and_name(r['sender_type'],
25
25
  r['receiver_type'],
26
26
  r['name'])
27
- relations[name].update_attribute(:default, r['default'])
27
+ relations[name].update_attribute(:reflexive, r['reflexive'])
28
28
 
29
29
  # FIXME: optimize
30
30
  relations[name].relation_permissions.destroy_all
@@ -1,3 +1,3 @@
1
1
  module SocialStream
2
- VERSION = "0.0.3".freeze
2
+ VERSION = "0.0.4".freeze
3
3
  end
data/lib/social_stream.rb CHANGED
@@ -16,7 +16,7 @@ module SocialStream
16
16
  :rememberable, :trackable ]
17
17
 
18
18
  mattr_accessor :activity_objects
19
- @@activity_objects = [ :post ]
19
+ @@activity_objects = [ :post, :comment ]
20
20
 
21
21
  class << self
22
22
  def setup
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: social_stream
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 3
10
- version: 0.0.3
9
+ - 4
10
+ version: 0.0.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Antonio Tapiador
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2010-10-20 00:00:00 +02:00
19
+ date: 2010-10-21 00:00:00 +02:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
@@ -91,9 +91,11 @@ files:
91
91
  - app/models/permission.rb
92
92
  - app/models/actor.rb
93
93
  - app/models/activity_object_activity.rb
94
+ - app/models/comment.rb
94
95
  - app/models/activity.rb
95
96
  - app/models/relation.rb
96
97
  - app/models/activity_verb.rb
98
+ - app/controllers/comments_controller.rb
97
99
  - app/controllers/ties_controller.rb
98
100
  - app/controllers/activities_controller.rb
99
101
  - app/controllers/home_controller.rb
@@ -102,13 +104,17 @@ files:
102
104
  - app/views/ties/_suggestion.html.erb
103
105
  - app/views/ties/_pending.html.erb
104
106
  - app/views/devise/registrations/new.html.erb
107
+ - app/views/comments/_new.html.erb
108
+ - app/views/comments/create.js.erb
109
+ - app/views/comments/destroy.js.erb
110
+ - app/views/comments/_comment.html.erb
105
111
  - app/views/posts/_post.html.erb
106
112
  - app/views/posts/create.js.erb
107
113
  - app/views/posts/destroy.js.erb
108
114
  - app/views/activities/_activity.html.erb
109
115
  - app/views/activities/_activity_options.html.erb
110
- - app/views/activities/_subactivity_options.html.erb
111
116
  - app/views/activities/_jquery.html.erb
117
+ - app/views/activities/_comments.html.erb
112
118
  - app/views/activities/_new.html.erb
113
119
  - app/views/activities/_root_activity.html.erb
114
120
  - app/views/activities/_subactivity.html.erb
@@ -1,7 +0,0 @@
1
- <div class="activity_options">
2
- <ul class="activity_options" >
3
- <li><div class="post_time_ago"><%= t('time.ago', :time => time_ago_in_words(activity.created_at)) %></div></li>
4
- <li><div class="verb_like" id="like_<%= dom_id(activity) %>"> · <%= like_activity(activity)%></div></li>
5
- <li><div class="verb_delete"> · <%= link_to t('activity.delete'), activity.direct_object , :confirm => t('activity.confirm_delete'), :method => :delete, :remote => true %> </div></li>
6
- </ul>
7
- </div>