social_stream 0.3.6 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (266) hide show
  1. data/.gitignore +1 -0
  2. data/Gemfile +6 -0
  3. data/app/controllers/api_controller.rb +39 -0
  4. data/app/controllers/frontpage_controller.rb +2 -0
  5. data/app/controllers/groups_controller.rb +8 -2
  6. data/app/controllers/likes_controller.rb +9 -29
  7. data/app/controllers/logos_controller.rb +21 -0
  8. data/app/controllers/mailbox/conversation_controller.rb +110 -0
  9. data/app/controllers/mailbox_controller.rb +35 -0
  10. data/app/controllers/posts_controller.rb +2 -0
  11. data/app/controllers/profiles_controller.rb +3 -0
  12. data/app/controllers/ties_controller.rb +10 -0
  13. data/app/controllers/users_controller.rb +5 -5
  14. data/app/helpers/groups_helper.rb +0 -2
  15. data/app/helpers/subjects_helper.rb +11 -0
  16. data/app/helpers/ties_helper.rb +1 -1
  17. data/app/models/activity.rb +24 -1
  18. data/app/models/activity_object.rb +10 -0
  19. data/app/models/activity_object_activity.rb +10 -0
  20. data/app/models/actor.rb +87 -60
  21. data/app/models/group.rb +10 -4
  22. data/app/models/like.rb +34 -0
  23. data/app/models/logo.rb +51 -0
  24. data/app/models/permission.rb +7 -5
  25. data/app/models/profile.rb +24 -8
  26. data/app/models/tie.rb +15 -2
  27. data/app/models/user.rb +2 -2
  28. data/app/views/activities/_activities.html.erb +1 -1
  29. data/app/views/activities/_new.html.erb +12 -7
  30. data/app/views/api/activity_atom_feed.atom.builder +40 -0
  31. data/app/views/comments/_new.html.erb +1 -1
  32. data/app/views/devise/passwords/edit.html.erb +21 -0
  33. data/app/views/devise/passwords/new.html.erb +16 -0
  34. data/app/views/devise/registrations/new.html.erb +35 -19
  35. data/app/views/devise/sessions/new.html.erb +30 -0
  36. data/app/views/frontpage/_header.html.erb +18 -20
  37. data/app/views/frontpage/_search.html.erb +13 -0
  38. data/app/views/frontpage/_sponsor.html.erb +12 -13
  39. data/app/views/frontpage/index.html.erb +88 -80
  40. data/app/views/groups/_group.html.erb +2 -6
  41. data/app/views/groups/_index.html.erb +22 -25
  42. data/app/views/groups/_logo.html.erb +1 -1
  43. data/app/views/groups/_new.html.erb +56 -39
  44. data/app/views/groups/_profile.html.erb +142 -0
  45. data/app/views/groups/_sidebar_index.html.erb +73 -0
  46. data/app/views/groups/{_middle_show.html.erb → _sidebar_show.html.erb} +2 -2
  47. data/app/views/groups/_tabs.html.erb +37 -31
  48. data/app/views/groups/_toolbar_show.html.erb +12 -0
  49. data/app/views/groups/edit.html.erb +136 -0
  50. data/app/views/groups/index.html.erb +47 -46
  51. data/app/views/groups/new.html.erb +2 -0
  52. data/app/views/groups/show.html.erb +9 -4
  53. data/app/views/groups/update.js.erb +39 -0
  54. data/app/views/home/_groups.html.erb +4 -5
  55. data/app/views/{users/_middle_index.html.erb → home/_sidebar.html.erb} +0 -2
  56. data/app/views/home/index.html.erb +3 -5
  57. data/app/views/layouts/_footer.html.erb +4 -0
  58. data/app/views/layouts/_header.erb +29 -37
  59. data/app/views/layouts/_representation.html.erb +2 -2
  60. data/app/views/layouts/application.html.erb +47 -74
  61. data/app/views/layouts/frontpage.html.erb +27 -48
  62. data/app/views/layouts/test.html +44 -0
  63. data/app/views/likes/create.js.erb +1 -1
  64. data/app/views/likes/destroy.js.erb +1 -1
  65. data/app/views/logos/_form.html.erb +33 -0
  66. data/app/views/logos/_precrop.html.erb +48 -0
  67. data/app/views/logos/edit.html.erb +6 -0
  68. data/app/views/logos/index.html.erb +27 -0
  69. data/app/views/logos/new.html.erb +20 -0
  70. data/app/views/logos/show.html.erb +5 -0
  71. data/app/views/mailbox/_conversation.html.erb +23 -0
  72. data/app/views/mailbox/_conversations.html.erb +9 -0
  73. data/app/views/mailbox/_index.html.erb +16 -0
  74. data/app/views/{messages → mailbox}/_location.html.erb +0 -0
  75. data/app/views/mailbox/_menu_options.html.erb +19 -0
  76. data/app/views/mailbox/_show.html.erb +15 -0
  77. data/app/views/mailbox/conversation/_conversation.html.erb +40 -0
  78. data/app/views/mailbox/conversation/_form.html.erb +54 -0
  79. data/app/views/mailbox/conversation/_location.html.erb +3 -0
  80. data/app/views/mailbox/conversation/_new.html.erb +19 -0
  81. data/app/views/mailbox/conversation/_show.html.erb +27 -0
  82. data/app/views/mailbox/conversation/edit.html.erb +6 -0
  83. data/app/views/mailbox/conversation/new.html.erb +10 -0
  84. data/app/views/mailbox/conversation/new.js.erb +1 -0
  85. data/app/views/mailbox/conversation/show.html.erb +1 -0
  86. data/app/views/{messages → mailbox}/edit.html.erb +0 -0
  87. data/app/views/mailbox/index.html.erb +10 -0
  88. data/app/views/{messages → mailbox}/index.js.erb +0 -0
  89. data/app/views/mailbox/new.html.erb +14 -0
  90. data/app/views/mailbox/show.html.erb +11 -0
  91. data/app/views/mailbox/show.js.erb +1 -0
  92. data/app/views/menu/_group.html.erb +15 -0
  93. data/{lib/generators/social_stream/templates/public/stylesheets/users.css → app/views/menu/_home_user.html.erb} +0 -0
  94. data/app/views/menu/_options.html.erb +11 -0
  95. data/app/views/menu/_services.html.erb +11 -0
  96. data/app/views/menu/_tiesGroup.html.erb +14 -0
  97. data/app/views/menu/_tiesUser.html.erb +11 -0
  98. data/app/views/menu/_user.html.erb +15 -0
  99. data/app/views/profiles/show.html.erb +1 -0
  100. data/app/views/subjects/_contacts.html.erb +8 -9
  101. data/app/views/subjects/_menu_options.html.erb +14 -0
  102. data/app/views/subjects/_toolbar.html.erb +15 -0
  103. data/app/views/ties/_new.html.erb +3 -2
  104. data/app/views/ties/_pendings.html.erb +7 -12
  105. data/app/views/ties/_suggestions.html.erb +12 -12
  106. data/app/views/ties/_tie.html.erb +9 -7
  107. data/app/views/ties/new.js.erb +1 -2
  108. data/app/views/users/_groups.html.erb +4 -3
  109. data/app/views/users/_index.html.erb +24 -22
  110. data/app/views/users/_logo.html.erb +1 -1
  111. data/app/views/users/_profile.html.erb +167 -164
  112. data/app/views/users/_sidebar_index.html.erb +6 -0
  113. data/app/views/users/{_middle_show.html.erb → _sidebar_show.html.erb} +0 -0
  114. data/app/views/users/_toolbar_show.html.erb +17 -0
  115. data/app/views/users/edit.html.erb +193 -165
  116. data/app/views/users/index.html.erb +34 -47
  117. data/{spec/dummy/public/stylesheets/.gitkeep → app/views/users/info.html.erb} +0 -0
  118. data/app/views/users/show.html.erb +4 -4
  119. data/app/views/users/show.xml.builder +28 -0
  120. data/app/views/users/update.js.erb +3 -1
  121. data/config/locales/en.yml +88 -9
  122. data/config/routes.rb +30 -14
  123. data/lib/generators/social_stream/install_generator.rb +8 -2
  124. data/lib/generators/social_stream/templates/migration.rb +75 -81
  125. data/lib/generators/social_stream/templates/public/images/{frontpage/facebook.png → btn/1-facebook.png} +0 -0
  126. data/lib/generators/social_stream/templates/public/images/btn/edit.png +0 -0
  127. data/lib/generators/social_stream/templates/public/images/btn/facebook.png +0 -0
  128. data/lib/generators/social_stream/templates/public/images/btn/linkedin.png +0 -0
  129. data/lib/generators/social_stream/templates/public/images/btn/twitter-follow-icon.png +0 -0
  130. data/lib/generators/social_stream/templates/public/images/btn/twitter.png +0 -0
  131. data/lib/generators/social_stream/templates/public/images/frontpage/collaborate.png +0 -0
  132. data/lib/generators/social_stream/templates/public/images/frontpage/meet.png +0 -0
  133. data/lib/generators/social_stream/templates/public/images/frontpage/share.png +0 -0
  134. data/lib/generators/social_stream/templates/public/images/icons/favicon.ico +0 -0
  135. data/lib/generators/social_stream/templates/public/images/logo.png +0 -0
  136. data/lib/generators/social_stream/templates/public/images/w3c_css.png +0 -0
  137. data/lib/generators/social_stream/templates/public/images/w3c_xhtml.png +0 -0
  138. data/lib/generators/social_stream/templates/public/javascripts/jquery-ui-1.8.4.custom.min.js +3 -3
  139. data/lib/generators/social_stream/templates/public/javascripts/jquery-ui-personalized-1.5.2.packed.js +1 -0
  140. data/lib/generators/social_stream/templates/public/javascripts/jquery-ui.min.js +3 -3
  141. data/lib/generators/social_stream/templates/public/javascripts/jquery.Jcrop.min.js +163 -0
  142. data/lib/generators/social_stream/templates/public/javascripts/jquery.fcbkcomplete.min.js +76 -76
  143. data/lib/generators/social_stream/templates/public/javascripts/jquery.min.js +156 -5
  144. data/lib/generators/social_stream/templates/public/javascripts/main.js +9 -0
  145. data/lib/generators/social_stream/templates/public/javascripts/menu-collapsed.js +42 -0
  146. data/lib/generators/social_stream/templates/public/javascripts/menu.js +1 -1
  147. data/lib/generators/social_stream/templates/public/javascripts/rails.js +30 -29
  148. data/lib/generators/social_stream/templates/public/javascripts/superfish.js +121 -0
  149. data/lib/generators/social_stream/templates/public/stylesheets/default/activities.css +72 -0
  150. data/lib/generators/social_stream/templates/public/stylesheets/default/base.css +150 -0
  151. data/lib/generators/social_stream/templates/public/stylesheets/default/carousel.css +23 -0
  152. data/lib/generators/social_stream/templates/public/stylesheets/{fcbkComplete.css → default/fcbkComplete.css} +2 -2
  153. data/lib/generators/social_stream/templates/public/stylesheets/default/footer.css +25 -0
  154. data/lib/generators/social_stream/templates/public/stylesheets/default/frontpage.css +54 -0
  155. data/lib/generators/social_stream/templates/public/stylesheets/default/header.css +44 -0
  156. data/lib/generators/social_stream/templates/public/stylesheets/default/home.css +44 -0
  157. data/lib/generators/social_stream/templates/public/stylesheets/{images → default/images}/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
  158. data/lib/generators/social_stream/templates/public/stylesheets/{images → default/images}/ui-bg_flat_75_ffffff_40x100.png +0 -0
  159. data/lib/generators/social_stream/templates/public/stylesheets/{images → default/images}/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
  160. data/lib/generators/social_stream/templates/public/stylesheets/{images → default/images}/ui-bg_glass_65_ffffff_1x400.png +0 -0
  161. data/lib/generators/social_stream/templates/public/stylesheets/{images → default/images}/ui-bg_glass_75_dadada_1x400.png +0 -0
  162. data/lib/generators/social_stream/templates/public/stylesheets/{images → default/images}/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
  163. data/lib/generators/social_stream/templates/public/stylesheets/{images → default/images}/ui-bg_glass_95_fef1ec_1x400.png +0 -0
  164. data/lib/generators/social_stream/templates/public/stylesheets/{images → default/images}/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
  165. data/lib/generators/social_stream/templates/public/stylesheets/{images → default/images}/ui-icons_222222_256x240.png +0 -0
  166. data/lib/generators/social_stream/templates/public/stylesheets/{images → default/images}/ui-icons_2e83ff_256x240.png +0 -0
  167. data/lib/generators/social_stream/templates/public/stylesheets/{images → default/images}/ui-icons_454545_256x240.png +0 -0
  168. data/lib/generators/social_stream/templates/public/stylesheets/{images → default/images}/ui-icons_888888_256x240.png +0 -0
  169. data/lib/generators/social_stream/templates/public/stylesheets/{images → default/images}/ui-icons_cd0a0a_256x240.png +0 -0
  170. data/lib/generators/social_stream/templates/public/stylesheets/default/jqcloud.css +15 -0
  171. data/lib/generators/social_stream/templates/public/stylesheets/{jquery-ui.css → default/jquery-ui.css} +0 -0
  172. data/lib/generators/social_stream/templates/public/stylesheets/default/jquery.Jcrop.css +35 -0
  173. data/lib/generators/social_stream/templates/public/stylesheets/default/menu.css +33 -0
  174. data/lib/generators/social_stream/templates/public/stylesheets/{smoothness → default/smoothness}/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
  175. data/lib/generators/social_stream/templates/public/stylesheets/{smoothness → default/smoothness}/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
  176. data/lib/generators/social_stream/templates/public/stylesheets/{smoothness → default/smoothness}/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
  177. data/lib/generators/social_stream/templates/public/stylesheets/{smoothness → default/smoothness}/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
  178. data/lib/generators/social_stream/templates/public/stylesheets/{smoothness → default/smoothness}/images/ui-bg_glass_75_dadada_1x400.png +0 -0
  179. data/lib/generators/social_stream/templates/public/stylesheets/{smoothness → default/smoothness}/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
  180. data/lib/generators/social_stream/templates/public/stylesheets/{smoothness → default/smoothness}/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
  181. data/lib/generators/social_stream/templates/public/stylesheets/{smoothness → default/smoothness}/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
  182. data/lib/generators/social_stream/templates/public/stylesheets/{smoothness → default/smoothness}/images/ui-icons_222222_256x240.png +0 -0
  183. data/lib/generators/social_stream/templates/public/stylesheets/{smoothness → default/smoothness}/images/ui-icons_2e83ff_256x240.png +0 -0
  184. data/lib/generators/social_stream/templates/public/stylesheets/{smoothness → default/smoothness}/images/ui-icons_454545_256x240.png +0 -0
  185. data/lib/generators/social_stream/templates/public/stylesheets/{smoothness → default/smoothness}/images/ui-icons_888888_256x240.png +0 -0
  186. data/lib/generators/social_stream/templates/public/stylesheets/{smoothness → default/smoothness}/images/ui-icons_cd0a0a_256x240.png +0 -0
  187. data/lib/generators/social_stream/templates/public/stylesheets/{smoothness → default/smoothness}/jquery-ui-1.7.3.custom.css +0 -0
  188. data/lib/generators/social_stream/templates/public/stylesheets/{smoothness → default/smoothness}/jquery-ui-1.8.4.custom.css +0 -0
  189. data/lib/social_stream.rb +11 -2
  190. data/lib/social_stream/ability.rb +21 -3
  191. data/lib/social_stream/models/object.rb +5 -3
  192. data/lib/social_stream/models/subject.rb +50 -31
  193. data/lib/social_stream/rails.rb +5 -0
  194. data/lib/social_stream/test_helpers.rb +11 -0
  195. data/lib/social_stream/test_helpers/controllers.rb +64 -0
  196. data/lib/social_stream/version.rb +1 -1
  197. data/lib/tasks/db/populate.rake +110 -25
  198. data/social_stream.gemspec +7 -1
  199. data/spec/controllers/contacts_controller_spec.rb +1 -1
  200. data/spec/controllers/groups_controller_spec.rb +8 -0
  201. data/spec/controllers/home_controller_spec.rb +15 -0
  202. data/spec/controllers/likes_controller_spec.rb +29 -0
  203. data/spec/controllers/posts_controller_spec.rb +41 -0
  204. data/spec/controllers/profiles_controller_spec.rb +46 -0
  205. data/spec/controllers/users_controller_spec.rb +2 -2
  206. data/spec/dummy/.gitignore +4 -0
  207. data/spec/dummy/config/database.yml +8 -0
  208. data/spec/dummy/config/environments/test_pg.rb +35 -0
  209. data/spec/dummy/config/routes.rb +2 -0
  210. data/spec/factories/group.rb +1 -1
  211. data/spec/integration/navigation_spec.rb +1 -1
  212. data/spec/models/actor_spec.rb +4 -4
  213. data/spec/models/user_spec.rb +2 -2
  214. data/spec/spec_helper.rb +1 -1
  215. data/spec/support/db.rb +7 -0
  216. metadata +198 -116
  217. data/app/controllers/messages_controller.rb +0 -3
  218. data/app/models/message.rb +0 -2
  219. data/app/views/groups/_middle_index.html.erb +0 -74
  220. data/app/views/groups/_right_index.html.erb +0 -19
  221. data/app/views/groups/_right_show.html.erb +0 -8
  222. data/app/views/home/_middle.html.erb +0 -4
  223. data/app/views/home/_options.html.erb +0 -8
  224. data/app/views/home/_right.html.erb +0 -17
  225. data/app/views/messages/_form.html.erb +0 -24
  226. data/app/views/messages/_index.html.erb +0 -24
  227. data/app/views/messages/_message.html.erb +0 -17
  228. data/app/views/messages/_messages.html.erb +0 -2
  229. data/app/views/messages/index.html.erb +0 -1
  230. data/app/views/messages/new.html.erb +0 -14
  231. data/app/views/messages/show.html.erb +0 -21
  232. data/app/views/users/_menu.html.erb +0 -7
  233. data/app/views/users/_options.html.erb +0 -5
  234. data/app/views/users/_right_index.html.erb +0 -19
  235. data/app/views/users/_right_show.html.erb +0 -14
  236. data/lib/generators/social_stream/templates/public/images/btn/btn_share.png +0 -0
  237. data/lib/generators/social_stream/templates/public/images/favicon.ico +0 -0
  238. data/lib/generators/social_stream/templates/public/images/frontpage/collaborate.gif +0 -0
  239. data/lib/generators/social_stream/templates/public/images/frontpage/meet.gif +0 -0
  240. data/lib/generators/social_stream/templates/public/images/frontpage/share.gif +0 -0
  241. data/lib/generators/social_stream/templates/public/javascripts/hoverIntent.js +0 -84
  242. data/lib/generators/social_stream/templates/public/stylesheets/activities.css +0 -235
  243. data/lib/generators/social_stream/templates/public/stylesheets/base.css +0 -68
  244. data/lib/generators/social_stream/templates/public/stylesheets/boxy.css +0 -49
  245. data/lib/generators/social_stream/templates/public/stylesheets/browse.css +0 -162
  246. data/lib/generators/social_stream/templates/public/stylesheets/carousel.css +0 -57
  247. data/lib/generators/social_stream/templates/public/stylesheets/edit_user.css +0 -104
  248. data/lib/generators/social_stream/templates/public/stylesheets/frontpage.css +0 -708
  249. data/lib/generators/social_stream/templates/public/stylesheets/header.css +0 -116
  250. data/lib/generators/social_stream/templates/public/stylesheets/home.css +0 -121
  251. data/lib/generators/social_stream/templates/public/stylesheets/index.css +0 -625
  252. data/lib/generators/social_stream/templates/public/stylesheets/jqcloud.css +0 -62
  253. data/lib/generators/social_stream/templates/public/stylesheets/menu.css +0 -83
  254. data/lib/generators/social_stream/templates/public/stylesheets/message.css +0 -46
  255. data/lib/generators/social_stream/templates/public/stylesheets/middle.css +0 -113
  256. data/lib/generators/social_stream/templates/public/stylesheets/right.css +0 -58
  257. data/lib/generators/social_stream/templates/public/stylesheets/social_stream.css +0 -78
  258. data/lib/generators/social_stream/templates/public/stylesheets/ui.dropdownchecklist.css +0 -21
  259. data/spec/dummy/db/.gitignore +0 -2
  260. data/spec/dummy/log/.gitignore +0 -1
  261. data/spec/dummy/public/javascripts/application.js +0 -2
  262. data/spec/dummy/public/javascripts/controls.js +0 -965
  263. data/spec/dummy/public/javascripts/dragdrop.js +0 -974
  264. data/spec/dummy/public/javascripts/effects.js +0 -1123
  265. data/spec/dummy/public/javascripts/prototype.js +0 -6001
  266. data/spec/dummy/public/javascripts/rails.js +0 -175
