Overall, got sending a text to an arbitrary number working
[theonering] / src / channel / text.py
1 import time
2 import logging
3
4 import telepathy
5
6 import gtk_toolbox
7 import handle
8
9
10 _moduleLogger = logging.getLogger("channel.text")
11
12
13 class TextChannel(telepathy.server.ChannelTypeText):
14         """
15         Look into implementing ChannelInterfaceMessages for rich text formatting
16         """
17
18         def __init__(self, connection, h):
19                 telepathy.server.ChannelTypeText.__init__(self, connection, h)
20                 self._nextRecievedId = 0
21
22                 self._otherHandle = h
23                 handles = [h]
24                 #self.MembersChanged('', handles, [], [], [],
25                 #               0, telepathy.CHANNEL_GROUP_CHANGE_REASON_NONE)
26
27         @gtk_toolbox.log_exception(_moduleLogger)
28         def Send(self, messageType, text):
29                 if messageType != telepathy.CHANNEL_TEXT_MESSAGE_TYPE_NORMAL:
30                         raise telepathy.NotImplemented("Unhandled message type: %r" % messageType)
31
32                 self._conn.session.backend.send_sms(self._otherHandle.phoneNumber, text)
33
34                 self.Sent(int(time.time()), messageType, text)
35
36         @gtk_toolbox.log_exception(_moduleLogger)
37         def Close(self):
38                 telepathy.server.ChannelTypeText.Close(self)
39                 self.remove_from_connection()
40
41         def _on_message_received(self, contactId, contactNumber, message):
42                 """
43                 @todo Attatch this to receiving a message
44                 """
45                 currentReceivedId = self._nextRecievedId
46
47                 timestamp = int(time.time())
48                 h = handle.create_handle(self._conn, "contact", contactId, contactNumber)
49                 type = telepathy.CHANNEL_TEXT_MESSAGE_TYPE_NORMAL
50                 message = message.content
51
52                 _moduleLogger.info("Received message from User %r" % h)
53                 self.Received(id, timestamp, h, type, 0, message)
54
55                 self._nextRecievedId += 1