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/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)