@@ -1,3 +1,13 @@
1
+ # The {ActivityObject} is any object that receives actions. Examples are
2
+ # creating post, liking a comment, contacting a user.
3
+ #
4
+ # = ActivityObject subtypes
5
+ # All post, comment and user are {SocialStream::Models::Object objects}.
6
+ # Social Stream privides 3 {ActivityObject} subtypes, {Post}, {Comment} and
7
+ # {Actor}. The application developer can define as many {ActivityObject} subtypes
8
+ # as required.
9
+ # Objects are added to +config/initializers/social_stream.rb+
10
+ #
1
11
  class ActivityObject < ActiveRecord::Base
2
12
  @subtypes_name = :object
3
13
  include SocialStream::Models::Supertype
@@ -1,4 +1,14 @@
1
1
  class ActivityObjectActivity < ActiveRecord::Base
2
2
  belongs_to :activity, :dependent => :destroy
3
3
  belongs_to :activity_object
4
+
5
+ before_create :default_object_type
6
+
7
+ private
8
+
9
+ # Default objects are direct objects. http://activitystrea.ms/head/atom-activity.html#activity.object
10
+ # Other type of objects are targets. http://activitystrea.ms/head/atom-activity.html#activity.target
11
+ def default_object_type
12
+ self.object_type ||= "object"
13
+ end
4
14
  end
