Making phone numbers as consistent as possible so user started conversations don...
[theonering] / src / connection.py
index be98d59..8fa47bd 100644 (file)
@@ -130,6 +130,13 @@ class TheOneRingConnection(
                        requestedContactId, requestedContactNumber = handle.ContactHandle.from_handle_name(
                                requestedHandleName
                        )
+                       if not requestedContactId:
+                               # Sometimes GV doesn't give us a contactid for contacts, so
+                               # let's slow things down just a tad for better consistency for
+                               # the user
+                               ids = list(self.session.addressbook.find_contacts_with_number(requestedContactNumber))
+                               if ids:
+                                       requestedContactId = ids[0]
                        h = handle.create_handle(self, 'contact', requestedContactId, requestedContactNumber)
                elif handleType == telepathy.HANDLE_TYPE_LIST:
                        # Support only server side (immutable) lists
@@ -269,7 +276,8 @@ class TheOneRingConnection(
        def _on_conversations_updated(self, conv, conversationIds):
                _moduleLogger.debug("Incoming messages from: %r" % (conversationIds, ))
                for contactId, phoneNumber in conversationIds:
-                       h = handle.create_handle(self, 'contact', contactId, phoneNumber)
+                       handleName = handle.ContactHandle.to_handle_name(contactId, phoneNumber)
+                       h = self.get_handle_by_name(telepathy.HANDLE_TYPE_CONTACT, handleName)
                        # Just let the TextChannel decide whether it should be reported to the user or not
                        props = self._generate_props(telepathy.CHANNEL_TYPE_TEXT, h, False)
                        channel = self.__channelManager.channel_for_props(props, signal=True)