social_stream 0.26.0 → 0.26.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (114) hide show
  1. data/Gemfile +1 -1
  2. data/base/README.rdoc +2 -2
  3. data/base/app/assets/stylesheets/base.css.scss +1 -1
  4. data/base/app/controllers/activities_controller.rb +1 -2
  5. data/base/app/controllers/profiles_controller.rb +40 -8
  6. data/base/app/controllers/search_controller.rb +6 -49
  7. data/base/app/helpers/search_helper.rb +4 -34
  8. data/base/app/models/activity_object.rb +37 -4
  9. data/base/app/models/actor.rb +6 -0
  10. data/base/app/models/relation.rb +15 -0
  11. data/base/app/models/tie.rb +6 -0
  12. data/base/app/views/comments/create.js.erb +12 -7
  13. data/base/app/views/messages/_form.html.erb +1 -1
  14. data/base/app/views/posts/create.js.erb +8 -3
  15. data/base/app/views/search/_extended_search.html.erb +1 -1
  16. data/base/app/views/search/_extended_tab.html.erb +5 -0
  17. data/base/app/views/search/_form.html.erb +3 -3
  18. data/base/app/views/search/index.js.erb +3 -3
  19. data/base/config/routes.rb +6 -2
  20. data/base/lib/logos/groups/1.jpg +0 -0
  21. data/base/lib/logos/groups/10.jpg +0 -0
  22. data/base/lib/logos/groups/11.jpg +0 -0
  23. data/base/lib/logos/groups/12.jpg +0 -0
  24. data/base/lib/logos/groups/2.jpg +0 -0
  25. data/base/lib/logos/groups/3.jpg +0 -0
  26. data/base/lib/logos/groups/4.jpg +0 -0
  27. data/base/lib/logos/groups/5.jpg +0 -0
  28. data/base/lib/logos/groups/6.jpg +0 -0
  29. data/base/lib/logos/groups/7.jpg +0 -0
  30. data/base/lib/logos/groups/8.jpg +0 -0
  31. data/base/lib/logos/groups/9.jpg +0 -0
  32. data/base/lib/logos/partners/1.jpg +0 -0
  33. data/base/lib/logos/partners/1.png +0 -0
  34. data/base/lib/logos/partners/2.jpg +0 -0
  35. data/base/lib/logos/partners/2.png +0 -0
  36. data/base/lib/logos/users/1.jpg +0 -0
  37. data/base/lib/logos/users/10.jpg +0 -0
  38. data/base/lib/logos/users/11.jpg +0 -0
  39. data/base/lib/logos/users/12.jpg +0 -0
  40. data/base/lib/logos/users/2.jpg +0 -0
  41. data/base/lib/logos/users/3.jpg +0 -0
  42. data/base/lib/logos/users/4.jpg +0 -0
  43. data/base/lib/logos/users/5.jpg +0 -0
  44. data/base/lib/logos/users/6.jpg +0 -0
  45. data/base/lib/logos/users/7.jpg +0 -0
  46. data/base/lib/logos/users/8.jpg +0 -0
  47. data/base/lib/logos/users/9.jpg +0 -0
  48. data/base/lib/social_stream-base.rb +8 -0
  49. data/base/lib/social_stream/base/dependencies.rb +3 -1
  50. data/base/lib/social_stream/base/thinking-sphinx.rb +3 -1
  51. data/base/lib/social_stream/base/version.rb +1 -1
  52. data/base/lib/social_stream/controllers/helpers.rb +36 -30
  53. data/base/lib/social_stream/controllers/objects.rb +89 -1
  54. data/base/lib/social_stream/controllers/subjects.rb +3 -1
  55. data/base/lib/social_stream/models/object.rb +18 -0
  56. data/base/lib/social_stream/models/subject.rb +2 -0
  57. data/base/lib/social_stream/population/activity_object.rb +55 -0
  58. data/base/lib/social_stream/{populate.rb → population/power_law.rb} +3 -4
  59. data/base/lib/social_stream/population/timestamps.rb +12 -0
  60. data/base/lib/social_stream/search.rb +107 -0
  61. data/base/lib/tasks/db/populate.rake +13 -26
  62. data/base/social_stream-base.gemspec +3 -1
  63. data/base/spec/models/post_spec.rb +14 -0
  64. data/documents/app/controllers/documents_controller.rb +10 -34
  65. data/documents/app/controllers/pictures_controller.rb +6 -0
  66. data/documents/app/models/document.rb +2 -2
  67. data/documents/app/views/audios/index.html.erb +1 -1
  68. data/documents/app/views/common_documents/_headers.html.erb +20 -15
  69. data/documents/app/views/common_documents/_index.html.erb +5 -6
  70. data/documents/app/views/documents/index.html.erb +1 -1
  71. data/documents/app/views/documents/search.html.erb +3 -0
  72. data/documents/app/views/pictures/index.html.erb +1 -1
  73. data/documents/app/views/videos/index.html.erb +1 -1
  74. data/documents/config/routes.rb +2 -0
  75. data/documents/lib/samples/car.jpg +0 -0
  76. data/documents/lib/samples/house.jpg +0 -0
  77. data/documents/lib/samples/loremipsum.odt +0 -0
  78. data/documents/lib/samples/loremipsum.pdf +0 -0
  79. data/documents/lib/samples/siren.mp3 +0 -0
  80. data/documents/lib/samples/water.mp3 +0 -0
  81. data/documents/lib/social_stream/documents/version.rb +1 -1
  82. data/documents/lib/tasks/db/populate_documents.rake +6 -23
  83. data/documents/social_stream-documents.gemspec +1 -1
  84. data/events/app/assets/javascripts/social_stream-events.js +3 -0
  85. data/events/app/assets/javascripts/social_stream.event.js +5 -0
  86. data/events/app/controllers/events_controller.rb +1 -3
  87. data/events/app/models/event.rb +1 -1
  88. data/events/app/views/events/create.js.erb +1 -1
  89. data/events/app/views/events/index.html.erb +1 -1
  90. data/events/lib/social_stream/events/version.rb +1 -1
  91. data/events/social_stream-events.gemspec +1 -2
  92. data/lib/social_stream.rb +6 -6
  93. data/lib/social_stream/release/component.rb +29 -0
  94. data/lib/social_stream/release/component/version_file.rb +1 -1
  95. data/lib/social_stream/release/global.rb +65 -0
  96. data/lib/social_stream/release/global/version_file.rb +1 -1
  97. data/lib/social_stream/version.rb +1 -1
  98. data/linkser/lib/social_stream/linkser/version.rb +1 -1
  99. data/linkser/lib/tasks/db/populate_links.rake +4 -23
  100. data/linkser/social_stream-linkser.gemspec +2 -2
  101. data/presence/lib/social_stream/presence/version.rb +1 -1
  102. data/presence/social_stream-presence.gemspec +2 -2
  103. data/release.thor +69 -0
  104. data/social_stream.gemspec +6 -6
  105. data/spec/dummy/.gitignore +4 -1
  106. data/spec/dummy/app/assets/javascripts/application.js +5 -2
  107. data/spec/dummy/app/assets/stylesheets/application.css +6 -1
  108. data/spec/dummy/db/schema.rb +4 -2
  109. metadata +76 -40
  110. data/events/app/assets/javascripts/social_stream.events.tools.js.coffee +0 -50
  111. data/lib/social_stream/release.rb +0 -63
  112. data/lib/social_stream/release/component/release.rb +0 -29
  113. data/lib/social_stream/release/global/release.rb +0 -70
  114. data/social_stream.thor +0 -21
