Beispiel #1
0
    def roster_message(self, jid, msg, tim, encrypted=False, msg_type='',
    subject=None, resource='', msg_id=None, user_nick='', xhtml=None,
    form_node=None, displaymarking=None):
        """
        Display the message or show notification in the roster
        """
        contact = None
        fjid = jid

        # Try to catch the contact with correct resource
        if resource:
            fjid = jid + '/' + resource
            contact = gajim.contacts.get_contact(self.conn.name, jid, resource)

        highest_contact = gajim.contacts.get_contact_with_highest_priority(
                self.conn.name, jid)
        if not contact:
            # If there is another resource, it may be a message from an invisible
            # resource
            lcontact = gajim.contacts.get_contacts(self.conn.name, jid)
            if (len(lcontact) > 1 or (lcontact and lcontact[0].resource and \
            lcontact[0].show != 'offline')) and jid.find('@') > 0:
                contact = gajim.contacts.copy_contact(highest_contact)
                contact.resource = resource
                if resource:
                    fjid = jid + '/' + resource
                contact.priority = 0
                contact.show = 'offline'
                contact.status = ''
                gajim.contacts.add_contact(self.conn.name, contact)

            else:
                # Default to highest prio
                fjid = jid
                contact = highest_contact

        if not contact:
            # contact is not in roster
            contact = gajim.interface.roster.add_to_not_in_the_roster(
                    self.conn.name, jid, user_nick)

        if not self.control:
            ctrl = gajim.interface.msg_win_mgr.get_control(fjid, self.conn.name)
            if ctrl:
                self.control = ctrl
                self.control.set_session(self)
            else:
                fjid = jid

        # Do we have a queue?
        no_queue = len(gajim.events.get_events(self.conn.name, fjid)) == 0

        popup = helpers.allow_popup_window(self.conn.name)

        if msg_type == 'normal' and popup: # it's single message to be autopopuped
            dialogs.SingleMessageWindow(self.conn.name, contact.jid,
                    action='receive', from_whom=jid, subject=subject, message=msg,
                    resource=resource, session=self, form_node=form_node)
            return

        # We print if window is opened and it's not a single message
        if self.control and msg_type != 'normal':
            typ = ''

            if msg_type == 'error':
                typ = 'error'

            self.control.print_conversation(msg, typ, tim=tim, encrypted=encrypted,
                    subject=subject, xhtml=xhtml, displaymarking=displaymarking)

            if msg_id:
                gajim.logger.set_read_messages([msg_id])

            return

        # We save it in a queue
        type_ = 'chat'
        event_type = 'message_received'

        if msg_type == 'normal':
            type_ = 'normal'
            event_type = 'single_message_received'

        show_in_roster = notify.get_show_in_roster(event_type, self.conn.name,
                contact, self)
        show_in_systray = notify.get_show_in_systray(event_type, self.conn.name,
                contact)

        event = gajim.events.create_event(type_, (msg, subject, msg_type, tim,
            encrypted, resource, msg_id, xhtml, self, form_node, displaymarking,
            False), show_in_roster=show_in_roster,
            show_in_systray=show_in_systray)

        gajim.events.add_event(self.conn.name, fjid, event)

        if popup:
            if not self.control:
                self.control = gajim.interface.new_chat(contact,
                    self.conn.name, session=self)

                if len(gajim.events.get_events(self.conn.name, fjid)):
                    self.control.read_queue()
        else:
            if no_queue: # We didn't have a queue: we change icons
                gajim.interface.roster.draw_contact(jid, self.conn.name)

            gajim.interface.roster.show_title() # we show the * or [n]
        # Select the big brother contact in roster, it's visible because it has
        # events.
        family = gajim.contacts.get_metacontacts_family(self.conn.name, jid)
        if family:
            nearby_family, bb_jid, bb_account = \
                    gajim.contacts.get_nearby_family_and_big_brother(family,
                    self.conn.name)
        else:
            bb_jid, bb_account = jid, self.conn.name
        gajim.interface.roster.select_contact(bb_jid, bb_account)
