Exemplo n.º 1
0
    def _capsDiscoCB(self, jid, node, identities, features, dataforms):
        contact = gajim.contacts.get_contact_from_full_jid(self.name, jid)
        if not contact:
            room_jid, nick = gajim.get_room_and_nick_from_fjid(jid)
            contact = gajim.contacts.get_gc_contact(self.name, room_jid, nick)
            if contact is None:
                return
        if not contact.caps_node:
            return  # we didn't asked for that?
        if contact.caps_hash_method != "old" and not node.startswith(contact.caps_node + "#"):
            return
        if contact.caps_hash_method != "old":
            node, hash = node.split("#", 1)
            computed_hash = helpers.compute_caps_hash(
                identities, features, dataforms=dataforms, hash_method=contact.caps_hash_method
            )
            if computed_hash != hash:
                # wrong hash, forget it
                contact.caps_node = ""
                contact.caps_hash_method = ""
                contact.caps_hash = ""
                return
                # if we don't have this info already...
            caps = gajim.capscache[(contact.caps_hash_method, contact.caps_hash)]
        else:
            # if we don't have this info already...
            caps = gajim.capscache[(contact.caps_hash_method, contact.caps_node + "#" + contact.caps_hash)]
        if caps.queried == 2:
            return

        caps.update(identities, features)
Exemplo n.º 2
0
    def execute(self, request):
        account = self.connection.name
        # Forward messages
        events = gajim.events.get_events(account, types=["chat", "normal", "printed_chat"])
        j, resource = gajim.get_room_and_nick_from_fjid(self.jid)
        for jid in events:
            for event in events[jid]:
                ev_typ = event.type_
                if ev_typ == "printed_chat":
                    ev_typ = "chat"
                gajim.nec.push_outgoing_event(
                    MessageOutgoingEvent(
                        None,
                        account=account,
                        jid=j,
                        message=event.parameters[0],
                        type_=ev_typ,
                        subject=event.parameters[1],
                        resource=resource,
                        forward_from=jid,
                        delayed=event.time_,
                    )
                )

        # Inform other client of completion
        response, cmd = self.buildResponse(request, status="completed")
        cmd.addChild("note", {}, _("All unread messages have been forwarded."))

        self.connection.connection.send(response)

        return False  # finish the session
Exemplo n.º 3
0
	def _capsDiscoCB(self, jid, node, identities, features, dataforms):
		contact = gajim.contacts.get_contact_from_full_jid(self.name, jid)
		if not contact:
			room_jid, nick = gajim.get_room_and_nick_from_fjid(jid)
			contact = gajim.contacts.get_gc_contact(self.name, room_jid, nick)
			if contact is None:
				return
		if not contact.caps_node:
			return # we didn't asked for that?
		if contact.caps_hash_method != 'old' and not node.startswith(
		contact.caps_node + '#'):
			return
		if contact.caps_hash_method != 'old':
			node, hash = node.split('#', 1)
			computed_hash = helpers.compute_caps_hash(identities, features,
				dataforms=dataforms, hash_method=contact.caps_hash_method)
			if computed_hash != hash:
				# wrong hash, forget it
				contact.caps_node = ''
				contact.caps_hash_method = ''
				contact.caps_hash = ''
				return
			# if we don't have this info already...
			caps = gajim.capscache[(contact.caps_hash_method, contact.caps_hash)]
		else:
			# if we don't have this info already...
			caps = gajim.capscache[(contact.caps_hash_method, contact.caps_node + \
				'#' + contact.caps_hash)]
		if caps.queried == 2:
			return

		caps.update(identities, features)