@@ -1,14 +1,13 @@
1
1
  module SocialStream
2
- module Populate
3
-
4
- class << self
2
+ module Population
3
+ class PowerLaw
5
4
  # Yields each element of array y times given by
6
5
  # {power law distribution}[http://en.wikipedia.org/wiki/Power_law]
7
6
  # y = ax**k + e
8
7
  #
9
8
  # Options: Each constant in the function
10
9
  #
11
- def power_law(array, options = {})
10
+ def initialize(array, options = {})
12
11
  options[:a] ||= array.size
13
12
  options[:k] ||= -2.5
14
13
  options[:e] ||= 1
@@ -0,0 +1,12 @@
1
+ module SocialStream
2
+ module Population
3
+ class Timestamps
4
+ attr_reader :created, :updated
5
+
6
+ def initialize
7
+ @updated = Time.at(rand(Time.now.to_i))
8
+ @created = Time.at(rand(@updated.to_i))
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,107 @@
1
+ module SocialStream
2
+ module Search
3
+ class << self
4
+ def keys(search_type)
5
+ case search_type
6
+ when :quick
7
+ SocialStream.quick_search_models
8
+ when :extended
9
+ extended_search_models.keys
10
+ end
11
+ end
12
+
13
+ def models(search_type, key = nil)
14
+ case search_type
15
+ when :quick
16
+ quick_search_models
17
+ when :extended
18
+ if key.present?
19
+ if extended_search_models.keys.include?(key.to_sym)
20
+ extended_search_models[key.to_sym]
21
+ else
22
+ if extended_search_models.values.flatten.map{ |k| k.to_s }.include?(key.to_s.classify)
23
+ [key.to_s.classify.constantize]
24
+ else
25
+ raise "Unknown search key #{ key }"
26
+ end
27
+ end
28
+ else
29
+ extended_search_models.values.flatten
30
+ end
31
+ else
32
+ raise "Unknown search type #{ search_type }"
33
+ end
34
+ end
35
+
36
+ def search(query, subject, options = {})
37
+ ThinkingSphinx.search *args_for_search(query, subject, options)
38
+ end
39
+
40
+ def count(query, subject, options = {})
41
+ ThinkingSphinx.count *args_for_search(query, subject, options)
42
+ end
43
+
44
+
45
+ private
46
+
47
+ def quick_search_models
48
+ @quick_search_models ||=
49
+ parse_quick_search_models
50
+ end
51
+
52
+ def parse_quick_search_models
53
+ SocialStream.quick_search_models.map{ |m|
54
+ m.to_s.classify.constantize
55
+ }
56
+ end
57
+
58
+ def extended_search_models
59
+ @extended_search_models ||=
60
+ parse_extended_search_models
61
+ end
62
+
63
+ # Get a normalized hash from the configuration. Converts this:
64
+ #
65
+ # [ :excursion, :user, { :resource => [ :post, :comment, :picture ] }
66
+ #
67
+ # into this:
68
+ #
69
+ # {
70
+ # :excursion => [ Excursion ],
71
+ # :user => [ User ],
72
+ # :resource => [ Post, Comment, Picture ]
73
+ # }
74
+ #
75
+ def parse_extended_search_models
76
+ SocialStream.extended_search_models.inject({}) do |hash, entry|
77
+ case entry
78
+ when Hash
79
+ hash.update entry.inject({}){ |h, e|
80
+ h[e.first] = Array.wrap(e.last).map{ |f| f.to_s.classify.constantize }
81
+ h
82
+ }
83
+ when Symbol
84
+ hash[entry] = Array.wrap(entry.to_s.classify.constantize)
85
+ else
86
+ raise "Unknown entry in config.extended_search_models #{ entry }"
87
+ end
88
+
89
+ hash
90
+ end
91
+ end
92
+
93
+ def args_for_search(query, subject, options = {})
94
+ options[:mode] ||= :extended
95
+
96
+ models = models(options[:mode], options[:key])
97
+ relation_ids = Relation.ids_shared_with(subject)
98
+
99
+ [
100
+ query,
101
+ :classes => models,
102
+ :with => { :relation_ids => relation_ids }
103
+ ]
104
+ end
105
+ end
106
+ end
107
+ end
@@ -17,8 +17,9 @@ namespace :db do
17
17
  task :read_environment => :environment do
