Lessons learned from looking at telepathy-python to better understand what it was...
[theonering] / src / channel / text.py
index e6cc6af..51d1a91 100644 (file)
@@ -1,45 +1,51 @@
 import time
-import weakref
+import logger
 
 import telepathy
 
 import handle
 
 
-class ButterflyTextChannel(
-               telepathy.server.ChannelTypeText,
-               telepathy.server.ChannelInterfaceGroup,
-               telepathy.server.ChannelInterfaceChatState
-       ):
+_moduleLogger = logger.getLogger("channel.text")
 
-       def __init__(self, connection, conversation):
-               self._recv_id = 0
-               self._conversation = conversation
-               self._conn_ref = weakref.ref(connection)
 
-               telepathy.server.ChannelTypeText.__init__(self, connection, None)
-               telepathy.server.ChannelInterfaceGroup.__init__(self)
-               telepathy.server.ChannelInterfaceChatState.__init__(self)
+class TextChannel(telepathy.server.ChannelTypeText):
+       """
+       Look into implementing ChannelInterfaceMessages for rich text formatting
+       """
 
-               self.GroupFlagsChanged(telepathy.CHANNEL_GROUP_FLAG_CAN_ADD, 0)
-               self.__add_initial_participants()
+       def __init__(self, connection):
+               h = None
+               telepathy.server.ChannelTypeText.__init__(self, connection, h)
+               self._nextRecievedId = 0
 
-       def SetChatState(self, state):
-               if state == telepathy.CHANNEL_CHAT_STATE_COMPOSING:
-                       self._conversation.send_typing_notification()
-               h = handle.create_handle(self._conn_ref(), 'self')
-               self.ChatStateChanged(h, state)
+               handles = []
+               # @todo Populate participants
+               self.MembersChanged('', handles, [], [], [],
+                               0, telepathy.CHANNEL_GROUP_CHANGE_REASON_NONE)
 
        def Send(self, messageType, text):
-               if messageType == telepathy.CHANNEL_TEXT_MESSAGE_TYPE_NORMAL:
-                       self._conversation.send_text_message(text)
-               elif messageType == telepathy.CHANNEL_TEXT_MESSAGE_TYPE_ACTION and text == u"nudge":
-                       self._conversation.send_nudge()
-               else:
+               if messageType != telepathy.CHANNEL_TEXT_MESSAGE_TYPE_NORMAL:
                        raise telepathy.NotImplemented("Unhandled message type")
+               # @todo implement sending message
                self.Sent(int(time.time()), messageType, text)
 
        def Close(self):
-               self._conversation.leave()
                telepathy.server.ChannelTypeText.Close(self)
                self.remove_from_connection()
+
+       def _on_message_received(self, sender, message):
+               """
+               @todo Attatch this to receiving a message
+               """
+               currentReceivedId = self._nextRecievedId
+
+               timestamp = int(time.time())
+               h = handle.create_handle(self._conn, "contact", sender.account)
+               type = telepathy.CHANNEL_TEXT_MESSAGE_TYPE_NORMAL
+               message = message.content
+
+               _moduleLogger.info("Received message from User %r" % h)
+               self.Received(id, timestamp, h, type, 0, message)
+
+               self._nextRecievedId += 1