Changeset 9307
- Timestamp:
- 02/06/08 02:40:51 (8 months ago)
- Location:
- branches/session_centric/src
- Files:
-
- 1 added
- 4 modified
-
common/connection_handlers.py (modified) (3 diffs)
-
common/events.py (modified) (1 diff)
-
gajim.py (modified) (2 diffs)
-
roster_window.py (modified) (5 diffs)
-
session.py (added)
Legend:
- Unmodified
- Added
- Removed
-
branches/session_centric/src/common/connection_handlers.py
r9299 r9307 50 50 from music_track_listener import MusicTrackListener 51 51 52 from common.stanza_session import EncryptedStanzaSession 52 # XXX interface leaking into the back end? 53 import session 53 54 54 55 STATUS_LIST = ['offline', 'connecting', 'online', 'chat', 'away', 'xa', 'dnd', … … 1714 1715 if treat_as: 1715 1716 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) 1719 1720 # END messageCB 1720 1721 … … 1787 1788 1788 1789 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) 1790 1791 1791 1792 if not jid in self.sessions: -
branches/session_centric/src/common/events.py
r8927 r9307 169 169 {jid1: [], jid2: []} 170 170 if jid is given, returns all events from the given jid in a list: [] 171 option naly only from given type'''171 optionally only from given type''' 172 172 if not self._events.has_key(account): 173 173 return [] -
branches/session_centric/src/gajim.py
r9299 r9307 728 728 array[3], None, None, None, None, None, [], None, None)) 729 729 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-0172735 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 = None751 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 = False759 if groupchat_control and groupchat_control.type_id == \760 message_control.TYPE_GC:761 # It's a Private message762 pm = True763 msg_type = 'pm'764 765 chat_control = None766 jid_of_control = full_jid_with_resource767 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 one770 # without resource771 ctrl = self.msg_win_mgr.get_control(full_jid_with_resource, account)772 if ctrl:773 chat_control = ctrl774 elif not pm and (not highest_contact or not highest_contact.resource):775 # unknow contact or offline message776 jid_of_control = jid777 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_resource781 chat_control = None782 elif not pm:783 jid_of_control = jid784 chat_control = self.msg_win_mgr.get_control(jid, account)785 786 # Handle chat states787 contact = gajim.contacts.get_contact(account, jid, resource)788 if contact:789 if contact.composing_xep != 'XEP-0085': # We cache xep85 support790 contact.composing_xep = composing_xep791 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 jep22794 contact.chatstate = chatstate795 if contact.our_chatstate == 'ask': # we were jep85 disco?796 contact.our_chatstate = 'active' # no more797 chat_control.handle_incoming_chatstate()798 elif contact.chatstate != 'active':799 # got no valid jep85 answer, peer does not support it800 contact.chatstate = False801 elif chatstate == 'active':802 # Brand new message, incoming.803 contact.our_chatstate = chatstate804 contact.chatstate = chatstate805 if msg_id: # Do not overwrite an existing msg_id with None806 contact.msg_id = msg_id807 808 # THIS MUST BE AFTER chatstates handling809 # AND BEFORE playsound (else we ear sounding on chatstates!)810 if not message: # empty message text811 return812 813 if gajim.config.get('ignore_unknown_contacts') and \814 not gajim.contacts.get_contacts(account, jid) and not pm:815 return816 if not contact:817 # contact is not in the roster, create a fake one to display818 # notification819 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 = False825 if msg_type == 'normal':826 if not gajim.events.get_events(account, jid, ['normal']):827 first = True828 elif not chat_control and not gajim.events.get_events(account,829 jid_of_control, [msg_type]): # msg_type can be chat or pm830 first = True831 832 if pm:833 nickname = resource834 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 element844 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 notifications850 msg = message851 if subject:852 msg = _('Subject: %s') % subject + '\n' + msg853 focused = False854 if chat_control:855 parent_win = chat_control.parent_win856 if chat_control == parent_win.get_active_control() and \857 parent_win.window.has_focus:858 focused = True859 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 865 730 def handle_event_msgerror(self, account, array): 866 731 #'MSGERROR' (account, (jid, error_code, error_msg, msg, time)) … … 2557 2422 'STATUS': self.handle_event_status, 2558 2423 'NOTIFY': self.handle_event_notify, 2559 'MSG': self.handle_event_msg,2560 2424 'MSGERROR': self.handle_event_msgerror, 2561 2425 'MSGSENT': self.handle_event_msgsent, -
branches/session_centric/src/roster_window.py
r9299 r9307 3930 3930 chat_control.read_queue() 3931 3931 3932 def new_chat(self, contact, account, resource = None, session= None):3932 def new_chat(self, session, contact, account, resource = None): 3933 3933 # Get target window, create a control, and associate it with the window 3934 3934 type_ = message_control.TYPE_CHAT … … 3946 3946 mw.new_tab(chat_control) 3947 3947 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 3951 3949 3952 3950 def new_chat_from_jid(self, account, fjid): … … 3964 3962 3965 3963 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 3967 3970 mw = gajim.interface.msg_win_mgr.get_window(fjid, account) 3968 3971 mw.set_active_tab(fjid, account) … … 3983 3986 is_continued=is_continued) 3984 3987 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 = None3991 # if chat window will be for specific resource3992 resource_for_chat = resource3993 fjid = jid3994 # Try to catch the contact with correct resource3995 if resource:3996 fjid = jid + '/' + resource3997 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 invisible4002 # resource4003 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 = resource4008 if resource:4009 fjid = jid + '/' + resource4010 contact.priority = 04011 contact.show = 'offline'4012 contact.status = ''4013 gajim.contacts.add_contact(account, contact)4014 4015 else:4016 # Default to highest prio4017 fjid = jid4018 resource_for_chat = None4019 contact = highest_contact4020 if not contact:4021 # contact is not in roster4022 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 roster4025 4026 # Look for a chat control that has the given resource4027 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 one4030 # without resource4031 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 = jid4035 resource_for_chat = None4036 4037 # Do we have a queue?4038 no_queue = len(gajim.events.get_events(account, fjid)) == 04039 4040 popup = helpers.allow_popup_window(account, advanced_notif_num)4041 4042 if msg_type == 'normal' and popup: # it's single message to be autopopuped4043 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 return4047 4048 # We print if window is opened and it's not a single message4049 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 return4060 4061 # We save it in a queue4062 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 he4079 # is not in the roster at all.4080 # show and select his line in roster4081 # do not change selection while DND'ing4082 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 icons4088 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 select4091 # line4092 self.show_and_select_path(path, jid, account)4093 3988 4094 3989 def on_preferences_menuitem_activate(self, widget): … … 4400 4295 win = gajim.interface.msg_win_mgr.get_window(fjid, account) 4401 4296 if not win: 4402 self.new_chat( contact, account, resource = resource, session = session)4297 self.new_chat(session, contact, account, resource = resource) 4403 4298 win = gajim.interface.msg_win_mgr.get_window(fjid, account) 4404 4299 ctrl = win.get_control(fjid, account)
