Lots more bug fixes
[theonering] / src / connection.py
index 2db7df6..69ed50c 100644 (file)
@@ -59,11 +59,16 @@ class TheOneRingConnection(
                        self._callbackNumber = parameters['forward'].encode('utf-8')
                        self._channelManager = channel_manager.ChannelManager(self)
 
-                       cookieFilePath = "%s/cookies.txt" % constants._data_path_
+                       cookieFilePath = None
                        self._session = gvoice.session.Session(cookieFilePath)
 
                        self.set_self_handle(handle.create_handle(self, 'connection'))
 
+                       self._callback = coroutines.func_sink(
+                               coroutines.expand_positional(
+                                       self._on_conversations_updated
+                               )
+                       )
                        _moduleLogger.info("Connection to the account %s created" % account)
                except Exception, e:
                        _moduleLogger.exception("Failed to create Connection")
@@ -96,6 +101,9 @@ class TheOneRingConnection(
                        telepathy.CONNECTION_STATUS_REASON_REQUESTED
                )
                try:
+                       self.session.conversations.updateSignalHandler.register_sink(
+                               self._callback
+                       )
                        self.session.login(*self._credentials)
                        self.session.backend.set_callback_number(self._callbackNumber)
                except gvoice.backend.NetworkError, e:
@@ -125,6 +133,10 @@ class TheOneRingConnection(
                """
                _moduleLogger.info("Disconnecting")
                try:
+                       self.session.conversations.updateSignalHandler.unregister_sink(
+                               self._callback
+                       )
+                       self._channelManager.close()
                        self.session.logout()
                        _moduleLogger.info("Disconnected")
                except Exception:
@@ -198,15 +210,15 @@ class TheOneRingConnection(
                h = handle.create_handle(self, 'contact', requestedContactId, requestedContactNumber)
                return h
 
-       @coroutines.func_sink
-       @coroutines.expand_positional
        @gobject_utils.async
-       def _on_conversations_updated(self, conversationIds):
+       @gtk_toolbox.log_exception(_moduleLogger)
+       def _on_conversations_updated(self, conv, conversationIds):
                # @todo get conversations update running
                # @todo test conversatiuons
+               _moduleLogger.info("Incoming messages from: %r" % (conversationIds, ))
                channelManager = self._channelManager
                for contactId, phoneNumber in conversationIds:
-                       h = self._create_contact_handle(contactId, phoneNumber)
+                       h = handle.create_handle(self, 'contact', contactId, phoneNumber)
                        # if its new, __init__ will take care of things
                        # if its old, its own update will take care of it
-                       channel = channelManager.channel_for_text(handle)
+                       channel = channelManager.channel_for_text(h)