Changeset 9307

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

move message handling into ChatControlSession?

Location:
branches/session_centric/src
Files:
1 added
4 modified

Legend:

Unmodified
Added
Removed
  • branches/session_centric/src/common/connection_handlers.py

    r9299 r9307  
    5050        from music_track_listener import MusicTrackListener 
    5151 
    52 from common.stanza_session import EncryptedStanzaSession  
     52# XXX interface leaking into the back end? 
     53import session 
    5354 
    5455STATUS_LIST = ['offline', 'connecting', 'online', 'chat', 'away', 'xa', 'dnd', 
     
    17141715                if treat_as: 
    17151716                        mtype = treat_as 
    1716                 self.dispatch('MSG', (frm, msgtxt, tim, encrypted, mtype, 
    1717                         subject, chatstate, msg_id, composing_xep, user_nick, msghtml, 
    1718                         session, form_node)) 
     1717 
     1718                session.received(frm, msgtxt, tim, encrypted, mtype, subject, chatstate, 
     1719      msg_id, composing_xep, user_nick, msghtml, form_node) 
    17191720        # END messageCB 
    17201721 
     
    17871788 
    17881789        def make_new_session(self, jid, thread_id = None, type = 'chat'): 
    1789                 sess = EncryptedStanzaSession(self, common.xmpp.JID(jid), thread_id, type) 
     1790                sess = session.ChatControlSession(self, common.xmpp.JID(jid), thread_id, type) 
    17901791 
    17911792                if not jid in self.sessions: 
  • branches/session_centric/src/common/events.py

    r8927 r9307  
    169169                {jid1: [], jid2: []} 
    170170                if jid is given, returns all events from the given jid in a list: [] 
    171                 optionnaly only from given type''' 
     171                optionally only from given type''' 
    172172                if not self._events.has_key(account): 
    173173                        return [] 
  • 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, 
  • branches/session_centric/src/roster_window.py

    r9299 r9307  
    39303930                        chat_control.read_queue() 
    39313931 
    3932         def new_chat(self, contact, account, resource = None, session = None): 
     3932        def new_chat(self, session, contact, account, resource = None): 
    39333933                # Get target window, create a control, and associate it with the window 
    39343934                type_ = message_control.TYPE_CHAT 
     
    39463946                mw.new_tab(chat_control) 
    39473947 
    3948                 if len(gajim.events.get_events(account, fjid)): 
    3949                         # We call this here to avoid race conditions with widget validation 
    3950                         chat_control.read_queue() 
     3948                return chat_control 
    39513949 
    39523950        def new_chat_from_jid(self, account, fjid): 
     
    39643962 
    39653963                if not gajim.interface.msg_win_mgr.has_window(fjid, account): 
    3966                         self.new_chat(contact, account, resource = resource) 
     3964                        session = account.make_new_session(account, fjid) 
     3965                        self.control = self.new_chat(session, contact, account, resource = resource) 
     3966 
     3967                        if len(gajim.events.get_events(account, fjid)): 
     3968                                chat_control.read_queue() 
     3969 
    39673970                mw = gajim.interface.msg_win_mgr.get_window(fjid, account) 
    39683971                mw.set_active_tab(fjid, account) 
     
    39833986                        is_continued=is_continued) 
    39843987                mw.new_tab(gc_control) 
    3985  
    3986         def on_message(self, jid, msg, tim, account, encrypted=False, msg_type='', 
    3987         subject=None, resource='', msg_id=None, user_nick='', 
    3988         advanced_notif_num=None, xhtml=None, session=None, form_node=None): 
    3989                 '''when we receive a message''' 
    3990                 contact = None 
    3991                 # if chat window will be for specific resource 
    3992                 resource_for_chat = resource 
    3993                 fjid = jid 
    3994                 # Try to catch the contact with correct resource 
    3995                 if resource: 
    3996                         fjid = jid + '/' + resource 
    3997                         contact = gajim.contacts.get_contact(account, jid, resource) 
    3998                 highest_contact = gajim.contacts.get_contact_with_highest_priority( 
    3999                         account, jid) 
    4000                 if not contact: 
    4001                         # If there is another resource, it may be a message from an invisible 
    4002                         # resource 
    4003                         lcontact = gajim.contacts.get_contacts(account, jid) 
    4004                         if (len(lcontact) > 1 or (lcontact and lcontact[0].resource and \ 
    4005                         lcontact[0].show != 'offline')) and jid.find('@') > 0: 
    4006                                 contact = gajim.contacts.copy_contact(highest_contact) 
    4007                                 contact.resource = resource 
    4008                                 if resource: 
    4009                                         fjid = jid + '/' + resource 
    4010                                 contact.priority = 0 
    4011                                 contact.show = 'offline' 
    4012                                 contact.status = '' 
    4013                                 gajim.contacts.add_contact(account, contact) 
    4014  
    4015                         else: 
    4016                                 # Default to highest prio 
    4017                                 fjid = jid 
    4018                                 resource_for_chat = None 
    4019                                 contact = highest_contact 
    4020                 if not contact: 
    4021                         # contact is not in roster 
    4022                         contact = self.add_to_not_in_the_roster(account, jid, user_nick) 
    4023  
    4024                 path = self.get_path(jid, account) # Try to get line of contact in roster 
    4025  
    4026                 # Look for a chat control that has the given resource 
    4027                 ctrl = gajim.interface.msg_win_mgr.get_control(fjid, account) 
    4028                 if not ctrl: 
    4029                         # if not, if message comes from highest prio, get control or open one 
    4030                         # without resource 
    4031                         if highest_contact and contact.resource == highest_contact.resource \ 
    4032                         and not jid == gajim.get_jid_from_account(account): 
    4033                                 ctrl = gajim.interface.msg_win_mgr.get_control(jid, account) 
    4034                                 fjid = jid 
    4035                                 resource_for_chat = None 
    4036  
    4037                 # Do we have a queue? 
    4038                 no_queue = len(gajim.events.get_events(account, fjid)) == 0 
    4039  
    4040                 popup = helpers.allow_popup_window(account, advanced_notif_num) 
    4041  
    4042                 if msg_type == 'normal' and popup: # it's single message to be autopopuped 
    4043                         dialogs.SingleMessageWindow(account, contact.jid, action='receive', 
    4044                                 from_whom=jid, subject=subject, message=msg, resource=resource, 
    4045                                 session=session, form_node=form_node) 
    4046                         return 
    4047  
    4048                 # We print if window is opened and it's not a single message 
    4049                 if ctrl and msg_type != 'normal': 
    4050                         typ = '' 
    4051                         if msg_type == 'error': 
    4052                                 typ = 'status' 
    4053                         if session: 
    4054                                 ctrl.set_session(session) 
    4055                         ctrl.print_conversation(msg, typ, tim = tim, encrypted = encrypted, 
    4056                                                 subject = subject, xhtml = xhtml) 
    4057                         if msg_id: 
    4058                                 gajim.logger.set_read_messages([msg_id]) 
    4059                         return 
    4060  
    4061                 # We save it in a queue 
    4062                 type_ = 'chat' 
    4063                 event_type = 'message_received' 
    4064                 if msg_type == 'normal': 
    4065                         type_ = 'normal' 
    4066                         event_type = 'single_message_received' 
    4067                 show_in_roster = notify.get_show_in_roster(event_type, account, contact) 
    4068                 show_in_systray = notify.get_show_in_systray(event_type, account, contact) 
    4069                 event = gajim.events.create_event(type_, (msg, subject, msg_type, tim, 
    4070                         encrypted, resource, msg_id, xhtml, session, form_node), 
    4071                         show_in_roster=show_in_roster, show_in_systray=show_in_systray) 
    4072                 gajim.events.add_event(account, fjid, event) 
    4073                 if popup: 
    4074                         if not ctrl: 
    4075                                 self.new_chat(contact, account, resource=resource_for_chat) 
    4076                                 if path and not self.dragging and gajim.config.get( 
    4077                                 'scroll_roster_to_last_message'): 
    4078                                         # we curently see contact in our roster OR he 
    4079                                         # is not in the roster at all. 
    4080                                         # show and select his line in roster 
    4081                                         # do not change selection while DND'ing 
    4082                                         self.tree.expand_row(path[0:1], False) 
    4083                                         self.tree.expand_row(path[0:2], False) 
    4084                                         self.tree.scroll_to_cell(path) 
    4085                                         self.tree.set_cursor(path) 
    4086                 else: 
    4087                         if no_queue: # We didn't have a queue: we change icons 
    4088                                 self.draw_contact(jid, account) 
    4089                         self.show_title() # we show the * or [n] 
    4090                         # Show contact in roster (if he is invisible for example) and select 
    4091                         # line 
    4092                         self.show_and_select_path(path, jid, account) 
    40933988 
    40943989        def on_preferences_menuitem_activate(self, widget): 
     
    44004295                win = gajim.interface.msg_win_mgr.get_window(fjid, account) 
    44014296                if not win: 
    4402                         self.new_chat(contact, account, resource = resource, session = session) 
     4297                        self.new_chat(session, contact, account, resource = resource) 
    44034298                        win = gajim.interface.msg_win_mgr.get_window(fjid, account) 
    44044299                        ctrl = win.get_control(fjid, account)