Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import { JID } from '@xmpp/jid';
/*
* All return an instance of JID.JID, the new operator is optional.
*/
let addr = new JID('alice@wonderland.net/rabbithole'); // OK
addr = new JID('alice', 'wonderland.net', 'rabbithole'); // BEST; see section on escaping below
/*
* local
*/
addr.local = 'alice';
addr.local; // alice
// same as
addr.setLocal('alice');
addr.getLocal(); // alice
/*
* domain
*/
addr.domain = 'wonderland.net';
addr.domain; // wonderland.net
// same as
import {JID} from '@xmpp/jid';
/*
* All return an instance of JID.JID, the new operator is optional.
*/
let addr = new JID('alice@wonderland.net/rabbithole'); // OK
addr = new JID('alice', 'wonderland.net', 'rabbithole'); // BEST; see section on escaping below
/*
* local
*/
addr.local = 'alice';
addr.local; // alice
// same as
addr.setLocal('alice');
addr.getLocal(); // alice
/*
* domain
*/
addr.domain = 'wonderland.net';
addr.domain; // wonderland.net
// same as
addr.setDomain('wonderland.net');
addr.getDomain(); // wonderland.net
/*
* resource
*/
addr.resource = 'rabbithole';
addr.resource; // rabbithole
// same as
addr.setResource('rabbithole');
addr.getResource(); // rabbithole
addr.toString(); // alice@wonderland.net/rabbithole
addr.bare(); // returns a JID without resource
const some_jid = new JID('is', 'a', 'test');
addr.equals(some_jid); // returns true if the two JIDs are equal, false otherwise
import { JID } from '@xmpp/jid';
/*
* All return an instance of JID.JID, the new operator is optional.
*/
let addr = new JID('alice@wonderland.net/rabbithole'); // OK
addr = new JID('alice', 'wonderland.net', 'rabbithole'); // BEST; see section on escaping below
/*
* local
*/
addr.local = 'alice';
addr.local; // alice
// same as
addr.setLocal('alice');
addr.getLocal(); // alice
/*
* domain
*/
addr.domain = 'wonderland.net';
addr.domain; // wonderland.net
addr.setDomain('wonderland.net');
addr.getDomain(); // wonderland.net
/*
* resource
*/
addr.resource = 'rabbithole';
addr.resource; // rabbithole
// same as
addr.setResource('rabbithole');
addr.getResource(); // rabbithole
addr.toString(); // alice@wonderland.net/rabbithole
addr.bare(); // returns a JID without resource
const some_jid = new JID('is', 'a', 'test');
addr.equals(some_jid); // returns true if the two JIDs are equal, false otherwise
import {JID} from '@xmpp/jid';
/*
* All return an instance of JID.JID, the new operator is optional.
*/
let addr = new JID('alice@wonderland.net/rabbithole'); // OK
addr = new JID('alice', 'wonderland.net', 'rabbithole'); // BEST; see section on escaping below
/*
* local
*/
addr.local = 'alice';
addr.local; // alice
// same as
addr.setLocal('alice');
addr.getLocal(); // alice
/*
* domain
*/
addr.domain = 'wonderland.net';
addr.domain; // wonderland.net
public getAccount(username: string, protocolId: string, mxid: string): IPurpleAccount|null {
const j = jid(username);
if (j.domain === this.myAddress.domain &&
j.local.startsWith("#") &&
this.serviceHandler.parseAliasFromJID(j)) {
// Account is an gateway alias, not trying.
return null;
}
const uLower = username.toLowerCase();
log.debug("Getting account", username);
if (protocolId !== "xmpp-js") {
return null;
}
if (this.accounts.has(uLower)) {
return this.accounts.get(uLower)!;
}
const acct = new XmppJsAccount(username, this.defaultRes, this, mxid);
this.accounts.set(uLower, acct);
private async handleMessageStanza(stanza: Element, alias: string|null) {
if (!stanza.attrs.from || !stanza.attrs.to) {
return;
}
const to = jid(stanza.attrs.to)!;
let localAcct: any = this.accounts.get(`${to!.local}@${to!.domain}`)!;
let from = jid(stanza.attrs.from);
let convName = `${from.local}@${from.domain}`;
if (alias) {
// If this is an alias, we want to do some gateway related things.
if (!to.resource) {
// Group message to a MUC, so reflect it to other XMPP users
// and set the right to/from addresses.
convName = `${to.local}@${to.domain}`;
log.info(`Sending gateway group message to ${convName}`);
if (!this.gateway!.reflectXMPPMessage(convName, stanza)) {
log.warn(`Message could not be sent, not forwarding to Matrix`);
return;
}
stanza.attrs.from = this.gateway!.getAnonIDForJID(
private async handleMessageStanza(stanza: Element, alias: string|null) {
if (!stanza.attrs.from || !stanza.attrs.to) {
return;
}
const to = jid(stanza.attrs.to)!;
let localAcct: any = this.accounts.get(`${to!.local}@${to!.domain}`)!;
let from = jid(stanza.attrs.from);
let convName = `${from.local}@${from.domain}`;
if (alias) {
// If this is an alias, we want to do some gateway related things.
if (!to.resource) {
// Group message to a MUC, so reflect it to other XMPP users
// and set the right to/from addresses.
convName = `${to.local}@${to.domain}`;
log.info(`Sending gateway group message to ${convName}`);
if (!this.gateway!.reflectXMPPMessage(convName, stanza)) {
log.warn(`Message could not be sent, not forwarding to Matrix`);
return;
}
stanza.attrs.from = this.gateway!.getAnonIDForJID(
convName, stanza.attrs.from) || false;
if (stanza.attrs.from === false) {
private handlePresenceStanza(stanza: Element, gatewayAlias: string|null) {
const to = jid(stanza.getAttr("to"));
// XMPP is case insensitive.
const localAcct = this.accounts.get(`${to.local}@${to.domain}`);
const from = jid(stanza.getAttr("from"));
const convName = `${from.local}@${from.domain}`;
const delta = this.presenceCache.add(stanza);
if (!delta) {
return;
}
if (delta.error && localAcct) {
if (delta.error === "conflict") {
log.info(`${from.toString()} conflicted with another user, attempting to fix`);
localAcct.xmppRetryJoin(from).catch((err) => {
log.error("Failed to retry join", err);
});