public
Homepage: http://www.inoutopen.com
Clone URL: git://github.com/jwulff/in_out_open.git
lots of awesome jabber stuff
jwulff (author)
Wed Apr 23 12:35:40 -0700 2008
commit  c3fec7886a83257ef1d1ef3d780f68e0e3c42df8
tree    5238fa8571acd7fb5d33ba815b1d1a33f4734c8d
parent  04eb8f82e7b2704509bcccb1ad468bce2c756121
...
24
25
26
 
 
 
 
 
 
 
 
 
 
27
...
24
25
26
27
28
29
30
31
32
33
34
35
36
37
0
@@ -24,4 +24,14 @@ class TeamsController < ApplicationController
0
     @team.destroy
0
     redirect_to teams_url
0
   end
0
+
0
+ def edit
0
+ @team = Team.find params[:id]
0
+ end
0
+
0
+ def update
0
+ @team = Team.find params[:team][:id]
0
+ @team.update_attributes! params[:team]
0
+ redirect_to team_url(@team)
0
+ end
0
 end
...
17
18
19
20
21
 
22
23
24
...
17
18
19
 
 
20
21
22
23
0
@@ -17,8 +17,7 @@ class Message < ActiveRecord::Base
0
     out += "in "
0
     out += "#{self.team}"
0
     out += " to" if self.kind_of?(Status)
0
- out += ":"
0
- out += "\n\n"
0
+ out += ": "
0
     out += "#{self.text}"
0
     return out
0
   end
...
8
9
10
 
 
 
 
11
12
13
...
8
9
10
11
12
13
14
15
16
17
0
@@ -8,6 +8,10 @@ class Team < ActiveRecord::Base
0
   validates_format_of :short_name,
0
                       :with => /\A([a-z]*)\Z/,
0
                       :message => 'can only consist of lowercase letters'
0
+
0
+ validates_format_of :jabber_id,
0
+ :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i,
0
+ :message => 'must be valid'
0
   
0
   def to_s
0
     name
...
1
 
2
3
4
5
 
 
 
 
 
 
 
 
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
29
30
31
32
33
34
35
...
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
 
 
 
40
41
42
43
0
@@ -1,34 +1,42 @@
0
-require 'xmpp4r'
0
+require 'drb'
0
 
0
 class MessageJabberObserver < ActiveRecord::Observer
0
   observe Message
0
   
0
+ def jabber_drb_server
0
+ unless @jabber_drb_server
0
+ DRb.start_service
0
+ @jabber_drb_server = DRbObject.new nil, 'druby://:7777'
0
+ end
0
+ return @jabber_drb_server
0
+ end
0
+
0
   def after_create(message)
0
- begin
0
- jabber_id = Jabber::JID::new JABBER_USER_ID
0
- jabber_client = Jabber::Client::new jabber_id
0
- jabber_client.connect
0
- jabber_client.auth JABBER_PASSWORD
0
-
0
- body = message.summary
0
-
0
- for user in message.team.users
0
- next if user.jabber_id.blank?
0
- begin
0
- jabber_message = Jabber::Message::new user.jabber_id, body
0
- jabber_message.set_type :normal
0
- jabber_message.set_id '1'
0
- jabber_message.set_subject 'InOutOpen'
0
- jabber_client.send jabber_message
0
- ActiveRecord::Base.logger.info "Jabber notification sent to #{to}."
0
- rescue => e
0
- ActiveRecord::Base.logger.error e.message
0
- ActiveRecord::Base.logger.error e.backtrace.join("\n")
0
- end
0
+ # Send message to chat room.
0
+ if message.team.jabber_id && message.team.jabber_room
0
+ begin
0
+ jabber_drb_server.send_message_to_jabber_room message.team.jabber_id,
0
+ message.team.jabber_password,
0
+ message.team.jabber_room,
0
+ message.summary
0
+ rescue => e
0
+ ActiveRecord::Base.logger.error e.message
0
+ ActiveRecord::Base.logger.error e.backtrace.join("\n")
0
+ end
0
+ end
0
+
0
+ # Send individual messages.
0
+ for user in message.team.users
0
+ next if user.jabber_id.blank? || message.team.jabber_id.blank?
0
+ begin
0
+ jabber_drb_server.send_message_to_jabber_id message.team.jabber_id,
0
+ message.team.jabber_password,
0
+ user.jabber_id,
0
+ message.summary
0
+ rescue => e
0
+ ActiveRecord::Base.logger.error e.message
0
+ ActiveRecord::Base.logger.error e.backtrace.join("\n")
0
       end