Beispiel #2
0
    def roster_message2(self, obj):
        """
        Display the message or show notification in the roster
        """
        contact = None
        jid = obj.jid
        resource = obj.resource

        fjid = jid

        # Try to catch the contact with correct resource
        if resource:
            fjid = jid + '/' + resource
            contact = gajim.contacts.get_contact(obj.conn.name, jid, resource)

        highest_contact = gajim.contacts.get_contact_with_highest_priority(
            obj.conn.name, jid)
        if not contact:
            # If there is another resource, it may be a message from an
            # invisible resource
            lcontact = gajim.contacts.get_contacts(obj.conn.name, jid)
            if (len(lcontact) > 1 or (lcontact and lcontact[0].resource and \
            lcontact[0].show != 'offline')) and jid.find('@') > 0:
                contact = gajim.contacts.copy_contact(highest_contact)
                contact.resource = resource
                contact.priority = 0
                contact.show = 'offline'
                contact.status = ''
                gajim.contacts.add_contact(obj.conn.name, contact)

            else:
                # Default to highest prio
                fjid = jid
                contact = highest_contact

        if not contact:
            # contact is not in roster
            contact = gajim.interface.roster.add_to_not_in_the_roster(
                obj.conn.name, jid, obj.user_nick)

        if not self.control:
            ctrl = gajim.interface.msg_win_mgr.search_control(obj.jid,
                obj.conn.name, obj.resource)
            if ctrl:
                self.control = ctrl
                self.control.set_session(self)
            else:
                fjid = jid

        obj.popup = helpers.allow_popup_window(self.conn.name)

        type_ = 'chat'
        event_type = 'message_received'

        if obj.mtype == 'normal':
            type_ = 'normal'
            event_type = 'single_message_received'

        if self.control and obj.mtype != 'normal':
            obj.show_in_roster = False
            obj.show_in_systray = False
        else:
            obj.show_in_roster = notify.get_show_in_roster(event_type,
                self.conn.name, contact, self)
            obj.show_in_systray = notify.get_show_in_systray(event_type,
                self.conn.name, contact)

        if (not self.control and obj.mtype != 'normal') or \
        (obj.mtype == 'normal' and not obj.popup):
            event = gajim.events.create_event(type_, (obj.msgtxt, obj.subject,
                obj.mtype, obj.timestamp, obj.encrypted, obj.resource,
                obj.msg_id, obj.xhtml, self, obj.form_node, obj.displaymarking,
                obj.forwarded and obj.sent),
                show_in_roster=obj.show_in_roster,
                show_in_systray=obj.show_in_systray)

            gajim.events.add_event(self.conn.name, fjid, event)
Beispiel #3
0
	def roster_message(self, jid, msg, tim, encrypted=False, msg_type='',
	subject=None, resource='', msg_id=None, user_nick='',
	advanced_notif_num=None, xhtml=None, form_node=None):

		contact = None
		# if chat window will be for specific resource
		resource_for_chat = resource

		fjid = jid

		# Try to catch the contact with correct resource
		if resource:
			fjid = jid + '/' + resource
			contact = gajim.contacts.get_contact(self.conn.name, jid, resource)

		highest_contact = gajim.contacts.get_contact_with_highest_priority(
			self.conn.name, jid)
		if not contact:
			# If there is another resource, it may be a message from an invisible
			# resource
			lcontact = gajim.contacts.get_contacts(self.conn.name, jid)
			if (len(lcontact) > 1 or (lcontact and lcontact[0].resource and \
			lcontact[0].show != 'offline')) and jid.find('@') > 0:
				contact = gajim.contacts.copy_contact(highest_contact)
				contact.resource = resource
				if resource:
					fjid = jid + '/' + resource
				contact.priority = 0
				contact.show = 'offline'
				contact.status = ''
				gajim.contacts.add_contact(self.conn.name, contact)

			else:
				# Default to highest prio
				fjid = jid
				resource_for_chat = None
				contact = highest_contact

		if not contact:
			# contact is not in roster
			contact = gajim.interface.roster.add_to_not_in_the_roster(
				self.conn.name, jid, user_nick)

		if not self.control:
			# if no control exists and message comes from highest prio, the new
			# control shouldn't have a resource
			if highest_contact and contact.resource == highest_contact.resource \
			and not jid == gajim.get_jid_from_account(self.conn.name):
				fjid = jid
				resource_for_chat = None

		# Do we have a queue?
		no_queue = len(gajim.events.get_events(self.conn.name, fjid)) == 0

		popup = helpers.allow_popup_window(self.conn.name, advanced_notif_num)

		if msg_type == 'normal' and popup: # it's single message to be autopopuped
			dialogs.SingleMessageWindow(self.conn.name, contact.jid,
				action='receive', from_whom=jid, subject=subject, message=msg,
				resource=resource, session=self, form_node=form_node)
			return

		# We print if window is opened and it's not a single message
		if self.control and msg_type != 'normal':
			typ = ''

			if msg_type == 'error':
				typ = 'status'

			self.control.print_conversation(msg, typ, tim=tim, encrypted=encrypted,
				subject=subject, xhtml=xhtml)

			if msg_id:
				gajim.logger.set_read_messages([msg_id])

			return

		# We save it in a queue
		type_ = 'chat'
		event_type = 'message_received'

		if msg_type == 'normal':
			type_ = 'normal'
			event_type = 'single_message_received'

		show_in_roster = notify.get_show_in_roster(event_type, self.conn.name,
			contact, self)
		show_in_systray = notify.get_show_in_systray(event_type, self.conn.name,
			contact)

		event = gajim.events.create_event(type_, (msg, subject, msg_type, tim,
			encrypted, resource, msg_id, xhtml, self, form_node),
			show_in_roster=show_in_roster, show_in_systray=show_in_systray)

		gajim.events.add_event(self.conn.name, fjid, event)

		if popup:
			if not self.control:
				self.control = gajim.interface.new_chat(contact,
					self.conn.name, resource=resource_for_chat, session=self)

				if len(gajim.events.get_events(self.conn.name, fjid)):
					self.control.read_queue()
		else:
			if no_queue: # We didn't have a queue: we change icons
				gajim.interface.roster.draw_contact(jid, self.conn.name)

			gajim.interface.roster.show_title() # we show the * or [n]
		# Select contact row in roster.
		gajim.interface.roster.select_contact(jid, self.conn.name)
