Browse files

ack offline user

  • Loading branch information...
1 parent c8b16eb commit 96423f3e7c9a4ba6620498f43cbd4f2b1a4f5d32 @asterite asterite committed Nov 7, 2012
Showing with 13 additions and 7 deletions.
  1. +2 −2 lib/msn/messenger.rb
  2. +11 −5 lib/msn/notification_server.rb
View
4 lib/msn/messenger.rb
@@ -104,8 +104,8 @@ def accept_message(message)
call_handler @on_message_handler, message
end
- def accept_message_ack(id, ok)
- call_handler @on_message_ack_handler, id, ok
+ def accept_message_ack(id, status)
+ call_handler @on_message_ack_handler, id, status
end
def contact_request(email, display_name)
View
16 lib/msn/notification_server.rb
@@ -46,7 +46,10 @@ def send_message(email, text)
@message_ids[trid] = message_id
end
switchboard.usr username_guid, response[5]
- switchboard.cal email
+ cal_response = switchboard.cal email
+ if cal_response[0] == '217'
+ messenger.accept_message_ack message_id, :offline
+ end
end.resume
end
@@ -148,12 +151,10 @@ def create_switchboard(email, host_and_port)
host, port = host_and_port.split(':')
switchboard = EM.connect host, port, Msn::Switchboard, messenger
switchboard.on_event 'ACK' do |header|
- trid = header[1].to_i
- messenger.accept_message_ack @message_ids.delete(trid), true
+ notify_ack header[1].to_i, :ack
end
switchboard.on_event 'NAK' do |header|
- trid = header[1].to_i
- messenger.accept_message_ack @message_ids.delete(trid), false
+ notify_ack header[1].to_i, :nak
end
switchboard.on_event 'BYE' do |header|
destroy_switchboard email if header[1] =~ /#{email}/
@@ -166,6 +167,11 @@ def destroy_switchboard(email)
switchboard.close_connection if switchboard
end
+ def notify_ack(trid, status)
+ id = @message_ids.delete(trid)
+ messenger.accept_message_ack id, :nak if id
+ end
+
def unbind
if @reconnect_host
reconnect @reconnect_host, @reconnect_port.to_i

0 comments on commit 96423f3

Please sign in to comment.