0
- rescue => e
0
- ActiveRecord::Base.logger.error e.message
0
- ActiveRecord::Base.logger.error e.backtrace.join("\n")
0
     end
0
   end
0
 end
0
\ No newline at end of file
...
1
2
3
4
5
6
7
8
9
10
...
18
19
20
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
22
23
24
25
26
 
...
1
2
3
 
 
 
 
4
5
6
...
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
 
 
 
 
33
34
0
@@ -1,10 +1,6 @@
0
 =form.hidden_field :id
0
 %fieldset
0
   %legend
0
- -if @new_team.new_record?
0
- New
0
- -else
0
- Edit
0
     Team
0
   %table
0
     %tr
0
@@ -18,8 +14,20 @@
0
       %td
0
         =form.text_field :short_name
0
     %tr
0
+ %th
0
+ Jabber ID
0
+ %td
0
+ =form.text_field :jabber_id
0
+ %tr
0
+ %th
0
+ Jabber Password
0
+ %td
0
+ =form.text_field :jabber_password
0
+ %tr
0
+ %th
0
+ Jabber Room
0
+ %td
0
+ =form.text_field :jabber_room
0
+ %tr
0
       %th{ :colspan => 2 }
0
- -if @new_team.new_record?
0
- =form.submit 'Create'
0
- -else
0
- =form.submit 'Update'
0
\ No newline at end of file
0
+ =form.submit 'Save'
...
26
27
28
 
 
29
30
31
...
26
27
28
29
30
31
32
33
0
@@ -26,6 +26,8 @@ namespace :deploy do
0
       symlink
0
       say_green "Writing database.yml."
0
       config.database
0
+ say_green "Writing jabber_settings.yml."
0
+ config.jabber
0
       say_green "Running migrations."
0
       migrate
0
     end
...
69
70
71
72
73
74
75
76
77
78
...
69
70
71
 
 
 
 
72
73
74
0
@@ -69,10 +69,6 @@ APPLICATION_NAME = 'In Out Open'
0
 PRODUCTION_HOST = 'www.inoutopen.com'
0
 USER_NONCE_SALT = 'nevernude'
0
 
0
-jabber_settings = YAML.load(File.read(File.join(RAILS_ROOT, 'config', 'jabber_settings.yml')))
0
-JABBER_USER_ID = jabber_settings['jabber_user_id']
0
-JABBER_PASSWORD = jabber_settings['jabber_password']
0
-
0
 ExceptionNotifier.exception_recipients = %w( johnw@orcasnet.com )
0
 
0
 class ActionController::Base
...
63
64
65
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
66
67
...
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
0
@@ -63,4 +63,37 @@ RAILS_ROOT = "/var/www/#{APPLICATION}/current"
0
       end
0
     end
0
   end
0
+end
0
+
0
+God.watch do |w|
0
+ w.uid = 'rails_admin'
0
+ w.gid = 'rails_admin'
0
+ w.group = APPLICATION
0
+
0
+ w.name = "#{APPLICATION}-jabber_drb_server"
0
+ w.interval = 30.seconds # default
0
+
0
+ w.start = "ruby #{RAILS_ROOT}/script/jabber_drb_server"
0
+ #w.stop = lambda { w.pid_file ? `kill -9 #{File.read w.pid_file}` : nil }
0
+ #w.restart = lambda { w.pid_file ? `kill -9 #{File.read w.pid_file}; ruby #{NDIF_RAILS_ROOT}/script/geocode_and_update_people` : `ruby #{NDIF_RAILS_ROOT}/script/geocode_and_update_people` }
0
+ w.start_grace = 10.seconds
0
+ w.restart_grace = 10.seconds
0
+
0
+ w.behavior(:clean_pid_file)
0
+
0
+ w.start_if do |start|
0
+ start.condition(:process_running) do |c|
0
+ c.notify = 'john'
0
+ c.interval = 5.seconds
0
+ c.running = false
0
+ end
0
+ end
0
+
0
+ w.restart_if do |restart|
0
+ restart.condition(:memory_usage) do |c|
0
+ c.notify = 'john'
0
+ c.above = 250.megabytes
0
+ c.times = [3, 5] # 3 out of 5 intervals
0
+ end
0
+ end
0
 end
0
\ No newline at end of file

Comments

    No one has commented yet.