18
18
  require 'forgery'
19
19
 
20
- @LOGOS_PATH = File.join(Rails.root, 'lib', 'logos')
21
- @LOGOS_TOTAL = (ENV["LOGOS_TOTAL"] || 10).to_i
20
+ @SS_BASE_PATH = Gem::Specification.find_by_name('social_stream-base').full_gem_path
21
+ @LOGOS_PATH = File.join(@SS_BASE_PATH, 'lib', 'logos')
22
+ @LOGOS_TOTAL = (ENV["LOGOS_TOTAL"] || 12).to_i
22
23
  @USERS = (ENV["USERS"] || 9).to_i
23
24
  @GROUPS = (ENV["GROUPS"] || 10).to_i
24
25
  if ENV["HARDCORE"].present?
@@ -122,6 +123,13 @@ namespace :db do
122
123
  end
123
124
  end
124
125
 
126
+ Activity.includes(:activity_verb).merge(ActivityVerb.verb_name(["follow", "make-friend"])).each do |a|
127
+ t = SocialStream::Population::Timestamps.new
128
+
129
+ a.update_attributes :created_at => t.created,
130
+ :updated_at => t.updated
131
+ end
132
+
125
133
  ties_end = Time.now
126
134
  puts ' -> ' + (ties_end - ties_start).round(4).to_s + 's'
