Forcing calls to quit immediately rather than giving time to cancel to fix issues...
[theonering] / src / channel / call.py
index fefece3..bdd82dc 100644 (file)
@@ -47,7 +47,7 @@ class CallChannel(
                tp.ChannelInterfaceCallState.__init__(self)
                tp.ChannelInterfaceHold.__init__(self)
                self.__contactHandle = contactHandle
-               self.__calledNumer = None
+               self.__calledNumber = None
 
                self._implement_property_get(
                        telepathy.interfaces.CHANNEL_INTERFACE,
@@ -79,8 +79,10 @@ class CallChannel(
                })
 
                self.GroupFlagsChanged(0, 0)
+               added, removed = [self._conn.GetSelfHandle()], []
+               localPending, remotePending = [], [contactHandle]
                self.MembersChanged(
-                       '', [self._conn.GetSelfHandle()], [], [], [contactHandle],
+                       '', added, removed, localPending, remotePending,
                        0, telepathy.CHANNEL_GROUP_CHANGE_REASON_NONE
                )
 
@@ -96,11 +98,10 @@ class CallChannel(
 
        def close(self):
                _moduleLogger.debug("Closing call")
+               self._delayedClose.cancel()
+
                tp.ChannelTypeStreamedMedia.Close(self)
                self.remove_from_connection()
-               if self.__calledNumer is not None:
-                       self._conn.session.backend.cancel(self.__calledNumer)
-               self._delayedClose.cancel()
 
        @misc_utils.log_exception(_moduleLogger)
        def GetLocalPendingMembersWithInfo(self):
@@ -157,13 +158,9 @@ class CallChannel(
                """
                contact = self._conn.get_handle_by_id(telepathy.constants.HANDLE_TYPE_CONTACT, contactId)
                assert self.__contactHandle == contact, "%r != %r" % (self.__contactHandle, contact)
-               contactNumber = contact.phoneNumber
 
-               self.__calledNumer = contactNumber
-               self.CallStateChanged(self.__contactHandle, telepathy.constants.CHANNEL_CALL_STATE_RINGING)
-               self._conn.session.backend.call(contactNumber)
-               self._delayedClose.start(seconds=2)
-               self.CallStateChanged(self.__contactHandle, telepathy.constants.CHANNEL_CALL_STATE_FORWARDED)
+               le = gobject_utils.AsyncLinearExecution(self._conn.session.pool, self._call)
+               le.start(contact)
 
                streamId = 0
                streamState = telepathy.constants.MEDIA_STREAM_STATE_CONNECTED
@@ -172,6 +169,34 @@ class CallChannel(
                return [(streamId, contact, streamTypes[0], streamState, streamDirection, pendingSendFlags)]
 
        @misc_utils.log_exception(_moduleLogger)
+       def _call(self, contact):
+               contactNumber = contact.phoneNumber
+
+               self.__calledNumber = contactNumber
+               self.CallStateChanged(self.__contactHandle, telepathy.constants.CHANNEL_CALL_STATE_RINGING)
+
+               self._delayedClose.start(seconds=0)
+               self.CallStateChanged(self.__contactHandle, telepathy.constants.CHANNEL_CALL_STATE_FORWARDED)
+
+               try:
+                       result = yield (
+                               self._conn.session.backend.call,
+                               (contactNumber, ),
+                               {},
+                       )
+               except Exception, e:
+                       _moduleLogger.exception("While placing call to %s" % (self.__calledNumber, ))
+                       self._conn.force_log_display()
+                       accountNumber = misc_utils.normalize_number(self._conn.session.backend.get_account_number())
+                       self._conn.log_to_user(
+                               __name__,
+                               "Error while placing call from %s to %s:\n%s" % (
+                                       accountNumber, self.__calledNumber, str(e)
+                               )
+                       )
+                       return
+
+       @misc_utils.log_exception(_moduleLogger)
        def GetCallStates(self):
                """
                For org.freedesktop.Telepathy.Channel.Interface.CallState
@@ -202,11 +227,9 @@ class CallChannel(
                if not Hold:
                        return
                _moduleLogger.debug("Closing without cancel to get out of users way")
-               self.__calledNumer = None
                self.close()
 
        @misc_utils.log_exception(_moduleLogger)
        def _on_close_requested(self, *args):
                _moduleLogger.debug("Cancel now disallowed")
-               self.__calledNumer = None
                self.close()