Split core handlers into its own (broken) class.
This commit is contained in:
parent
c1be52847b
commit
34d110e643
1 changed files with 1267 additions and 1262 deletions
|
@ -46,7 +46,12 @@ try:
|
|||
except ImportError:
|
||||
PYGMENTS = False
|
||||
|
||||
def _join_initial_rooms(self, bookmarks):
|
||||
|
||||
class HandlerCore:
|
||||
def __init__(self, core):
|
||||
self.core = core
|
||||
|
||||
def _join_initial_rooms(self, bookmarks):
|
||||
"""Join all rooms given in the iterator `bookmarks`"""
|
||||
for bm in bookmarks:
|
||||
if not (bm.autojoin or config.get('open_all_bookmarks')):
|
||||
|
@ -65,7 +70,7 @@ def _join_initial_rooms(self, bookmarks):
|
|||
status=self.status.message,
|
||||
show=self.status.show)
|
||||
|
||||
def check_bookmark_storage(self, features):
|
||||
def check_bookmark_storage(self, features):
|
||||
private = 'jabber:iq:private' in features
|
||||
pep_ = 'http://jabber.org/protocol/pubsub#publish' in features
|
||||
self.bookmarks.available_storage['private'] = private
|
||||
|
@ -84,7 +89,7 @@ def check_bookmark_storage(self, features):
|
|||
if not self.xmpp.anon and config.get('use_remote_bookmarks'):
|
||||
self.bookmarks.get_remote(self.xmpp, self.information, _join_remote_only)
|
||||
|
||||
def on_session_start_features(self, _):
|
||||
def on_session_start_features(self, _):
|
||||
"""
|
||||
Enable carbons & blocking on session start if wanted and possible
|
||||
"""
|
||||
|
@ -103,7 +108,7 @@ def on_session_start_features(self, _):
|
|||
self.xmpp.plugin['xep_0030'].get_info(jid=self.xmpp.boundjid.domain,
|
||||
callback=callback)
|
||||
|
||||
def on_carbon_received(self, message):
|
||||
def on_carbon_received(self, message):
|
||||
"""
|
||||
Carbon <received/> received
|
||||
"""
|
||||
|
@ -127,7 +132,7 @@ def on_carbon_received(self, message):
|
|||
else:
|
||||
receive_message(recv)
|
||||
|
||||
def on_carbon_sent(self, message):
|
||||
def on_carbon_sent(self, message):
|
||||
"""
|
||||
Carbon <sent/> received
|
||||
"""
|
||||
|
@ -148,9 +153,9 @@ def on_carbon_sent(self, message):
|
|||
else:
|
||||
send_message(sent)
|
||||
|
||||
### Invites ###
|
||||
### Invites ###
|
||||
|
||||
def on_groupchat_invitation(self, message):
|
||||
def on_groupchat_invitation(self, message):
|
||||
"""
|
||||
Mediated invitation received
|
||||
"""
|
||||
|
@ -173,11 +178,11 @@ def on_groupchat_invitation(self, message):
|
|||
logger.log_roster_change(inviter.full, 'invited you to %s' % jid.full)
|
||||
self.pending_invites[jid.bare] = inviter.full
|
||||
|
||||
def on_groupchat_decline(self, decline):
|
||||
def on_groupchat_decline(self, decline):
|
||||
"Mediated invitation declined; skip for now"
|
||||
pass
|
||||
|
||||
def on_groupchat_direct_invitation(self, message):
|
||||
def on_groupchat_direct_invitation(self, message):
|
||||
"""
|
||||
Direct invitation received
|
||||
"""
|
||||
|
@ -205,9 +210,9 @@ def on_groupchat_direct_invitation(self, message):
|
|||
self.pending_invites[room.bare] = inviter.full
|
||||
logger.log_roster_change(inviter.full, 'invited you to %s' % room.bare)
|
||||
|
||||
### "classic" messages ###
|
||||
### "classic" messages ###
|
||||
|
||||
def on_message(self, message):
|
||||
def on_message(self, message):
|
||||
"""
|
||||
When receiving private message from a muc OR a normal message
|
||||
(from one of our contacts)
|
||||
|
@ -224,7 +229,7 @@ def on_message(self, message):
|
|||
return self.on_groupchat_private_message(message)
|
||||
return self.on_normal_message(message)
|
||||
|
||||
def on_error_message(self, message):
|
||||
def on_error_message(self, message):
|
||||
"""
|
||||
When receiving any message with type="error"
|
||||
"""
|
||||
|
@ -246,7 +251,7 @@ def on_error_message(self, message):
|
|||
self.refresh_window()
|
||||
|
||||
|
||||
def on_normal_message(self, message):
|
||||
def on_normal_message(self, message):
|
||||
"""
|
||||
When receiving "normal" messages (not a private message from a
|
||||
muc participant)
|
||||
|
@ -350,7 +355,7 @@ def on_normal_message(self, message):
|
|||
else:
|
||||
self.refresh_window()
|
||||
|
||||
def on_nick_received(self, message):
|
||||
def on_nick_received(self, message):
|
||||
"""
|
||||
Called when a pep notification for an user nickname
|
||||
is received
|
||||
|
@ -364,7 +369,7 @@ def on_nick_received(self, message):
|
|||
else:
|
||||
contact.name = ''
|
||||
|
||||
def on_gaming_event(self, message):
|
||||
def on_gaming_event(self, message):
|
||||
"""
|
||||
Called when a pep notification for user gaming
|
||||
is received
|
||||
|
@ -398,7 +403,7 @@ def on_gaming_event(self, message):
|
|||
else:
|
||||
self.information(contact.bare_jid + ' stopped playing.', 'Gaming')
|
||||
|
||||
def on_mood_event(self, message):
|
||||
def on_mood_event(self, message):
|
||||
"""
|
||||
Called when a pep notification for an user mood
|
||||
is received.
|
||||
|
@ -431,7 +436,7 @@ def on_mood_event(self, message):
|
|||
else:
|
||||
self.information(contact.bare_jid + ' stopped having his/her mood.', 'Mood')
|
||||
|
||||
def on_activity_event(self, message):
|
||||
def on_activity_event(self, message):
|
||||
"""
|
||||
Called when a pep notification for an user activity
|
||||
is received.
|
||||
|
@ -470,7 +475,7 @@ def on_activity_event(self, message):
|
|||
else:
|
||||
self.information(contact.bare_jid + ' stopped doing his/her activity.', 'Activity')
|
||||
|
||||
def on_tune_event(self, message):
|
||||
def on_tune_event(self, message):
|
||||
"""
|
||||
Called when a pep notification for an user tune
|
||||
is received
|
||||
|
@ -506,7 +511,7 @@ def on_tune_event(self, message):
|
|||
else:
|
||||
self.information(contact.bare_jid + ' stopped listening to music.', 'Tune')
|
||||
|
||||
def on_groupchat_message(self, message):
|
||||
def on_groupchat_message(self, message):
|
||||
"""
|
||||
Triggered whenever a message is received from a multi-user chat room.
|
||||
"""
|
||||
|
@ -576,13 +581,13 @@ def on_groupchat_message(self, message):
|
|||
and self.own_nick != message['from'].resource):
|
||||
curses.beep()
|
||||
|
||||
def on_muc_own_nickchange(self, muc):
|
||||
def on_muc_own_nickchange(self, muc):
|
||||
"We changed our nick in a MUC"
|
||||
for tab in self.get_tabs(tabs.PrivateTab):
|
||||
if tab.parent_muc == muc:
|
||||
tab.own_nick = muc.own_nick
|
||||
|
||||
def on_groupchat_private_message(self, message):
|
||||
def on_groupchat_private_message(self, message):
|
||||
"""
|
||||
We received a Private Message (from someone in a Muc)
|
||||
"""
|
||||
|
@ -647,24 +652,24 @@ def on_groupchat_private_message(self, message):
|
|||
tab.state = 'private'
|
||||
self.refresh_tab_win()
|
||||
|
||||
### Chatstates ###
|
||||
### Chatstates ###
|
||||
|
||||
def on_chatstate_active(self, message):
|
||||
def on_chatstate_active(self, message):
|
||||
self.on_chatstate(message, "active")
|
||||
|
||||
def on_chatstate_inactive(self, message):
|
||||
def on_chatstate_inactive(self, message):
|
||||
self.on_chatstate(message, "inactive")
|
||||
|
||||
def on_chatstate_composing(self, message):
|
||||
def on_chatstate_composing(self, message):
|
||||
self.on_chatstate(message, "composing")
|
||||
|
||||
def on_chatstate_paused(self, message):
|
||||
def on_chatstate_paused(self, message):
|
||||
self.on_chatstate(message, "paused")
|
||||
|
||||
def on_chatstate_gone(self, message):
|
||||
def on_chatstate_gone(self, message):
|
||||
self.on_chatstate(message, "gone")
|
||||
|
||||
def on_chatstate(self, message, state):
|
||||
def on_chatstate(self, message, state):
|
||||
if message['type'] == 'chat':
|
||||
if not self.on_chatstate_normal_conversation(message, state):
|
||||
tab = self.get_tab_by_name(message['from'].full, tabs.PrivateTab)
|
||||
|
@ -674,7 +679,7 @@ def on_chatstate(self, message, state):
|
|||
elif message['type'] == 'groupchat':
|
||||
self.on_chatstate_groupchat_conversation(message, state)
|
||||
|
||||
def on_chatstate_normal_conversation(self, message, state):
|
||||
def on_chatstate_normal_conversation(self, message, state):
|
||||
tab = self.get_conversation_by_jid(message['from'], False)
|
||||
if not tab:
|
||||
return False
|
||||
|
@ -691,7 +696,7 @@ def on_chatstate_normal_conversation(self, message, state):
|
|||
self.refresh_tab_win()
|
||||
return True
|
||||
|
||||
def on_chatstate_private_conversation(self, message, state):
|
||||
def on_chatstate_private_conversation(self, message, state):
|
||||
"""
|
||||
Chatstate received in a private conversation from a MUC
|
||||
"""
|
||||
|
@ -709,7 +714,7 @@ def on_chatstate_private_conversation(self, message, state):
|
|||
self.refresh_tab_win()
|
||||
return True
|
||||
|
||||
def on_chatstate_groupchat_conversation(self, message, state):
|
||||
def on_chatstate_groupchat_conversation(self, message, state):
|
||||
"""
|
||||
Chatstate received in a MUC
|
||||
"""
|
||||
|
@ -728,9 +733,9 @@ def on_chatstate_groupchat_conversation(self, message, state):
|
|||
_composing_tab_state(tab, state)
|
||||
self.refresh_tab_win()
|
||||
|
||||
### subscription-related handlers ###
|
||||
### subscription-related handlers ###
|
||||
|
||||
def on_roster_update(self, iq):
|
||||
def on_roster_update(self, iq):
|
||||
"""
|
||||
The roster was received.
|
||||
"""
|
||||
|
@ -749,7 +754,7 @@ def on_roster_update(self, iq):
|
|||
if isinstance(self.current_tab(), tabs.RosterInfoTab):
|
||||
self.refresh_window()
|
||||
|
||||
def on_subscription_request(self, presence):
|
||||
def on_subscription_request(self, presence):
|
||||
"""subscribe received"""
|
||||
jid = presence['from'].bare
|
||||
contact = roster[jid]
|
||||
|
@ -772,7 +777,7 @@ def on_subscription_request(self, presence):
|
|||
if isinstance(self.current_tab(), tabs.RosterInfoTab):
|
||||
self.refresh_window()
|
||||
|
||||
def on_subscription_authorized(self, presence):
|
||||
def on_subscription_authorized(self, presence):
|
||||
"""subscribed received"""
|
||||
jid = presence['from'].bare
|
||||
contact = roster[jid]
|
||||
|
@ -786,7 +791,7 @@ def on_subscription_authorized(self, presence):
|
|||
if isinstance(self.current_tab(), tabs.RosterInfoTab):
|
||||
self.refresh_window()
|
||||
|
||||
def on_subscription_remove(self, presence):
|
||||
def on_subscription_remove(self, presence):
|
||||
"""unsubscribe received"""
|
||||
jid = presence['from'].bare
|
||||
contact = roster[jid]
|
||||
|
@ -798,7 +803,7 @@ def on_subscription_remove(self, presence):
|
|||
if isinstance(self.current_tab(), tabs.RosterInfoTab):
|
||||
self.refresh_window()
|
||||
|
||||
def on_subscription_removed(self, presence):
|
||||
def on_subscription_removed(self, presence):
|
||||
"""unsubscribed received"""
|
||||
jid = presence['from'].bare
|
||||
contact = roster[jid]
|
||||
|
@ -814,9 +819,9 @@ def on_subscription_removed(self, presence):
|
|||
if isinstance(self.current_tab(), tabs.RosterInfoTab):
|
||||
self.refresh_window()
|
||||
|
||||
### Presence-related handlers ###
|
||||
### Presence-related handlers ###
|
||||
|
||||
def on_presence(self, presence):
|
||||
def on_presence(self, presence):
|
||||
if presence.match('presence/muc') or presence.xml.find('{http://jabber.org/protocol/muc#user}x'):
|
||||
return
|
||||
jid = presence['from']
|
||||
|
@ -839,7 +844,7 @@ def on_presence(self, presence):
|
|||
tab.refresh()
|
||||
self.doupdate()
|
||||
|
||||
def on_presence_error(self, presence):
|
||||
def on_presence_error(self, presence):
|
||||
jid = presence['from']
|
||||
contact = roster[jid.bare]
|
||||
if not contact:
|
||||
|
@ -851,7 +856,7 @@ def on_presence_error(self, presence):
|
|||
if tab:
|
||||
tab.remote_wants_chatstates = None
|
||||
|
||||
def on_got_offline(self, presence):
|
||||
def on_got_offline(self, presence):
|
||||
"""
|
||||
A JID got offline
|
||||
"""
|
||||
|
@ -876,7 +881,7 @@ def on_got_offline(self, presence):
|
|||
if isinstance(self.current_tab(), tabs.RosterInfoTab):
|
||||
self.refresh_window()
|
||||
|
||||
def on_got_online(self, presence):
|
||||
def on_got_online(self, presence):
|
||||
"""
|
||||
A JID got online
|
||||
"""
|
||||
|
@ -909,7 +914,7 @@ def on_got_online(self, presence):
|
|||
if isinstance(self.current_tab(), tabs.RosterInfoTab):
|
||||
self.refresh_window()
|
||||
|
||||
def on_groupchat_presence(self, presence):
|
||||
def on_groupchat_presence(self, presence):
|
||||
"""
|
||||
Triggered whenever a presence stanza is received from a user in a multi-user chat room.
|
||||
Display the presence on the room window and update the
|
||||
|
@ -922,15 +927,15 @@ def on_groupchat_presence(self, presence):
|
|||
tab.handle_presence(presence)
|
||||
|
||||
|
||||
### Connection-related handlers ###
|
||||
### Connection-related handlers ###
|
||||
|
||||
def on_failed_connection(self, error):
|
||||
def on_failed_connection(self, error):
|
||||
"""
|
||||
We cannot contact the remote server
|
||||
"""
|
||||
self.information("Connection to remote server failed: %s" % (error,), 'Error')
|
||||
|
||||
def on_disconnected(self, event):
|
||||
def on_disconnected(self, event):
|
||||
"""
|
||||
When we are disconnected from remote server
|
||||
"""
|
||||
|
@ -946,14 +951,14 @@ def on_disconnected(self, event):
|
|||
self.information("Auto-reconnecting.", 'Info')
|
||||
self.xmpp.start()
|
||||
|
||||
def on_stream_error(self, event):
|
||||
def on_stream_error(self, event):
|
||||
"""
|
||||
When we receive a stream error
|
||||
"""
|
||||
if event and event['text']:
|
||||
self.information('Stream error: %s' % event['text'], 'Error')
|
||||
|
||||
def on_failed_all_auth(self, event):
|
||||
def on_failed_all_auth(self, event):
|
||||
"""
|
||||
Authentication failed
|
||||
"""
|
||||
|
@ -961,7 +966,7 @@ def on_failed_all_auth(self, event):
|
|||
'Error')
|
||||
self.legitimate_disconnect = True
|
||||
|
||||
def on_no_auth(self, event):
|
||||
def on_no_auth(self, event):
|
||||
"""
|
||||
Authentication failed (no mech)
|
||||
"""
|
||||
|
@ -969,19 +974,19 @@ def on_no_auth(self, event):
|
|||
'Error')
|
||||
self.legitimate_disconnect = True
|
||||
|
||||
def on_connected(self, event):
|
||||
def on_connected(self, event):
|
||||
"""
|
||||
Remote host responded, but we are not yet authenticated
|
||||
"""
|
||||
self.information("Connected to server.", 'Info')
|
||||
|
||||
def on_connecting(self, event):
|
||||
def on_connecting(self, event):
|
||||
"""
|
||||
Just before we try to connect to the server
|
||||
"""
|
||||
self.legitimate_disconnect = False
|
||||
|
||||
def on_session_start(self, event):
|
||||
def on_session_start(self, event):
|
||||
"""
|
||||
Called when we are connected and authenticated
|
||||
"""
|
||||
|
@ -1011,9 +1016,9 @@ def on_session_start(self, event):
|
|||
# Start the ping's plugin regular event
|
||||
self.xmpp.set_keepalive_values()
|
||||
|
||||
### Other handlers ###
|
||||
### Other handlers ###
|
||||
|
||||
def on_status_codes(self, message):
|
||||
def on_status_codes(self, message):
|
||||
"""
|
||||
Handle groupchat messages with status codes.
|
||||
Those are received when a room configuration change occurs.
|
||||
|
@ -1070,7 +1075,7 @@ def on_status_codes(self, message):
|
|||
if modif:
|
||||
self.refresh_window()
|
||||
|
||||
def on_groupchat_subject(self, message):
|
||||
def on_groupchat_subject(self, message):
|
||||
"""
|
||||
Triggered when the topic is changed.
|
||||
"""
|
||||
|
@ -1098,7 +1103,7 @@ def on_groupchat_subject(self, message):
|
|||
if self.get_tab_by_name(room_from, tabs.MucTab) is self.current_tab():
|
||||
self.refresh_window()
|
||||
|
||||
def on_receipt(self, message):
|
||||
def on_receipt(self, message):
|
||||
"""
|
||||
When a delivery receipt is received (XEP-0184)
|
||||
"""
|
||||
|
@ -1117,13 +1122,13 @@ def on_receipt(self, message):
|
|||
except AckError:
|
||||
log.debug('Error while receiving an ack', exc_info=True)
|
||||
|
||||
def on_data_form(self, message):
|
||||
def on_data_form(self, message):
|
||||
"""
|
||||
When a data form is received
|
||||
"""
|
||||
self.information('%s' % message)
|
||||
|
||||
def on_attention(self, message):
|
||||
def on_attention(self, message):
|
||||
"""
|
||||
Attention probe received.
|
||||
"""
|
||||
|
@ -1141,7 +1146,7 @@ def on_attention(self, message):
|
|||
return
|
||||
self.information('%s tab not found.' % jid_from, 'Error')
|
||||
|
||||
def room_error(self, error, room_name):
|
||||
def room_error(self, error, room_name):
|
||||
"""
|
||||
Display the error in the tab
|
||||
"""
|
||||
|
@ -1163,7 +1168,7 @@ def room_error(self, error, room_name):
|
|||
tab.add_message('You can join the room with an other nick, by typing "/join /other_nick"', typ=2)
|
||||
self.refresh_window()
|
||||
|
||||
def outgoing_stanza(self, stanza):
|
||||
def outgoing_stanza(self, stanza):
|
||||
"""
|
||||
We are sending a new stanza, write it in the xml buffer if needed.
|
||||
"""
|
||||
|
@ -1186,7 +1191,7 @@ def outgoing_stanza(self, stanza):
|
|||
self.current_tab().refresh()
|
||||
self.doupdate()
|
||||
|
||||
def incoming_stanza(self, stanza):
|
||||
def incoming_stanza(self, stanza):
|
||||
"""
|
||||
We are receiving a new stanza, write it in the xml buffer if needed.
|
||||
"""
|
||||
|
@ -1208,11 +1213,11 @@ def incoming_stanza(self, stanza):
|
|||
self.current_tab().refresh()
|
||||
self.doupdate()
|
||||
|
||||
def ssl_invalid_chain(self, tb):
|
||||
def ssl_invalid_chain(self, tb):
|
||||
self.information('The certificate sent by the server is invalid.', 'Error')
|
||||
self.disconnect()
|
||||
|
||||
def validate_ssl(self, pem):
|
||||
def validate_ssl(self, pem):
|
||||
"""
|
||||
Check the server certificate using the slixmpp ssl_cert event
|
||||
"""
|
||||
|
@ -1273,7 +1278,7 @@ def validate_ssl(self, pem):
|
|||
if not config.silent_set('certificate', sha2_found_cert):
|
||||
self.information('Unable to write in the config file', 'Error')
|
||||
|
||||
def _composing_tab_state(tab, state):
|
||||
def _composing_tab_state(tab, state):
|
||||
"""
|
||||
Set a tab state to or from the "composing" state
|
||||
according to the config and the current tab state
|
||||
|
@ -1299,9 +1304,9 @@ def _composing_tab_state(tab, state):
|
|||
elif tab.state == 'composing' and state != 'composing':
|
||||
tab.restore_state()
|
||||
|
||||
### Ad-hoc commands
|
||||
### Ad-hoc commands
|
||||
|
||||
def on_next_adhoc_step(self, iq, adhoc_session):
|
||||
def on_next_adhoc_step(self, iq, adhoc_session):
|
||||
status = iq['command']['status']
|
||||
xform = iq.xml.find('{http://jabber.org/protocol/commands}command/{jabber:x:data}x')
|
||||
if xform is not None:
|
||||
|
@ -1334,21 +1339,21 @@ def on_next_adhoc_step(self, iq, adhoc_session):
|
|||
notes = '\n'.join([note[1] for note in iq['command']['notes']])
|
||||
self.information("Adhoc command %s: %s" % (status, notes), "Info")
|
||||
|
||||
def on_adhoc_error(self, iq, adhoc_session):
|
||||
def on_adhoc_error(self, iq, adhoc_session):
|
||||
self.xmpp.plugin['xep_0050'].terminate_command(adhoc_session)
|
||||
error_message = self.get_error_message(iq)
|
||||
self.information("An error occured while executing the command: %s" % (error_message),
|
||||
'Error')
|
||||
|
||||
def cancel_adhoc_command(self, form, session):
|
||||
def cancel_adhoc_command(self, form, session):
|
||||
self.xmpp.plugin['xep_0050'].cancel_command(session)
|
||||
self.close_tab()
|
||||
|
||||
def validate_adhoc_step(self, form, session):
|
||||
def validate_adhoc_step(self, form, session):
|
||||
session['payload'] = form
|
||||
self.xmpp.plugin['xep_0050'].continue_command(session)
|
||||
self.close_tab()
|
||||
|
||||
def terminate_adhoc_command(self, form, session):
|
||||
def terminate_adhoc_command(self, form, session):
|
||||
self.xmpp.plugin['xep_0050'].terminate_command(session)
|
||||
self.close_tab()
|
||||
|
|
Loading…
Reference in a new issue