diff --git a/src/gajim-remote.py b/src/gajim-remote.py index e350409e5..91ff086a6 100755 --- a/src/gajim-remote.py +++ b/src/gajim-remote.py @@ -137,6 +137,15 @@ class GajimRemote: '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'), [ diff --git a/src/remote_control.py b/src/remote_control.py index d68f626fb..3208e9cf1 100644 --- a/src/remote_control.py +++ b/src/remote_control.py @@ -225,6 +225,31 @@ class SignalObject(dbus.service.Object): 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 @@ class SignalObject(dbus.service.Object): 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