data/app/models/actor.rb CHANGED
@@ -1,89 +1,106 @@
1
- # An {Actor} is a social entity. This includes individuals, but also groups, departments, organizations even nations or states.
1
+ # An {Actor} is a social entity. This includes individuals, but also groups, departments,
2
+ # organizations even nations or states.
2
3
  #
3
4
  # Actors are the nodes of a social network. Two actors are linked by a {Tie}. The
4
5
  # type of a {tie} is a {Relation}. Each actor can define and customize their relations.
5
6
  #
6
7
  # = Actor subtypes
7
8
  # An actor subtype is called a {SocialStream::Models::Subject Subject}.
8
- # {SocialStream} provides two actor subtypes, {User} and {Group}, but the
9
+ # {SocialStream} provides 2 actor subtypes, {User} and {Group}, but the
9
10
  # application developer can define as many actor subtypes as required.
10
11
  # Actors subtypes are added to +config/initializers/social_stream.rb+
11
12
  #
12
13
  class Actor < ActiveRecord::Base
13
14
  @subtypes_name = :subject
14
15
  include SocialStream::Models::Supertype
15
-
16
+
16
17
  validates_presence_of :name, :subject_type
17
-
18
- acts_as_url :name, :url_attribute => :permalink
19
-
18
+
19
+ acts_as_messageable
20
+ acts_as_url :name, :url_attribute => :slug
21
+
20
22
  has_attached_file :logo,
