@vinzsocket/baileys 3.0.0 → 3.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/WAProto/GenerateStatics.sh +2 -2
- package/WAProto/WAProto.proto +1339 -493
- package/WAProto/fix-imports.js +79 -14
- package/WAProto/index.d.ts +5274 -1945
- package/WAProto/index.js +97691 -1
- package/lib/Defaults/index.d.ts +25 -8
- package/lib/Defaults/index.d.ts.map +1 -1
- package/lib/Defaults/index.js +124 -109
- package/lib/Defaults/index.js.map +1 -1
- package/lib/Signal/Group/ciphertext-message.js +11 -15
- package/lib/Signal/Group/group-session-builder.js +27 -32
- package/lib/Signal/Group/group_cipher.d.ts +1 -2
- package/lib/Signal/Group/group_cipher.d.ts.map +1 -1
- package/lib/Signal/Group/group_cipher.js +75 -92
- package/lib/Signal/Group/group_cipher.js.map +1 -1
- package/lib/Signal/Group/index.js +12 -77
- package/lib/Signal/Group/keyhelper.d.ts.map +1 -1
- package/lib/Signal/Group/keyhelper.js +16 -24
- package/lib/Signal/Group/keyhelper.js.map +1 -1
- package/lib/Signal/Group/sender-chain-key.d.ts +1 -1
- package/lib/Signal/Group/sender-chain-key.d.ts.map +1 -1
- package/lib/Signal/Group/sender-chain-key.js +24 -34
- package/lib/Signal/Group/sender-chain-key.js.map +1 -1
- package/lib/Signal/Group/sender-key-distribution-message.d.ts.map +1 -1
- package/lib/Signal/Group/sender-key-distribution-message.js +62 -58
- package/lib/Signal/Group/sender-key-distribution-message.js.map +1 -1
- package/lib/Signal/Group/sender-key-message.d.ts.map +1 -1
- package/lib/Signal/Group/sender-key-message.js +64 -65
- package/lib/Signal/Group/sender-key-message.js.map +1 -1
- package/lib/Signal/Group/sender-key-name.js +41 -44
- package/lib/Signal/Group/sender-key-record.d.ts +1 -1
- package/lib/Signal/Group/sender-key-record.d.ts.map +1 -1
- package/lib/Signal/Group/sender-key-record.js +36 -47
- package/lib/Signal/Group/sender-key-record.js.map +1 -1
- package/lib/Signal/Group/sender-key-state.d.ts +4 -4
- package/lib/Signal/Group/sender-key-state.d.ts.map +1 -1
- package/lib/Signal/Group/sender-key-state.js +76 -93
- package/lib/Signal/Group/sender-key-state.js.map +1 -1
- package/lib/Signal/Group/sender-message-key.d.ts.map +1 -1
- package/lib/Signal/Group/sender-message-key.js +25 -31
- package/lib/Signal/Group/sender-message-key.js.map +1 -1
- package/lib/Signal/libsignal.d.ts +4 -7
- package/lib/Signal/libsignal.d.ts.map +1 -1
- package/lib/Signal/libsignal.js +417 -401
- package/lib/Signal/libsignal.js.map +1 -1
- package/lib/Signal/lid-mapping.d.ts +16 -23
- package/lib/Signal/lid-mapping.d.ts.map +1 -1
- package/lib/Signal/lid-mapping.js +273 -108
- package/lib/Signal/lid-mapping.js.map +1 -1
- package/lib/Socket/Client/index.js +3 -25
- package/lib/Socket/Client/types.d.ts +2 -2
- package/lib/Socket/Client/types.d.ts.map +1 -1
- package/lib/Socket/Client/types.js +10 -14
- package/lib/Socket/Client/websocket.d.ts +1 -1
- package/lib/Socket/Client/websocket.d.ts.map +1 -1
- package/lib/Socket/Client/websocket.js +53 -54
- package/lib/Socket/Client/websocket.js.map +1 -1
- package/lib/Socket/business.d.ts +45 -16
- package/lib/Socket/business.d.ts.map +1 -1
- package/lib/Socket/business.js +374 -360
- package/lib/Socket/business.js.map +1 -1
- package/lib/Socket/chats.d.ts +34 -8
- package/lib/Socket/chats.d.ts.map +1 -1
- package/lib/Socket/chats.js +1162 -1038
- package/lib/Socket/chats.js.map +1 -1
- package/lib/Socket/communities.d.ts +56 -16
- package/lib/Socket/communities.d.ts.map +1 -1
- package/lib/Socket/communities.js +418 -466
- package/lib/Socket/communities.js.map +1 -1
- package/lib/Socket/groups.d.ts +32 -8
- package/lib/Socket/groups.d.ts.map +1 -1
- package/lib/Socket/groups.js +337 -390
- package/lib/Socket/groups.js.map +1 -1
- package/lib/Socket/index.d.ts +56 -16
- package/lib/Socket/index.d.ts.map +1 -1
- package/lib/Socket/index.js +10 -18
- package/lib/Socket/index.js.map +1 -1
- package/lib/Socket/messages-recv.d.ts +49 -19
- package/lib/Socket/messages-recv.d.ts.map +1 -1
- package/lib/Socket/messages-recv.js +1738 -1391
- package/lib/Socket/messages-recv.js.map +1 -1
- package/lib/Socket/messages-send.d.ts +45 -15
- package/lib/Socket/messages-send.d.ts.map +1 -1
- package/lib/Socket/messages-send.js +1101 -1242
- package/lib/Socket/messages-send.js.map +1 -1
- package/lib/Socket/mex.js +38 -48
- package/lib/Socket/newsletter.d.ts +30 -7
- package/lib/Socket/newsletter.d.ts.map +1 -1
- package/lib/Socket/newsletter.js +175 -222
- package/lib/Socket/newsletter.js.map +1 -1
- package/lib/Socket/socket.d.ts +15 -6
- package/lib/Socket/socket.d.ts.map +1 -1
- package/lib/Socket/socket.js +932 -913
- package/lib/Socket/socket.js.map +1 -1
- package/lib/Types/Auth.d.ts +12 -0
- package/lib/Types/Auth.d.ts.map +1 -1
- package/lib/Types/Auth.js +2 -3
- package/lib/Types/Bussines.js +2 -3
- package/lib/Types/Call.d.ts +2 -1
- package/lib/Types/Call.d.ts.map +1 -1
- package/lib/Types/Call.js +2 -3
- package/lib/Types/Chat.d.ts +1 -0
- package/lib/Types/Chat.d.ts.map +1 -1
- package/lib/Types/Chat.js +8 -5
- package/lib/Types/Contact.d.ts +2 -0
- package/lib/Types/Contact.d.ts.map +1 -1
- package/lib/Types/Contact.js +2 -3
- package/lib/Types/Events.d.ts +66 -9
- package/lib/Types/Events.d.ts.map +1 -1
- package/lib/Types/Events.js +2 -1
- package/lib/Types/GroupMetadata.d.ts +5 -0
- package/lib/Types/GroupMetadata.d.ts.map +1 -1
- package/lib/Types/GroupMetadata.js +2 -3
- package/lib/Types/Label.js +23 -26
- package/lib/Types/LabelAssociation.js +5 -8
- package/lib/Types/Message.d.ts +31 -11
- package/lib/Types/Message.d.ts.map +1 -1
- package/lib/Types/Message.js +9 -18
- package/lib/Types/Message.js.map +1 -1
- package/lib/Types/{Newsletter.d.ts → Mex.d.ts} +11 -5
- package/lib/Types/Mex.d.ts.map +1 -0
- package/lib/Types/Mex.js +37 -0
- package/lib/Types/Mex.js.map +1 -0
- package/lib/Types/Product.js +2 -3
- package/lib/Types/Signal.d.ts +21 -16
- package/lib/Types/Signal.d.ts.map +1 -1
- package/lib/Types/Signal.js +2 -1
- package/lib/Types/Socket.d.ts +23 -17
- package/lib/Types/Socket.d.ts.map +1 -1
- package/lib/Types/Socket.js +3 -2
- package/lib/Types/Socket.js.map +1 -1
- package/lib/Types/State.d.ts +58 -0
- package/lib/Types/State.d.ts.map +1 -1
- package/lib/Types/State.js +55 -15
- package/lib/Types/State.js.map +1 -1
- package/lib/Types/USync.js +2 -1
- package/lib/Types/index.d.ts +1 -1
- package/lib/Types/index.d.ts.map +1 -1
- package/lib/Types/index.js +25 -163
- package/lib/Types/index.js.map +1 -1
- package/lib/Utils/auth-utils.d.ts +7 -2
- package/lib/Utils/auth-utils.d.ts.map +1 -1
- package/lib/Utils/auth-utils.js +272 -458
- package/lib/Utils/auth-utils.js.map +1 -1
- package/lib/Utils/browser-utils.d.ts +4 -0
- package/lib/Utils/browser-utils.d.ts.map +1 -0
- package/lib/Utils/browser-utils.js +28 -0
- package/lib/Utils/browser-utils.js.map +1 -0
- package/lib/Utils/business.js +208 -221
- package/lib/Utils/chat-utils.d.ts +35 -6
- package/lib/Utils/chat-utils.d.ts.map +1 -1
- package/lib/Utils/chat-utils.js +828 -800
- package/lib/Utils/chat-utils.js.map +1 -1
- package/lib/Utils/companion-reg-client-utils.d.ts +17 -0
- package/lib/Utils/companion-reg-client-utils.d.ts.map +1 -0
- package/lib/Utils/companion-reg-client-utils.js +35 -0
- package/lib/Utils/companion-reg-client-utils.js.map +1 -0
- package/lib/Utils/crypto.d.ts +7 -11
- package/lib/Utils/crypto.d.ts.map +1 -1
- package/lib/Utils/crypto.js +88 -142
- package/lib/Utils/crypto.js.map +1 -1
- package/lib/Utils/decode-wa-message.d.ts +22 -2
- package/lib/Utils/decode-wa-message.d.ts.map +1 -1
- package/lib/Utils/decode-wa-message.js +293 -261
- package/lib/Utils/decode-wa-message.js.map +1 -1
- package/lib/Utils/event-buffer.d.ts +2 -0
- package/lib/Utils/event-buffer.d.ts.map +1 -1
- package/lib/Utils/event-buffer.js +599 -558
- package/lib/Utils/event-buffer.js.map +1 -1
- package/lib/Utils/generics.d.ts +6 -7
- package/lib/Utils/generics.d.ts.map +1 -1
- package/lib/Utils/generics.js +331 -362
- package/lib/Utils/generics.js.map +1 -1
- package/lib/Utils/history.d.ts +14 -10
- package/lib/Utils/history.d.ts.map +1 -1
- package/lib/Utils/history.js +129 -93
- package/lib/Utils/history.js.map +1 -1
- package/lib/Utils/identity-change-handler.d.ts +44 -0
- package/lib/Utils/identity-change-handler.d.ts.map +1 -0
- package/lib/Utils/identity-change-handler.js +50 -0
- package/lib/Utils/identity-change-handler.js.map +1 -0
- package/lib/Utils/index.d.ts +4 -4
- package/lib/Utils/index.d.ts.map +1 -1
- package/lib/Utils/index.js +22 -234
- package/lib/Utils/index.js.map +1 -1
- package/lib/Utils/link-preview.d.ts +1 -2
- package/lib/Utils/link-preview.d.ts.map +1 -1
- package/lib/Utils/link-preview.js +69 -83
- package/lib/Utils/link-preview.js.map +1 -1
- package/lib/Utils/logger.js +3 -9
- package/lib/Utils/lt-hash.d.ts +7 -12
- package/lib/Utils/lt-hash.d.ts.map +1 -1
- package/lib/Utils/lt-hash.js +3 -50
- package/lib/Utils/lt-hash.js.map +1 -1
- package/lib/Utils/make-mutex.d.ts +1 -0
- package/lib/Utils/make-mutex.d.ts.map +1 -1
- package/lib/Utils/make-mutex.js +30 -40
- package/lib/Utils/make-mutex.js.map +1 -1
- package/lib/Utils/message-retry-manager.d.ts +38 -5
- package/lib/Utils/message-retry-manager.d.ts.map +1 -1
- package/lib/Utils/message-retry-manager.js +259 -159
- package/lib/Utils/message-retry-manager.js.map +1 -1
- package/lib/Utils/messages-media.d.ts +30 -10
- package/lib/Utils/messages-media.d.ts.map +1 -1
- package/lib/Utils/messages-media.js +734 -710
- package/lib/Utils/messages-media.js.map +1 -1
- package/lib/Utils/messages.d.ts +19 -4
- package/lib/Utils/messages.d.ts.map +1 -1
- package/lib/Utils/messages.js +817 -800
- package/lib/Utils/messages.js.map +1 -1
- package/lib/Utils/noise-handler.d.ts +4 -4
- package/lib/Utils/noise-handler.d.ts.map +1 -1
- package/lib/Utils/noise-handler.js +195 -165
- package/lib/Utils/noise-handler.js.map +1 -1
- package/lib/Utils/offline-node-processor.d.ts +17 -0
- package/lib/Utils/offline-node-processor.d.ts.map +1 -0
- package/lib/Utils/offline-node-processor.js +40 -0
- package/lib/Utils/offline-node-processor.js.map +1 -0
- package/lib/Utils/pre-key-manager.d.ts +28 -0
- package/lib/Utils/pre-key-manager.d.ts.map +1 -0
- package/lib/Utils/pre-key-manager.js +106 -0
- package/lib/Utils/pre-key-manager.js.map +1 -0
- package/lib/Utils/process-message.d.ts +26 -9
- package/lib/Utils/process-message.d.ts.map +1 -1
- package/lib/Utils/process-message.js +601 -422
- package/lib/Utils/process-message.js.map +1 -1
- package/lib/Utils/reporting-utils.d.ts +11 -0
- package/lib/Utils/reporting-utils.d.ts.map +1 -0
- package/lib/Utils/reporting-utils.js +258 -0
- package/lib/Utils/reporting-utils.js.map +1 -0
- package/lib/Utils/signal.d.ts +17 -4
- package/lib/Utils/signal.d.ts.map +1 -1
- package/lib/Utils/signal.js +180 -203
- package/lib/Utils/signal.js.map +1 -1
- package/lib/Utils/stanza-ack.d.ts +11 -0
- package/lib/Utils/stanza-ack.d.ts.map +1 -0
- package/lib/Utils/stanza-ack.js +38 -0
- package/lib/Utils/stanza-ack.js.map +1 -0
- package/lib/Utils/sync-action-utils.d.ts +19 -0
- package/lib/Utils/sync-action-utils.d.ts.map +1 -0
- package/lib/Utils/sync-action-utils.js +49 -0
- package/lib/Utils/sync-action-utils.js.map +1 -0
- package/lib/Utils/tc-token-utils.d.ts +37 -0
- package/lib/Utils/tc-token-utils.d.ts.map +1 -0
- package/lib/Utils/tc-token-utils.js +163 -0
- package/lib/Utils/tc-token-utils.js.map +1 -0
- package/lib/Utils/use-multi-file-auth-state.js +98 -98
- package/lib/Utils/use-multi-file-auth-state.js.map +1 -1
- package/lib/Utils/validate-connection.d.ts.map +1 -1
- package/lib/Utils/validate-connection.js +191 -185
- package/lib/Utils/validate-connection.js.map +1 -1
- package/lib/WABinary/constants.js +1297 -35
- package/lib/WABinary/decode.d.ts.map +1 -1
- package/lib/WABinary/decode.js +254 -229
- package/lib/WABinary/decode.js.map +1 -1
- package/lib/WABinary/encode.js +210 -209
- package/lib/WABinary/encode.js.map +1 -1
- package/lib/WABinary/generic-utils.d.ts +1 -1
- package/lib/WABinary/generic-utils.d.ts.map +1 -1
- package/lib/WABinary/generic-utils.js +99 -105
- package/lib/WABinary/generic-utils.js.map +1 -1
- package/lib/WABinary/index.js +6 -58
- package/lib/WABinary/jid-utils.d.ts +12 -1
- package/lib/WABinary/jid-utils.d.ts.map +1 -1
- package/lib/WABinary/jid-utils.js +83 -67
- package/lib/WABinary/jid-utils.js.map +1 -1
- package/lib/WABinary/types.js +2 -2
- package/lib/WAM/BinaryInfo.js +9 -13
- package/lib/WAM/constants.d.ts +1 -1
- package/lib/WAM/constants.d.ts.map +1 -1
- package/lib/WAM/constants.js +22853 -1
- package/lib/WAM/constants.js.map +1 -1
- package/lib/WAM/encode.js +135 -132
- package/lib/WAM/index.js +4 -36
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts.map +1 -1
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +50 -31
- package/lib/WAUSync/Protocols/USyncContactProtocol.js.map +1 -1
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +50 -58
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +25 -29
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +35 -37
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts +4 -2
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +23 -27
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +47 -61
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +2 -1
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts.map +1 -1
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +27 -23
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js.map +1 -1
- package/lib/WAUSync/Protocols/index.d.ts.map +1 -1
- package/lib/WAUSync/Protocols/index.js +6 -58
- package/lib/WAUSync/Protocols/index.js.map +1 -1
- package/lib/WAUSync/USyncQuery.d.ts +1 -1
- package/lib/WAUSync/USyncQuery.d.ts.map +1 -1
- package/lib/WAUSync/USyncQuery.js +94 -94
- package/lib/WAUSync/USyncQuery.js.map +1 -1
- package/lib/WAUSync/USyncUser.d.ts +4 -0
- package/lib/WAUSync/USyncUser.d.ts.map +1 -1
- package/lib/WAUSync/USyncUser.js +30 -26
- package/lib/WAUSync/USyncUser.js.map +1 -1
- package/lib/WAUSync/index.js +4 -36
- package/lib/index.d.ts +0 -1
- package/lib/index.js +11 -112
- package/package.json +49 -22
- package/README.md +0 -1315
- package/lib/Signal/Group/queue-job.d.ts +0 -2
- package/lib/Signal/Group/queue-job.js +0 -59
- package/lib/Store/index.d.ts +0 -4
- package/lib/Store/index.js +0 -47
- package/lib/Store/make-cache-manager-store.d.ts +0 -17
- package/lib/Store/make-cache-manager-store.js +0 -104
- package/lib/Store/make-in-memory-store.d.ts +0 -118
- package/lib/Store/make-in-memory-store.js +0 -490
- package/lib/Store/make-ordered-dictionary.d.ts +0 -14
- package/lib/Store/make-ordered-dictionary.js +0 -81
- package/lib/Store/object-repository.d.ts +0 -10
- package/lib/Store/object-repository.js +0 -30
- package/lib/Types/Newsletter.d.ts.map +0 -1
- package/lib/Types/Newsletter.js +0 -34
- package/lib/Types/Newsletter.js.map +0 -1
- package/lib/Utils/baileys-event-stream.d.ts +0 -17
- package/lib/Utils/baileys-event-stream.d.ts.map +0 -1
- package/lib/Utils/baileys-event-stream.js +0 -71
- package/lib/Utils/baileys-event-stream.js.map +0 -1
- package/lib/Utils/extended-messages.d.ts +0 -73
- package/lib/Utils/extended-messages.js +0 -283
- package/lib/Utils/lid-resolver.d.ts +0 -17
- package/lib/Utils/lid-resolver.js +0 -79
- package/lib/Utils/mention.d.ts +0 -27
- package/lib/Utils/mention.js +0 -135
|
@@ -1,479 +1,431 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
}
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
upsertMessage
|
|
19
|
-
} = sock;
|
|
20
|
-
const communityQuery = async (jid, type, content) => query({
|
|
21
|
-
tag: 'iq',
|
|
22
|
-
attrs: {
|
|
23
|
-
type,
|
|
24
|
-
xmlns: 'w:g2',
|
|
25
|
-
to: jid
|
|
26
|
-
},
|
|
27
|
-
content
|
|
28
|
-
});
|
|
29
|
-
const communityMetadata = async jid => {
|
|
30
|
-
const result = await communityQuery(jid, 'get', [{
|
|
31
|
-
tag: 'query',
|
|
32
|
-
attrs: {
|
|
33
|
-
request: 'interactive'
|
|
34
|
-
}
|
|
35
|
-
}]);
|
|
36
|
-
return extractCommunityMetadata(result);
|
|
37
|
-
};
|
|
38
|
-
const communityFetchAllParticipating = async () => {
|
|
39
|
-
const result = await query({
|
|
40
|
-
tag: 'iq',
|
|
41
|
-
attrs: {
|
|
42
|
-
to: '@g.us',
|
|
43
|
-
xmlns: 'w:g2',
|
|
44
|
-
type: 'get'
|
|
45
|
-
},
|
|
46
|
-
content: [{
|
|
47
|
-
tag: 'participating',
|
|
48
|
-
attrs: {},
|
|
49
|
-
content: [{
|
|
50
|
-
tag: 'participants',
|
|
51
|
-
attrs: {}
|
|
52
|
-
}, {
|
|
53
|
-
tag: 'description',
|
|
54
|
-
attrs: {}
|
|
55
|
-
}]
|
|
56
|
-
}]
|
|
1
|
+
import { proto } from '../../WAProto/index.js';
|
|
2
|
+
import { WAMessageStubType } from '../Types/index.js';
|
|
3
|
+
import { generateMessageID, generateMessageIDV2, unixTimestampSeconds } from '../Utils/index.js';
|
|
4
|
+
import logger from '../Utils/logger.js';
|
|
5
|
+
import { getBinaryNodeChild, getBinaryNodeChildren, getBinaryNodeChildString, jidEncode, jidNormalizedUser } from '../WABinary/index.js';
|
|
6
|
+
import { makeBusinessSocket } from './business.js';
|
|
7
|
+
export const makeCommunitiesSocket = (config) => {
|
|
8
|
+
const sock = makeBusinessSocket(config);
|
|
9
|
+
const { authState, ev, query, upsertMessage } = sock;
|
|
10
|
+
const communityQuery = async (jid, type, content) => query({
|
|
11
|
+
tag: 'iq',
|
|
12
|
+
attrs: {
|
|
13
|
+
type,
|
|
14
|
+
xmlns: 'w:g2',
|
|
15
|
+
to: jid
|
|
16
|
+
},
|
|
17
|
+
content
|
|
57
18
|
});
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
const
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
19
|
+
const communityMetadata = async (jid) => {
|
|
20
|
+
const result = await communityQuery(jid, 'get', [{ tag: 'query', attrs: { request: 'interactive' } }]);
|
|
21
|
+
return extractCommunityMetadata(result);
|
|
22
|
+
};
|
|
23
|
+
const communityFetchAllParticipating = async () => {
|
|
24
|
+
const result = await query({
|
|
25
|
+
tag: 'iq',
|
|
26
|
+
attrs: {
|
|
27
|
+
to: '@g.us',
|
|
28
|
+
xmlns: 'w:g2',
|
|
29
|
+
type: 'get'
|
|
30
|
+
},
|
|
31
|
+
content: [
|
|
32
|
+
{
|
|
33
|
+
tag: 'participating',
|
|
34
|
+
attrs: {},
|
|
35
|
+
content: [
|
|
36
|
+
{ tag: 'participants', attrs: {} },
|
|
37
|
+
{ tag: 'description', attrs: {} }
|
|
38
|
+
]
|
|
39
|
+
}
|
|
40
|
+
]
|
|
67
41
|
});
|
|
68
|
-
data
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
42
|
+
const data = {};
|
|
43
|
+
const communitiesChild = getBinaryNodeChild(result, 'communities');
|
|
44
|
+
if (communitiesChild) {
|
|
45
|
+
const communities = getBinaryNodeChildren(communitiesChild, 'community');
|
|
46
|
+
for (const communityNode of communities) {
|
|
47
|
+
const meta = extractCommunityMetadata({
|
|
48
|
+
tag: 'result',
|
|
49
|
+
attrs: {},
|
|
50
|
+
content: [communityNode]
|
|
51
|
+
});
|
|
52
|
+
data[meta.id] = meta;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
sock.ev.emit('groups.update', Object.values(data));
|
|
56
|
+
return data;
|
|
57
|
+
};
|
|
58
|
+
async function parseGroupResult(node) {
|
|
59
|
+
logger.info({ node }, 'parseGroupResult');
|
|
60
|
+
const groupNode = getBinaryNodeChild(node, 'group');
|
|
61
|
+
if (groupNode) {
|
|
62
|
+
try {
|
|
63
|
+
logger.info({ groupNode }, 'groupNode');
|
|
64
|
+
const metadata = await sock.groupMetadata(`${groupNode.attrs.id}@g.us`);
|
|
65
|
+
return metadata ? metadata : Optional.empty();
|
|
66
|
+
}
|
|
67
|
+
catch (error) {
|
|
68
|
+
console.error('Error parsing group metadata:', error);
|
|
69
|
+
return Optional.empty();
|
|
70
|
+
}
|
|
71
|
+
}
|
|
88
72
|
return Optional.empty();
|
|
89
|
-
}
|
|
90
73
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
74
|
+
const Optional = {
|
|
75
|
+
empty: () => null,
|
|
76
|
+
of: (value) => (value !== null ? { value } : null)
|
|
77
|
+
};
|
|
78
|
+
sock.ws.on('CB:ib,,dirty', async (node) => {
|
|
79
|
+
const { attrs } = getBinaryNodeChild(node, 'dirty');
|
|
80
|
+
if (attrs.type !== 'communities') {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
await communityFetchAllParticipating();
|
|
84
|
+
await sock.cleanDirtyBits('groups');
|
|
85
|
+
});
|
|
86
|
+
return {
|
|
87
|
+
...sock,
|
|
88
|
+
communityMetadata,
|
|
89
|
+
communityCreate: async (subject, body) => {
|
|
90
|
+
const descriptionId = generateMessageID().substring(0, 12);
|
|
91
|
+
const result = await communityQuery('@g.us', 'set', [
|
|
92
|
+
{
|
|
93
|
+
tag: 'create',
|
|
94
|
+
attrs: { subject },
|
|
95
|
+
content: [
|
|
96
|
+
{
|
|
97
|
+
tag: 'description',
|
|
98
|
+
attrs: { id: descriptionId },
|
|
99
|
+
content: [
|
|
100
|
+
{
|
|
101
|
+
tag: 'body',
|
|
102
|
+
attrs: {},
|
|
103
|
+
content: Buffer.from(body || '', 'utf-8')
|
|
104
|
+
}
|
|
105
|
+
]
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
tag: 'parent',
|
|
109
|
+
attrs: { default_membership_approval_mode: 'request_required' }
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
tag: 'allow_non_admin_sub_group_creation',
|
|
113
|
+
attrs: {}
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
tag: 'create_general_chat',
|
|
117
|
+
attrs: {}
|
|
118
|
+
}
|
|
119
|
+
]
|
|
120
|
+
}
|
|
121
|
+
]);
|
|
122
|
+
return await parseGroupResult(result);
|
|
118
123
|
},
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
tag: 'create_general_chat',
|
|
139
|
-
attrs: {}
|
|
140
|
-
}]
|
|
141
|
-
}]);
|
|
142
|
-
return await parseGroupResult(result);
|
|
143
|
-
},
|
|
144
|
-
communityCreateGroup: async (subject, participants, parentCommunityJid) => {
|
|
145
|
-
const key = (0, _index3.generateMessageIDV2)();
|
|
146
|
-
const result = await communityQuery('@g.us', 'set', [{
|
|
147
|
-
tag: 'create',
|
|
148
|
-
attrs: {
|
|
149
|
-
subject,
|
|
150
|
-
key
|
|
124
|
+
communityCreateGroup: async (subject, participants, parentCommunityJid) => {
|
|
125
|
+
const key = generateMessageIDV2();
|
|
126
|
+
const result = await communityQuery('@g.us', 'set', [
|
|
127
|
+
{
|
|
128
|
+
tag: 'create',
|
|
129
|
+
attrs: {
|
|
130
|
+
subject,
|
|
131
|
+
key
|
|
132
|
+
},
|
|
133
|
+
content: [
|
|
134
|
+
...participants.map(jid => ({
|
|
135
|
+
tag: 'participant',
|
|
136
|
+
attrs: { jid }
|
|
137
|
+
})),
|
|
138
|
+
{ tag: 'linked_parent', attrs: { jid: parentCommunityJid } }
|
|
139
|
+
]
|
|
140
|
+
}
|
|
141
|
+
]);
|
|
142
|
+
return await parseGroupResult(result);
|
|
151
143
|
},
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
jid: parentCommunityJid
|
|
161
|
-
}
|
|
162
|
-
}]
|
|
163
|
-
}]);
|
|
164
|
-
return await parseGroupResult(result);
|
|
165
|
-
},
|
|
166
|
-
communityLeave: async id => {
|
|
167
|
-
await communityQuery('@g.us', 'set', [{
|
|
168
|
-
tag: 'leave',
|
|
169
|
-
attrs: {},
|
|
170
|
-
content: [{
|
|
171
|
-
tag: 'community',
|
|
172
|
-
attrs: {
|
|
173
|
-
id
|
|
174
|
-
}
|
|
175
|
-
}]
|
|
176
|
-
}]);
|
|
177
|
-
},
|
|
178
|
-
communityUpdateSubject: async (jid, subject) => {
|
|
179
|
-
await communityQuery(jid, 'set', [{
|
|
180
|
-
tag: 'subject',
|
|
181
|
-
attrs: {},
|
|
182
|
-
content: Buffer.from(subject, 'utf-8')
|
|
183
|
-
}]);
|
|
184
|
-
},
|
|
185
|
-
communityLinkGroup: async (groupJid, parentCommunityJid) => {
|
|
186
|
-
await communityQuery(parentCommunityJid, 'set', [{
|
|
187
|
-
tag: 'links',
|
|
188
|
-
attrs: {},
|
|
189
|
-
content: [{
|
|
190
|
-
tag: 'link',
|
|
191
|
-
attrs: {
|
|
192
|
-
link_type: 'sub_group'
|
|
193
|
-
},
|
|
194
|
-
content: [{
|
|
195
|
-
tag: 'group',
|
|
196
|
-
attrs: {
|
|
197
|
-
jid: groupJid
|
|
198
|
-
}
|
|
199
|
-
}]
|
|
200
|
-
}]
|
|
201
|
-
}]);
|
|
202
|
-
},
|
|
203
|
-
communityUnlinkGroup: async (groupJid, parentCommunityJid) => {
|
|
204
|
-
await communityQuery(parentCommunityJid, 'set', [{
|
|
205
|
-
tag: 'unlink',
|
|
206
|
-
attrs: {
|
|
207
|
-
unlink_type: 'sub_group'
|
|
144
|
+
communityLeave: async (id) => {
|
|
145
|
+
await communityQuery('@g.us', 'set', [
|
|
146
|
+
{
|
|
147
|
+
tag: 'leave',
|
|
148
|
+
attrs: {},
|
|
149
|
+
content: [{ tag: 'community', attrs: { id } }]
|
|
150
|
+
}
|
|
151
|
+
]);
|
|
208
152
|
},
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
153
|
+
communityUpdateSubject: async (jid, subject) => {
|
|
154
|
+
await communityQuery(jid, 'set', [
|
|
155
|
+
{
|
|
156
|
+
tag: 'subject',
|
|
157
|
+
attrs: {},
|
|
158
|
+
content: Buffer.from(subject, 'utf-8')
|
|
159
|
+
}
|
|
160
|
+
]);
|
|
161
|
+
},
|
|
162
|
+
communityLinkGroup: async (groupJid, parentCommunityJid) => {
|
|
163
|
+
await communityQuery(parentCommunityJid, 'set', [
|
|
164
|
+
{
|
|
165
|
+
tag: 'links',
|
|
166
|
+
attrs: {},
|
|
167
|
+
content: [
|
|
168
|
+
{
|
|
169
|
+
tag: 'link',
|
|
170
|
+
attrs: { link_type: 'sub_group' },
|
|
171
|
+
content: [{ tag: 'group', attrs: { jid: groupJid } }]
|
|
172
|
+
}
|
|
173
|
+
]
|
|
174
|
+
}
|
|
175
|
+
]);
|
|
176
|
+
},
|
|
177
|
+
communityUnlinkGroup: async (groupJid, parentCommunityJid) => {
|
|
178
|
+
await communityQuery(parentCommunityJid, 'set', [
|
|
179
|
+
{
|
|
180
|
+
tag: 'unlink',
|
|
181
|
+
attrs: { unlink_type: 'sub_group' },
|
|
182
|
+
content: [{ tag: 'group', attrs: { jid: groupJid } }]
|
|
183
|
+
}
|
|
184
|
+
]);
|
|
185
|
+
},
|
|
186
|
+
communityFetchLinkedGroups: async (jid) => {
|
|
187
|
+
let communityJid = jid;
|
|
188
|
+
let isCommunity = false;
|
|
189
|
+
// Try to determine if it is a subgroup or a community
|
|
190
|
+
const metadata = await sock.groupMetadata(jid);
|
|
191
|
+
if (metadata.linkedParent) {
|
|
192
|
+
// It is a subgroup, get the community jid
|
|
193
|
+
communityJid = metadata.linkedParent;
|
|
237
194
|
}
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
const participantsAffected = (0, _index4.getBinaryNodeChildren)(node, 'participant');
|
|
264
|
-
return participantsAffected.map(p => {
|
|
265
|
-
return {
|
|
266
|
-
status: p.attrs.error || '200',
|
|
267
|
-
jid: p.attrs.jid,
|
|
268
|
-
content: p
|
|
269
|
-
};
|
|
270
|
-
});
|
|
271
|
-
},
|
|
272
|
-
communityUpdateDescription: async (jid, description) => {
|
|
273
|
-
const metadata = await communityMetadata(jid);
|
|
274
|
-
const prev = metadata.descId ?? null;
|
|
275
|
-
await communityQuery(jid, 'set', [{
|
|
276
|
-
tag: 'description',
|
|
277
|
-
attrs: {
|
|
278
|
-
...(description ? {
|
|
279
|
-
id: (0, _index3.generateMessageID)()
|
|
280
|
-
} : {
|
|
281
|
-
delete: 'true'
|
|
282
|
-
}),
|
|
283
|
-
...(prev ? {
|
|
284
|
-
prev
|
|
285
|
-
} : {})
|
|
195
|
+
else {
|
|
196
|
+
// It is a community
|
|
197
|
+
isCommunity = true;
|
|
198
|
+
}
|
|
199
|
+
// Fetch all subgroups of the community
|
|
200
|
+
const result = await communityQuery(communityJid, 'get', [{ tag: 'sub_groups', attrs: {} }]);
|
|
201
|
+
const linkedGroupsData = [];
|
|
202
|
+
const subGroupsNode = getBinaryNodeChild(result, 'sub_groups');
|
|
203
|
+
if (subGroupsNode) {
|
|
204
|
+
const groupNodes = getBinaryNodeChildren(subGroupsNode, 'group');
|
|
205
|
+
for (const groupNode of groupNodes) {
|
|
206
|
+
linkedGroupsData.push({
|
|
207
|
+
id: groupNode.attrs.id ? jidEncode(groupNode.attrs.id, 'g.us') : undefined,
|
|
208
|
+
subject: groupNode.attrs.subject || '',
|
|
209
|
+
creation: groupNode.attrs.creation ? Number(groupNode.attrs.creation) : undefined,
|
|
210
|
+
owner: groupNode.attrs.creator ? jidNormalizedUser(groupNode.attrs.creator) : undefined,
|
|
211
|
+
size: groupNode.attrs.size ? Number(groupNode.attrs.size) : undefined
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
return {
|
|
216
|
+
communityJid,
|
|
217
|
+
isCommunity,
|
|
218
|
+
linkedGroups: linkedGroupsData
|
|
219
|
+
};
|
|
286
220
|
},
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
221
|
+
communityRequestParticipantsList: async (jid) => {
|
|
222
|
+
const result = await communityQuery(jid, 'get', [
|
|
223
|
+
{
|
|
224
|
+
tag: 'membership_approval_requests',
|
|
225
|
+
attrs: {}
|
|
226
|
+
}
|
|
227
|
+
]);
|
|
228
|
+
const node = getBinaryNodeChild(result, 'membership_approval_requests');
|
|
229
|
+
const participants = getBinaryNodeChildren(node, 'membership_approval_request');
|
|
230
|
+
return participants.map(v => v.attrs);
|
|
231
|
+
},
|
|
232
|
+
communityRequestParticipantsUpdate: async (jid, participants, action) => {
|
|
233
|
+
const result = await communityQuery(jid, 'set', [
|
|
234
|
+
{
|
|
235
|
+
tag: 'membership_requests_action',
|
|
236
|
+
attrs: {},
|
|
237
|
+
content: [
|
|
238
|
+
{
|
|
239
|
+
tag: action,
|
|
240
|
+
attrs: {},
|
|
241
|
+
content: participants.map(jid => ({
|
|
242
|
+
tag: 'participant',
|
|
243
|
+
attrs: { jid }
|
|
244
|
+
}))
|
|
245
|
+
}
|
|
246
|
+
]
|
|
247
|
+
}
|
|
248
|
+
]);
|
|
249
|
+
const node = getBinaryNodeChild(result, 'membership_requests_action');
|
|
250
|
+
const nodeAction = getBinaryNodeChild(node, action);
|
|
251
|
+
const participantsAffected = getBinaryNodeChildren(nodeAction, 'participant');
|
|
252
|
+
return participantsAffected.map(p => {
|
|
253
|
+
return { status: p.attrs.error || '200', jid: p.attrs.jid };
|
|
254
|
+
});
|
|
255
|
+
},
|
|
256
|
+
communityParticipantsUpdate: async (jid, participants, action) => {
|
|
257
|
+
const result = await communityQuery(jid, 'set', [
|
|
258
|
+
{
|
|
259
|
+
tag: action,
|
|
260
|
+
attrs: action === 'remove' ? { linked_groups: 'true' } : {},
|
|
261
|
+
content: participants.map(jid => ({
|
|
262
|
+
tag: 'participant',
|
|
263
|
+
attrs: { jid }
|
|
264
|
+
}))
|
|
265
|
+
}
|
|
266
|
+
]);
|
|
267
|
+
const node = getBinaryNodeChild(result, action);
|
|
268
|
+
const participantsAffected = getBinaryNodeChildren(node, 'participant');
|
|
269
|
+
return participantsAffected.map(p => {
|
|
270
|
+
return { status: p.attrs.error || '200', jid: p.attrs.jid, content: p };
|
|
271
|
+
});
|
|
272
|
+
},
|
|
273
|
+
communityUpdateDescription: async (jid, description) => {
|
|
274
|
+
const metadata = await communityMetadata(jid);
|
|
275
|
+
const prev = metadata.descId ?? null;
|
|
276
|
+
await communityQuery(jid, 'set', [
|
|
277
|
+
{
|
|
278
|
+
tag: 'description',
|
|
279
|
+
attrs: {
|
|
280
|
+
...(description ? { id: generateMessageID() } : { delete: 'true' }),
|
|
281
|
+
...(prev ? { prev } : {})
|
|
282
|
+
},
|
|
283
|
+
content: description ? [{ tag: 'body', attrs: {}, content: Buffer.from(description, 'utf-8') }] : undefined
|
|
284
|
+
}
|
|
285
|
+
]);
|
|
286
|
+
},
|
|
287
|
+
communityInviteCode: async (jid) => {
|
|
288
|
+
const result = await communityQuery(jid, 'get', [{ tag: 'invite', attrs: {} }]);
|
|
289
|
+
const inviteNode = getBinaryNodeChild(result, 'invite');
|
|
290
|
+
return inviteNode?.attrs.code;
|
|
291
|
+
},
|
|
292
|
+
communityRevokeInvite: async (jid) => {
|
|
293
|
+
const result = await communityQuery(jid, 'set', [{ tag: 'invite', attrs: {} }]);
|
|
294
|
+
const inviteNode = getBinaryNodeChild(result, 'invite');
|
|
295
|
+
return inviteNode?.attrs.code;
|
|
296
|
+
},
|
|
297
|
+
communityAcceptInvite: async (code) => {
|
|
298
|
+
const results = await communityQuery('@g.us', 'set', [{ tag: 'invite', attrs: { code } }]);
|
|
299
|
+
const result = getBinaryNodeChild(results, 'community');
|
|
300
|
+
return result?.attrs.jid;
|
|
301
|
+
},
|
|
302
|
+
/**
|
|
303
|
+
* revoke a v4 invite for someone
|
|
304
|
+
* @param communityJid community jid
|
|
305
|
+
* @param invitedJid jid of person you invited
|
|
306
|
+
* @returns true if successful
|
|
307
|
+
*/
|
|
308
|
+
communityRevokeInviteV4: async (communityJid, invitedJid) => {
|
|
309
|
+
const result = await communityQuery(communityJid, 'set', [
|
|
310
|
+
{ tag: 'revoke', attrs: {}, content: [{ tag: 'participant', attrs: { jid: invitedJid } }] }
|
|
311
|
+
]);
|
|
312
|
+
return !!result;
|
|
313
|
+
},
|
|
314
|
+
/**
|
|
315
|
+
* accept a CommunityInviteMessage
|
|
316
|
+
* @param key the key of the invite message, or optionally only provide the jid of the person who sent the invite
|
|
317
|
+
* @param inviteMessage the message to accept
|
|
318
|
+
*/
|
|
319
|
+
communityAcceptInviteV4: ev.createBufferedFunction(async (key, inviteMessage) => {
|
|
320
|
+
key = typeof key === 'string' ? { remoteJid: key } : key;
|
|
321
|
+
const results = await communityQuery(inviteMessage.groupJid, 'set', [
|
|
322
|
+
{
|
|
323
|
+
tag: 'accept',
|
|
324
|
+
attrs: {
|
|
325
|
+
code: inviteMessage.inviteCode,
|
|
326
|
+
expiration: inviteMessage.inviteExpiration.toString(),
|
|
327
|
+
admin: key.remoteJid
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
]);
|
|
331
|
+
// if we have the full message key
|
|
332
|
+
// update the invite message to be expired
|
|
333
|
+
if (key.id) {
|
|
334
|
+
// create new invite message that is expired
|
|
335
|
+
inviteMessage = proto.Message.GroupInviteMessage.fromObject(inviteMessage);
|
|
336
|
+
inviteMessage.inviteExpiration = 0;
|
|
337
|
+
inviteMessage.inviteCode = '';
|
|
338
|
+
ev.emit('messages.update', [
|
|
339
|
+
{
|
|
340
|
+
key,
|
|
341
|
+
update: {
|
|
342
|
+
message: {
|
|
343
|
+
groupInviteMessage: inviteMessage
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
]);
|
|
368
348
|
}
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
349
|
+
// generate the community add message
|
|
350
|
+
await upsertMessage({
|
|
351
|
+
key: {
|
|
352
|
+
remoteJid: inviteMessage.groupJid,
|
|
353
|
+
id: generateMessageIDV2(sock.user?.id),
|
|
354
|
+
fromMe: false,
|
|
355
|
+
participant: key.remoteJid // TODO: investigate if this makes any sense at all
|
|
356
|
+
},
|
|
357
|
+
messageStubType: WAMessageStubType.GROUP_PARTICIPANT_ADD,
|
|
358
|
+
messageStubParameters: [JSON.stringify(authState.creds.me)],
|
|
359
|
+
participant: key.remoteJid,
|
|
360
|
+
messageTimestamp: unixTimestampSeconds()
|
|
361
|
+
}, 'notify');
|
|
362
|
+
return results.attrs.from;
|
|
363
|
+
}),
|
|
364
|
+
communityGetInviteInfo: async (code) => {
|
|
365
|
+
const results = await communityQuery('@g.us', 'get', [{ tag: 'invite', attrs: { code } }]);
|
|
366
|
+
return extractCommunityMetadata(results);
|
|
379
367
|
},
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
attrs: {
|
|
400
|
-
expiration: ephemeralExpiration.toString()
|
|
401
|
-
}
|
|
402
|
-
} : {
|
|
403
|
-
tag: 'not_ephemeral',
|
|
404
|
-
attrs: {}
|
|
405
|
-
};
|
|
406
|
-
await communityQuery(jid, 'set', [content]);
|
|
407
|
-
},
|
|
408
|
-
communitySettingUpdate: async (jid, setting) => {
|
|
409
|
-
await communityQuery(jid, 'set', [{
|
|
410
|
-
tag: setting,
|
|
411
|
-
attrs: {}
|
|
412
|
-
}]);
|
|
413
|
-
},
|
|
414
|
-
communityMemberAddMode: async (jid, mode) => {
|
|
415
|
-
await communityQuery(jid, 'set', [{
|
|
416
|
-
tag: 'member_add_mode',
|
|
417
|
-
attrs: {},
|
|
418
|
-
content: mode
|
|
419
|
-
}]);
|
|
420
|
-
},
|
|
421
|
-
communityJoinApprovalMode: async (jid, mode) => {
|
|
422
|
-
await communityQuery(jid, 'set', [{
|
|
423
|
-
tag: 'membership_approval_mode',
|
|
424
|
-
attrs: {},
|
|
425
|
-
content: [{
|
|
426
|
-
tag: 'community_join',
|
|
427
|
-
attrs: {
|
|
428
|
-
state: mode
|
|
429
|
-
}
|
|
430
|
-
}]
|
|
431
|
-
}]);
|
|
432
|
-
},
|
|
433
|
-
communityFetchAllParticipating
|
|
434
|
-
};
|
|
368
|
+
communityToggleEphemeral: async (jid, ephemeralExpiration) => {
|
|
369
|
+
const content = ephemeralExpiration
|
|
370
|
+
? { tag: 'ephemeral', attrs: { expiration: ephemeralExpiration.toString() } }
|
|
371
|
+
: { tag: 'not_ephemeral', attrs: {} };
|
|
372
|
+
await communityQuery(jid, 'set', [content]);
|
|
373
|
+
},
|
|
374
|
+
communitySettingUpdate: async (jid, setting) => {
|
|
375
|
+
await communityQuery(jid, 'set', [{ tag: setting, attrs: {} }]);
|
|
376
|
+
},
|
|
377
|
+
communityMemberAddMode: async (jid, mode) => {
|
|
378
|
+
await communityQuery(jid, 'set', [{ tag: 'member_add_mode', attrs: {}, content: mode }]);
|
|
379
|
+
},
|
|
380
|
+
communityJoinApprovalMode: async (jid, mode) => {
|
|
381
|
+
await communityQuery(jid, 'set', [
|
|
382
|
+
{ tag: 'membership_approval_mode', attrs: {}, content: [{ tag: 'community_join', attrs: { state: mode } }] }
|
|
383
|
+
]);
|
|
384
|
+
},
|
|
385
|
+
communityFetchAllParticipating
|
|
386
|
+
};
|
|
435
387
|
};
|
|
436
|
-
|
|
437
|
-
const
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
388
|
+
export const extractCommunityMetadata = (result) => {
|
|
389
|
+
const community = getBinaryNodeChild(result, 'community');
|
|
390
|
+
const descChild = getBinaryNodeChild(community, 'description');
|
|
391
|
+
let desc;
|
|
392
|
+
let descId;
|
|
393
|
+
if (descChild) {
|
|
394
|
+
desc = getBinaryNodeChildString(descChild, 'body');
|
|
395
|
+
descId = descChild.attrs.id;
|
|
396
|
+
}
|
|
397
|
+
const communityId = community.attrs.id?.includes('@')
|
|
398
|
+
? community.attrs.id
|
|
399
|
+
: jidEncode(community.attrs.id || '', 'g.us');
|
|
400
|
+
const eph = getBinaryNodeChild(community, 'ephemeral')?.attrs.expiration;
|
|
401
|
+
const memberAddMode = getBinaryNodeChildString(community, 'member_add_mode') === 'all_member_add';
|
|
402
|
+
const metadata = {
|
|
403
|
+
id: communityId,
|
|
404
|
+
subject: community.attrs.subject || '',
|
|
405
|
+
subjectOwner: community.attrs.s_o,
|
|
406
|
+
subjectTime: Number(community.attrs.s_t || 0),
|
|
407
|
+
size: getBinaryNodeChildren(community, 'participant').length,
|
|
408
|
+
creation: Number(community.attrs.creation || 0),
|
|
409
|
+
owner: community.attrs.creator ? jidNormalizedUser(community.attrs.creator) : undefined,
|
|
410
|
+
desc,
|
|
411
|
+
descId,
|
|
412
|
+
linkedParent: getBinaryNodeChild(community, 'linked_parent')?.attrs.jid || undefined,
|
|
413
|
+
restrict: !!getBinaryNodeChild(community, 'locked'),
|
|
414
|
+
announce: !!getBinaryNodeChild(community, 'announcement'),
|
|
415
|
+
isCommunity: !!getBinaryNodeChild(community, 'parent'),
|
|
416
|
+
isCommunityAnnounce: !!getBinaryNodeChild(community, 'default_sub_community'),
|
|
417
|
+
joinApprovalMode: !!getBinaryNodeChild(community, 'membership_approval_mode'),
|
|
418
|
+
memberAddMode,
|
|
419
|
+
participants: getBinaryNodeChildren(community, 'participant').map(({ attrs }) => {
|
|
420
|
+
return {
|
|
421
|
+
// TODO: IMPLEMENT THE PN/LID FIELDS HERE!!
|
|
422
|
+
id: attrs.jid,
|
|
423
|
+
admin: (attrs.type || null)
|
|
424
|
+
};
|
|
425
|
+
}),
|
|
426
|
+
ephemeralDuration: eph ? +eph : undefined,
|
|
427
|
+
addressingMode: getBinaryNodeChildString(community, 'addressing_mode')
|
|
428
|
+
};
|
|
429
|
+
return metadata;
|
|
478
430
|
};
|
|
479
|
-
|
|
431
|
+
//# sourceMappingURL=communities.js.map
|