social_stream-base 0.18.1 → 0.19.0
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.
- data/app/assets/javascripts/social_stream.action.js +40 -0
- data/app/assets/javascripts/social_stream.comments.js +26 -1
- data/app/assets/javascripts/social_stream.timeline.js +15 -7
- data/app/assets/javascripts/social_stream.wall.js.erb +1 -0
- data/app/assets/stylesheets/social_stream-base.css.scss +13 -0
- data/app/models/activity.rb +5 -1
- data/app/models/activity_action.rb +6 -0
- data/app/models/activity_object.rb +131 -9
- data/app/models/actor.rb +2 -0
- data/app/models/channel.rb +0 -1
- data/app/models/comment.rb +0 -6
- data/app/views/activity_actions/_update.js.erb +11 -0
- data/app/views/activity_actions/create.js.erb +1 -1
- data/app/views/activity_actions/update.js.erb +1 -1
- data/app/views/comments/create.js.erb +1 -1
- data/app/views/posts/create.js.erb +1 -1
- data/db/migrate/20120111141717_create_social_stream.rb +265 -0
- data/db/migrate/20120326083509_object_channels_to_actions.rb +45 -0
- data/lib/social_stream/ability/base.rb +2 -2
- data/lib/social_stream/base/version.rb +1 -1
- data/lib/social_stream/controllers/cancan_devise_integration.rb +9 -5
- data/lib/social_stream/models/object.rb +0 -72
- data/lib/social_stream/models/subject.rb +2 -1
- data/lib/social_stream/models/subtype.rb +6 -1
- data/spec/controllers/groups_controller_spec.rb +6 -0
- data/spec/factories/post.rb +6 -0
- data/spec/models/activity_action_spec.rb +35 -0
- metadata +69 -77
- data/app/assets/stylesheets/social_stream-base.css +0 -5
- data/app/views/activity_actions/_update_form.js.erb +0 -2
- data/db/migrate/20110610112023_create_social_stream.rb +0 -319
- data/db/migrate/20110705103202_empty_ties_count.rb +0 -17
- data/db/migrate/20110712090343_remove_spheres.rb +0 -30
- data/db/migrate/20110712142140_remove_permission_function.rb +0 -26
- data/db/migrate/20110912074426_add_reject_relation.rb +0 -29
- data/db/migrate/20111124100618_object_actors.rb +0 -52
- data/db/migrate/20111221103509_add_language_field.rb +0 -13
- data/db/migrate/20120103103125_add_channels.rb +0 -88
- data/db/migrate/20120109081509_update_notify_permissions.rb +0 -15
- data/db/migrate/20120111120920_remove_language_default.rb +0 -9
- data/db/migrate/20120111141717_activity_channels.rb +0 -74
@@ -0,0 +1,40 @@
|
|
1
|
+
SocialStream.Action = (function(SS, $, undefined){
|
2
|
+
var updateCallbacks = [];
|
3
|
+
|
4
|
+
var addUpdateCallback = function(callback){
|
5
|
+
updateCallbacks.push(callback);
|
6
|
+
}
|
7
|
+
|
8
|
+
var update = function(action){
|
9
|
+
$.each(updateCallbacks, function(i, callback){ callback(action); });
|
10
|
+
}
|
11
|
+
|
12
|
+
var updateFollow = function(action){
|
13
|
+
var follow = action.follow;
|
14
|
+
|
15
|
+
if (!follow) {
|
16
|
+
return;
|
17
|
+
}
|
18
|
+
|
19
|
+
followForms(action).replaceWith(follow.form);
|
20
|
+
followSentences(action).replaceWith(follow.sentence);
|
21
|
+
}
|
22
|
+
|
23
|
+
var followForms = function(action) {
|
24
|
+
return $('.follow_form-' + action.activity_object.id);
|
25
|
+
}
|
26
|
+
|
27
|
+
var followSentences = function(action) {
|
28
|
+
return $('.follow_sentence-' + action.activity_object.id);
|
29
|
+
}
|
30
|
+
|
31
|
+
addUpdateCallback(updateFollow);
|
32
|
+
|
33
|
+
return {
|
34
|
+
addUpdateCallback: addUpdateCallback,
|
35
|
+
update: update,
|
36
|
+
followForms: followForms,
|
37
|
+
followSentences: followSentences
|
38
|
+
}
|
39
|
+
|
40
|
+
})(SocialStream, jQuery);
|
@@ -10,22 +10,38 @@ SocialStream.Comments = (function(SS, $, undefined){
|
|
10
10
|
$(".activity_new_comment").each(function(){
|
11
11
|
if ($.trim($(this).siblings(".activity_comments").text()) != ""){
|
12
12
|
$(this).show();
|
13
|
+
$(this).find(".input_new_comments").val("");
|
13
14
|
}
|
14
15
|
});
|
15
16
|
|
17
|
+
hideNewCommentElements();
|
18
|
+
newCommentWatermark();
|
19
|
+
newCommentAutoSize();
|
20
|
+
newCommentClick();
|
21
|
+
newCommentLink();
|
22
|
+
}
|
23
|
+
|
24
|
+
var hideNewCommentElements = function(){
|
16
25
|
$(".activities_comment_btn").hide();
|
17
26
|
$(".actor_name_new_comment").hide();
|
18
27
|
$(".actor_logo_new_comment").hide();
|
28
|
+
}
|
19
29
|
|
30
|
+
var newCommentWatermark = function(){
|
20
31
|
$(".input_new_comments").watermark(I18n.t('comment.input'),"#666");
|
32
|
+
}
|
33
|
+
|
21
34
|
|
35
|
+
var newCommentAutoSize = function(){
|
22
36
|
$(".input_new_comments")
|
23
37
|
.change(function(){autoSize(this);})
|
24
38
|
.keydown(function(){autoSize(this);})
|
25
39
|
.keyup(function(){autoSize(this);});
|
26
40
|
|
27
41
|
$(".input_new_comments").each(function(){autoSize(this)});
|
42
|
+
}
|
28
43
|
|
44
|
+
var newCommentClick = function(){
|
29
45
|
$(".input_new_comments").click(function(){
|
30
46
|
$(".activities_comment_btn").hide();
|
31
47
|
$(".new_comment").removeClass("new_comment_shown");
|
@@ -38,7 +54,9 @@ SocialStream.Comments = (function(SS, $, undefined){
|
|
38
54
|
comment.find(".actor_logo_new_comment").show();
|
39
55
|
return false;
|
40
56
|
});
|
57
|
+
}
|
41
58
|
|
59
|
+
var newCommentLink = function(){
|
42
60
|
//javascript for tocomment option
|
43
61
|
$(".to_comment").click(function(){
|
44
62
|
$(this).parents(".activity_content").find(".activity_new_comment").show();
|
@@ -49,7 +67,7 @@ SocialStream.Comments = (function(SS, $, undefined){
|
|
49
67
|
.focus()
|
50
68
|
.val("");
|
51
69
|
|
52
|
-
|
70
|
+
return false;
|
53
71
|
});
|
54
72
|
}
|
55
73
|
|
@@ -61,6 +79,13 @@ SocialStream.Comments = (function(SS, $, undefined){
|
|
61
79
|
}
|
62
80
|
|
63
81
|
SocialStream.Timeline.addInitCallback(initNew);
|
82
|
+
|
83
|
+
SocialStream.Timeline.addCreateCallback(hideNewCommentElements);
|
84
|
+
SocialStream.Timeline.addCreateCallback(newCommentWatermark);
|
85
|
+
SocialStream.Timeline.addCreateCallback(newCommentAutoSize);
|
86
|
+
SocialStream.Timeline.addCreateCallback(newCommentClick);
|
87
|
+
SocialStream.Timeline.addCreateCallback(newCommentLink);
|
88
|
+
|
64
89
|
SocialStream.Objects.addInitCallback(initNew);
|
65
90
|
|
66
91
|
return {
|
@@ -1,14 +1,24 @@
|
|
1
1
|
SocialStream.Timeline = (function(SS, $, undefined){
|
2
|
+
// FIXME: DRY!!
|
2
3
|
var initCallbacks = [];
|
4
|
+
var createCallbacks = [];
|
3
5
|
|
4
6
|
var addInitCallback = function(callback){
|
5
7
|
initCallbacks.push(callback);
|
6
8
|
}
|
7
9
|
|
10
|
+
var addCreateCallback = function(callback){
|
11
|
+
createCallbacks.push(callback);
|
12
|
+
}
|
13
|
+
|
8
14
|
var init = function(){
|
9
15
|
$.each(initCallbacks, function(i, callback){ callback(); });
|
10
16
|
}
|
11
17
|
|
18
|
+
var create = function(activityId){
|
19
|
+
$.each(createCallbacks, function(i, callback){ callback(activityId); });
|
20
|
+
}
|
21
|
+
|
12
22
|
var initPrivacyTooltips = function(activityId) {
|
13
23
|
var fullId = '.activity_audience';
|
14
24
|
var summaryId = '.activity_audience_summary';
|
@@ -51,19 +61,17 @@ SocialStream.Timeline = (function(SS, $, undefined){
|
|
51
61
|
};
|
52
62
|
|
53
63
|
|
54
|
-
var newActivity = function(activityId){
|
55
|
-
initPrivacyTooltips(activityId);
|
56
|
-
SS.Wall.unblockForms();
|
57
|
-
}
|
58
|
-
|
59
64
|
addInitCallback(initPrivacyTooltips);
|
60
65
|
addInitCallback(initComments);
|
61
66
|
|
67
|
+
addCreateCallback(initPrivacyTooltips);
|
68
|
+
|
62
69
|
return {
|
63
70
|
addInitCallback: addInitCallback,
|
64
71
|
init: init,
|
72
|
+
addCreateCallback: addCreateCallback,
|
73
|
+
create: create,
|
65
74
|
initPrivacyTooltips: initPrivacyTooltips,
|
66
|
-
showAllComments: showAllComments
|
67
|
-
newActivity: newActivity
|
75
|
+
showAllComments: showAllComments
|
68
76
|
};
|
69
77
|
}) (SocialStream, jQuery);
|
data/app/models/activity.rb
CHANGED
@@ -331,13 +331,17 @@ class Activity < ActiveRecord::Base
|
|
331
331
|
def fill_relations
|
332
332
|
return if relation_ids.present?
|
333
333
|
|
334
|
-
# FIXME: repeated in SocialStream::Models::Object#_relation_ids
|
335
334
|
self.relation_ids =
|
335
|
+
# FIXME: repeated in ActivityObject#_relation_ids
|
336
|
+
if SocialStream.relation_model == :custom
|
336
337
|
if channel.reflexive?
|
337
338
|
receiver.relation_customs.map(&:id)
|
338
339
|
else
|
339
340
|
receiver.relation_customs.allow(channel.author, 'create', 'activity').map(&:id)
|
340
341
|
end
|
342
|
+
else
|
343
|
+
Array.wrap Relation::Public.instance.id
|
344
|
+
end
|
341
345
|
end
|
342
346
|
|
343
347
|
#
|
@@ -15,6 +15,8 @@ class ActivityAction < ActiveRecord::Base
|
|
15
15
|
where(:activity_object_id => ActivityObject.normalize_id(activity_object))
|
16
16
|
}
|
17
17
|
|
18
|
+
before_create :follow_by_author_and_owner
|
19
|
+
|
18
20
|
private
|
19
21
|
|
20
22
|
# Updates the follower_count counter in the {ActivityObject}
|
@@ -25,4 +27,8 @@ class ActivityAction < ActiveRecord::Base
|
|
25
27
|
activity_object.increment!(:follower_count) :
|
26
28
|
activity_object.decrement!(:follower_count)
|
27
29
|
end
|
30
|
+
|
31
|
+
def follow_by_author_and_owner
|
32
|
+
self.follow = true if author? || user_author? || owner?
|
33
|
+
end
|
28
34
|
end
|
@@ -9,8 +9,8 @@
|
|
9
9
|
# Objects are added to +config/initializers/social_stream.rb+
|
10
10
|
#
|
11
11
|
class ActivityObject < ActiveRecord::Base
|
12
|
-
|
13
|
-
|
12
|
+
attr_writer :_relation_ids
|
13
|
+
attr_reader :_activity_parent_id
|
14
14
|
|
15
15
|
# ActivityObject is a supertype of SocialStream.objects
|
16
16
|
supertype_of :object
|
@@ -22,7 +22,8 @@ class ActivityObject < ActiveRecord::Base
|
|
22
22
|
|
23
23
|
has_many :received_actions,
|
24
24
|
:class_name => "ActivityAction",
|
25
|
-
:dependent => :destroy
|
25
|
+
:dependent => :destroy,
|
26
|
+
:autosave => true
|
26
27
|
has_many :followers,
|
27
28
|
:through => :received_actions,
|
28
29
|
:source => :actor,
|
@@ -43,10 +44,71 @@ class ActivityObject < ActiveRecord::Base
|
|
43
44
|
|
44
45
|
validates_presence_of :object_type
|
45
46
|
|
47
|
+
# TODO: This is currently defined in lib/social_stream/models/object.rb
|
48
|
+
#
|
49
|
+
# Need to fix activity_object_spec_helper before activating it
|
50
|
+
#
|
51
|
+
# validates_presence_of :author_id, :owner_id, :user_author_id, :unless => :acts_as_actor?
|
52
|
+
# after_create :create_post_activity, :unless => :acts_as_actor?
|
53
|
+
|
46
54
|
scope :authored_by, lambda { |subject|
|
47
|
-
joins(:
|
55
|
+
joins(:received_author_action).merge(ActivityAction.sent_by(subject))
|
48
56
|
}
|
49
57
|
|
58
|
+
scope :followed, order("activity_objects.follower_count DESC")
|
59
|
+
|
60
|
+
def received_role_action(role)
|
61
|
+
received_actions.
|
62
|
+
find{ |a| a.__send__ "#{ role }?" }
|
63
|
+
end
|
64
|
+
|
65
|
+
%w{ author user_author owner }.each do |role|
|
66
|
+
code = <<-EOC
|
67
|
+
def #{ role }_id # def author_id
|
68
|
+
received_role_action(:#{ role }). # received_role_action(:author).
|
69
|
+
try(:actor_id) # try(:actor_id)
|
70
|
+
end # end
|
71
|
+
|
72
|
+
def #{ role }_id=(actor_id) # def author_id=(actor_id)
|
73
|
+
action = # action =
|
74
|
+
received_actions. # received_actions.
|
75
|
+
find{ |a| a.actor_id == actor_id } # select{ |a| a.actor_id == actor_id }
|
76
|
+
#
|
77
|
+
if action # if action
|
78
|
+
action.#{ role } = true # action.author = true
|
79
|
+
else # else
|
80
|
+
received_actions. # received_actions.
|
81
|
+
build :actor_id => actor_id, # build :actor_id => actor_id,
|
82
|
+
:#{ role } => true # :author => true
|
83
|
+
end # end
|
84
|
+
#
|
85
|
+
actor_id # actor_id
|
86
|
+
end # end
|
87
|
+
|
88
|
+
def #{ role } # def author
|
89
|
+
received_role_action(:#{ role }). # received_role_action(:author).
|
90
|
+
try(:actor) # try(:actor)
|
91
|
+
end # end
|
92
|
+
|
93
|
+
def #{ role }=(actor) # def author=(actor)
|
94
|
+
self.#{ role }_id = # self.author_id =
|
95
|
+
Actor.normalize_id(actor) # Actor.normalize_id(actor)
|
96
|
+
end # end
|
97
|
+
|
98
|
+
def #{ role }_subject # def author_subject
|
99
|
+
#{ role }.subject # author.subject
|
100
|
+
end # end
|
101
|
+
|
102
|
+
EOC
|
103
|
+
|
104
|
+
class_eval code, __FILE__, __LINE__ - code.lines.count - 2
|
105
|
+
end
|
106
|
+
|
107
|
+
# Was the author represented when this {ActivityObject} was created?
|
108
|
+
def represented_author?
|
109
|
+
author_id != user_author_id
|
110
|
+
end
|
111
|
+
|
50
112
|
# The object of this activity object
|
51
113
|
def object
|
52
114
|
subtype_instance.is_a?(Actor) ?
|
@@ -54,11 +116,6 @@ class ActivityObject < ActiveRecord::Base
|
|
54
116
|
subtype_instance
|
55
117
|
end
|
56
118
|
|
57
|
-
# The activity in which this activity_object was created
|
58
|
-
def post_activity
|
59
|
-
activities.includes(:activity_verb).where('activity_verbs.name' => 'post').first
|
60
|
-
end
|
61
|
-
|
62
119
|
# Does this {ActivityObject} has {Actor}?
|
63
120
|
def acts_as_actor?
|
64
121
|
object_type == "Actor"
|
@@ -69,4 +126,69 @@ class ActivityObject < ActiveRecord::Base
|
|
69
126
|
received_actions.sent_by(actor).first
|
70
127
|
end
|
71
128
|
|
129
|
+
# The activity in which this activity_object was created
|
130
|
+
def post_activity
|
131
|
+
activities.includes(:activity_verb).where('activity_verbs.name' => 'post').first
|
132
|
+
end
|
133
|
+
|
134
|
+
# Build the post activity when this object is not saved
|
135
|
+
def build_post_activity
|
136
|
+
Activity.new :author => author,
|
137
|
+
:user_author => user_author,
|
138
|
+
:owner => owner,
|
139
|
+
:relation_ids => Array(_relation_ids)
|
140
|
+
end
|
141
|
+
|
142
|
+
def _relation_ids
|
143
|
+
@_relation_ids ||=
|
144
|
+
if author.blank? || owner.blank?
|
145
|
+
nil
|
146
|
+
else
|
147
|
+
# FIXME: repeated in Activity#fill_relations
|
148
|
+
if SocialStream.relation_model == :custom
|
149
|
+
if author == owner
|
150
|
+
owner.relation_customs.map(&:id)
|
151
|
+
else
|
152
|
+
owner.
|
153
|
+
relation_customs.
|
154
|
+
allow(author, 'create', 'activity').
|
155
|
+
map(&:id)
|
156
|
+
end
|
157
|
+
else
|
158
|
+
Array.wrap Relation::Public.instance.id
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
def _activity_parent
|
164
|
+
@_activity_parent ||= Activity.find(_activity_parent_id)
|
165
|
+
end
|
166
|
+
|
167
|
+
def _activity_parent_id=(id)
|
168
|
+
self._relation_ids = Activity.find(id).relation_ids
|
169
|
+
@_activity_parent_id = id
|
170
|
+
end
|
171
|
+
|
172
|
+
private
|
173
|
+
|
174
|
+
def create_post_activity
|
175
|
+
create_activity "post"
|
176
|
+
end
|
177
|
+
|
178
|
+
def create_update_activity
|
179
|
+
create_activity "update"
|
180
|
+
end
|
181
|
+
|
182
|
+
def create_activity(verb)
|
183
|
+
a = Activity.new :verb => verb,
|
184
|
+
:author_id => author_id,
|
185
|
+
:user_author => user_author,
|
186
|
+
:owner => owner,
|
187
|
+
:relation_ids => _relation_ids,
|
188
|
+
:parent_id => _activity_parent_id
|
189
|
+
|
190
|
+
a.activity_objects << self
|
191
|
+
|
192
|
+
a.save!
|
193
|
+
end
|
72
194
|
end
|
data/app/models/actor.rb
CHANGED
@@ -113,6 +113,8 @@ class Actor < ActiveRecord::Base
|
|
113
113
|
joins(:received_contacts).merge(Contact.active.sent_by(a))
|
114
114
|
}
|
115
115
|
|
116
|
+
scope :followed, joins(:activity_object).merge(ActivityObject.followed)
|
117
|
+
|
116
118
|
scope :followed_by, lambda { |a|
|
117
119
|
select("DISTINCT actors.*").
|
118
120
|
joins(:received_ties => { :relation => :permissions }).
|
data/app/models/channel.rb
CHANGED
@@ -19,7 +19,6 @@ class Channel < ActiveRecord::Base
|
|
19
19
|
belongs_to :user_author,
|
20
20
|
:class_name => "Actor"
|
21
21
|
|
22
|
-
has_many :activity_objects, :dependent => :destroy
|
23
22
|
has_many :activities, :dependent => :destroy
|
24
23
|
|
25
24
|
validates_uniqueness_of :author_id, :scope => [ :owner_id, :user_author_id ]
|
data/app/models/comment.rb
CHANGED
@@ -10,16 +10,10 @@ class Comment < ActiveRecord::Base
|
|
10
10
|
has created_at
|
11
11
|
end
|
12
12
|
|
13
|
-
|
14
13
|
def parent_post
|
15
14
|
self.post_activity.parent.direct_object
|
16
15
|
end
|
17
16
|
|
18
|
-
def _activity_parent_id=(id)
|
19
|
-
self._relation_ids = Activity.find(id).relation_ids
|
20
|
-
@_activity_parent_id = id
|
21
|
-
end
|
22
|
-
|
23
17
|
def title
|
24
18
|
description.truncate(30, :separator =>' ')
|
25
19
|
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
SocialStream.Action.update({
|
2
|
+
activity_object: {
|
3
|
+
id: "<%= dom_id(@activity_action.activity_object) %>",
|
4
|
+
type: "<%= @activity_action.activity_object.object_type %>"
|
5
|
+
},
|
6
|
+
follow: {
|
7
|
+
following: <%= @activity_action.follow? %>,
|
8
|
+
form: "<%= escape_javascript render(:partial => 'activity_actions/follow_form', :locals => { :activity_object => @activity_action.activity_object }) %>",
|
9
|
+
sentence: "<%= escape_javascript render(:partial => 'activity_actions/follow_sentence', :locals => { :activity_object => @activity_action.activity_object }) %>"
|
10
|
+
}
|
11
|
+
});
|
@@ -1 +1 @@
|
|
1
|
-
<%= render :partial => '
|
1
|
+
<%= render :partial => 'update' %>
|
@@ -1 +1 @@
|
|
1
|
-
<%= render :partial => '
|
1
|
+
<%= render :partial => 'update' %>
|
@@ -1,4 +1,4 @@
|
|
1
1
|
//Display the new post
|
2
2
|
$("#wall").prepend("<%= escape_javascript(render @post.post_activity) %>");
|
3
3
|
|
4
|
-
SocialStream.Timeline.
|
4
|
+
SocialStream.Timeline.create("<%= escape_javascript dom_id(@post.post_activity) %>");
|