21
23
  :styles => { :tie => "30x30>",
22
24
  :actor => '35x35>',
23
25
  :profile => '94x94' },
24
26
  :default_url => "/images/:attachment/:style/:subtype_class.png"
25
-
27
+
26
28
  has_one :profile, :dependent => :destroy
27
-
29
+
28
30
  has_many :sent_ties,
29
31
  :class_name => "Tie",
30
32
  :foreign_key => 'sender_id',
31
33
  :dependent => :destroy
32
-
34
+
33
35
  has_many :received_ties,
34
36
  :class_name => "Tie",
35
37
  :foreign_key => 'receiver_id',
36
38
  :dependent => :destroy
37
-
39
+
38
40
  has_many :senders,
39
41
  :through => :received_ties,
40
42
  :uniq => true
41
-
43
+
42
44
  has_many :receivers,
43
45
  :through => :sent_ties,
44
46
  :uniq => true
45
-
47
+
46
48
  after_create :initialize_ties
47
-
49
+
48
50
  after_create :create_profile
49
-
51
+
50
52
  class << self
51
53
  # Get actor's id from an object, if possible
52
54
  def normalize_id(a)
53
55
  case a
54
- when Integer
55
- a
56
- when Array
56
+ when Array
57
57
  a.map{ |e| normalize_id(e) }