Beispiel #4
0
    def roster_message(self,
                       jid,
                       msg,
                       tim,
                       encrypted=False,
                       msg_type='',
                       subject=None,
                       resource='',
                       msg_id=None,
                       user_nick='',
                       advanced_notif_num=None,
                       xhtml=None,
                       form_node=None):

        contact = None
        # if chat window will be for specific resource
        resource_for_chat = resource

        fjid = jid

        # Try to catch the contact with correct resource
        if resource:
            fjid = jid + '/' + resource
            contact = gajim.contacts.get_contact(self.conn.name, jid, resource)

        highest_contact = gajim.contacts.get_contact_with_highest_priority(
            self.conn.name, jid)
        if not contact:
            # If there is another resource, it may be a message from an invisible
            # resource
            lcontact = gajim.contacts.get_contacts(self.conn.name, jid)
            if (len(lcontact) > 1 or (lcontact and lcontact[0].resource and \
            lcontact[0].show != 'offline')) and jid.find('@') > 0:
                contact = gajim.contacts.copy_contact(highest_contact)
                contact.resource = resource
                if resource:
                    fjid = jid + '/' + resource
                contact.priority = 0
                contact.show = 'offline'
                contact.status = ''
                gajim.contacts.add_contact(self.conn.name, contact)

            else:
                # Default to highest prio
                fjid = jid
                resource_for_chat = None
                contact = highest_contact

        if not contact:
            # contact is not in roster
            contact = gajim.interface.roster.add_to_not_in_the_roster(
                self.conn.name, jid, user_nick)

        if not self.control:
            # if no control exists and message comes from highest prio, the new
            # control shouldn't have a resource
            if highest_contact and contact.resource == highest_contact.resource \
            and not jid == gajim.get_jid_from_account(self.conn.name):
                fjid = jid
                resource_for_chat = None

        # Do we have a queue?
        no_queue = len(gajim.events.get_events(self.conn.name, fjid)) == 0

        popup = helpers.allow_popup_window(self.conn.name, advanced_notif_num)

        if msg_type == 'normal' and popup:  # it's single message to be autopopuped
            dialogs.SingleMessageWindow(self.conn.name,
                                        contact.jid,
                                        action='receive',
                                        from_whom=jid,
                                        subject=subject,
                                        message=msg,
                                        resource=resource,
                                        session=self,
                                        form_node=form_node)
            return

        # We print if window is opened and it's not a single message
        if self.control and msg_type != 'normal':
            typ = ''

            if msg_type == 'error':
                typ = 'status'

            self.control.print_conversation(msg,
                                            typ,
                                            tim=tim,
                                            encrypted=encrypted,
                                            subject=subject,
                                            xhtml=xhtml)

            if msg_id:
                gajim.logger.set_read_messages([msg_id])

            return

        # We save it in a queue
        type_ = 'chat'
        event_type = 'message_received'

        if msg_type == 'normal':
            type_ = 'normal'
            event_type = 'single_message_received'

        show_in_roster = notify.get_show_in_roster(event_type, self.conn.name,
                                                   contact, self)
        show_in_systray = notify.get_show_in_systray(event_type,
                                                     self.conn.name, contact)

        event = gajim.events.create_event(
            type_, (msg, subject, msg_type, tim, encrypted, resource, msg_id,
                    xhtml, self, form_node),
            show_in_roster=show_in_roster,
            show_in_systray=show_in_systray)

        gajim.events.add_event(self.conn.name, fjid, event)

        if popup:
            if not self.control:
                self.control = gajim.interface.new_chat(
                    contact,
                    self.conn.name,
                    resource=resource_for_chat,
                    session=self)

                if len(gajim.events.get_events(self.conn.name, fjid)):
                    self.control.read_queue()
        else:
            if no_queue:  # We didn't have a queue: we change icons
                gajim.interface.roster.draw_contact(jid, self.conn.name)

            gajim.interface.roster.show_title()  # we show the * or [n]
        # Select contact row in roster.
        gajim.interface.roster.select_contact(jid, self.conn.name)
