fix traceback when adding a new contact. Fixes #6054

This commit is contained in:
Yann Leboulanger 2010-12-16 07:15:29 +01:00
parent 0c2d703f25
commit d19629ad87
5 changed files with 123 additions and 19 deletions

View file

@ -1829,3 +1829,100 @@ class GatewayPromptReceivedEvent(nec.NetworkIncomingEvent, HelperEvent):
self.prompt = None
self.prompt_jid = None
return True
class NotificationEvent(nec.NetworkIncomingEvent):
name = 'notification'
base_network_events = ['decrypted-message-received']
def detect_type(self):
if self.base_event.name == 'decrypted-message-received':
self.notif_type='msg'
def get_focused(self):
self.control_focused = False
if self.control:
parent_win = self.control.parent_win
if parent_win and self.control == parent_win.get_active_control() \
and parent_win.window.has_focus:
self.control_focused = True
def handle_incoming_msg_event(self, msg_obj):
self.control = msg_obj.session.control
self.get_focused()
if not self.control and not gajim.events.get_events(self.conn.name, \
self.control.jid, [msg_obj.mtype]):
self.first_unread = True
if msg_obj.mtype == 'pm':
nick = msg_obj.resource
else:
nick = gajim.get_name_from_jid(self.conn.name, msg_obj.jid)
if self.first_unread:
self.sound_event = 'first_message_received'
elif self.control_focused:
self.sound_event = 'next_message_received_focused'
else:
self.sound_event = 'next_message_received_unfocused'
if gajim.config.get('notification_preview_message'):
self.popup_text = msg_obj.msgtxt
if self.popup_text.startswith('/me ') or self.popup_text.startswith(
'/me\n'):
self.popup_text = '* ' + nick + self.popup_text[3:]
else:
# We don't want message preview, do_preview = False
self.popup_text = ''
if msg_obj.mtype == 'normal': # single message
self.popup_event_type = _('New Single Message')
self.popup_image = 'gajim-single_msg_recv'
self.popup_title = _('New Single Message from %(nickname)s') % \
{'nickname': nick}
elif msg_obj.mtype == 'pm':
self.popup_event_type = _('New Private Message')
self.popup_image = 'gajim-priv_msg_recv'
self.popup_title = _('New Private Message from group chat %s') % \
msg_obj.jid
if self.popup_text:
self.popup_text = _('%(nickname)s: %(message)s') % \
{'nickname': nick, 'message': self.popup_text}
else:
self.popup_text = _('Messaged by %(nickname)s') % \
{'nickname': nick}
else: # chat message
self.popup_event_type = _('New Message')
self.popup_image = 'gajim-chat_msg_recv'
self.popup_title = _('New Message from %(nickname)s') % \
{'nickname': nick}
self.popup_image = gtkgui_helpers.get_icon_path(self.popup_image, 48)
def handle_incoming_msg_event(self, msg_obj):
pass
def generate(self):
# what's needed to compute output
self.control = None
self.control_focused = False
self.first_unread = False
# For output
self.sound_event = ''
self.show_popup = False
self.popup_title = ''
self.popup_text = ''
self.popup_event_type = ''
self.popup_image = ''
self.open_chat = False
self.activate_urgency_hint = False
self.command_to_run = ''
self.show_in_notification_area = False
self.show_in_roster = False
self.detect_type()
if self.notif_type == 'msg':
self.handle_incoming_msg_event(self.base_event)
elif self.notif_type == 'pres':
self.handle_incoming_pres_event(self.base_event)
return True

View file

@ -133,6 +133,9 @@ connection_handlers.ConnectionHandlersBase, connection_handlers.ConnectionJingle
msg = session.decrypt_stanza(msg)
except Exception:
self.dispatch('FAILED_DECRYPT', (frm, tim, session))
gajim.nec.push_incoming_event(FailedDecryptEvent(None,
conn=self, msg_obj=obj))
msgtxt = msg.getBody()
subject = msg.getSubject() # if not there, it's None

View file