58
- when Actor
59
- a.id
60
58
  else
61
- a.actor.id
59
+ Actor.normalize(a).id
60
+ end
61
+ end
62
+ # Get actor from object, if possible
63
+ def normalize(a)
64
+ case a
65
+ when Actor
66
+ a
67
+ when Integer
68
+ Actor.find a
69
+ when Array
70
+ a.map{ |e| Actor.normalize(e) }
71
+ else
72
+ begin
73
+ a.actor
74
+ rescue
75
+ raise "Unable to normalize actor #{ a.inspect }"
76
+ end
62
77
  end
63
78
  end
64
79
  end
65
-
80
+
81
+
82
+
66
83
  # The subject instance for this actor
67
84
  def subject
68
85
  subtype_instance ||
69
- activity_object.try(:object)
86
+ activity_object.try(:object)
70
87
  end
71
-
88
+
72
89
  # All the ties sent or received by this actor
73
90
  def ties
74
91
  Tie.sent_or_received_by(self)
75
92
  end
76
-
93
+
77
94
  # Relations defined and managed by this actor
78
95
  def relations
79
96
  Relation.includes(:ties).merge(Tie.sent_by(self))
80
97
  end
81
-
98
+
82
99
  # A given relation defined and managed by this actor
83
100
  def relation(name)