127
135
  end
@@ -159,31 +167,10 @@ namespace :db do
159
167
  # POSTS
160
168
  desc "Create posts"
161
169
  task :create_posts => :read_environment do
162
- puts 'Post population'
163
- posts_start = Time.now
164
-
165
- SocialStream::Populate.power_law(Tie.positive.all) do |t|
166
- updated = Time.at(rand(Time.now.to_i))
167
-
168
- author = t.sender
169
- owner = t.receiver
170
- user_author = ( t.sender.subject_type == "User" ? t.sender : t.sender.user_author )
171
-
172
- p = Post.create :text =>
173
- "This post should be for #{ t.relation.name } of #{ t.sender.name }.\n#{ Forgery::LoremIpsum.paragraph(:random => true) }",
174
- :created_at => Time.at(rand(updated.to_i)),
175
- :updated_at => updated,
176
- :author_id => author.id,
177
- :owner_id => owner.id,
178
- :user_author_id => user_author.id,
179
- :relation_ids => Array(t.relation_id)
180
-
181
- p.post_activity.update_attributes(:created_at => p.created_at,
182
- :updated_at => p.updated_at)
170
+ SocialStream::Population::ActivityObject.new Post do |p|
171
+ p.text =
172
+ "This post should be for #{ p.relations.map(&:name).join(", ") } of #{ p.owner.name }.\n#{ Forgery::LoremIpsum.paragraph(:random => true) }"
183
173
  end
184
-
185
- posts_end = Time.now
186
- puts ' -> ' + (posts_end - posts_start).round(4).to_s + 's'
187
174
  end
188
175
 
189
176
 
@@ -15,6 +15,8 @@ Gem::Specification.new do |s|
15
15
  #
16
16
  # Do not forget to require the file at lib/social_stream/base/dependencies !
17
17
  #
18
+ # Deep Merge support for Hashes
19
+ s.add_runtime_dependency('deep_merge')
18
20
  # Rails
19
21
  s.add_runtime_dependency('rails', '>= 3.1.0')
20
22
  # Activity and Relation hierarchies
@@ -70,7 +72,7 @@ Gem::Specification.new do |s|
70
72
  if RUBY_VERSION < '1.9'
71
73
  s.add_development_dependency('ruby-debug')
72
74
  else
73
- s.add_development_dependency('ruby-debug19')
75
+ s.add_development_dependency('debugger')
74
76
  end
75
77
  # Specs
76
78
  s.add_development_dependency('rspec-rails', '~> 2.6.1')
@@ -104,6 +104,18 @@ describe Post do
104
104
  post.post_activity.relations.should include(tie.relation)
105
105
  end
106
106
  end
107
+
108
+ describe "a new post" do
109
+ before do
110
+ @user = Factory(:user)
111
+ @post = Post.create!(:text => "test",
112
+ :author_id => @user.actor_id)
113
+ end
114
+
115
+ it "should be shared with user relations" do
116
+ @post.relation_ids.sort.should eq(@user.relation_ids.sort)
117
+ end
118
+ end
107
119
  end
108
120
 
109
121
  describe "authored_by" do
@@ -113,4 +125,6 @@ describe Post do
113
125
  Post.authored_by(post.author).should include(post)
114
126
  end
115
127
  end
128
+
129
+
116
130
  end
@@ -1,21 +1,19 @@
1
1
  class DocumentsController < ApplicationController
2
- include ActionView::Helpers::SanitizeHelper
3
2
  include SocialStream::Controllers::Objects
4
3
 
5
- belongs_to_subjects :optional => true
6
-
7
4
  before_filter :profile_subject!, :only => :index
8
5
 
9
- PER_PAGE=20
10
-
11
6
  def index
12
- super do |format|
13
- format.json { render :json => collection.map{|a| a.activity_objects.first.document} }
14
- if params[:no_layout].present?
15
- format.html { render :action => :index, :layout => false }
16
- else
17
- format.html { render :action => :index }
18
- end
7
+ respond_to do |format|
8
+ format.html {
9
+ collection
10
+
11
+ if params[:no_layout].present?
12
+ render :layout => false
13
+ end
14
+ }
15
+
16
+ format.json { render :json => collection }
19
17
  end
20
18
  end
21
19
 
@@ -64,31 +62,9 @@ class DocumentsController < ApplicationController
64
62
 
65
63
  private
66
64
 
67
- def collection
68
- @activities = profile_subject.wall(:profile,
69
- :for => current_subject,
70
- :object_type => Array(self.class.index_object_type))
71
- if params[:q].present?
72
- @activities = @activities.joins(:activity_objects).where('activity_objects.title LIKE ? OR activity_objects.description LIKE ?', get_search_query, get_search_query)
73
- end
74
- @activities = @activities.page(params[:page]).per(PER_PAGE)
75
- end
76
-
77
65
  class << self
78
66
  def index_object_type
79
67
  [ :Audio, :Video, :Picture, :Document ]
80
68
  end
81
69
  end
82
-
83
- def get_search_query
84
- search_query = ""
85
- param = strip_tags(params[:q]) || ""
86
- bare_query = param unless bare_query.html_safe?
87
- search_query_words = bare_query.strip.split
88
- search_query_words.each_index do |i|
89
- search_query+= search_query_words[i] + " " if i < (search_query_words.size - 1)
90
- search_query+= "%" + search_query_words[i] + "% " if i == (search_query_words.size - 1)
91
- end
92
- return search_query.strip
93
- end
94
70
  end
@@ -1,2 +1,8 @@
1
1
  class PicturesController < DocumentsController
2
+ before_filter :default_style
3
+
4
+ protected
5
+ def default_style
6
+ params[:style] ||= 'original'
7
+ end
2
8
  end
@@ -6,6 +6,8 @@ class Document < ActiveRecord::Base
6
6
  has_attached_file :file,
7
7
  :url => '/:class/:id.:extension',
8
8
  :path => ':rails_root/documents/:class/:id_partition/:style/:filename.:extension'
9
+
10
+ paginates_per 20
9
11
 
10
12
  validates_attachment_presence :file
11
13
  validates_presence_of :title
@@ -18,8 +20,6 @@ class Document < ActiveRecord::Base
18
20
  activity_object_index
19
21
 
20
22
  indexes file_file_name, :as => :file_name
21
-
22
- where "type IS NULL"
23
23
  end
24
24
 
25
25
  class << self
@@ -1 +1 @@
1
- <%=render(:partial => 'common_documents/index') %>
1
+ <%= render :partial => 'common_documents/index', :locals => { :documents => @audios } %>
@@ -1,25 +1,30 @@
1
1
  <% content_for :title do %>
2
- <%= profile_subject.name + ": " + t('repository.title') %>
2
+ <%= "#{ profile_subject && profile_subject.name + ': ' }#{ t('repository.title') }" %>
3
3
  <% end %>
4
4
 
5
5
  <% sidebar %>
6
6
 
7
- <%if profile_subject_is_current?%>
8
- <%= location(
9
- link_to(t('repository.title'), polymorphic_path(controller.controller_name),:remote => true)
10
- ) %>
11
- <%else%>
12
- <%= location(
13
- link_to(profile_subject.name, polymorphic_path(profile_subject),:remote => true),
14
- link_to(t('repository.title'), polymorphic_path([profile_subject, controller.controller_name]),:remote => true)
15
- ) %>
16
- <%end%>
7
+ <% if profile_subject %>
8
+ <%= location(
9
+ link_to(profile_subject.name, polymorphic_path(profile_subject),:remote => true),
10
+ link_to(t('repository.title'), polymorphic_path([profile_subject, controller.controller_name]),:remote => true)
11
+ ) %>
12
+ <% else %>
13
+ <%= location(
14
+ link_to(t('repository.title'), polymorphic_path(controller.controller_name),:remote => true)
15
+ ) %>
16
+ <% end %>
17
+
18
+ <% if profile_subject %>
19
+ <% toolbar :profile, :subject => profile_subject %>
20
+ <% elsif user_signed_in? %>
21
+ <% toolbar %>
22
+ <% end %>
17
23
 