@ -1056,16 +1056,16 @@ class AddNewContactWindow:
transport = self.protocol_jid_combobox.get_active_text().decode(
'utf-8')
if self.account:
self.adding_jid = (jid, transport)
self.adding_jid = (jid, transport, type_)
gajim.connections[self.account].request_gateway_prompt(
transport, jid)
else:
jid = jid.replace('@', '%') + '@' + transport
self._add_jid(jid)
self._add_jid(jid, type_)
else:
self._add_jid(jid)
self._add_jid(jid, type_)
def _add_jid(self, jid):
def _add_jid(self, jid, type_):
# check if jid is conform to RFC and stringprep it
try:
jid = helpers.parse_jid(jid)
@ -1239,12 +1239,12 @@ class AddNewContactWindow:
def _nec_gateway_prompt_received(self, obj):
if self.adding_jid:
jid, transport, type_ = self.adding_jid
if obj.prompt_jid:
self._add_jid(obj.prompt_jid)
self._add_jid(obj.prompt_jid, type_)
else:
jid, transport = self.adding_jid
jid = jid.replace('@', '%') + '@' + transport
self._add_jid(jid)
self._add_jid(jid, type_)
elif obj.jid in self.gateway_prompt:
if obj.desc:
self.gateway_prompt[obj.jid]['desc'] = obj.desc

View file

@ -305,7 +305,8 @@ class Interface:
elif gc_control:
gc_control.print_conversation('Error %s: %s' % (obj.errcode,
obj.errmsg))
return
if gc_control and gc_control.autorejoin:
gc_control.autorejoin = False
def handle_event_presence(self, obj):
# 'NOTIFY' (account, (jid, status, status message, resource,

View file

@ -106,14 +106,6 @@ class ChatControlSession(stanza_session.EncryptedStanzaSession):
pm = True
obj.mtype = 'pm'
highest_contact = gajim.contacts.get_contact_with_highest_priority(
self.conn.name, obj.jid)
# does this resource have the highest priority of any available?
is_highest = not highest_contact or not highest_contact.resource or \
obj.resource == highest_contact.resource or highest_contact.show ==\
'offline'
# Handle chat states
contact = gajim.contacts.get_contact(self.conn.name, obj.jid,
obj.resource)
@ -142,13 +134,14 @@ class ChatControlSession(stanza_session.EncryptedStanzaSession):
# THIS MUST BE AFTER chatstates handling
# AND BEFORE playsound (else we ear sounding on chatstates!)
if not obj.msgtxt: # empty message text
return
return True
if gajim.config.get_per('accounts', self.conn.name,
'ignore_unknown_contacts') and not gajim.contacts.get_contacts(
self.conn.name, obj.jid) and not pm:
return
return True
#FIXME Remove after advanced_notif will be removed
if not contact:
# contact is not in the roster, create a fake one to display
# notification
@ -158,6 +151,14 @@ class ChatControlSession(stanza_session.EncryptedStanzaSession):
advanced_notif_num = notify.get_advanced_notification(
'message_received', self.conn.name, contact)
highest_contact = gajim.contacts.get_contact_with_highest_priority(
self.conn.name, obj.jid)
# does this resource have the highest priority of any available?
is_highest = not highest_contact or not highest_contact.resource or \
obj.resource == highest_contact.resource or highest_contact.show ==\
'offline'
if not pm and is_highest:
jid_of_control = obj.jid
else:
@ -170,6 +171,7 @@ class ChatControlSession(stanza_session.EncryptedStanzaSession):
self.control = ctrl
self.control.set_session(self)
#TODO handled
# Is it a first or next message received ?
first = False
if not self.control and not gajim.events.get_events(self.conn.name, \
@ -201,8 +203,9 @@ class ChatControlSession(stanza_session.EncryptedStanzaSession):
msg = obj.msgtxt
if obj.subject:
msg = _('Subject: %s') % obj.subject + '\n' + msg
focused = False
#TODO handled
focused = False
if self.control:
parent_win = self.control.parent_win
if parent_win and self.control == parent_win.get_active_control() \