How to use the nbxmpp.JID function in nbxmpp

To help you get started, we’ve selected a few nbxmpp examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github gajim / gajim / gajim / application.py View on Github external
return

        for uri in uris:
            app.log('uri_handler').info('open %s', uri)
            if not uri.startswith('xmpp:'):
                continue
            # remove xmpp:
            uri = uri[5:]
            try:
                jid, cmd = uri.split('?')
            except ValueError:
                # No query argument
                jid, cmd = uri, 'message'

            try:
                jid = JID(jid)
            except InvalidJid as error:
                app.log('uri_handler').warning('Invalid JID %s: %s', uri, error)
                continue

            if cmd == 'join' and jid.getResource():
                app.log('uri_handler').warning('Invalid MUC JID %s', uri)
                continue

            jid = str(jid)

            if cmd == 'join':
                if len(accounts) == 1:
                    self.activate_action(
                        'groupchat-join',
                        GLib.Variant('as', [accounts[0], jid]))
                else:
github gajim / gajim / gajim / common / connection.py View on Github external
def get_own_jid(self, warn=False):
        """
        Return the last full JID we received on a bind event.
        In case we were never connected it returns the bare JID from config.
        """
        if self.registered_name:
            # This returns the full jid we received on the bind event
            return self.registered_name

        if warn:
            log.warning('only bare JID available')
        # This returns the bare jid
        return nbxmpp.JID(app.get_jid_from_account(self.name))
github gajim / gajim / gajim / common / types.py View on Github external
from gajim.common.logger import Logger

    from gajim.gui_interface import Interface


NetworkEventsControllerT = Union['NetworkEventsController']
InterfaceT = Union['Interface']
LoggerT = Union['Logger']

ConnectionT = Union['Client', 'ConnectionZeroconf']
ContactsT = Union['Contact', 'GC_Contact']
ContactT = Union['Contact']
LegacyContactsAPIT = Union['LegacyContactsAPI']

# PEP
PEPNotifyCallback = Callable[[nbxmpp.JID, nbxmpp.Node], None]
PEPHandlersDict = Dict[str, List[PEPNotifyCallback]]

# Configpaths
PathTuple = Tuple[Optional[PathLocation], str, Optional[PathType]]

# Plugins
PluginExtensionPoints = Dict[str, Tuple[Optional[Callable[..., None]],
                                        Optional[Callable[..., None]]]]
EventHandlersDict = Dict[str, Tuple[int, Callable[['NetworkEvent'], Optional[bool]]]]
PluginEvents = List['NetworkEvent']
github gajim / gajim / gajim / common / zeroconf / connection_zeroconf.py View on Github external
def get_own_jid(self, *args, **kwargs):
        return nbxmpp.JID(self.username + '@' + self.host)
github gajim / gajim / gajim / common / jingle_session.py View on Github external
def __make_jingle(self, action, reason=None):
        stanza = nbxmpp.Iq(typ='set', to=nbxmpp.JID(self.peerjid),
                           frm=self.ourjid)
        attrs = {
            'action': action,
            'sid': self.sid,
            'initiator' : self.initiator
        }
        jingle = stanza.addChild('jingle', attrs=attrs,
                                 namespace=Namespace.JINGLE)
        if reason is not None:
            jingle.addChild(node=reason)
        return stanza, jingle
github gajim / gajim / gajim / common / client.py View on Github external
def get_own_jid(self):
        """
        Return the last full JID we received on a bind event.
        In case we were never connected it returns the bare JID from config.
        """
        if self._client is not None:
            jid = self._client.get_bound_jid()
            if jid is not None:
                return jid

        # This returns the bare jid
        return nbxmpp.JID(app.get_jid_from_account(self._account))
github gajim / gajim / gajim / common / modules / adhoc_commands.py View on Github external
def is_same_jid(self, jid):
        """
        Test if the bare jid given is the same as our bare jid
        """
        return nbxmpp.JID(jid).getStripped() == self.get_own_bare_jid()
github gajim / gajim / gajim / common / connection_handlers.py View on Github external
def make_new_session(self, jid, thread_id=None, type_='chat', cls=None):
        """
        Create and register a new session

        thread_id=None to generate one.
        type_ should be 'chat' or 'pm'.
        """
        if not cls:
            cls = app.default_session_type

        sess = cls(self, nbxmpp.JID(jid), thread_id, type_)

        # determine if this session is a pm session
        # if not, discard the resource so that all sessions are stored bare
        if type_ != 'pm':
            jid = app.get_jid_without_resource(jid)

        if not jid in self.sessions:
            self.sessions[jid] = {}

        self.sessions[jid][sess.thread_id] = sess

        return sess