84
101
  relations.find_by_name(name)
85
102
  end
86
-
103
+
87
104
  # All the actors this one has relation with
88
105
  #
89
106
  # Options:
@@ -95,32 +112,32 @@ class Actor < ActiveRecord::Base
95
112
  def actors(options = {})
96
113
  subject_types = Array(options[:subject_type] || self.class.subtypes)
97
114
  subject_classes = subject_types.map{ |s| s.to_s.classify }
98
-
115
+
99
116
  as = Actor.select("DISTINCT actors.*").
100
- where('actors.subject_type' => subject_classes).
101
- includes(subject_types)
102
-
103
-
117
+ where('actors.subject_type' => subject_classes).
118
+ includes(subject_types)
119
+
120
+
104
121
  case options[:direction]
105
- when :senders
122
+ when :senders
106
123
  as = as.joins(:sent_ties).merge(Tie.received_by(self))
107
- when :receivers
124
+ when :receivers
108
125
  as = as.joins(:received_ties).merge(Tie.sent_by(self))
109
126
  else
110
127
  raise "actors in both directions is not supported yet"
111
128
  end
112
-
129
+
113
130
  if options[:include_self].blank?
114
131
  as = as.where("actors.id != ?", self.id)
115
132
  end
116
-
133
+
117
134
  if options[:relations].present?
