Ticket #2026: remote-send_single_message.diff

File remote-send_single_message.diff, 3.2 kB (added by maciekp@…, 2 years ago)

Diff: add send_single_message to gajim-remote

  • src/remote_control.py

     
    161161                                self.change_status, 
    162162                                self.open_chat, 
    163163                                self.send_message, 
     164                                self.send_single_message, 
    164165                                self.contact_info, 
    165166                                self.send_file, 
    166167                                self.prefs_list, 
     
    269270                        return True 
    270271                return False 
    271272 
     273        def send_single_message(self, *args): 
     274                ''' send_single_message(jid, subject, message, keyID=None, account=None) 
     275                send 'message' to 'jid', using account (optional) 'account'. 
     276                if keyID is specified, encrypt the message with the pgp key ''' 
     277                jid, subject, message, keyID, account = self._get_real_arguments(args, 5) 
     278                if not jid or not message: 
     279                        return None # or raise error 
     280                if not keyID: 
     281                        keyID = '' 
     282                 
     283                connected_account, contact = self.get_account_and_contact(account, jid) 
     284                 
     285                if connected_account: 
     286                        connection = gajim.connections[connected_account] 
     287                        res = connection.send_message(jid, message, keyID, 
     288                                                      type='normal', 
     289                                                      subject=subject) 
     290                        return True 
     291                return False 
     292 
    272293        def open_chat(self, *args): 
    273294                ''' start_chat(jid, account=None) -> shows the tabbed window for new  
    274295                message to 'jid', using account(optional) 'account' ''' 
     
    580601        open_chat = method(INTERFACE)(open_chat) 
    581602        contact_info = method(INTERFACE)(contact_info) 
    582603        send_message = method(INTERFACE)(send_message) 
     604        send_single_message = method(INTERFACE)(send_single_message) 
    583605        send_file = method(INTERFACE)(send_file) 
    584606        prefs_list = method(INTERFACE)(prefs_list) 
    585607        prefs_put = method(INTERFACE)(prefs_put) 
  • src/gajim-remote.py

     
    138138                                                (_('account'), _('if specified, the message will be sent ' 
    139139                                                        'using this account'), False), 
    140140                                        ] 
     141                                ], 
     142                        'send_single_message':[ 
     143                                        _('Sends new single message to a contact in the roster. Both OpenPGP key ' 
     144                                        'and account are optional. If you want to set only \'account\', ' 
     145                                        'without \'OpenPGP key\', just set \'OpenPGP key\' to \'\'.'),  
     146                                        [ 
     147                                                ('jid', _('JID of the contact that will receive the message'), True), 
     148                                                (_('subject'), _('message subject'), True), 
     149                                                (_('message'), _('message contents'), True), 
     150                                                (_('pgp key'), _('if specified, the message will be encrypted ' 
     151                                                        'using this public key'), False), 
     152                                                (_('account'), _('if specified, the message will be sent ' 
     153                                                        'using this account'), False), 
     154                                        ] 
    141155                                ],  
    142156                        'contact_info': [ 
    143157                                        _('Gets detailed info on a contact'),  
     
    253267        def print_result(self, res): 
    254268                ''' Print retrieved result to the output ''' 
    255269                if res is not None: 
    256                         if self.command in ('open_chat', 'send_message', 'start_chat'): 
    257                                 if self.command == 'send_message': 
     270                        if self.command in ('open_chat', 'send_message', 'send_single_message', 'start_chat'): 
     271                                if self.command in ('send_message', 'send_single_message'): 
    258272                                        self.argv_len -= 2 
    259273                                 
    260274                                if res is False: