summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRiccardo (C10uD) <c10ud.dev@gmail.com>2011-03-26 17:59:42 +0100
committerLouis-Francis Ratté-Boulianne <louis-francis.ratte-boulianne@collabora.co.uk>2011-04-12 23:37:20 -0400
commitdf7a14eef27ce0c340969d1b85be8a034b2964a8 (patch)
tree1086fa7871dbe5ff12c85d092c219be0ee994573
parentd7b85e3d04b843162a8ee77be9831a080c2a8d80 (diff)
Timeout the switchboard after 60 seconds of inactivity
Also fixed the behaviour with multi-user conversations.
-rw-r--r--papyon/msnp/switchboard.py17
1 files changed, 16 insertions, 1 deletions
diff --git a/papyon/msnp/switchboard.py b/papyon/msnp/switchboard.py
index c29cf37..7bb3d83 100644
--- a/papyon/msnp/switchboard.py
+++ b/papyon/msnp/switchboard.py
@@ -106,6 +106,7 @@ class SwitchboardProtocol(BaseProtocol):
BaseProtocol.__init__(self, client, transport, proxies)
self.participants = {}
self.end_points = {}
+ self.inactivity_timer_id = 0
self.__session_id = session_id
self.__key = key
self.__state = ProtocolState.CLOSED
@@ -172,10 +173,14 @@ class SwitchboardProtocol(BaseProtocol):
return self._send_command('MSG', (ack,), message, True,
(self._on_message_sent, message, callback), errback)
- def leave(self):
+ def leave(self, inactivity=False):
"""Leave the conversation"""
if self.state != ProtocolState.OPEN:
return
+ if self.inactivity_timer_id:
+ gobject.source_remove(self.inactivity_timer_id)
+ if inactivity:
+ logger.info("Switchboard timed out. Going to leave it.")
logger.info("Leaving switchboard %s" % self.__session_id)
self._send_command('OUT')
self._state = ProtocolState.CLOSING
@@ -269,9 +274,11 @@ class SwitchboardProtocol(BaseProtocol):
display_name = urllib.unquote(command.arguments[1])
contact = self.__search_account(account, display_name)
message = Message(contact, command.payload)
+ self._update_switchboard_timeout()
self.emit("message-received", message)
def _handle_ACK(self, command):
+ self._update_switchboard_timeout()
self.emit("message-delivered", command.transaction_id)
def _handle_NAK(self, command):
@@ -294,6 +301,14 @@ class SwitchboardProtocol(BaseProtocol):
pass
else:
logger.error('Notification got error :' + unicode(error))
+
+ def _update_switchboard_timeout(self):
+ if self.inactivity_timer_id:
+ gobject.source_remove(self.inactivity_timer_id)
+ self.inactivity_timer_id = 0
+ if len(self.participants) == 1: # don't leave multi-user conversations
+ self.inactivity_timer_id = gobject.timeout_add_seconds(60, self.leave, True)
+
# callbacks --------------------------------------------------------------
def _connect_cb(self, transport):
self._state = ProtocolState.OPENING