X-Git-Url: http://git.maemo.org/git/?p=theonering;a=blobdiff_plain;f=src%2Fchannel%2Ftext.py;h=51d1a9166c71848219d3defe9145bb53d72b2966;hp=84f9c9956cea47ae9f7d207b88e69532d600fbb7;hb=a1133bfb13b2e4924f0c196d20750832f6058c90;hpb=c1299d00ddbb17aa0bf8826f9f6e98d0a756c16f diff --git a/src/channel/text.py b/src/channel/text.py index 84f9c99..51d1a91 100644 --- a/src/channel/text.py +++ b/src/channel/text.py @@ -1,45 +1,51 @@ import time -import weakref +import logger import telepathy import handle -class TheOneRingChannelText( - 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