Beispiel #5
0
    def roster_message(self, jid, msg, tim, encrypted=False, msg_type='',
    subject=None, resource='', msg_log_id=None, user_nick='', xhtml=None,
    form_node=None, displaymarking=None, additional_data={}):
        """
        Display the message or show notification in the roster
        """
        contact = None
        fjid = jid

        # Try to catch the contact with correct resource
        if resource:
            fjid = jid + '/' + resource
            contact = gajim.contacts.get_contact(self.conn.name, jid, resource)

        highest_contact = gajim.contacts.get_contact_with_highest_priority(
                self.conn.name, jid)
        if not contact:
            # If there is another resource, it may be a message from an invisible
            # resource
            lcontact = gajim.contacts.get_contacts(self.conn.name, jid)
            if (len(lcontact) > 1 or (lcontact and lcontact[0].resource and \
            lcontact[0].show != 'offline')) and jid.find('@') > 0:
                contact = gajim.contacts.copy_contact(highest_contact)
                contact.resource = resource
                if resource:
                    fjid = jid + '/' + resource
                contact.priority = 0
                contact.show = 'offline'
                contact.status = ''
                gajim.contacts.add_contact(self.conn.name, contact)

            else:
                # Default to highest prio
                fjid = jid
                contact = highest_contact

        if not contact:
            # contact is not in roster
            contact = gajim.interface.roster.add_to_not_in_the_roster(
                    self.conn.name, jid, user_nick)

        if not self.control:
            ctrl = gajim.interface.msg_win_mgr.get_control(fjid, self.conn.name)
            if ctrl:
                self.control = ctrl
                self.control.set_session(self)
            else:
                fjid = jid

        # Do we have a queue?
        no_queue = len(gajim.events.get_events(self.conn.name, fjid)) == 0

        popup = helpers.allow_popup_window(self.conn.name)

        if msg_type == 'normal' and popup: # it's single message to be autopopuped
            dialogs.SingleMessageWindow(self.conn.name, contact.jid,
                    action='receive', from_whom=jid, subject=subject, message=msg,
                    resource=resource, session=self, form_node=form_node)
            return

        # We print if window is opened and it's not a single message
        if self.control and msg_type != 'normal':
            typ = ''

            if msg_type == 'error':
                typ = 'error'

            self.control.print_conversation(msg, typ, tim=tim, encrypted=encrypted,
                    subject=subject, xhtml=xhtml, displaymarking=displaymarking,
                    additional_data=additional_data)

            if msg_log_id:
                gajim.logger.set_read_messages([msg_log_id])

            return

        # We save it in a queue
        event_t = events.ChatEvent
        event_type = 'message_received'

        if msg_type == 'normal':
            event_t = events.NormalEvent
            event_type = 'single_message_received'

        show_in_roster = notify.get_show_in_roster(event_type, self.conn.name,
                contact, self)
        show_in_systray = notify.get_show_in_systray(event_type, self.conn.name,
                contact)

        event = event_t(msg, subject, msg_type, tim, encrypted, resource,
            msg_log_id, xhtml=xhtml, session=self, form_node=form_node,
            displaymarking=displaymarking, sent_forwarded=False,
            show_in_roster=show_in_roster, show_in_systray=show_in_systray,
            additional_data=additional_data)

        gajim.events.add_event(self.conn.name, fjid, event)

        if popup:
            if not self.control:
                self.control = gajim.interface.new_chat(contact,
                    self.conn.name, session=self)

                if len(gajim.events.get_events(self.conn.name, fjid)):
                    self.control.read_queue()
        else:
            if no_queue: # We didn't have a queue: we change icons
                gajim.interface.roster.draw_contact(jid, self.conn.name)

            gajim.interface.roster.show_title() # we show the * or [n]
        # Select the big brother contact in roster, it's visible because it has
        # events.
        family = gajim.contacts.get_metacontacts_family(self.conn.name, jid)
        if family:
            nearby_family, bb_jid, bb_account = \
                    gajim.contacts.get_nearby_family_and_big_brother(family,
                    self.conn.name)
        else:
            bb_jid, bb_account = jid, self.conn.name
        gajim.interface.roster.select_contact(bb_jid, bb_account)
Beispiel #6
0
    def roster_message2(self, obj):
        """
        Display the message or show notification in the roster
        """
        contact = None
        jid = obj.jid
        resource = obj.resource

        fjid = jid

        # Try to catch the contact with correct resource
        if resource:
            fjid = jid + '/' + resource
            contact = gajim.contacts.get_contact(obj.conn.name, jid, resource)

        highest_contact = gajim.contacts.get_contact_with_highest_priority(
            obj.conn.name, jid)
        if not contact:
            # If there is another resource, it may be a message from an
            # invisible resource
            lcontact = gajim.contacts.get_contacts(obj.conn.name, jid)
            if (len(lcontact) > 1 or (lcontact and lcontact[0].resource and \
            lcontact[0].show != 'offline')) and jid.find('@') > 0:
                contact = gajim.contacts.copy_contact(highest_contact)
                contact.resource = resource
                contact.priority = 0
                contact.show = 'offline'
                contact.status = ''
                gajim.contacts.add_contact(obj.conn.name, contact)

            else:
                # Default to highest prio
                fjid = jid
                contact = highest_contact

        if not contact:
            # contact is not in roster
            contact = gajim.interface.roster.add_to_not_in_the_roster(
                obj.conn.name, jid, obj.user_nick)

        if not self.control:
            ctrl = gajim.interface.msg_win_mgr.search_control(obj.jid,
                obj.conn.name, obj.resource)
            if ctrl:
                self.control = ctrl
                self.control.set_session(self)
            else:
                fjid = jid

        obj.popup = helpers.allow_popup_window(self.conn.name)

        event_t = events.ChatEvent
        event_type = 'message_received'

        if obj.mtype == 'normal':
            event_t = events.NormalEvent
            event_type = 'single_message_received'

        if self.control and obj.mtype != 'normal':
            obj.show_in_roster = False
            obj.show_in_systray = False
        else:
            obj.show_in_roster = notify.get_show_in_roster(event_type,
                self.conn.name, contact, self)
            obj.show_in_systray = notify.get_show_in_systray(event_type,
                self.conn.name, contact)

        if (not self.control and obj.mtype != 'normal') or \
        (obj.mtype == 'normal' and not obj.popup):
            event = event_t(obj.msgtxt, obj.subject, obj.mtype, obj.timestamp,
                obj.encrypted, obj.resource, obj.msg_log_id,
                correct_id=(obj.id_, obj.correct_id), xhtml=obj.xhtml,
                session=self, form_node=obj.form_node,
                displaymarking=obj.displaymarking,
                sent_forwarded=obj.forwarded and obj.sent,
                show_in_roster=obj.show_in_roster,
                show_in_systray=obj.show_in_systray)

            gajim.events.add_event(self.conn.name, fjid, event)