| | 228 | def _get_account_for_groupchat(self, account, room_jid): |
| | 229 | '''get the account which is connected to groupchat (if not given) |
| | 230 | or check if the given account is connected to the groupchat''' |
| | 231 | correct_account = None |
| | 232 | accounts = gajim.contacts.get_accounts() |
| | 233 | # if there is only one account in roster, take it as default |
| | 234 | # if user did not ask for account |
| | 235 | if not account and len(accounts) == 1: |
| | 236 | account = accounts[0] |
| | 237 | if account: |
| | 238 | if gajim.connections[account].connected > 1 and \ |
| | 239 | room_jid in gajim.gc_connected[account] and \ |
| | 240 | gajim.gc_connected[account][room_jid]: |
| | 241 | # account and groupchat are connected |
| | 242 | connected_account = account |
| | 243 | else: |
| | 244 | for account in accounts: |
| | 245 | if gajim.connections[account].connected > 1 and \ |
| | 246 | room_jid in gajim.gc_connected[account] and \ |
| | 247 | gajim.gc_connected[account][room_jid]: |
| | 248 | # account and groupchat are connected |
| | 249 | connected_account = account |
| | 250 | break |
| | 251 | return connected_account |
| | 252 | |
| | 298 | |
| | 299 | @dbus.service.method(INTERFACE, in_signature='sss', out_signature='b') |
| | 300 | def send_groupchat_message(self, room_jid, message, account): |
| | 301 | '''Send 'message' to groupchat 'room_jid', |
| | 302 | using account (optional) 'account'.''' |
| | 303 | if not room_jid or not message: |
| | 304 | return DBUS_BOOLEAN(False) |
| | 305 | connected_account = self._get_account_for_groupchat(account, room_jid) |
| | 306 | if connected_account: |
| | 307 | connection = gajim.connections[connected_account] |
| | 308 | connection.send_gc_message(room_jid, message) |
| | 309 | return DBUS_BOOLEAN(True) |
| | 310 | return DBUS_BOOLEAN(False) |