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