diff options
author | Krzysztof Klinikowski <kkszysiu@gmail.com> | 2010-03-22 21:25:35 +0100 |
---|---|---|
committer | Krzysztof Klinikowski <kkszysiu@gmail.com> | 2010-03-22 21:25:35 +0100 |
commit | 4d36d4d1f60101e64ace5c457bedd9cb0732e8f6 (patch) | |
tree | a248715fbaded2a02e7fe147b085e58e9bf104ba | |
parent | 689574c6ebcfe49d9117966909c09afb9fbd936a (diff) |
Messages sending to conferences should works now. (still needs testing)
-rw-r--r-- | sunshine/channel/text.py | 22 | ||||
-rw-r--r-- | sunshine/connection.py | 9 | ||||
-rwxr-xr-x | sunshine/lqsoft/pygadu/models.py | 5 | ||||
-rwxr-xr-x | sunshine/lqsoft/pygadu/twisted_protocol.py | 18 |
4 files changed, 47 insertions, 7 deletions
diff --git a/sunshine/channel/text.py b/sunshine/channel/text.py index c72fe58..15ff76c 100644 --- a/sunshine/channel/text.py +++ b/sunshine/channel/text.py @@ -86,6 +86,9 @@ class SunshineRoomTextChannel(telepathy.server.ChannelTypeText, telepathy.server self._conn_ref = weakref.ref(conn) self.conn = conn + if conversation != None: + self.contacts = conversation + self.handle = handle telepathy.server.ChannelTypeText.__init__(self, conn, manager, props) telepathy.server.ChannelInterfaceGroup.__init__(self) @@ -94,9 +97,19 @@ class SunshineRoomTextChannel(telepathy.server.ChannelTypeText, telepathy.server def Send(self, message_type, text): if message_type == telepathy.CHANNEL_TEXT_MESSAGE_TYPE_NORMAL: - logger.info("Sending message to %s, id %s, body: '%s'" % (str(self.handle.name), str(self.handle.id), unicode(text))) - msg = text.encode('windows-1250') - self.conn.gadu_client.sendTo(int(self.handle.name), str(text), str(msg)) + recipients = [] + if self.contacts != None: + for rhandle in self.contacts: + recipients.append(rhandle.name) + + for nr in recipients: + print nr + recs_tmp = sorted(recipients) + recs_tmp.remove(nr) + + logger.info("Sending message to %s, id %s, body: '%s'" % (str(nr), str(self.handle.id), unicode(text))) + msg = text.encode('windows-1250') + self.conn.gadu_client.sendToConf(int(nr), str(text), str(msg), recs_tmp) else: raise telepathy.NotImplemented("Unhandled message type") self.Sent(int(time.time()), message_type, text) @@ -126,7 +139,8 @@ class SunshineRoomTextChannel(telepathy.server.ChannelTypeText, telepathy.server def ListPendingMessages(self, clear): return telepathy.server.ChannelTypeText.ListPendingMessages(self, clear) - + def getContacts(self, contacts): + self.contacts = contacts # if clear: # messages = self._pending_offline_messages.values() diff --git a/sunshine/connection.py b/sunshine/connection.py index 9b9b7ba..8c25934 100644 --- a/sunshine/connection.py +++ b/sunshine/connection.py @@ -569,13 +569,16 @@ class SunshineConnection(telepathy.server.Connection, props = self._generate_props(telepathy.CHANNEL_TYPE_TEXT, room_handle, False) - channel = self._channel_manager.channel_for_props(props, - signal=True, conversation=None) if handles: - print handles + #print handles + channel = self._channel_manager.channel_for_props(props, + signal=True, conversation=handles) channel.MembersChanged('', handles, [], [], [], 0, telepathy.CHANNEL_GROUP_CHANGE_REASON_NONE) + else: + channel = self._channel_manager.channel_for_props(props, + signal=True, conversation=None) if int(msg.content.klass) == 9: timestamp = int(msg.time) diff --git a/sunshine/lqsoft/pygadu/models.py b/sunshine/lqsoft/pygadu/models.py index 0245728..6c70631 100755 --- a/sunshine/lqsoft/pygadu/models.py +++ b/sunshine/lqsoft/pygadu/models.py @@ -116,6 +116,11 @@ class GaduProfile(object): raise RuntimeError("You need to be connected, to send messages.") self.__connection.sendHTMLMessage(uin, html_message + '\0', plain_message + '\0') + def sendToConf(self, uin, html_message, plain_message, recipients): + if not self.connected: + raise RuntimeError("You need to be connected, to send messages.") + self.__connection.sendConfMessage(uin, html_message + '\0', plain_message + '\0', recipients) + def importContacts(self, callback): """Issue an import request. This is non-blocking and returns no data.""" if not self.connected: diff --git a/sunshine/lqsoft/pygadu/twisted_protocol.py b/sunshine/lqsoft/pygadu/twisted_protocol.py index 7e38503..bc6dd55 100755 --- a/sunshine/lqsoft/pygadu/twisted_protocol.py +++ b/sunshine/lqsoft/pygadu/twisted_protocol.py @@ -203,6 +203,24 @@ class GaduClient(Protocol): self._sendPacket( klass( recipient=rcpt, seq=int(time.time()), content=payload) ) + def sendConfMessage(self, rcpt, html_text, plain_message, contacts): + klass = Resolver.by_name('MessageOutPacket') + + attrs = StructMsgAttrs() + attrs.richtext = StructRichText() + + #contacts_len = len(contacts) + contacts = map(int, contacts) + konference = StructConference(recipients=contacts) + + attrs.conference = konference + + payload = StructMessage(klass=StructMessage.CLASS.CHAT, \ + html_message=html_text, plain_message=plain_message, \ + attrs = attrs) + + self._sendPacket( klass( recipient=rcpt, seq=int(time.time()), content=payload) ) + def sendImportRequest(self, callback): if self.importrq_cb is not None: raise RuntimeError("There can be only one import request pending.") |