Exemplo n.º 4
0
	def _capsPresenceCB(self, con, presence):
		''' Handle incoming presence stanzas... This is a callback
		for xmpp registered in connection_handlers.py'''

		# we will put these into proper Contact object and ask
		# for disco... so that disco will learn how to interpret
		# these caps
		jid = helpers.get_full_jid_from_iq(presence)
		contact = gajim.contacts.get_contact_from_full_jid(self.name, jid)
		if contact is None:
			room_jid, nick = gajim.get_room_and_nick_from_fjid(jid)
			contact = gajim.contacts.get_gc_contact(
				self.name, room_jid, nick)
			if contact is None:
				# TODO: a way to put contact not-in-roster
				# into Contacts
				return	

		# get the caps element
		caps = presence.getTag('c')
		if not caps:
			contact.caps_node = None
			contact.caps_hash = None
			contact.caps_hash_method = None
			return

		hash_method, node, hash = caps['hash'], caps['node'], caps['ver']

		if hash_method is None and node and hash:
			# Old XEP-115 implentation
			hash_method = 'old'

		if hash_method is None or node is None or hash is None:
			# improper caps in stanza, ignoring
			contact.caps_node = None
			contact.caps_hash = None
			contact.hash_method = None
			return

		# start disco query...
		gajim.capscache.preload(self, jid, node, hash_method, hash)

		# overwriting old data
		contact.caps_node = node
		contact.caps_hash_method = hash_method
		contact.caps_hash = hash
Exemplo n.º 5
0
    def _capsPresenceCB(self, con, presence):
        """ Handle incoming presence stanzas... This is a callback
		for xmpp registered in connection_handlers.py"""

        # we will put these into proper Contact object and ask
        # for disco... so that disco will learn how to interpret
        # these caps
        jid = helpers.get_full_jid_from_iq(presence)
        contact = gajim.contacts.get_contact_from_full_jid(self.name, jid)
        if contact is None:
            room_jid, nick = gajim.get_room_and_nick_from_fjid(jid)
            contact = gajim.contacts.get_gc_contact(self.name, room_jid, nick)
            if contact is None:
                # TODO: a way to put contact not-in-roster
                # into Contacts
                return

                # get the caps element
        caps = presence.getTag("c")
        if not caps:
            contact.caps_node = None
            contact.caps_hash = None
            contact.caps_hash_method = None
            return

        hash_method, node, hash = caps["hash"], caps["node"], caps["ver"]

        if hash_method is None and node and hash:
            # Old XEP-115 implentation
            hash_method = "old"

        if hash_method is None or node is None or hash is None:
            # improper caps in stanza, ignoring
            contact.caps_node = None
            contact.caps_hash = None
            contact.hash_method = None
            return

            # start disco query...
        gajim.capscache.preload(self, jid, node, hash_method, hash)

        # overwriting old data
        contact.caps_node = node
        contact.caps_hash_method = hash_method
        contact.caps_hash = hash
Exemplo n.º 6
0
	def execute(self, request):
		account = self.connection.name
		# Forward messages
		events = gajim.events.get_events(account, types=['chat', 'normal'])
		j, resource = gajim.get_room_and_nick_from_fjid(self.jid)
		for jid in events:
			for event in events[jid]:
				self.connection.send_message(j, event.parameters[0], '',
					type_=event.type_, subject=event.parameters[1],
					resource=resource, forward_from=jid, delayed=event.time_)

		# Inform other client of completion
		response, cmd = self.buildResponse(request, status = 'completed')
		cmd.addChild('note', {}, _('All unread messages have been forwarded.'))

		self.connection.connection.send(response)

		return False	# finish the session
Exemplo n.º 7
0
    def execute(self, request):
        account = self.connection.name
        # Forward messages
        events = gajim.events.get_events(account, types=["chat", "normal"])
        j, resource = gajim.get_room_and_nick_from_fjid(self.jid)
        for jid in events:
            for event in events[jid]:
                ev_typ = event.type_
                if ev_typ == "printed_chat":
                    ev_typ = "chat"
                gajim.nec.push_outgoing_event(
                    MessageOutgoingEvent(
                        None,
                        account=account,
                        jid=j,
                        message=event.parameters[0],
                        type_=ev_typ,
                        subject=event.parameters[1],
                        resource=resource,
                        forward_from=jid,
                        delayed=event.time_,
                        now=True,
                    )
                )

        response, cmd = self.buildResponse(request, status="completed")
        cmd.addChild("note", {}, _("The status has been changed."))

        # if going offline, we need to push response so it won't go into
        # queue and disappear
        self.connection.connection.send(response, now=True)

        # send new status
        gajim.interface.roster.send_status(self.connection.name, "offline", "")
        # finish the session
        return False
