diff options
author | Olivier Le Thanh Duong <olivier@lethanh.be> | 2010-04-05 13:30:44 +0200 |
---|---|---|
committer | Olivier Le Thanh Duong <olivier@lethanh.be> | 2010-04-07 18:46:07 +0200 |
commit | 7e62e6de36f316e43d67355d2dacd71c1691597a (patch) | |
tree | 5eb8a5552f0c891c08f8f8945bf750e16f786018 | |
parent | 7b3c91b609d2b988777941b6f7469a0a841e808a (diff) |
Message iface: Use async_callbacks to return before emitting the signals
-rw-r--r-- | butterfly/channel/text.py | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/butterfly/channel/text.py b/butterfly/channel/text.py index dedd78e..64ad3cf 100644 --- a/butterfly/channel/text.py +++ b/butterfly/channel/text.py @@ -31,7 +31,6 @@ from telepathy._generated.Channel_Interface_Messages import ChannelInterfaceMess from telepathy.interfaces import CHANNEL_INTERFACE_MESSAGES from butterfly.handle import ButterflyHandleFactory -from butterfly.util.decorator import async __all__ = ['ButterflyTextChannel'] @@ -141,8 +140,6 @@ class ButterflyTextChannel( logger.warning('Tried sending a message with no conversation') return False - # run in an glib's idle so we emit the signal after either Send or SendMessage return - @async def _signal_text_sent(self, timestamp, message_type, text): headers = {'message-sent' : timestamp, 'message-type' : message_type @@ -190,8 +187,12 @@ class ButterflyTextChannel( handle = ButterflyHandleFactory(self._conn_ref(), 'self') self.ChatStateChanged(handle, state) - def Send(self, message_type, text): + @dbus.service.method(telepathy.CHANNEL_TYPE_TEXT, in_signature='us', out_signature='', + async_callbacks=('_success', '_error')) + def Send(self, message_type, text, _success, _error): if self._send_text_message(message_type, text): + # The function MUST return before emitting the signals + _success() timestamp = int(time.time()) self._signal_text_sent(timestamp, message_type, text) @@ -206,7 +207,9 @@ class ButterflyTextChannel( # We don't support pending message raise telepathy.InvalidArgument() - def SendMessage(self, message, flags): + @dbus.service.method(telepathy.CHANNEL_INTERFACE_MESSAGES, in_signature='aa{sv}u', + out_signature='s', async_callbacks=('_success', '_error')) + def SendMessage(self, message, flags, _success, _error): headers = message.pop(0) message_type = int(headers['message-type']) if message_type != telepathy.CHANNEL_TEXT_MESSAGE_TYPE_NORMAL: @@ -221,10 +224,10 @@ class ButterflyTextChannel( if self._send_text_message(message_type, text): timestamp = int(time.time()) + # The function MUST return before emitting the signals + _success('') self._signal_text_sent(timestamp, message_type, text) - return '' - def AcknowledgePendingMessages(self, ids): for id in ids: if id in self._pending_messages2: |