Overall, got sending a text to an arbitrary number working
[theonering] / src / channel / text.py
index 51d1a91..3daacf0 100644 (file)
@@ -1,12 +1,13 @@
 import time
-import logger
+import logging
 
 import telepathy
 
+import gtk_toolbox
 import handle
 
 
-_moduleLogger = logger.getLogger("channel.text")
+_moduleLogger = logging.getLogger("channel.text")
 
 
 class TextChannel(telepathy.server.ChannelTypeText):
@@ -14,34 +15,37 @@ class TextChannel(telepathy.server.ChannelTypeText):
        Look into implementing ChannelInterfaceMessages for rich text formatting
        """
 
-       def __init__(self, connection):
-               h = None
+       def __init__(self, connection, h):
                telepathy.server.ChannelTypeText.__init__(self, connection, h)
                self._nextRecievedId = 0
 
-               handles = []
-               # @todo Populate participants
-               self.MembersChanged('', handles, [], [], [],
-                               0, telepathy.CHANNEL_GROUP_CHANGE_REASON_NONE)
+               self._otherHandle = h
+               handles = [h]
+               #self.MembersChanged('', handles, [], [], [],
+               #               0, telepathy.CHANNEL_GROUP_CHANGE_REASON_NONE)
 
+       @gtk_toolbox.log_exception(_moduleLogger)
        def Send(self, messageType, text):
                if messageType != telepathy.CHANNEL_TEXT_MESSAGE_TYPE_NORMAL:
-                       raise telepathy.NotImplemented("Unhandled message type")
-               # @todo implement sending message
+                       raise telepathy.NotImplemented("Unhandled message type: %r" % messageType)
+
+               self._conn.session.backend.send_sms(self._otherHandle.phoneNumber, text)
+
                self.Sent(int(time.time()), messageType, text)
 
+       @gtk_toolbox.log_exception(_moduleLogger)
        def Close(self):
                telepathy.server.ChannelTypeText.Close(self)
                self.remove_from_connection()
 
-       def _on_message_received(self, sender, message):
+       def _on_message_received(self, contactId, contactNumber, message):
                """
                @todo Attatch this to receiving a message
                """
                currentReceivedId = self._nextRecievedId
 
                timestamp = int(time.time())
-               h = handle.create_handle(self._conn, "contact", sender.account)
+               h = handle.create_handle(self._conn, "contact", contactId, contactNumber)
                type = telepathy.CHANNEL_TEXT_MESSAGE_TYPE_NORMAL
                message = message.content