Adding testing of blank Text channel, fixing lots of little bugs along the way
authorEd Page <eopage@byu.net>
Wed, 16 Dec 2009 00:26:07 +0000 (18:26 -0600)
committerEd Page <eopage@byu.net>
Wed, 16 Dec 2009 00:26:07 +0000 (18:26 -0600)
hand_tests/generic.py
src/channel/text.py
src/gvoice/conversations.py
src/gvoice/session.py

index 63a9e31..e5155f7 100755 (executable)
@@ -376,6 +376,29 @@ class Call(Action):
                super(Call, self)._on_done()
 
 
                super(Call, self)._on_done()
 
 
+class SendText(Action):
+
+       def __init__(self, connAction, chanAction, handleAction, messageType, message):
+               super(SendText, self).__init__()
+               self._connAction = connAction
+               self._chanAction = chanAction
+               self._handleAction = handleAction
+               self._messageType = messageType
+               self._message = message
+
+       def queue_action(self):
+               self._chanAction.channel[telepathy.server.CHANNEL_TYPE_TEXT].SendText(
+                       self._messageType,
+                       self._message,
+                       reply_handler = self._on_done,
+                       error_handler = self._on_error,
+               )
+
+       def _on_done(self, handle):
+               print "Message sent"
+               super(SendText, self)._on_done()
+
+
 class Disconnect(Action):
 
        def __init__(self, connAction):
 class Disconnect(Action):
 
        def __init__(self, connAction):
@@ -432,21 +455,22 @@ if __name__ == '__main__':
                        lastAction.append_action(sps)
                        lastAction = sps
 
                        lastAction.append_action(sps)
                        lastAction = sps
 
-                       setdnd = SetSimplePresence(con, "dnd", "")
-                       lastAction.append_action(setdnd)
-                       lastAction = setdnd
+                       if False:
+                               setdnd = SetSimplePresence(con, "dnd", "")
+                               lastAction.append_action(setdnd)
+                               lastAction = setdnd
 
 
-                       sps = SimplePresenceStatus(con, uh)
-                       lastAction.append_action(sps)
-                       lastAction = sps
+                               sps = SimplePresenceStatus(con, uh)
+                               lastAction.append_action(sps)
+                               lastAction = sps
 
 
-                       setdnd = SetSimplePresence(con, "available", "")
-                       lastAction.append_action(setdnd)
-                       lastAction = setdnd
+                               setdnd = SetSimplePresence(con, "available", "")
+                               lastAction.append_action(setdnd)
+                               lastAction = setdnd
 
 
-                       sps = SimplePresenceStatus(con, uh)
-                       lastAction.append_action(sps)
-                       lastAction = sps
+                               sps = SimplePresenceStatus(con, uh)
+                               lastAction.append_action(sps)
+                               lastAction = sps
 
                if True:
                        rclh = RequestHandle(con, telepathy.HANDLE_TYPE_LIST, ["subscribe"])
 
                if True:
                        rclh = RequestHandle(con, telepathy.HANDLE_TYPE_LIST, ["subscribe"])
@@ -469,6 +493,7 @@ if __name__ == '__main__':
                        lastAction.append_action(rch)
                        lastAction = rch
 
                        lastAction.append_action(rch)
                        lastAction = rch
 
+                       # making a phone call
                        if True:
                                smHandle = rch
                                smHandleType = telepathy.HANDLE_TYPE_CONTACT
                        if True:
                                smHandle = rch
                                smHandleType = telepathy.HANDLE_TYPE_CONTACT
@@ -489,6 +514,22 @@ if __name__ == '__main__':
                                lastAction.append_action(call)
                                lastAction = call
 
                                lastAction.append_action(call)
                                lastAction = call
 
+                       # sending a text
+                       rtc = RequestChannel(
+                               con,
+                               rch,
+                               telepathy.CHANNEL_TYPE_TEXT,
+                               smHandleType,
+                       )
+                       lastAction.append_action(rtc)
+                       lastAction = rtc
+
+                       if False:
+                               sendtext = SendText(con, rtc, rch, telepathy.CHANNEL_TEXT_MESSAGE_TYPE_NORMAL, "Boo!")
+                               lastAction.append_action(sendtext)
+                               lastAction = sendtext
+
+
                dis = Disconnect(con)
                lastAction.append_action(dis)
                lastAction = dis
                dis = Disconnect(con)
                lastAction.append_action(dis)
                lastAction = dis
index 41a750d..f9c00ae 100644 (file)
@@ -25,13 +25,13 @@ class TextChannel(telepathy.server.ChannelTypeText):
                self._otherHandle = h
 
                self._conn.session.conversations.updateSignalHandler.register_sink(
                self._otherHandle = h
 
                self._conn.session.conversations.updateSignalHandler.register_sink(
-                       self._on_message_received
+                       self._on_conversations_updated
                )
 
                # The only reason there should be anything in the conversation is if
                # its new, so report it all
                try:
                )
 
                # The only reason there should be anything in the conversation is if
                # its new, so report it all
                try:
-                       conversation = self._conn.session.conversations[self._contactKey]
+                       conversation = self._conn.session.conversations.get_conversation(self._contactKey)
                except KeyError:
                        pass
                else:
                except KeyError:
                        pass
                else:
@@ -50,10 +50,10 @@ class TextChannel(telepathy.server.ChannelTypeText):
        def Close(self):
                try:
                        # Clear since the user has seen it all and it should start a new conversation
        def Close(self):
                try:
                        # Clear since the user has seen it all and it should start a new conversation
-                       self._conn.session.clear_conversation(self._contactKey)
+                       self._conn.session.conversations.clear_conversation(self._contactKey)
 
                        self._conn.session.conversations.updateSignalHandler.unregister_sink(
 
                        self._conn.session.conversations.updateSignalHandler.unregister_sink(
-                               self._on_message_received
+                               self._on_conversations_updated
                        )
                finally:
                        telepathy.server.ChannelTypeText.Close(self)
                        )
                finally:
                        telepathy.server.ChannelTypeText.Close(self)
@@ -70,7 +70,7 @@ class TextChannel(telepathy.server.ChannelTypeText):
        def _on_conversations_updated(self, conversationIds):
                if self._contactKey not in conversationIds:
                        return
        def _on_conversations_updated(self, conversationIds):
                if self._contactKey not in conversationIds:
                        return
-               conversation = self._conn.session.conversations[self._contactKey]
+               conversation = self._conn.session.conversations.get_conversation(self._contactKey)
                self._report_conversation(conversation)
 
        def _report_conversation(self, conversation):
                self._report_conversation(conversation)
 
        def _report_conversation(self, conversation):
index 3e0040c..357a844 100644 (file)
@@ -59,7 +59,10 @@ class Conversations(object):
                return self._conversations[key]
 
        def clear_conversation(self, key):
                return self._conversations[key]
 
        def clear_conversation(self, key):
-               del self._conversations[key]
+               try:
+                       del self._conversations[key]
+               except KeyError:
+                       _moduleLogger.info("Conversation never existed for %r" % (key,))
 
        def clear_all(self):
                self._conversations.clear()
 
        def clear_all(self):
                self._conversations.clear()
index 35157d9..bf5e328 100644 (file)
@@ -78,5 +78,5 @@ class Session(object):
                """
                if self._conversations is None:
                        _moduleLogger.info("Initializing conversations")
                """
                if self._conversations is None:
                        _moduleLogger.info("Initializing conversations")
-                       self._conversations = conversations.Conversationst(self.backend)
+                       self._conversations = conversations.Conversations(self.backend)
                return self._conversations
                return self._conversations