Author: roidelapluie
Date: 2007-07-18 14:07:21 +0200 (Wed, 18 Jul 2007)
New Revision: 8407
Modified:
trunk/src/gajim-remote.py
trunk/src/remote_control.py
Log:
Add send_groupchat_message to gajim-remote. Fix #2447.
Modified: trunk/src/gajim-remote.py
===================================================================
--- trunk/src/gajim-remote.py 2007-07-17 08:26:14 UTC (rev 8406)
+++ trunk/src/gajim-remote.py 2007-07-18 12:07:21 UTC (rev 8407)
@@ -137,6 +137,15 @@
'using this account'), False),
]
],
+ 'send_groupchat_message':[
+ _('Sends new message to a groupchat you\'ve joined.'),
+ [
+ ('room_jid', _('JID of the room that will receive the message'), True),
+ (_('message'), _('message contents'), True),
+ (_('account'), _('if specified, the message will be sent '
+ 'using this account'), False),
+ ]
+ ],
'contact_info': [
_('Gets detailed info on a contact'),
[
Modified: trunk/src/remote_control.py
===================================================================
--- trunk/src/remote_control.py 2007-07-17 08:26:14 UTC (rev 8406)
+++ trunk/src/remote_control.py 2007-07-18 12:07:21 UTC (rev 8407)
@@ -225,6 +225,31 @@
return connected_account, contact
+ def _get_account_for_groupchat(self, account, room_jid):
+ '''get the account which is connected to groupchat (if not given)
+ or check if the given account is connected to the groupchat'''
+ correct_account = None
+ accounts = gajim.contacts.get_accounts()
+ # if there is only one account in roster, take it as default
+ # if user did not ask for account
+ if not account and len(accounts) == 1:
+ account = accounts[0]
+ if account:
+ if gajim.connections[account].connected > 1 and \
+ room_jid in gajim.gc_connected[account] and \
+ gajim.gc_connected[account][room_jid]:
+ # account and groupchat are connected
+ connected_account = account
+ else:
+ for account in accounts:
+ if gajim.connections[account].connected > 1 and \
+ room_jid in gajim.gc_connected[account] and \
+ gajim.gc_connected[account][room_jid]:
+ # account and groupchat are connected
+ connected_account = account
+ break
+ return connected_account
+
@dbus.service.method(INTERFACE, in_signature='sss', out_signature='b')
def send_file(self, file_path, jid, account):
'''send file, located at 'file_path' to 'jid', using account
@@ -271,6 +296,19 @@
jid = self._get_real_jid(jid, account)
return self._send_message(jid, message, keyID, account, type, subject)
+ @dbus.service.method(INTERFACE, in_signature='sss', out_signature='b')
+ def send_groupchat_message(self, room_jid, message, account):
+ '''Send 'message' to groupchat 'room_jid',
+ using account (optional) 'account'.'''
+ if not room_jid or not message:
+ return DBUS_BOOLEAN(False)
+ connected_account = self._get_account_for_groupchat(account, room_jid)
+ if connected_account:
+ connection = gajim.connections[connected_account]
+ connection.send_gc_message(room_jid, message)
+ return DBUS_BOOLEAN(True)
+ return DBUS_BOOLEAN(False)
+
@dbus.service.method(INTERFACE, in_signature='ss', out_signature='b')
def open_chat(self, jid, account):
'''Shows the tabbed window for new message to 'jid', using account