social_stream 0.11.2 → 0.11.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (168) hide show
  1. data/Gemfile +0 -9
  2. data/base/app/assets/stylesheets/contacts.css.scss +8 -3
  3. data/base/app/assets/stylesheets/frontpage.css.scss +1 -1
  4. data/base/app/assets/stylesheets/search.css.scss +17 -1
  5. data/base/app/controllers/contacts_controller.rb +2 -5
  6. data/base/app/models/contact.rb +3 -2
  7. data/base/app/views/activities/_options.html.erb +1 -1
  8. data/base/app/views/contacts/_form.html.erb +14 -7
  9. data/base/app/views/frontpage/_social_networks.html.erb +3 -0
  10. data/base/app/views/groups/_new.html.erb +2 -2
  11. data/base/app/views/groups/_show.html.erb +1 -2
  12. data/base/app/views/groups/index.html.erb +1 -1
  13. data/base/app/views/layouts/_header_signed_out.erb +1 -3
  14. data/base/app/views/notifications/activities/_follow_subject.html.erb +5 -2
  15. data/base/app/views/notifications/activities/_like_subject.html.erb +6 -2
  16. data/base/app/views/notifications/activities/_make-friend_subject.html.erb +5 -2
  17. data/base/app/views/notifications/activities/_post_subject.html.erb +6 -1
  18. data/base/app/views/notifications/activities/_update_body.html.erb +5 -1
  19. data/base/app/views/notifications/activities/_update_subject.html.erb +5 -1
  20. data/base/app/views/posts/_post_focus_search.html.erb +37 -3
  21. data/base/app/views/posts/_post_global_search.html.erb +2 -0
  22. data/base/app/views/profiles/_contact.html.erb +1 -1
  23. data/base/app/views/search/index.js.erb +2 -0
  24. data/base/app/views/toolbar/_home.html.erb +4 -0
  25. data/base/config/locales/en.yml +26 -0
  26. data/base/config/locales/es.yml +26 -0
  27. data/base/lib/mailboxer/notification_decoder.rb +8 -6
  28. data/base/lib/social_stream-base.rb +1 -1
  29. data/base/lib/social_stream/base/version.rb +1 -1
  30. data/base/lib/social_stream/migrations/components.rb +1 -1
  31. data/base/lib/social_stream/toolbar_config/base.rb +12 -1
  32. data/base/social_stream-base.gemspec +1 -1
  33. data/base/spec/controllers/contacts_controller_spec.rb +4 -4
  34. data/events/app/assets/javascripts/social_stream-events.js +2 -2
  35. data/events/app/assets/stylesheets/social_stream-events.css +3 -0
  36. data/events/{app → vendor}/assets/javascripts/jquery.ad-gallery.js +0 -0
  37. data/events/{app → vendor}/assets/javascripts/jquery.ad-gallery.pack.js +0 -0
  38. data/events/{app → vendor}/assets/stylesheets/ad_next.png +0 -0
  39. data/events/{app → vendor}/assets/stylesheets/ad_prev.png +0 -0
  40. data/events/{app → vendor}/assets/stylesheets/ad_scroll_back.png +0 -0
  41. data/events/{app → vendor}/assets/stylesheets/ad_scroll_forward.png +0 -0
  42. data/events/{app → vendor}/assets/stylesheets/fullcalendar.css +0 -0
  43. data/events/{app → vendor}/assets/stylesheets/fullcalendar.print.css +0 -0
  44. data/events/{app → vendor}/assets/stylesheets/jquery.ad-gallery.css +0 -0
  45. data/events/{app → vendor}/assets/stylesheets/loader.gif +0 -0
  46. data/events/vendor/assets/stylesheets/social_stream-events.css +273 -0
  47. data/lib/social_stream.rb +0 -4
  48. data/lib/social_stream/version.rb +1 -1
  49. data/presence/.gitignore +4 -0
  50. data/presence/Gemfile +4 -0
  51. data/presence/Rakefile +1 -0
  52. data/presence/app/assets/audio/chat/onMessageAudio.mp3 +0 -0
  53. data/presence/app/assets/audio/chat/onMessageAudio.wav +0 -0
  54. data/presence/app/assets/images/arrow.png +0 -0
  55. data/presence/app/assets/images/black_arrow3.png +0 -0
  56. data/presence/app/assets/images/status/available.png +0 -0
  57. data/presence/app/assets/images/status/away.png +0 -0
  58. data/presence/app/assets/images/status/dnd.png +0 -0
  59. data/presence/app/assets/javascripts/jquery-ui-1.8.14.custom.min.js +789 -0
  60. data/presence/app/assets/javascripts/jquery.tools.min.js +17 -0
  61. data/presence/app/assets/javascripts/jquery.tools.tooltip.js +11 -0
  62. data/presence/app/assets/javascripts/jquery.ui.chatbox.js +260 -0
  63. data/presence/app/assets/javascripts/social_stream-presence.js +2 -0
  64. data/presence/app/assets/javascripts/store.js +27 -0
  65. data/presence/app/assets/javascripts/strophe.js +3612 -0
  66. data/presence/app/assets/javascripts/xmpp_client.js +498 -0
  67. data/presence/app/assets/stylesheets/chat.css +231 -0
  68. data/presence/app/assets/stylesheets/jquery.ui.chatbox.css +54 -0
  69. data/presence/app/assets/stylesheets/social_stream-presence.css +3 -0
  70. data/presence/app/controllers/xmpp_controller.rb +190 -0
  71. data/presence/app/helpers/xmpp_helper.rb +33 -0
  72. data/presence/app/views/xmpp/_chat.html.erb +59 -0
  73. data/presence/app/views/xmpp/_chat_connecting.html.erb +8 -0
  74. data/presence/app/views/xmpp/_chat_contacts.html.erb +46 -0
  75. data/presence/app/views/xmpp/_chat_off.html.erb +35 -0
  76. data/presence/app/views/xmpp/active_users.html.erb +33 -0
  77. data/presence/app/views/xmpp/chat.html.erb +13 -0
  78. data/presence/app/views/xmpp/index.html +19 -0
  79. data/presence/app/views/xmpp/test.html.erb +11 -0
  80. data/presence/config/routes.rb +15 -0
  81. data/presence/db/migrate/20110711111408_add_connected_column_to_user.rb +9 -0
  82. data/presence/db/migrate/20110928135031_add_status_column_to_user.rb +9 -0
  83. data/presence/ejabberd/conf/ejabberd.cfg +625 -0
  84. data/presence/ejabberd/conf/ejabberdctl.cfg +154 -0
  85. data/presence/ejabberd/conf/inetrc +3 -0
  86. data/presence/ejabberd/conf/server.pem +37 -0
  87. data/presence/ejabberd/conf/ssconfig.cfg +29 -0
  88. data/presence/ejabberd/ejabberd_scripts/authentication_script +117 -0
  89. data/presence/ejabberd/ejabberd_scripts/authentication_script_org +114 -0
  90. data/presence/ejabberd/ejabberd_scripts/compile_module +34 -0
  91. data/presence/ejabberd/ejabberd_scripts/generate_random_password +18 -0
  92. data/presence/ejabberd/ejabberd_scripts/kill_authentication_script.sh +13 -0
  93. data/presence/ejabberd/ejabberd_scripts/reset_connection_script +55 -0
  94. data/presence/ejabberd/ejabberd_scripts/reset_logs.sh +23 -0
  95. data/presence/ejabberd/ejabberd_scripts/set_connection_script +48 -0
  96. data/presence/ejabberd/ejabberd_scripts/set_presence_script +48 -0
  97. data/presence/ejabberd/ejabberd_scripts/show_config.sh +30 -0
  98. data/presence/ejabberd/ejabberd_scripts/start_ejabberd.sh +68 -0
  99. data/presence/ejabberd/ejabberd_scripts/stop_ejabberd.sh +12 -0
  100. data/presence/ejabberd/ejabberd_scripts/synchronize_presence_script +57 -0
  101. data/presence/ejabberd/ejabberd_scripts/unset_connection_script +48 -0
  102. data/presence/ejabberd/mod_admin_extra/mod_admin_extra.beam +0 -0
  103. data/presence/ejabberd/mod_admin_extra/mod_admin_extra.erl +1560 -0
  104. data/presence/ejabberd/mod_sspresence/mod_sspresence.erl +230 -0
  105. data/presence/lib/social_stream-presence.rb +13 -0
  106. data/presence/lib/social_stream/migrations/presence.rb +9 -0
  107. data/presence/lib/social_stream/presence/config.rb +9 -0
  108. data/presence/lib/social_stream/presence/engine.rb +49 -0
  109. data/presence/lib/social_stream/presence/models/buddy_manager.rb +67 -0
  110. data/presence/social_stream-presence.gemspec +28 -0
  111. data/presence/spec/demo/.gitignore +5 -0
  112. data/presence/spec/demo/.rspec +1 -0
  113. data/presence/spec/demo/README +261 -0
  114. data/presence/spec/demo/Rakefile +7 -0
  115. data/presence/spec/demo/app/assets/images/rails.png +0 -0
  116. data/presence/spec/demo/app/assets/javascripts/application.js +9 -0
  117. data/presence/spec/demo/app/assets/stylesheets/application.css +7 -0
  118. data/presence/spec/demo/app/controllers/application_controller.rb +3 -0
  119. data/presence/spec/demo/app/helpers/application_helper.rb +2 -0
  120. data/presence/spec/demo/app/mailers/.gitkeep +0 -0
  121. data/presence/spec/demo/app/models/.gitkeep +0 -0
  122. data/presence/spec/demo/app/views/layouts/application.html.erb +14 -0
  123. data/presence/spec/demo/autotest/discover.rb +2 -0
  124. data/presence/spec/demo/config.ru +4 -0
  125. data/presence/spec/demo/config/application.rb +41 -0
  126. data/presence/spec/demo/config/boot.rb +6 -0
  127. data/presence/spec/demo/config/database.yml +25 -0
  128. data/presence/spec/demo/config/environment.rb +5 -0
  129. data/presence/spec/demo/config/environments/development.rb +27 -0
  130. data/presence/spec/demo/config/environments/production.rb +54 -0
  131. data/presence/spec/demo/config/environments/test.rb +39 -0
  132. data/presence/spec/demo/config/initializers/backtrace_silencers.rb +7 -0
  133. data/presence/spec/demo/config/initializers/inflections.rb +10 -0
  134. data/presence/spec/demo/config/initializers/mime_types.rb +5 -0
  135. data/presence/spec/demo/config/initializers/secret_token.rb +7 -0
  136. data/presence/spec/demo/config/initializers/session_store.rb +8 -0
  137. data/presence/spec/demo/config/initializers/wrap_parameters.rb +12 -0
  138. data/presence/spec/demo/config/locales/en.yml +5 -0
  139. data/presence/spec/demo/config/routes.rb +58 -0
  140. data/presence/spec/demo/db/seeds.rb +7 -0
  141. data/presence/spec/demo/doc/README_FOR_APP +2 -0
  142. data/presence/spec/demo/lib/tasks/.gitkeep +0 -0
  143. data/presence/spec/demo/log/.gitkeep +0 -0
  144. data/presence/spec/demo/public/404.html +26 -0
  145. data/presence/spec/demo/public/422.html +26 -0
  146. data/presence/spec/demo/public/500.html +26 -0
  147. data/presence/spec/demo/public/favicon.ico +0 -0
  148. data/presence/spec/demo/public/index.html +241 -0
  149. data/presence/spec/demo/public/robots.txt +5 -0
  150. data/presence/spec/demo/script/rails +6 -0
  151. data/presence/spec/demo/spec/spec_helper.rb +27 -0
  152. data/presence/spec/demo/test/fixtures/.gitkeep +0 -0
  153. data/presence/spec/demo/test/functional/.gitkeep +0 -0
  154. data/presence/spec/demo/test/integration/.gitkeep +0 -0
  155. data/presence/spec/demo/test/performance/browsing_test.rb +12 -0
  156. data/presence/spec/demo/test/test_helper.rb +13 -0
  157. data/presence/spec/demo/test/unit/.gitkeep +0 -0
  158. data/presence/spec/demo/vendor/assets/stylesheets/.gitkeep +0 -0
  159. data/presence/spec/demo/vendor/plugins/.gitkeep +0 -0
  160. data/presence/spec/discover.rb +2 -0
  161. data/presence/spec/spec_helper.rb +27 -0
  162. data/social_stream.gemspec +9 -2
  163. data/spec/dummy/config/environments/{test_pg.rb → test_mysql.rb} +6 -2
  164. data/spec/dummy/config/environments/test_postgres.rb +39 -0
  165. data/spec/spec_helper.rb +1 -4
  166. metadata +135 -21
  167. data/base/app/views/groups/_new_activity.html.erb +0 -1
  168. data/base/app/views/groups/_new_activity_fields.html.erb +0 -7