18
- <% toolbar :profile, :subject => profile_subject %>
19
24
  <br class="clearfloat" />
20
25
  <div class="space_center"></div>
21
26
  <div id="repository_filter">
22
- <%= text_field_tag :filter_query, nil,:autocomplete => :off, :id => :repository_filter_input %>
27
+ <%= text_field_tag :q, nil,:autocomplete => :off, :id => :repository_filter_input %>
23
28
  <div id="order_by"><%= t('repository.order.by') %>: <%= t('repository.order.last_modified') %> · <%= t('repository.order.most_popular') %> </div>
24
29
  </div>
25
30
  <div class="space_center"></div>
@@ -38,7 +43,7 @@ $(document).ready(function() {
38
43
  $("#documents_grid").html("<center><%= escape_javascript(image_tag('loading.gif', :class => :loading)) %></center>");
39
44
  $.ajax({
40
45
  type : "GET",
41
- url : "<%= polymorphic_url([current_subject, Document.new]) %>?no_layout=true",
46
+ url : "<%= polymorphic_path([ profile_subject, Document.new ], :action => :search) %>",
42
47
  success : function(html) {
43
48
  if ($("#repository_filter_input").val()==searchstring){ //Only show if input value is still the same
44
49
  $("#documents_grid").html(html);
@@ -54,7 +59,7 @@ $(document).ready(function() {
54
59
  $("#documents_grid").html("<center><%= escape_javascript(image_tag('loading.gif', :class => :loading)) %></center>");
55
60
  $.ajax({
56
61
  type : "GET",
57
- url : "<%= polymorphic_url([current_subject, Document.new]) %>?q=" + searchstring + "&no_layout=true",
62
+ url : "<%= polymorphic_path([ profile_subject, Document.new ], :action => :search) %>?q=" + searchstring,
58
63
  success : function(html) {
59
64
  if ($("#repository_filter_input").val()==searchstring){ //Only show if input value is still the same
60
65
  $("#documents_grid").html(html);
@@ -1,14 +1,13 @@
1
- <% unless params[:no_layout].present? %>
1
+ <% if params[:no_layout].blank? %>
2
2
  <%= render :partial => "common_documents/headers" %>
3
3
  <div id="documents_grid">
4
4
  <% end %>
5
5
 
6
- <% @activities.each do |a| %>
7
- <% document = a.activity_objects.first.document %>
6
+ <% documents.each do |document| %>
8
7
  <div class="attachment_tile" id="<%= dom_id(document)%>">
9
8
  <div class="attachment_tile_thumb">
10
9
  <%= link_to thumb_for(document,48),
11
- document_path(document),
10
+ document,
12
11
  :type => document.type,
13
12
  :title => document.file_file_name,
14
13
  :path => document_path(document) %>
@@ -57,10 +56,10 @@ $(document).ready(function(){
57
56
  <% end %>
58
57
  <% end %>
59
58
 
60
- <% if @activities.size == DocumentsController::PER_PAGE %>
59
+ <% unless documents.last_page? %>
61
60
  <% next_url = url_for(:no_layout => true,
62
61
  :page => params[:page].present? ? params[:page].to_i + 1 : 2,
63
- :query => params[:query].present? ? params[:query] : "") %>
62
+ :q => params[:q]) %>
64
63
  <%= content_tag(:span, "", :class => "screw screw-after", :rel => next_url)%>
65
64
  <% end %>
66
65
 
@@ -1 +1 @@
1
- <%=render(:partial => 'common_documents/index') %>
1
+ <%= render :partial => 'common_documents/index', :locals => { :documents => collection } %>
@@ -0,0 +1,3 @@
1
+ <% params[:no_layout] = true %>
2
+ <%= render :partial => 'common_documents/index',
3
+ :locals => { :documents => @documents } %>
@@ -1 +1 @@
1
- <%=render(:partial => 'common_documents/index') %>
1
+ <%= render :partial => 'common_documents/index', :locals => { :documents => @pictures } %>