118
135
  as &= Tie.related_by(options[:relations])
119
136
  end
120
-
137
+
121
138
  as
122
139
  end
123
-
140
+
124
141
  # All the subject actors that send or receive at least one tie to this actor
125
142
  #
126
143
  # When passing a block, it will be evaluated for the actors query, allowing to add
@@ -129,23 +146,23 @@ class Actor < ActiveRecord::Base
129
146
  # See actors for options
130
147
  def subjects(options = {})
131
148
  as = actors(options)
132
-
149
+
133
150
  if block_given?
134
151
  as = yield(as)
135
152
  end
136
-
153
+
137
154
  as.map(&:subject)
138
155
  end
139
-
156
+
140
157
  # This is an scaffold for a recomendations engine
141
158
  #
142
-
159
+
143
160
  # Make n suggestions
144
161
  # TODO: make more
145
162
  def suggestions(n)
146
163
  n.times.map{ |m| suggestion }
147
164
  end
148
-
165
+
149
166
  # By now, it returns a tie suggesting a relation from SuggestedRelations
150
167
  # to another subject without any current relation
151
168
  #
@@ -155,10 +172,10 @@ class Actor < ActiveRecord::Base
155
172
  # @return [Tie]
156
173
  def suggestion(options = {})
157
174
  candidates_types =
158
- options[:type].present? ?
159
- Array(options[:type]) :
160
- self.class.subtypes
161
-
175
+ options[:type].present? ?
176
+ Array(options[:type]) :
177
+ self.class.subtypes
178
+
162
179
  candidates_classes = candidates_types.map{ |t| t.to_s.classify.constantize }
163
180
 
164
181
  # Candidates are all the instance of "type" minus all the subjects
@@ -168,56 +185,67 @@ class Actor < ActiveRecord::Base
168
185
  cs -= Array(subject) if subject.is_a?(klass)
169
186
  cs
170
187
  end
171
-
188
+
172
189
  candidate = candidates[rand(candidates.size)]
173
-
190
+
174
191
  return nil unless candidate.present?
175
-
192
+
176
193
  # Building ties with sent_ties catches them and excludes them from pending ties.
177
194
  # An useful side effect for excluding this ones from pending, but can be weird!
178
195
  # Maybe we must use:
179
196
  # Tie.sent_by(self).build :receiver_id => candidate.actor.id
180
197
  sent_ties.build :receiver_id => candidate.actor.id
181
198
  end
182
-
199
+
183
200
  # Set of ties sent by this actor received by a
184
201
  def ties_to(a)
185
202
  sent_ties.received_by(a)
186
203
  end
187
-
204
+
188
205
  # All the ties this actor has with subject that support permission
189
206
  def sent_ties_allowing(subject, action, objective)
190
207
  return [] if subject.blank?
191
-
208
+
192
209
  sent_ties.allowing(subject, action, objective)
193
210
  end
194
211
 
212
+ # The ties that allow attaching an activity to them. This method is used for caching
213
+ def active_ties
214
+ @active_ties ||= {}
215
+ end
216
+
217
+ # The ties that allow subject creating activities for this actor
218
+ def active_ties_for(subject)
219
+ active_ties[subject] ||=
220
+ sent_ties_allowing(subject, 'create', 'activity')
221
+ end
222
+
195
223
  def pending_ties
196
224
  @pending_ties ||=
