some coding standards
This commit is contained in:
parent
90ccd1f4b1
commit
8d6b7cd479
|
@ -39,7 +39,8 @@ import negotiation
|
||||||
|
|
||||||
class ChatControlSession(stanza_session.EncryptedStanzaSession):
|
class ChatControlSession(stanza_session.EncryptedStanzaSession):
|
||||||
def __init__(self, conn, jid, thread_id, type='chat'):
|
def __init__(self, conn, jid, thread_id, type='chat'):
|
||||||
stanza_session.EncryptedStanzaSession.__init__(self, conn, jid, thread_id, type = 'chat')
|
stanza_session.EncryptedStanzaSession.__init__(self, conn, jid, thread_id,
|
||||||
|
type='chat')
|
||||||
|
|
||||||
self.control = None
|
self.control = None
|
||||||
|
|
||||||
|
@ -116,8 +117,8 @@ class ChatControlSession(stanza_session.EncryptedStanzaSession):
|
||||||
|
|
||||||
if self.is_loggable() and msgtxt:
|
if self.is_loggable() and msgtxt:
|
||||||
try:
|
try:
|
||||||
msg_id = gajim.logger.write(log_type, full_jid_with_resource, msgtxt,
|
msg_id = gajim.logger.write(log_type, full_jid_with_resource,
|
||||||
tim=tim, subject=subject)
|
msgtxt, tim=tim, subject=subject)
|
||||||
except exceptions.PysqliteOperationalError, e:
|
except exceptions.PysqliteOperationalError, e:
|
||||||
self.conn.dispatch('ERROR', (_('Disk WriteError'), str(e)))
|
self.conn.dispatch('ERROR', (_('Disk WriteError'), str(e)))
|
||||||
|
|
||||||
|
@ -133,11 +134,13 @@ class ChatControlSession(stanza_session.EncryptedStanzaSession):
|
||||||
if gajim.jid_is_transport(jid):
|
if gajim.jid_is_transport(jid):
|
||||||
jid = jid.replace('@', '')
|
jid = jid.replace('@', '')
|
||||||
|
|
||||||
groupchat_control = gajim.interface.msg_win_mgr.get_gc_control(jid, self.conn.name)
|
groupchat_control = gajim.interface.msg_win_mgr.get_gc_control(jid,
|
||||||
|
self.conn.name)
|
||||||
|
|
||||||
if not groupchat_control and \
|
if not groupchat_control and \
|
||||||
jid in gajim.interface.minimized_controls[self.conn.name]:
|
jid in gajim.interface.minimized_controls[self.conn.name]:
|
||||||
groupchat_control = gajim.interface.minimized_controls[self.conn.name][jid]
|
groupchat_control = gajim.interface.minimized_controls[self.conn.name]\
|
||||||
|
[jid]
|
||||||
|
|
||||||
pm = False
|
pm = False
|
||||||
if groupchat_control and groupchat_control.type_id == \
|
if groupchat_control and groupchat_control.type_id == \
|
||||||
|
@ -151,7 +154,8 @@ class ChatControlSession(stanza_session.EncryptedStanzaSession):
|
||||||
|
|
||||||
# does this resource have the highest priority of any available?
|
# does this resource have the highest priority of any available?
|
||||||
is_highest = not highest_contact or not highest_contact.resource or \
|
is_highest = not highest_contact or not highest_contact.resource or \
|
||||||
resource == highest_contact.resource or highest_contact.show == 'offline'
|
resource == highest_contact.resource or highest_contact.show == \
|
||||||
|
'offline'
|
||||||
|
|
||||||
# Handle chat states
|
# Handle chat states
|
||||||
contact = gajim.contacts.get_contact(self.conn.name, jid, resource)
|
contact = gajim.contacts.get_contact(self.conn.name, jid, resource)
|
||||||
|
@ -198,7 +202,8 @@ class ChatControlSession(stanza_session.EncryptedStanzaSession):
|
||||||
jid_of_control = full_jid_with_resource
|
jid_of_control = full_jid_with_resource
|
||||||
|
|
||||||
if not self.control:
|
if not self.control:
|
||||||
ctrl = gajim.interface.msg_win_mgr.get_control(jid_of_control, self.conn.name)
|
ctrl = gajim.interface.msg_win_mgr.get_control(jid_of_control,
|
||||||
|
self.conn.name)
|
||||||
if ctrl:
|
if ctrl:
|
||||||
self.control = ctrl
|
self.control = ctrl
|
||||||
self.control.set_session(self)
|
self.control.set_session(self)
|
||||||
|
@ -213,8 +218,8 @@ class ChatControlSession(stanza_session.EncryptedStanzaSession):
|
||||||
nickname = resource
|
nickname = resource
|
||||||
if self.control:
|
if self.control:
|
||||||
# print if a control is open
|
# print if a control is open
|
||||||
self.control.print_conversation(msgtxt,
|
self.control.print_conversation(msgtxt, tim=tim, xhtml=xhtml,
|
||||||
tim = tim, xhtml = xhtml, encrypted = encrypted)
|
encrypted=encrypted)
|
||||||
else:
|
else:
|
||||||
# otherwise pass it off to the control to be queued
|
# otherwise pass it off to the control to be queued
|
||||||
groupchat_control.on_private_message(nickname, msgtxt, tim,
|
groupchat_control.on_private_message(nickname, msgtxt, tim,
|
||||||
|
@ -242,10 +247,9 @@ class ChatControlSession(stanza_session.EncryptedStanzaSession):
|
||||||
first, nickname, msg, focused], advanced_notif_num)
|
first, nickname, msg, focused], advanced_notif_num)
|
||||||
|
|
||||||
if gajim.interface.remote_ctrl:
|
if gajim.interface.remote_ctrl:
|
||||||
gajim.interface.remote_ctrl.raise_signal('NewMessage',
|
gajim.interface.remote_ctrl.raise_signal('NewMessage', (self.conn.name,
|
||||||
(self.conn.name, [full_jid_with_resource, msgtxt, tim,
|
[full_jid_with_resource, msgtxt, tim, encrypted, msg_type, subject,
|
||||||
encrypted, msg_type, subject, chatstate, msg_id,
|
chatstate, msg_id, composing_xep, user_nick, xhtml, form_node]))
|
||||||
composing_xep, user_nick, xhtml, form_node]))
|
|
||||||
|
|
||||||
# display the message or show notification in the roster
|
# display the message or show notification in the roster
|
||||||
def roster_message(self, jid, msg, tim, encrypted=False, msg_type='',
|
def roster_message(self, jid, msg, tim, encrypted=False, msg_type='',
|
||||||
|
@ -333,8 +337,10 @@ class ChatControlSession(stanza_session.EncryptedStanzaSession):
|
||||||
type_ = 'normal'
|
type_ = 'normal'
|
||||||
event_type = 'single_message_received'
|
event_type = 'single_message_received'
|
||||||
|
|
||||||
show_in_roster = notify.get_show_in_roster(event_type, self.conn.name, contact, self)
|
show_in_roster = notify.get_show_in_roster(event_type, self.conn.name,
|
||||||
show_in_systray = notify.get_show_in_systray(event_type, self.conn.name, contact)
|
contact, self)
|
||||||
|
show_in_systray = notify.get_show_in_systray(event_type, self.conn.name,
|
||||||
|
contact)
|
||||||
|
|
||||||
event = gajim.events.create_event(type_, (msg, subject, msg_type, tim,
|
event = gajim.events.create_event(type_, (msg, subject, msg_type, tim,
|
||||||
encrypted, resource, msg_id, xhtml, self, form_node),
|
encrypted, resource, msg_id, xhtml, self, form_node),
|
||||||
|
@ -371,7 +377,8 @@ class ChatControlSession(stanza_session.EncryptedStanzaSession):
|
||||||
if form.getType() == 'form' and 'security' in form.asDict():
|
if form.getType() == 'form' and 'security' in form.asDict():
|
||||||
# we don't support 3-message negotiation as the responder
|
# we don't support 3-message negotiation as the responder
|
||||||
if 'dhkeys' in form.asDict():
|
if 'dhkeys' in form.asDict():
|
||||||
self.fail_bad_negotiation('3 message negotiation not supported when responding', ('dhkeys',))
|
self.fail_bad_negotiation('3 message negotiation not supported '
|
||||||
|
'when responding', ('dhkeys',))
|
||||||
return
|
return
|
||||||
|
|
||||||
negotiated, not_acceptable, ask_user = self.verify_options_bob(form)
|
negotiated, not_acceptable, ask_user = self.verify_options_bob(form)
|
||||||
|
@ -388,12 +395,14 @@ class ChatControlSession(stanza_session.EncryptedStanzaSession):
|
||||||
not_acceptable.append(key)
|
not_acceptable.append(key)
|
||||||
self.respond_e2e_bob(form, negotiated, not_acceptable)
|
self.respond_e2e_bob(form, negotiated, not_acceptable)
|
||||||
|
|
||||||
self.dialog = dialogs.YesNoDialog(_('Confirm these session options'),
|
self.dialog = dialogs.YesNoDialog(_('Confirm these session '
|
||||||
|
'options'),
|
||||||
_('''The remote client wants to negotiate an session with these features:
|
_('''The remote client wants to negotiate an session with these features:
|
||||||
|
|
||||||
%s
|
%s
|
||||||
|
|
||||||
Are these options acceptable?''') % (negotiation.describe_features(ask_user)),
|
Are these options acceptable?''') % (negotiation.describe_features(
|
||||||
|
ask_user)),
|
||||||
on_response_yes=accept_nondefault_options,
|
on_response_yes=accept_nondefault_options,
|
||||||
on_response_no=reject_nondefault_options)
|
on_response_no=reject_nondefault_options)
|
||||||
else:
|
else:
|
||||||
|
@ -403,7 +412,8 @@ class ChatControlSession(stanza_session.EncryptedStanzaSession):
|
||||||
|
|
||||||
# alice accepts
|
# alice accepts
|
||||||
elif self.status == 'requested-e2e' and form.getType() == 'submit':
|
elif self.status == 'requested-e2e' and form.getType() == 'submit':
|
||||||
negotiated, not_acceptable, ask_user = self.verify_options_alice(form)
|
negotiated, not_acceptable, ask_user = self.verify_options_alice(
|
||||||
|
form)
|
||||||
|
|
||||||
if ask_user:
|
if ask_user:
|
||||||
def accept_nondefault_options(is_checked):
|
def accept_nondefault_options(is_checked):
|
||||||
|
@ -421,7 +431,9 @@ class ChatControlSession(stanza_session.EncryptedStanzaSession):
|
||||||
dialog.destroy()
|
dialog.destroy()
|
||||||
|
|
||||||
dialog = dialogs.YesNoDialog(_('Confirm these session options'),
|
dialog = dialogs.YesNoDialog(_('Confirm these session options'),
|
||||||
_('The remote client selected these options:\n\n%s\n\nContinue with the session?') % (negotiation.describe_features(ask_user)),
|
_('The remote client selected these options:\n\n%s\n\n'
|
||||||
|
'Continue with the session?') % (
|
||||||
|
negotiation.describe_features(ask_user)),
|
||||||
on_response_yes = accept_nondefault_options,
|
on_response_yes = accept_nondefault_options,
|
||||||
on_response_no = reject_nondefault_options)
|
on_response_no = reject_nondefault_options)
|
||||||
else:
|
else:
|
||||||
|
@ -460,8 +472,8 @@ class ChatControlSession(stanza_session.EncryptedStanzaSession):
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
# non-esession negotiation. this isn't very useful, but i'm keeping it around
|
# non-esession negotiation. this isn't very useful, but i'm keeping it
|
||||||
# to test my test suite.
|
# around to test my test suite.
|
||||||
if form.getType() == 'form':
|
if form.getType() == 'form':
|
||||||
if not self.control:
|
if not self.control:
|
||||||
jid, resource = gajim.get_room_and_nick_from_fjid(self.jid)
|
jid, resource = gajim.get_room_and_nick_from_fjid(self.jid)
|
||||||
|
@ -473,8 +485,8 @@ class ChatControlSession(stanza_session.EncryptedStanzaSession):
|
||||||
contact = gajim.contacts.create_contact(jid=jid,
|
contact = gajim.contacts.create_contact(jid=jid,
|
||||||
resource=resource, show=self.conn.get_status())
|
resource=resource, show=self.conn.get_status())
|
||||||
|
|
||||||
gajim.interface.new_chat(contact, account,
|
gajim.interface.new_chat(contact, account, resource=resource,
|
||||||
resource = resource, session = self)
|
session=self)
|
||||||
|
|
||||||
negotiation.FeatureNegotiationWindow(account, self.jid, self, form)
|
negotiation.FeatureNegotiationWindow(account, self.jid, self, form)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue