Merge duplicate code

This commit is contained in:
Jean-Marie Traissard 2006-06-16 17:01:36 +00:00
parent 42d74e39fa
commit 9ec77f1dd9
1 changed files with 14 additions and 22 deletions

View File

@ -249,12 +249,10 @@ class SignalObject(DbusPrototype):
connected_account, contact, file_path) connected_account, contact, file_path)
return True return True
return False return False
def send_message(self, *args): def _send_message(self, jid, message, keyID, account, type = 'chat', subject = None):
''' send_message(jid, message, keyID=None, account=None) ''' can be called from send_chat_message (default when send_message)
send chat 'message' to 'jid', using account (optional) 'account'. or send_single_message'''
if keyID is specified, encrypt the message with the pgp key '''
jid, message, keyID, account = self._get_real_arguments(args, 4)
if not jid or not message: if not jid or not message:
return None # or raise error return None # or raise error
if not keyID: if not keyID:
@ -264,29 +262,23 @@ class SignalObject(DbusPrototype):
if connected_account: if connected_account:
connection = gajim.connections[connected_account] connection = gajim.connections[connected_account]
res = connection.send_message(jid, message, keyID) res = connection.send_message(jid, message, keyID, type, subject)
return True return True
return False return False
def send_chat_message(self, *args):
''' send_message(jid, message, keyID=None, account=None)
send chat 'message' to 'jid', using account (optional) 'account'.
if keyID is specified, encrypt the message with the pgp key '''
jid, message, keyID, account = self._get_real_arguments(args, 4)
return self._send_message(jid, message, keyID, account)
def send_single_message(self, *args): def send_single_message(self, *args):
''' send_single_message(jid, subject, message, keyID=None, account=None) ''' send_single_message(jid, subject, message, keyID=None, account=None)
send single 'message' to 'jid', using account (optional) 'account'. send single 'message' to 'jid', using account (optional) 'account'.
if keyID is specified, encrypt the message with the pgp key ''' if keyID is specified, encrypt the message with the pgp key '''
jid, subject, message, keyID, account = self._get_real_arguments(args, 5) jid, subject, message, keyID, account = self._get_real_arguments(args, 5)
if not jid or not message: return self._send_message(jid, message, keyID, account, type, subject)
return None # or raise error
if not keyID:
keyID = ''
connected_account, contact = self.get_account_and_contact(account, jid)
if connected_account:
connection = gajim.connections[connected_account]
res = connection.send_message(jid, message, keyID,
type='normal',
subject=subject)
return True
return False
def open_chat(self, *args): def open_chat(self, *args):
''' start_chat(jid, account=None) -> shows the tabbed window for new ''' start_chat(jid, account=None) -> shows the tabbed window for new
@ -598,7 +590,7 @@ class SignalObject(DbusPrototype):
change_status = method(INTERFACE)(change_status) change_status = method(INTERFACE)(change_status)
open_chat = method(INTERFACE)(open_chat) open_chat = method(INTERFACE)(open_chat)
contact_info = method(INTERFACE)(contact_info) contact_info = method(INTERFACE)(contact_info)
send_message = method(INTERFACE)(send_message) send_message = method(INTERFACE)(send_chat_message)
send_single_message = method(INTERFACE)(send_single_message) send_single_message = method(INTERFACE)(send_single_message)
send_file = method(INTERFACE)(send_file) send_file = method(INTERFACE)(send_file)
prefs_list = method(INTERFACE)(prefs_list) prefs_list = method(INTERFACE)(prefs_list)