Exemplo n.º 8
0
	def __init__(self, event_type, jid, account, msg_type = '', file_props = None):
		self.account = account
		self.jid = jid
		self.msg_type = msg_type
		self.file_props = file_props

		if jid in gajim.contacts[account]:
			actor = gajim.get_first_contact_instance_from_jid(account, jid).name
		else:
			actor = jid

		txt = actor # default value of txt

		if event_type == _('Contact Signed In'):
			img = 'contact_online.png'
			ntype = 'presence.online'
		elif event_type == _('Contact Signed Out'):
			img = 'contact_offline.png'
			ntype = 'presence.offline'
		elif event_type in (_('New Message'), _('New Single Message'),
			_('New Private Message')):
			ntype = 'im.received'
			if event_type == _('New Private Message'):
				room_jid, nick = gajim.get_room_and_nick_from_fjid(jid)
				room_name,t = gajim.get_room_name_and_server_from_room_jid(room_jid)
				txt = _('%(nickname)s in room %(room_name)s has sent you a new message.')\
					% {'nickname': nick, 'room_name': room_name}
				img = 'priv_msg_recv.png'
			else:
				#we talk about a name here
				txt = _('%s has sent you a new message.') % actor
				if event_type == _('New Message'):
					img = 'chat_msg_recv.png'
				else: # New Single Message
					img = 'single_msg_recv.png'
		elif event_type == _('File Transfer Request'):
			img = 'ft_request.png'
			ntype = 'transfer'
			#we talk about a name here
			txt = _('%s wants to send you a file.') % actor
		elif event_type == _('File Transfer Error'):
			img = 'ft_stopped.png'
			ntype = 'transfer.error'
		elif event_type in (_('File Transfer Completed'), _('File Transfer Stopped')):
			ntype = 'transfer.complete'
			if file_props is not None:
				if file_props['type'] == 'r':
					# get the name of the sender, as it is in the roster
					sender = unicode(file_props['sender']).split('/')[0]
					name = gajim.get_first_contact_instance_from_jid(
						account, sender).name
					filename = os.path.basename(file_props['file-name'])
					if event_type == _('File Transfer Completed'):
						txt = _('You successfully received %(filename)s from %(name)s.')\
							% {'filename': filename, 'name': name}
						img = 'ft_done.png'
					else: # ft stopped
						txt = _('File transfer of %(filename)s from %(name)s stopped.')\
							% {'filename': filename, 'name': name}
						img = 'ft_stopped.png'
				else:
					receiver = file_props['receiver']
					if hasattr(receiver, 'jid'):
						receiver = receiver.jid
					receiver = receiver.split('/')[0]
					# get the name of the contact, as it is in the roster
					name = gajim.get_first_contact_instance_from_jid(
						account, receiver).name
					filename = os.path.basename(file_props['file-name'])
					if event_type == _('File Transfer Completed'):
						txt = _('You successfully sent %(filename)s to %(name)s.')\
							% {'filename': filename, 'name': name}
						img = 'ft_done.png'
					else: # ft stopped
						txt = _('File transfer of %(filename)s to %(name)s stopped.')\
							% {'filename': filename, 'name': name}
						img = 'ft_stopped.png'
			else:
				txt = ''
		else:
			# defaul failsafe values
			img = 'chat_msg_recv.png' # img to display
			ntype = 'im'	 # Notification Type

		path = os.path.join(gajim.DATA_DIR, 'pixmaps', 'events', img)
		path = os.path.abspath(path)

		self.notif = dbus_support.get_notifications_interface()
		if self.notif is None:
			raise dbus.dbus_bindings.DBusException()
		self.id = self.notif.Notify(dbus.String(_('Gajim')),
			dbus.String(path), dbus.UInt32(0), ntype, dbus.Byte(0),
			dbus.String(event_type), dbus.String(txt),
			[dbus.String(path)], {'default':0}, [''], True, dbus.UInt32(5))
		notification_response_manager.attach_to_interface()
		notification_response_manager.pending[self.id] = self