use NEC to handle message error events

This commit is contained in:
Denis Fomin 2010-12-01 23:38:39 +03:00
parent 5726eb39c3
commit e644047c59
4 changed files with 32 additions and 26 deletions

View File

@ -1365,8 +1365,9 @@ ConnectionJingle, ConnectionIBBytestream):
'or remove it (all history will be lost).') % \
common.logger.LOG_DB_PATH
self.dispatch('DB_ERROR', (pritext, sectext))
self.dispatch('MSGERROR', (frm, msg.getErrorCode(), error_msg, msgtxt,
tim, session))
gajim.nec.push_incoming_event(MessageErrorEvent(None, conn=self,
fjid=frm, error_code=msg.getErrorCode(), error_msg=error_msg,
msg=msgtxt, time_=tim, session=session))
def _dispatch_gc_msg_with_captcha(self, stanza, msg_obj):
msg_obj.stanza = stanza

View File

@ -1153,6 +1153,10 @@ class MessageSentEvent(nec.NetworkIncomingEvent):
name = 'message-sent'
base_network_events = []
class MessageErrorEvent(nec.NetworkIncomingEvent):
name = 'message-error'
base_network_events = []
class AnonymousAuthEvent(nec.NetworkIncomingEvent):
name = 'anonymous-auth'
base_network_events = []

View File

@ -339,7 +339,9 @@ class ConnectionZeroconf(CommonConnection, ConnectionHandlersZeroconf):
def on_send_not_ok(reason):
reason += ' ' + _('Your message could not be sent.')
self.dispatch('MSGERROR', [jid, -1, reason, None, None, session])
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):
@ -348,8 +350,10 @@ class ConnectionZeroconf(CommonConnection, ConnectionHandlersZeroconf):
if ret == -1:
# Contact Offline
self.dispatch('MSGERROR', [jid, -1, _('Contact is offline. Your '
'message could not be sent.'), None, None, session])
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, composing_xep=composing_xep,
@ -372,8 +376,9 @@ class ConnectionZeroconf(CommonConnection, ConnectionHandlersZeroconf):
thread_id = data[1]
frm = unicode(data[0])
session = self.get_or_create_session(frm, thread_id)
self.dispatch('MSGERROR', [frm, -1,
_('Connection to host could not be established: Timeout while '
'sending data.'), None, None, session])
gajim.nec.push_incoming_event(MessageErrorEvent(
None, conn=self, fjid=frm, error_code=-1, error_msg=_(
'Connection to host could not be established: Timeout while '
'sending data.'), msg=None, time_=None, session=session))
# END ConnectionZeroconf

View File

@ -385,21 +385,18 @@ class Interface:
ctrl.set_session(None)
ctrl.contact = highest
def handle_event_msgerror(self, account, array):
#'MSGERROR' (account, (jid, error_code, error_msg, msg, time[,
# session]))
full_jid_with_resource = array[0]
jids = full_jid_with_resource.split('/', 1)
def handle_event_msgerror(self, obj):
#'MSGERROR' (account, (jid, error_code, error_msg, msg, time[session]))
account = obj.conn.name
jids = obj.fjid.split('/', 1)
jid = jids[0]
if array[1] == '503':
if obj.error_code == '503':
# If we get server-not-found error, stop sending chatstates
for contact in gajim.contacts.get_contacts(account, jid):
contact.composing_xep = False
session = None
if len(array) > 5:
session = array[5]
session = obj.session
gc_control = self.msg_win_mgr.get_gc_control(jid, account)
if not gc_control and \
@ -414,8 +411,7 @@ class Interface:
if session:
ctrl = session.control
else:
ctrl = self.msg_win_mgr.get_control(full_jid_with_resource,
account)
ctrl = self.msg_win_mgr.get_control(obj.fjid, account)
if not ctrl:
tv = gc_control.list_treeview
@ -430,11 +426,11 @@ class Interface:
ctrl = self.new_private_chat(gc_c, account, session)
ctrl.print_conversation(_('Error %(code)s: %(msg)s') % {
'code': array[1], 'msg': array[2]}, 'status')
'code': obj.error_code, 'msg': obj.error_msg}, 'status')
return
gc_control.print_conversation(_('Error %(code)s: %(msg)s') % {
'code': array[1], 'msg': array[2]}, 'status')
'code': obj.error_code, 'msg': obj.error_msg}, 'status')
if gc_control.parent_win and \
gc_control.parent_win.get_active_jid() == jid:
gc_control.set_subject(gc_control.subject)
@ -442,12 +438,12 @@ class Interface:
if gajim.jid_is_transport(jid):
jid = jid.replace('@', '')
msg = array[2]
if array[3]:
msg = obj.error_msg
if obj.msg:
msg = _('error while sending %(message)s ( %(error)s )') % {
'message': array[3], 'error': msg}
'message': obj.msg, 'error': msg}
if session:
session.roster_message(jid, msg, array[4], msg_type='error')
session.roster_message(jid, msg, obj.time_, msg_type='error')
def handle_event_msgsent(self, obj):
#('MSGSENT', account, (jid, msg, keyID))
@ -1379,7 +1375,6 @@ class Interface:
'ERROR': [self.handle_event_error],
'DB_ERROR': [self.handle_event_db_error],
'INFORMATION': [self.handle_event_information],
'MSGERROR': [self.handle_event_msgerror],
'FILE_REQUEST': [self.handle_event_file_request],
'FILE_REQUEST_ERROR': [self.handle_event_file_request_error],
'FILE_SEND_ERROR': [self.handle_event_file_send_error],
@ -1405,6 +1400,7 @@ class Interface:
'jingle-error-received': [self.handle_event_jingle_error],
'jingle-request-received': [self.handle_event_jingle_incoming],
'last-result-received': [self.handle_event_last_status_time],
'message-error': [self.handle_event_msgerror],
'message-not-sent': [self.handle_event_msgnotsent],
'message-sent': [self.handle_event_msgsent],
'metacontacts-received': [self.handle_event_metacontacts],