Path: blob/master/node_modules/@adiwajshing/baileys/lib/WABinary/jid-utils.js
1129 views
"use strict";1Object.defineProperty(exports, "__esModule", { value: true });2exports.jidNormalizedUser = exports.isJidStatusBroadcast = exports.isJidGroup = exports.isJidBroadcast = exports.isJidUser = exports.areJidsSameUser = exports.jidDecode = exports.jidEncode = exports.STORIES_JID = exports.PSA_WID = exports.SERVER_JID = exports.OFFICIAL_BIZ_JID = exports.S_WHATSAPP_NET = void 0;3exports.S_WHATSAPP_NET = '@s.whatsapp.net';4exports.OFFICIAL_BIZ_JID = '[email protected]';5exports.SERVER_JID = '[email protected]';6exports.PSA_WID = '[email protected]';7exports.STORIES_JID = 'status@broadcast';8const jidEncode = (user, server, device, agent) => {9return `${user || ''}${!!agent ? `_${agent}` : ''}${!!device ? `:${device}` : ''}@${server}`;10};11exports.jidEncode = jidEncode;12const jidDecode = (jid) => {13const sepIdx = typeof jid === 'string' ? jid.indexOf('@') : -1;14if (sepIdx < 0) {15return undefined;16}17const server = jid.slice(sepIdx + 1);18const userCombined = jid.slice(0, sepIdx);19const [userAgent, device] = userCombined.split(':');20const [user, agent] = userAgent.split('_');21return {22server,23user,24agent: agent ? +agent : undefined,25device: device ? +device : undefined26};27};28exports.jidDecode = jidDecode;29/** is the jid a user */30const areJidsSameUser = (jid1, jid2) => {31var _a, _b;32return (((_a = (0, exports.jidDecode)(jid1)) === null || _a === void 0 ? void 0 : _a.user) === ((_b = (0, exports.jidDecode)(jid2)) === null || _b === void 0 ? void 0 : _b.user));33};34exports.areJidsSameUser = areJidsSameUser;35/** is the jid a user */36const isJidUser = (jid) => (jid === null || jid === void 0 ? void 0 : jid.endsWith('@s.whatsapp.net'));37exports.isJidUser = isJidUser;38/** is the jid a broadcast */39const isJidBroadcast = (jid) => (jid === null || jid === void 0 ? void 0 : jid.endsWith('@broadcast'));40exports.isJidBroadcast = isJidBroadcast;41/** is the jid a group */42const isJidGroup = (jid) => (jid === null || jid === void 0 ? void 0 : jid.endsWith('@g.us'));43exports.isJidGroup = isJidGroup;44/** is the jid the status broadcast */45const isJidStatusBroadcast = (jid) => jid === 'status@broadcast';46exports.isJidStatusBroadcast = isJidStatusBroadcast;47const jidNormalizedUser = (jid) => {48const { user, server } = (0, exports.jidDecode)(jid);49return (0, exports.jidEncode)(user, server === 'c.us' ? 's.whatsapp.net' : server);50};51exports.jidNormalizedUser = jidNormalizedUser;525354