remove send_message from connection object. Use Event everywhere

This commit is contained in:
Yann Leboulanger 2013-07-26 14:45:16 +02:00
parent 3fe6a7b974
commit d8264118de
4 changed files with 25 additions and 81 deletions

View File

@ -26,6 +26,7 @@ import nbxmpp
import helpers
import dataforms
import gajim
from common.connection_handlers_events import MessageOutgoingEvent
import logging
log = logging.getLogger('gajim.c.commands')
@ -285,9 +286,10 @@ class ForwardMessagesCommand(AdHocCommand):
ev_typ = event.type_
if ev_typ == 'printed_chat':
ev_typ = 'chat'
self.connection.send_message(j, event.parameters[0], '',
gajim.nec.push_outgoing_event(MessageOutgoingEvent(None,
account=account, jid=j, message=event.parameters[0],
type_=ev_typ, subject=event.parameters[1],
resource=resource, forward_from=jid, delayed=event.time_)
resource=resource, forward_from=jid, delayed=event.time_))
# Inform other client of completion
response, cmd = self.buildResponse(request, status = 'completed')
@ -315,10 +317,14 @@ class FwdMsgThenDisconnectCommand(AdHocCommand):
j, resource = gajim.get_room_and_nick_from_fjid(self.jid)
for jid in events:
for event in events[jid]:
self.connection.send_message(j, event.parameters[0], '',
type_=event.type_, subject=event.parameters[1],
ev_typ = event.type_
if ev_typ == 'printed_chat':
ev_typ = 'chat'
gajim.nec.push_outgoing_event(MessageOutgoingEvent(None,
account=account, jid=j, message=event.parameters[0],
type_=ev_typ, subject=event.parameters[1],
resource=resource, forward_from=jid, delayed=event.time_,
now=True)
now=True))
response, cmd = self.buildResponse(request, status = 'completed')
cmd.addChild('note', {}, _('The status has been changed.'))

View File

@ -1989,31 +1989,6 @@ class Connection(CommonConnection, ConnectionHandlers):
self.connection.send(msg_iq)
def send_message(self, jid, msg, keyID=None, type_='chat', subject='',
chatstate=None, msg_id=None, resource=None, user_nick=None, xhtml=None,
label=None, session=None, forward_from=None, form_node=None,
original_message=None, delayed=None, attention=False, correction_msg=None,
callback=None, callback_args=[], now=False):
def cb(jid, msg, keyID, forward_from, session, original_message,
subject, type_, msg_iq, xhtml):
msg_id = self.connection.send(msg_iq, now=now)
jid = helpers.parse_jid(jid)
gajim.nec.push_incoming_event(MessageSentEvent(None, conn=self,
jid=jid, message=msg, keyID=keyID, chatstate=chatstate))
if callback:
callback(msg_id, *callback_args)
self.log_message(jid, msg, forward_from, session, original_message,
subject, type_, xhtml)
self._prepare_message(jid, msg, keyID, type_=type_, subject=subject,
chatstate=chatstate, msg_id=msg_id, resource=resource,
user_nick=user_nick, xhtml=xhtml, label=label, session=session,
forward_from=forward_from, form_node=form_node,
original_message=original_message, delayed=delayed,
attention=attention, correction_msg=correction_msg, callback=cb)
def _nec_message_outgoing(self, obj):
if obj.account != self.name:
return

View File

@ -333,46 +333,6 @@ class ConnectionZeroconf(CommonConnection, ConnectionHandlersZeroconf):
title=_('Could not change status of account "%s"') % self.name,
msg=_('Please check if avahi-daemon is running.')))
def send_message(self, jid, msg, keyID, type_='chat', subject='',
chatstate=None, msg_id=None, resource=None, user_nick=None, xhtml=None,
label=None, session=None, forward_from=None, form_node=None,
original_message=None, delayed=None, attention=False, callback=None,
callback_args=[], now=True):
def on_send_ok(msg_id):
gajim.nec.push_incoming_event(MessageSentEvent(None, conn=self,
jid=jid, message=msg, keyID=keyID, chatstate=None))
if callback:
callback(msg_id, *callback_args)
self.log_message(jid, msg, forward_from, session, original_message,
subject, type_)
def on_send_not_ok(reason):
reason += ' ' + _('Your message could not be sent.')
gajim.nec.push_incoming_event(MessageErrorEvent(None, conn=self,
fjid=jid, error_code=-1, error_msg=reason, msg=None, time_=None,
session=session))
def cb(jid, msg, keyID, forward_from, session, original_message, subject,
type_, msg_iq):
ret = self.connection.send(msg_iq, msg is not None, on_ok=on_send_ok,
on_not_ok=on_send_not_ok)
if ret == -1:
# Contact Offline
gajim.nec.push_incoming_event(MessageErrorEvent(None, conn=self,
fjid=jid, error_code=-1, error_msg=_(
'Contact is offline. Your message could not be sent.'),
msg=None, time_=None, session=session))
self._prepare_message(jid, msg, keyID, type_=type_, subject=subject,
chatstate=chatstate, msg_id=msg_id, resource=resource,
user_nick=user_nick, xhtml=xhtml, session=session,
forward_from=forward_from, form_node=form_node,
original_message=original_message, delayed=delayed,
attention=attention, callback=cb)
def _nec_message_outgoing(self, obj):
if obj.account != self.name:
return

View File

@ -60,6 +60,7 @@ from common import helpers
from common import i18n
from common import dataforms
from common.exceptions import GajimGeneralException
from common.connection_handlers_events import MessageOutgoingEvent
class EditGroupsDialog:
"""
@ -3164,6 +3165,15 @@ class SingleMessageWindow:
sender_list = [j.strip() for j in self.to_entry.get_text().decode(
'utf-8').split(',')]
subject = self.subject_entry.get_text().decode('utf-8')
begin, end = self.message_tv_buffer.get_bounds()
message = self.message_tv_buffer.get_text(begin, end).decode('utf-8')
if self.form_widget:
form_node = self.form_widget.data_form
else:
form_node = None
for to_whom_jid in sender_list:
if to_whom_jid in self.completion_dict:
to_whom_jid = self.completion_dict[to_whom_jid].jid
@ -3175,10 +3185,6 @@ class SingleMessageWindow:
'valid.') % to_whom_jid)
return True
subject = self.subject_entry.get_text().decode('utf-8')
begin, end = self.message_tv_buffer.get_bounds()
message = self.message_tv_buffer.get_text(begin, end).decode('utf-8')
if '/announce/' in to_whom_jid:
gajim.connections[self.account].send_motd(to_whom_jid, subject,
message)
@ -3190,14 +3196,11 @@ class SingleMessageWindow:
session = gajim.connections[self.account].make_new_session(
to_whom_jid)
if self.form_widget:
form_node = self.form_widget.data_form
else:
form_node = None
# FIXME: allow GPG message some day
gajim.connections[self.account].send_message(to_whom_jid, message,
keyID=None, type_='normal', subject=subject, session=session,
form_node=form_node)
gajim.nec.push_outgoing_event(MessageOutgoingEvent(None,
account=self.account, jid=to_whom_jid, message=message,
type_='normal', subject=subject, session=session,
form_node=form_node))
self.subject_entry.set_text('') # we sent ok, clear the subject
self.message_tv_buffer.set_text('') # we sent ok, clear the textview