Permalink
Browse files

Message ack

  • Loading branch information...
1 parent 683e229 commit 494febfdc0fd5f73c92b179f863965bbb55c199d Ary Borenszweig committed Nov 7, 2012
Showing with 30 additions and 3 deletions.
  1. +8 −0 lib/msn/messenger.rb
  2. +20 −2 lib/msn/notification_server.rb
  3. +1 −0 lib/msn/protocol.rb
  4. +1 −1 lib/msn/switchboard.rb
View
@@ -84,6 +84,10 @@ def on_message(&handler)
@on_message_handler = handler
end
+ def on_message_ack(&handler)
+ @on_message_ack_handler = handler
+ end
+
def on_contact_request(&handler)
@on_contact_request = handler
end
@@ -96,6 +100,10 @@ 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
+ end
+
def contact_request(email, display_name)
call_handler @on_contact_request, email, display_name
end
@@ -11,6 +11,9 @@ def initialize(messenger)
@guid = Guid.new.to_s
@switchboards = {}
+ @message_id = 1
+ @message_ids = {}
+
on_event 'ADL' do |header, data|
data = Nokogiri::XML(data)
domain = data.xpath('//ml/d').first['n']
@@ -26,21 +29,28 @@ def username_guid
end
def send_message(email, text)
+ message_id = @message_id
+ @message_id += 1
+
switchboard = @switchboards[email]
if switchboard
- switchboard.send_message text
+ trid = switchboard.send_message text
+ @message_ids[trid] = message_id
else
Fiber.new do
response = xfr "SB"
switchboard = create_switchboard email, response[3]
switchboard.on_event 'JOI' do
switchboard.clear_event 'JOI'
- switchboard.send_message text
+ trid = switchboard.send_message text
+ @message_ids[trid] = message_id
end
switchboard.usr username_guid, response[5]
switchboard.cal email
end.resume
end
+
+ message_id
end
def username
@@ -137,6 +147,14 @@ def login_to_nexus(policy, nonce)
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
+ end
+ switchboard.on_event 'NAK' do |header|
+ trid = header[1].to_i
+ messenger.accept_message_ack @message_ids.delete(trid), false
+ end
switchboard.on_event 'BYE' do |header|
destroy_switchboard email if header[1] =~ /#{email}/
end
View
@@ -94,6 +94,7 @@ def send_command_internal(text)
Msn::Messenger.log_info ">> #{text}"
send_data text
@trid += 1
+ @trid - 1
end
def on_event(kind, &block)
View
@@ -17,7 +17,7 @@ def initialize(messenger)
end
def send_message(text)
- send_payload_command "MSG", "N", "MIME-Version: 1.0\r\nContent-Type: text/plain; charset=UTF-8\r\nUser-Agent: pidgin/2.10.5devel\r\nX-MMS-IM-Format: FN=Segoe%20UI; EF=; CO=0; PF=0; RL=0\r\n\r\n#{text}"
+ send_payload_command "MSG", "A", "MIME-Version: 1.0\r\nContent-Type: text/plain; charset=UTF-8\r\nUser-Agent: pidgin/2.10.5devel\r\nX-MMS-IM-Format: FN=Segoe%20UI; EF=; CO=0; PF=0; RL=0\r\n\r\n#{text}"
end
end

0 comments on commit 494febf

Please sign in to comment.