@@ -0,0 +1,230 @@
1
+ -module(mod_sspresence).
2
+
3
+ -behavior(gen_mod).
4
+
5
+ -include("ejabberd.hrl").
6
+
7
+ -export([start/2, stop/1, on_register_connection/3, on_remove_connection/3, on_presence/4, on_unset_presence/4, isConnected/1, on_packet_send/3]).
8
+
9
+ start(Host, _Opts) ->
10
+ ?INFO_MSG("mod_sspresence starting", []),
11
+ ejabberd_hooks:add(sm_register_connection_hook, Host, ?MODULE, on_register_connection, 50),
12
+ ejabberd_hooks:add(sm_remove_connection_hook, Host, ?MODULE, on_remove_connection, 50),
13
+ ejabberd_hooks:add(set_presence_hook, Host, ?MODULE, on_presence, 50),
14
+ ejabberd_hooks:add(unset_presence_hook, Host, ?MODULE, on_unset_presence, 50),
15
+ ejabberd_hooks:add(user_send_packet, Host, ?MODULE, on_packet_send, 50),
16
+ %Uncomment to reset connected users directly when module sspresence starts.
17
+ %reset_connections(),
18
+ ok.
19
+
20
+ stop(Host) ->
21
+ ?INFO_MSG("mod_sspresence stopping", []),
22
+ ejabberd_hooks:delete(sm_register_connection_hook, Host, ?MODULE, on_register_connection, 50),
23
+ ejabberd_hooks:delete(sm_remove_connection_hook, Host, ?MODULE, on_remove_connection, 50),
24
+ ejabberd_hooks:delete(set_presence_hook, Host, ?MODULE, on_presence, 50),
25
+ ejabberd_hooks:delete(unset_presence_hook, Host, ?MODULE, on_unset_presence, 50),
26
+ ejabberd_hooks:delete(user_send_packet, Host, ?MODULE, on_packet_send, 50),
27
+ ok.
28
+
29
+
30
+
31
+ on_register_connection(_SID, _JID, _Info) ->
32
+ {_A,User,_B,_C,_D,_E,_F} = _JID,
33
+ ?INFO_MSG("mod_sspresence: on_register_connection (~p)", [User]),
34
+ Login_path = string:concat(getOptionValue("scripts_path="), "/set_connection_script "),
35
+ os:cmd(string:join([Login_path, User ], " ")),
36
+ ok.
37
+
38
+ on_remove_connection(_SID, _JID, _SessionInfo) ->
39
+ {_A,User,_B,_C,_D,_E,_F} = _JID,
40
+ ?INFO_MSG("mod_sspresence: on_remove_connection (~p)", [User]),
41
+ Connected = isConnected(User),
42
+ case Connected of
43
+ true -> ok;
44
+ _ -> Logout_path = string:concat(getOptionValue("scripts_path="), "/unset_connection_script "),
45
+ os:cmd(string:join([Logout_path, User ], " "))
46
+ end,
47
+ ok.
48
+
49
+ on_presence(User, _Server, _Resource, Packet) ->
50
+ ?INFO_MSG("mod_sspresence: on_presence (~p)", [User]),
51
+ {_xmlelement, Type, _Attr, Subel} = Packet,
52
+
53
+ case Type of
54
+ "presence" -> Status = getStatusFromSubel(Subel),
55
+ Login_path = string:concat(getOptionValue("scripts_path="), "/set_presence_script "),
56
+ ?INFO_MSG("mod_sspresence: set_presence_script call with user (~p) and status (~p)", [User,Status]),
57
+ os:cmd(string:join([Login_path, User , Status], " "));
58
+ _ -> ok
59
+ end,
60
+ ok.
61
+
62
+ on_unset_presence(User, _Server, _Resource, _Status) ->
63
+ ?INFO_MSG("mod_sspresence: on_unset_presence (~p)", [User]),
64
+ ok.
65
+
66
+ on_packet_send(From, _To, {xmlelement, Type, _Attr, Subel} = _Packet) ->
67
+ case Type of
68
+ "message" ->
69
+ {_SenderJID,Sender,_SenderDomain,_A,_B,_C,_D} = From,
70
+
71
+ SSlogin = getOptionValue("ss_login="),
72
+
73
+ case Sender of
74
+ SSlogin ->
75
+ Message = getMessageFromSubel(Subel),
76
+ execute(Message);
77
+ _ -> ok
78
+ end;
79
+ _ -> ok
80
+ end.
81
+
82
+
83
+ getStatusFromSubel(Subel) ->
84
+ try
85
+ %Strophe tuples
86
+ [{_A,"status",[],[{_B,_StatusStrophe}]},{_C,"show",[],[{_D,ShowStrophe}]}|_R1] = Subel,
87
+ parseXmlCdata(ShowStrophe)
88
+ catch
89
+ _:Reason ->
90
+ try
91
+ %Pidgin tuples
92
+ [{_E,"show",[],[{_F,ShowPidgin}]}|_R2] = Subel,
93
+ parseXmlCdata(ShowPidgin)
94
+ catch
95
+ _:Reason -> "chat" %Status when parsed failed
96
+ after
97
+ noop
98
+ end
99
+ after
100
+ noop
101
+ end.
102
+
103
+
104
+ getMessageFromSubel(Subel) ->
105
+ [{_I,_J,_K,[{_L,MessageData}]}] = Subel,
106
+ parseXmlCdata(MessageData).
107
+
108
+
109
+ parseXmlCdata(Msg) ->
110
+ MessageString = binary_to_list(list_to_binary(io_lib:format("~p", [Msg]))),
111
+ lists:sublist(MessageString, 4, string:len(MessageString)-6).
112
+
113
+
114
+ execute(Message) ->
115
+ %?INFO_MSG("Message vale: ~p", [Message]),
116
+ [Order|Params] = string:tokens(Message, "&"),
117
+
118
+ case Order of
119
+ "AddItemToRoster" ->
120
+ case length(Params) of
121
+ 4 -> [UserSID,BuddySID,BuddyName,Subscription_type] = Params,
122
+ ?INFO_MSG("Execute: ~p with params ~p", [Order,Params]),
123
+
124
+ %Command Name: add_rosteritem
125
+ % Needs mod_admin_extra (http://www.ejabberd.im/ejabberd-modules)
126
+ % ejabberdctl add_rosteritem localuser localserver user server nick group subs
127
+ %subs= none, from, to or both",
128
+
129
+ %frank-williamson@trapo adds demo@trapo to its roster
130
+ %ejabberdctl add_rosteritem frank-williamson trapo demo trapo NickName SocialStream from
131
+
132
+ %frank-williamson@trapo adds demo@trapo and demo@trapo adds frank-williamson@trapo to its roster
133
+ %ejabberdctl add_rosteritem frank-williamson trapo demo trapo NickName SocialStream both
134
+
135
+ [ContactName|_R] = string:tokens(BuddyName, " "),
136
+ [UserSlug,UserDomain] = string:tokens(UserSID, "@"),
137
+ [BuddySlug,BuddyDomain] = string:tokens(BuddySID, "@"),
138
+
139
+ Command = lists:concat(["ejabberdctl add_rosteritem ", UserSlug , " ", UserDomain, " ", BuddySlug, " ", BuddyDomain , " ", ContactName , " ", "SocialStream" , " ", Subscription_type]),
140
+ os:cmd(Command),
141
+ ?INFO_MSG("Execute command: ~p", [Command]),
142
+ ok;
143
+ _ -> ?INFO_MSG("Incorrect parameters", []),
144
+ ok
145
+ end,
146
+ ok;
147
+
148
+ "Synchronize" ->
149
+ synchronize(),
150
+ ok;
151
+
152
+ _ -> ?INFO_MSG("Command not found", []),
153
+ ok
154
+ end.
155
+
156
+
157
+ %%GETTERS CONFIG VALUES
158
+ %%CONFIG FILE: /etc/ejabberd/ssconfig.cfg
159
+
160
+ getOptionValue(Option) ->
161
+ {_, In} = file:open("/etc/ejabberd/ssconfig.cfg", read),
162
+ parser(In,Option).
163
+
164
+
165
+ parser(In,Option) ->
166
+ L = io:get_line(In, ''),
167
+
168
+ case L of
169
+ eof -> "Undefined";
170
+ _ -> {_,S,_} = regexp:gsub(L, "\\n", ""),
171
+
172
+
173
+ %%IGNORE COMMENTS
174
+ case string:str(S, "#") of
175
+ 0 ->
176
+ case string:str(S, Option) of
177
+ 0 -> ok,
178
+ %% Continue with next line
179
+ parser(In,Option);
180
+
181
+ %% return path
182
+ _ -> lists:sublist(S, string:len(Option)+1, string:len(S))
183
+ end;
184
+
185
+ _ -> %% Comment: Continue with next line
186
+ parser(In,Option)
187
+ end
188
+ end.
189
+
190
+
191
+ %%Check if a user is connected (any active session with Ejabberd server)
192
+ isConnected(User) ->
193
+
194
+ Command = string:concat("ejabberdctl connected-users | grep ", User),
195
+ Output = os:cmd(Command),
196
+
197
+ case Output of
198
+ [] -> false;
199
+ _ -> Sessions = string:tokens(Output, "\n"),
200
+
201
+ catch lists:foreach(
202
+ fun(S) ->
203
+ [Slug|_R] = string:tokens(S, "@"),
204
+ %User.slug connected = Slug
205
+
206
+ case Slug of
207
+ User -> throw(true);
208
+ _ -> false
209
+ end
210
+
211
+ end,
212
+ Sessions)
213
+ end.
214
+
215
+
216
+ %%Send all connected users to Social Stream Rails Application
217
+ synchronize() ->
218
+ Synchronize_path = string:concat(getOptionValue("scripts_path="), "/synchronize_presence_script "),
219
+ os:cmd(Synchronize_path),
220
+ ok.
221
+
222
+
223
+ %Reset all connections
224
+ %reset_connections() ->
225
+ % Reset_path = string:concat(getOptionValue("scripts_path="), "/reset_connection_script "),
226
+ % os:cmd(Reset_path),
227
+ %ok.
228
+
229
+
230
+
@@ -0,0 +1,13 @@
1
+ require 'social_stream-base'
2
+
3
+ module SocialStream
4
+ module Presence
5
+
6
+ module Models
7
+ autoload :BuddyManager, 'social_stream/presence/models/buddy_manager'
8
+ end
9
+
10
+ end
11
+ end
12
+
13
+ require 'social_stream/presence/engine'
@@ -0,0 +1,9 @@
1
+ require 'social_stream/migrations/components'
2
+
3
+ module SocialStream
4
+ module Migrations
5
+ # Migrate Documents
6
+ class Presence < Components
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module Socialstream
2
+ module Presence
3
+ DOMAIN = "trapo"
4
+ BOSH_SERVICE = "http://localhost:8080/http-bind"
5
+ PASSWORD = "DnVCB8G|R$VGmZ@2?5=CYS8z)NrL@LuQ&LTCUh^9B(DF4gC&sQpfbCMbaNKEdNrGYkT4L5zxM0wNWs5q3?ww(b&0d5fK87z^BmgJMMF2SKXT9pEk^UEcch!GX!Avf5GT9)j@FpHe)4RH)BK7J98u!sUmJHUN(Je6aBmn!FtZ4Ab5h8$|nsvUt3Jkq?21HOH$r0sDyJZZvGOCgFS2EKw@0wXsJRHYVRPBe&Eb!1X55e55bQ^h2AW&^R70TK0m)Fu8"
6
+ XMPP_SERVER_PASSWORD = "G&s6GBnO)anw2Ene%K12Cb=0quj@uDmA"
7
+ VERSION = "0.0.3"
8
+ end
9
+ end
@@ -0,0 +1,49 @@
1
+ require 'xmpp4r'
2
+ require 'xmpp4r/muc'
3
+ require 'xmpp4r/roster'
4
+ require 'xmpp4r/client'
5
+ require 'xmpp4r/message'
6
+
7
+ module SocialStream
8
+ module Presence
9
+ class Engine < Rails::Engine
10
+ config.to_prepare do
11
+
12
+ #Patching Tie
13
+ Tie.class_eval do
14
+ include SocialStream::Presence::Models::BuddyManager
15
+ end
16
+
17
+ end
18
+
19
+ initializer "social_stream-presence.synchronize" do
20
+ #Synchronize User Presence
21
+ #Implement case XMMP Server Down
22
+ Thread.start {
23
+ begin
24
+ client = Jabber::Client.new(Jabber::JID.new('social_stream-presence@trapo'))
25
+ client.connect
26
+ password = Socialstream::Presence::PASSWORD
27
+ client.auth(password)
28
+
29
+ msg = Jabber::Message::new("social_stream-presence@trapo", "Synchronize")
30
+ msg.type=:chat
31
+ client.send(msg)
32
+ client.close()
33
+
34
+ rescue Errno::ECONNREFUSED
35
+ #XMPP Server Down
36
+ #Reset Connected Users
37
+ users = User.find_all_by_connected(true)
38
+ users.each do |user|
39
+ user.connected = false
40
+ user.save!
41
+ end
42
+
43
+ end
44
+ }
45
+ end
46
+
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,67 @@
1
+ require "social_stream/presence/config"
2
+ require 'xmpp4r'
3
+ require 'xmpp4r/muc'
4
+ require 'xmpp4r/roster'
5
+ require 'xmpp4r/client'
6
+ require 'xmpp4r/message'
7
+
8
+ module SocialStream
9
+ module Presence
10
+ module Models
11
+ module BuddyManager
12
+ extend ActiveSupport::Concern
13
+
14
+ included do
15
+ after_create :save_buddy
16
+ end
17
+
18
+ module InstanceMethods
19
+
20
+ def save_buddy
21
+
22
+ unless self.receiver.subject_type == "User" and self.sender.subject_type == "User"
23
+ return
24
+ end
25
+
26
+ #XMPP DOMAIN
27
+ domain = Socialstream::Presence::DOMAIN
28
+ #PASSWORD
29
+ password= Socialstream::Presence::PASSWORD
30
+
31
+ user_sid = self.sender.slug + "@" + domain
32
+ buddy_sid = self.receiver.slug + "@" + domain
33
+ buddy_name = self.receiver.name
34
+
35
+ #Check Subscription_type
36
+ if isBidirectionalTie
37
+ sType = "both"
38
+ else
39
+ sType = "from"
40
+ end
41
+
42
+ begin
43
+ client = Jabber::Client.new(Jabber::JID.new('social_stream-presence@trapo'))
44
+ client.connect
45
+ password = Socialstream::Presence::PASSWORD
46
+ client.auth(password)
47
+
48
+ #Sending a message
49
+ #AddItemToRoster[UserSID,BuddySID,BuddyName,Subscription_type]
50
+ msg = Jabber::Message::new('social_stream-presence@trapo', "AddItemToRoster&" + user_sid + "&" + buddy_sid + "&" + buddy_name + "&" + sType)
51
+ msg.type=:chat
52
+ client.send(msg)
53
+ rescue Errno::ECONNREFUSED
54
+ #Rescue...
55
+ end
56
+
57
+ end
58
+
59
+ def isBidirectionalTie
60
+ return true
61
+ end
62
+
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,28 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "social_stream/presence/config"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "social_stream-presence"
7
+ s.version = Socialstream::Presence::VERSION
8
+ s.authors = ["Aldo Gordillo"]
9
+ s.email = ["iamchrono@gmail.com"]
10
+ s.homepage = "https://github.com/ging/social_stream-presence"
11
+ s.summary = "Presence capabilities for Social Stream, the core for building social network websites"
12
+ s.description = "Social Stream is a Ruby on Rails engine providing your application with social networking features and activity streams."
13
+
14
+ s.rubyforge_project = "social_stream-presence"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ # Gem dependencies
22
+ s.add_runtime_dependency('social_stream-base','~> 0.9.18')
23
+
24
+ s.add_runtime_dependency "xmpp4r"
25
+
26
+ s.add_development_dependency "ruby-debug19"
27
+
28
+ end
@@ -0,0 +1,5 @@
1
+ .bundle
2
+ db/*.sqlite3
3
+ log/*.log
4
+ tmp/
5
+ .sass-cache/
@@ -0,0 +1 @@
1
+ --colour
@@ -0,0 +1,261 @@
1
+ == Welcome to Rails
2
+
3
+ Rails is a web-application framework that includes everything needed to create
4
+ database-backed web applications according to the Model-View-Control pattern.
5
+
6
+ This pattern splits the view (also called the presentation) into "dumb"
7
+ templates that are primarily responsible for inserting pre-built data in between
8
+ HTML tags. The model contains the "smart" domain objects (such as Account,
9
+ Product, Person, Post) that holds all the business logic and knows how to
10
+ persist themselves to a database. The controller handles the incoming requests
11
+ (such as Save New Account, Update Product, Show Post) by manipulating the model
12
+ and directing data to the view.
13
+
14
+ In Rails, the model is handled by what's called an object-relational mapping
15
+ layer entitled Active Record. This layer allows you to present the data from
16
+ database rows as objects and embellish these data objects with business logic
17
+ methods. You can read more about Active Record in
18
+ link:files/vendor/rails/activerecord/README.html.
19
+
20
+ The controller and view are handled by the Action Pack, which handles both
21
+ layers by its two parts: Action View and Action Controller. These two layers
22
+ are bundled in a single package due to their heavy interdependence. This is
23
+ unlike the relationship between the Active Record and Action Pack that is much
24
+ more separate. Each of these packages can be used independently outside of
25
+ Rails. You can read more about Action Pack in
26
+ link:files/vendor/rails/actionpack/README.html.
27
+
28
+
29
+ == Getting Started
30
+
31
+ 1. At the command prompt, create a new Rails application:
32
+ <tt>rails new myapp</tt> (where <tt>myapp</tt> is the application name)
33
+
34
+ 2. Change directory to <tt>myapp</tt> and start the web server:
35
+ <tt>cd myapp; rails server</tt> (run with --help for options)
36
+
37
+ 3. Go to http://localhost:3000/ and you'll see:
38
+ "Welcome aboard: You're riding Ruby on Rails!"
39
+
40
+ 4. Follow the guidelines to start developing your application. You can find
41
+ the following resources handy:
42
+
43
+ * The Getting Started Guide: http://guides.rubyonrails.org/getting_started.html
44
+ * Ruby on Rails Tutorial Book: http://www.railstutorial.org/
45
+
46
+
47
+ == Debugging Rails
48
+
49
+ Sometimes your application goes wrong. Fortunately there are a lot of tools that
50
+ will help you debug it and get it back on the rails.
51
+
52
+ First area to check is the application log files. Have "tail -f" commands
53
+ running on the server.log and development.log. Rails will automatically display
54
+ debugging and runtime information to these files. Debugging info will also be
55
+ shown in the browser on requests from 127.0.0.1.
56
+
57
+ You can also log your own messages directly into the log file from your code
58
+ using the Ruby logger class from inside your controllers. Example:
59
+
60
+ class WeblogController < ActionController::Base
61
+ def destroy
62
+ @weblog = Weblog.find(params[:id])
63
+ @weblog.destroy
64
+ logger.info("#{Time.now} Destroyed Weblog ID ##{@weblog.id}!")
65
+ end
66
+ end
67
+
68
+ The result will be a message in your log file along the lines of:
69
+
70
+ Mon Oct 08 14:22:29 +1000 2007 Destroyed Weblog ID #1!
71
+
72
+ More information on how to use the logger is at http://www.ruby-doc.org/core/
73
+
74
+ Also, Ruby documentation can be found at http://www.ruby-lang.org/. There are
75
+ several books available online as well:
76
+
77
+ * Programming Ruby: http://www.ruby-doc.org/docs/ProgrammingRuby/ (Pickaxe)
78
+ * Learn to Program: http://pine.fm/LearnToProgram/ (a beginners guide)
79
+
80
+ These two books will bring you up to speed on the Ruby language and also on
81
+ programming in general.
82
+
83
+
84
+ == Debugger
85
+
86
+ Debugger support is available through the debugger command when you start your
87
+ Mongrel or WEBrick server with --debugger. This means that you can break out of
88
+ execution at any point in the code, investigate and change the model, and then,
89
+ resume execution! You need to install ruby-debug to run the server in debugging
90
+ mode. With gems, use <tt>sudo gem install ruby-debug</tt>. Example:
91
+
92
+ class WeblogController < ActionController::Base
93
+ def index
94
+ @posts = Post.all
95
+ debugger
96
+ end
97
+ end
98
+
99
+ So the controller will accept the action, run the first line, then present you
100
+ with a IRB prompt in the server window. Here you can do things like:
101
+
102
+ >> @posts.inspect
103
+ => "[#<Post:0x14a6be8
104
+ @attributes={"title"=>nil, "body"=>nil, "id"=>"1"}>,
105
+ #<Post:0x14a6620
106
+ @attributes={"title"=>"Rails", "body"=>"Only ten..", "id"=>"2"}>]"
107
+ >> @posts.first.title = "hello from a debugger"
108
+ => "hello from a debugger"
109
+
110
+ ...and even better, you can examine how your runtime objects actually work:
111
+
112
+ >> f = @posts.first
113
+ => #<Post:0x13630c4 @attributes={"title"=>nil, "body"=>nil, "id"=>"1"}>
114
+ >> f.
115
+ Display all 152 possibilities? (y or n)
116
+
117
+ Finally, when you're ready to resume execution, you can enter "cont".
118
+
119
+
120
+ == Console
121
+
122
+ The console is a Ruby shell, which allows you to interact with your
123
+ application's domain model. Here you'll have all parts of the application
124
+ configured, just like it is when the application is running. You can inspect
125
+ domain models, change values, and save to the database. Starting the script
126
+ without arguments will launch it in the development environment.
127
+
128
+ To start the console, run <tt>rails console</tt> from the application
129
+ directory.
130
+
131
+ Options:
132
+
133
+ * Passing the <tt>-s, --sandbox</tt> argument will rollback any modifications
134
+ made to the database.
135
+ * Passing an environment name as an argument will load the corresponding
136
+ environment. Example: <tt>rails console production</tt>.
137
+
138
+ To reload your controllers and models after launching the console run
139
+ <tt>reload!</tt>
140
+
141
+ More information about irb can be found at:
142
+ link:http://www.rubycentral.org/pickaxe/irb.html
143
+
144
+
145
+ == dbconsole
146
+
147
+ You can go to the command line of your database directly through <tt>rails
148
+ dbconsole</tt>. You would be connected to the database with the credentials
149
+ defined in database.yml. Starting the script without arguments will connect you
150
+ to the development database. Passing an argument will connect you to a different
151
+ database, like <tt>rails dbconsole production</tt>. Currently works for MySQL,
152
+ PostgreSQL and SQLite 3.
153
+
154
+ == Description of Contents
155
+
156
+ The default directory structure of a generated Ruby on Rails application:
157
+
158
+ |-- app
159
+ | |-- assets
160
+ | |-- images
161
+ | |-- javascripts
162
+ | `-- stylesheets
163
+ | |-- controllers
164
+ | |-- helpers
165
+ | |-- mailers
166
+ | |-- models
167
+ | `-- views
168
+ | `-- layouts
169
+ |-- config
170
+ | |-- environments
171
+ | |-- initializers
172
+ | `-- locales
173
+ |-- db
174
+ |-- doc
175
+ |-- lib
176
+ | `-- tasks
177
+ |-- log
178
+ |-- public
179
+ |-- script
180
+ |-- test
181
+ | |-- fixtures
182
+ | |-- functional
183
+ | |-- integration
184
+ | |-- performance
185
+ | `-- unit
186
+ |-- tmp
187
+ | |-- cache
188
+ | |-- pids
189
+ | |-- sessions
190
+ | `-- sockets
191
+ `-- vendor
192
+ |-- assets
193
+ `-- stylesheets
194
+ `-- plugins
195
+
196
+ app
197
+ Holds all the code that's specific to this particular application.
198
+
199
+ app/assets
200
+ Contains subdirectories for images, stylesheets, and JavaScript files.
201
+
202
+ app/controllers
203
+ Holds controllers that should be named like weblogs_controller.rb for
204
+ automated URL mapping. All controllers should descend from
205
+ ApplicationController which itself descends from ActionController::Base.
206
+
207
+ app/models
208
+ Holds models that should be named like post.rb. Models descend from
209
+ ActiveRecord::Base by default.
210
+
211
+ app/views
212
+ Holds the template files for the view that should be named like
213
+ weblogs/index.html.erb for the WeblogsController#index action. All views use
214
+ eRuby syntax by default.
215
+
216
+ app/views/layouts
217
+ Holds the template files for layouts to be used with views. This models the
218
+ common header/footer method of wrapping views. In your views, define a layout
219
+ using the <tt>layout :default</tt> and create a file named default.html.erb.
220
+ Inside default.html.erb, call <% yield %> to render the view using this
221
+ layout.
222
+
223
+ app/helpers
224
+ Holds view helpers that should be named like weblogs_helper.rb. These are
225
+ generated for you automatically when using generators for controllers.
226
+ Helpers can be used to wrap functionality for your views into methods.
227
+
228
+ config
229
+ Configuration files for the Rails environment, the routing map, the database,
230
+ and other dependencies.
231
+
232
+ db
233
+ Contains the database schema in schema.rb. db/migrate contains all the
234
+ sequence of Migrations for your schema.
235
+
236
+ doc
237
+ This directory is where your application documentation will be stored when
238
+ generated using <tt>rake doc:app</tt>
239
+
240
+ lib
241
+ Application specific libraries. Basically, any kind of custom code that
242
+ doesn't belong under controllers, models, or helpers. This directory is in
243
+ the load path.
244
+
245
+ public
246
+ The directory available for the web server. Also contains the dispatchers and the
247
+ default HTML files. This should be set as the DOCUMENT_ROOT of your web
248
+ server.
249
+
250
+ script
251
+ Helper scripts for automation and generation.
252
+
253
+ test
254
+ Unit and functional tests along with fixtures. When using the rails generate
255
+ command, template test files will be generated for you and placed in this
256
+ directory.
257
+
258
+ vendor
259
+ External libraries that the application depends on. Also includes the plugins
260
+ subdirectory. If the app has frozen rails, those gems also go here, under
261
+ vendor/rails/. This directory is in the load path.