Show
Ignore:
Timestamp:
02/06/08 02:40:51 (10 months ago)
Author:
bct
Message:

move message handling into ChatControlSession?

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • branches/session_centric/src/gajim.py

    r9299 r9307  
    728728                                array[3], None, None, None, None, None, [], None, None)) 
    729729 
    730  
    731         def handle_event_msg(self, account, array): 
    732                 # 'MSG' (account, (jid, msg, time, encrypted, msg_type, subject, 
    733                 # chatstate, msg_id, composing_xep, user_nick, xhtml, session, form_node)) 
    734                 # user_nick is JEP-0172 
    735  
    736                 full_jid_with_resource = array[0] 
    737                 jid = gajim.get_jid_without_resource(full_jid_with_resource) 
    738                 resource = gajim.get_resource_from_jid(full_jid_with_resource) 
    739  
    740                 message = array[1] 
    741                 encrypted = array[3] 
    742                 msg_type = array[4] 
    743                 subject = array[5] 
    744                 chatstate = array[6] 
    745                 msg_id = array[7] 
    746                 composing_xep = array[8] 
    747                 xhtml = array[10] 
    748                 session = array[11] 
    749                 if gajim.config.get('ignore_incoming_xhtml'): 
    750                         xhtml = None 
    751                 if gajim.jid_is_transport(jid): 
    752                         jid = jid.replace('@', '') 
    753  
    754                 groupchat_control = self.msg_win_mgr.get_control(jid, account) 
    755                 if not groupchat_control and \ 
    756                 jid in self.minimized_controls[account]: 
    757                         groupchat_control = self.minimized_controls[account][jid] 
    758                 pm = False 
    759                 if groupchat_control and groupchat_control.type_id == \ 
    760                 message_control.TYPE_GC: 
    761                         # It's a Private message 
    762                         pm = True 
    763                         msg_type = 'pm' 
    764  
    765                 chat_control = None 
    766                 jid_of_control = full_jid_with_resource 
    767                 highest_contact = gajim.contacts.get_contact_with_highest_priority( 
    768                         account, jid) 
    769                 # Look for a chat control that has the given resource, or default to one 
    770                 # without resource 
    771                 ctrl = self.msg_win_mgr.get_control(full_jid_with_resource, account) 
    772                 if ctrl: 
    773                         chat_control = ctrl 
    774                 elif not pm and (not highest_contact or not highest_contact.resource): 
    775                         # unknow contact or offline message 
    776                         jid_of_control = jid 
    777                         chat_control = self.msg_win_mgr.get_control(jid, account) 
    778                 elif highest_contact and resource != highest_contact.resource and \ 
    779                 highest_contact.show != 'offline': 
    780                         jid_of_control = full_jid_with_resource 
    781                         chat_control = None 
    782                 elif not pm: 
    783                         jid_of_control = jid 
    784                         chat_control = self.msg_win_mgr.get_control(jid, account) 
    785  
    786                 # Handle chat states 
    787                 contact = gajim.contacts.get_contact(account, jid, resource) 
    788                 if contact: 
    789                         if contact.composing_xep != 'XEP-0085': # We cache xep85 support 
    790                                 contact.composing_xep = composing_xep 
    791                         if chat_control and chat_control.type_id == message_control.TYPE_CHAT: 
    792                                 if chatstate is not None: 
    793                                         # other peer sent us reply, so he supports jep85 or jep22 
    794                                         contact.chatstate = chatstate 
    795                                         if contact.our_chatstate == 'ask': # we were jep85 disco? 
    796                                                 contact.our_chatstate = 'active' # no more 
    797                                         chat_control.handle_incoming_chatstate() 
    798                                 elif contact.chatstate != 'active': 
    799                                         # got no valid jep85 answer, peer does not support it 
    800                                         contact.chatstate = False 
    801                         elif chatstate == 'active': 
    802                                 # Brand new message, incoming. 
    803                                 contact.our_chatstate = chatstate 
    804                                 contact.chatstate = chatstate 
    805                                 if msg_id: # Do not overwrite an existing msg_id with None 
    806                                         contact.msg_id = msg_id 
    807  
    808                 # THIS MUST BE AFTER chatstates handling 
    809                 # AND BEFORE playsound (else we ear sounding on chatstates!) 
    810                 if not message: # empty message text 
    811                         return 
    812  
    813                 if gajim.config.get('ignore_unknown_contacts') and \ 
    814                         not gajim.contacts.get_contacts(account, jid) and not pm: 
    815                         return 
    816                 if not contact: 
    817                         # contact is not in the roster, create a fake one to display 
    818                         # notification 
    819                         contact = common.contacts.Contact(jid = jid, resource = resource) 
    820                 advanced_notif_num = notify.get_advanced_notification('message_received', 
    821                         account, contact) 
    822  
    823                 # Is it a first or next message received ? 
    824                 first = False 
    825                 if msg_type == 'normal': 
    826                         if not gajim.events.get_events(account, jid, ['normal']): 
    827                                 first = True 
    828                 elif not chat_control and not gajim.events.get_events(account, 
    829                 jid_of_control, [msg_type]): # msg_type can be chat or pm 
    830                         first = True 
    831  
    832                 if pm: 
    833                         nickname = resource 
    834                         groupchat_control.on_private_message(nickname, message, array[2], 
    835                                 xhtml, session, msg_id) 
    836                 else: 
    837                         # array: (jid, msg, time, encrypted, msg_type, subject) 
    838                         if encrypted: 
    839                                 self.roster.on_message(jid, message, array[2], account, array[3], 
    840                                         msg_type, subject, resource, msg_id, array[9], 
    841                                         advanced_notif_num, session=session, form_node=array[12]) 
    842                         else: 
    843                                 # xhtml in last element 
    844                                 self.roster.on_message(jid, message, array[2], account, array[3], 
    845                                         msg_type, subject, resource, msg_id, array[9], 
    846                                         advanced_notif_num, xhtml=xhtml, session=session, 
    847                                         form_node=array[12]) 
    848                         nickname = gajim.get_name_from_jid(account, jid) 
    849                 # Check and do wanted notifications 
    850                 msg = message 
    851                 if subject: 
    852                         msg = _('Subject: %s') % subject + '\n' + msg 
    853                 focused = False 
    854                 if chat_control: 
    855                         parent_win = chat_control.parent_win 
    856                         if chat_control == parent_win.get_active_control() and \ 
    857                         parent_win.window.has_focus: 
    858                                 focused = True 
    859                 notify.notify('new_message', jid_of_control, account, [msg_type, 
    860                         first, nickname, msg, focused], advanced_notif_num) 
    861  
    862                 if self.remote_ctrl: 
    863                         self.remote_ctrl.raise_signal('NewMessage', (account, array)) 
    864  
    865730        def handle_event_msgerror(self, account, array): 
    866731                #'MSGERROR' (account, (jid, error_code, error_msg, msg, time)) 
     
    25572422                        'STATUS': self.handle_event_status, 
    25582423                        'NOTIFY': self.handle_event_notify, 
    2559                         'MSG': self.handle_event_msg, 
    25602424                        'MSGERROR': self.handle_event_msgerror, 
    25612425                        'MSGSENT': self.handle_event_msgsent,