197
- received_ties.where('ties.sender_id NOT IN (?)', sent_ties.map(&:receiver_id).uniq).map(&:sender_id).uniq.
198
- map{ |i| Tie.new :sender => self,
225
+ received_ties.where('ties.sender_id NOT IN (?)', sent_ties.map(&:receiver_id).uniq).map(&:sender_id).uniq.
226
+ map{ |i| Tie.new :sender => self,
199
227
  :receiver_id => i }
200
228
  end
201
-
229
+
202
230
  # The set of activities in the wall of this actor, includes all the activities
203
231
  # from the ties the actor has access to
204
232
  #
205
233
  def home_wall
206
234
  Activity.home_wall ties
207
235
  end
208
-
236
+
209
237
  # The set of activities in the wall profile of this actor, includes the activities
210
238
  # from the ties of this actor that can be read by user
211
239
  #
212
240
  def profile_wall(user)
213
241
  # FIXME: show public activities
214
242
  return [] if user.blank?
215
-
243
+
216
244
  Activity.profile_wall ties.allowing(user, 'read', 'activity')
217
245
  end
218
-
246
+
219
247
  private
220
-
248
+
221
249
  def initialize_ties
222
250
  ::SocialStream::Relations.create(subject_type).each do |r|
223
251
  sent_ties.create! :receiver => self,
@@ -225,4 +253,3 @@ class Actor < ActiveRecord::Base
225
253
  end
226
254
  end
227
255
  end
228
-
data/app/models/group.rb CHANGED
@@ -2,12 +2,18 @@ class Group < ActiveRecord::Base
2
2
  attr_accessor :_founder
3
3
  attr_accessor :_participants
4
4
 
5
- def followers
6
- subjects(:subject_type => :user, :direction => :senders)
7
- end
5
+ delegate :description, :description=, :to => :profile!
8
6
 
9
7
  after_create :create_founder
10
8
  after_create :create_participants
9
+
10
+ def profile!
11
+ actor!.profile || actor!.build_profile
12
+ end
13
+
14
+ def followers
15
+ subjects(:subject_type => :user, :direction => :senders)
16
+ end
11
17
 
12
18
  def recent_groups
13
19
  subjects(:subject_type => :group, :direction => :receivers) do |q|
@@ -21,7 +27,7 @@ class Group < ActiveRecord::Base
21
27
  #Creates the ties between the group and the founder
22
28
  def create_founder
23
29
  founder =
24
- Actor.find_by_permalink(_founder) || raise("Cannot create group without founder")
30
+ Actor.find_by_slug(_founder) || raise("Cannot create group without founder")
25
31
 
26
32
  sent_ties.create! :receiver => founder,
27
33
  :relation => relations.sort.first
@@ -0,0 +1,34 @@
1
+ # Convenience class for managing like activities
2
+ class Like
3
+ attr_reader :activity
4
+
5
+ class << self
6
+ # Find the children activity of activity_id liked by subject
7
+ def find(subject, activity_id)
8
+ find_activity(activity_id).liked_by(subject).first
9
+ end
10
+
11
+ # Like #find but raises error if not found
12
+ def find!(subject, activity_id)
13
+ find(subject, activity_id) ||
14
+ raise(ActiveRecord::RecordNotFound)
15
+ end
16
+
17
+ # Find the activity that is liked
18
+ def find_activity(id)
19
+ Activity.find(id) ||
20
+ raise(ActiveRecord::RecordNotFound)
21
+ end
22
+ end
23
+
24
+ # Initialize a new like activity
25
+ def initialize(subject, activity_id)
26
+ @subject = subject
27
+ @activity = self.class.find_activity(activity_id)
28
+ @like = @activity.new_like(@subject)
29
+ end
30
+
31
+ def save
32
+ @like.save
33
+ end
34
+ end
@@ -0,0 +1,51 @@
1
+ require 'RMagick'
2
+
3
+ class Logo < ActiveRecord::Base
4
+ has_attached_file :logo,
5
+ :styles => { :tie => "30x30>",
6
+ :actor => '35x35>',
7
+ :profile => '94x94' },
8
+ :default_url => "/images/:attachment/:style/:subtype_class.png"
9
+ before_post_process :process_precrop
10
+ attr_accessor :crop_x, :crop_y, :crop_w, :crop_h
11
+ validates_attachment_presence :logo
12
+
13
+ def process_precrop
14
+ logo.errors['precrop'] = "You have to make precrop"
15
+
16
+ images_path = File.join(RAILS_ROOT, "public", "images")
17
+ tmp_path = FileUtils.mkdir_p(File.join(images_path, "tmp"))
18
+
19
+ resize_image(logo.queued_for_write[:original].path,600,600)
20
+
21
+ my_file_name = File.basename(logo.queued_for_write[:original].path)
22
+ FileUtils.cp(logo.queued_for_write[:original].path,tmp_path)
23
+ temp_file = File.open(logo.queued_for_write[:original].path, "w+")
24
+ end
25
+
26
+ def image_dimensions(name)
27
+ images_path = File.join(RAILS_ROOT, "public", "images")
28
+ tmp_path = FileUtils.mkdir_p(File.join(images_path, "tmp"))
29
+ file_path = File.join(tmp_path,name)
30
+
31
+ img_orig = Magick::Image.read(file_path).first
32
+ dimensions = {}
33
+ dimensions[:width] = img_orig.columns
34
+ dimensions[:height] = img_orig.rows
35
+ dimensions
36
+ end
37
+
38
+ def resize_image(path,width,height)
39
+ img_orig = Magick::Image.read(path).first
40
+ img_orig = img_orig.resize_to_fit(width, height)
41
+ img_orig.write(path)
42
+ end
43
+
44
+ def make_precrop(path,x,y,width,height)
45
+ img_orig = Magick::Image.read(path).first
46
+ crop_args = [x,y,width,height]
47
+ img_orig = img_orig.crop(*crop_args)
48
+ img_orig.write(path)
49
+ end
50
+ end
51
+