@oxidezap/baileyrs 0.3.18 → 0.4.1
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/README.md +20 -4
- package/lib/Bridge/schema.js +4 -0
- package/lib/Compatibility/field-aliases.d.ts +7 -0
- package/lib/Compatibility/field-aliases.js +12 -0
- package/lib/Compatibility/legacy-store/adapter.js +56 -20
- package/lib/Compatibility/legacy-store/multi-file.js +1 -0
- package/lib/Compatibility/legacy-store/routing.d.ts +1 -0
- package/lib/Compatibility/legacy-store/routing.js +7 -0
- package/lib/Compatibility/legacy-store/snapshot.js +20 -1
- package/lib/Compatibility/legacy-store/types.d.ts +2 -0
- package/lib/Compatibility/proto-runtime.js +39 -14
- package/lib/Media/content.js +41 -23
- package/lib/Socket/core.js +2 -1
- package/lib/Socket/events-core.js +10 -1
- package/lib/Socket/messages-core.js +12 -5
- package/lib/Socket/unsupported-config.d.ts +2 -2
- package/lib/Socket/unsupported-config.js +1 -2
- package/lib/Types/Auth.d.ts +1 -0
- package/lib/Types/Message.d.ts +10 -0
- package/lib/Utils/atomic-store.d.ts +6 -5
- package/lib/Utils/atomic-store.js +36 -1
- package/lib/Utils/messages-core.d.ts +3 -16
- package/lib/Utils/messages-core.js +50 -130
- package/lib/Utils/transactional-file-store.js +1 -0
- package/lib/Utils/use-memory-store.js +11 -1
- package/lib/WAProto/compatibility-schema.d.ts +7 -1
- package/lib/WAProto/compatibility-schema.js +75 -4
- package/lib/WAProto/runtime.d.ts +12721 -3769
- package/lib/host-types.d.ts +1 -0
- package/package.json +8 -8
package/lib/Types/Message.d.ts
CHANGED
|
@@ -147,6 +147,14 @@ type SharePhoneNumber = {
|
|
|
147
147
|
type RequestPhoneNumber = {
|
|
148
148
|
requestPhoneNumber: boolean;
|
|
149
149
|
};
|
|
150
|
+
export type StickerAudioContent = WAMediaUpload | {
|
|
151
|
+
media: WAMediaUpload;
|
|
152
|
+
mimetype?: string;
|
|
153
|
+
seconds?: number;
|
|
154
|
+
ptt?: boolean;
|
|
155
|
+
waveform?: Uint8Array;
|
|
156
|
+
backgroundArgb?: number;
|
|
157
|
+
};
|
|
150
158
|
export type AnyMediaMessageContent = (({
|
|
151
159
|
image: WAMediaUpload;
|
|
152
160
|
caption?: string;
|
|
@@ -167,6 +175,8 @@ export type AnyMediaMessageContent = (({
|
|
|
167
175
|
} | ({
|
|
168
176
|
sticker: WAMediaUpload;
|
|
169
177
|
isAnimated?: boolean;
|
|
178
|
+
/** Optional audio track to send as an audio sticker (`audioStickerMessage`). */
|
|
179
|
+
audio?: StickerAudioContent;
|
|
170
180
|
} & WithDimensions) | ({
|
|
171
181
|
document: WAMediaUpload;
|
|
172
182
|
mimetype: string;
|
|
@@ -1,21 +1,22 @@
|
|
|
1
1
|
import type { JsStoreCallbacks } from '@oxidezap/whatsapp-rust-bridge';
|
|
2
|
-
export type AtomicStoreCallbacks = Pick<JsStoreCallbacks, 'commitPatch' | 'touchTcTokenSenderTimestamp' | 'storeReceivedTcToken'>;
|
|
2
|
+
export type AtomicStoreCallbacks = Pick<JsStoreCallbacks, 'commitPatch' | 'commitSnapshot' | 'touchTcTokenSenderTimestamp' | 'storeReceivedTcToken'>;
|
|
3
3
|
export type OrdinaryStoreCallbacks = Omit<JsStoreCallbacks, keyof AtomicStoreCallbacks> & {
|
|
4
4
|
flush?(): Promise<void>;
|
|
5
5
|
};
|
|
6
6
|
export type AtomicRows = Map<string, Uint8Array>;
|
|
7
7
|
/**
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* stages the writes, so a change costs the rows it touches.
|
|
8
|
+
* A transaction view can stage writes against its own rows instead of copying
|
|
9
|
+
* the whole store into an `AtomicRows` map.
|
|
11
10
|
*/
|
|
12
11
|
export interface AtomicRowView {
|
|
13
12
|
get(key: string): Uint8Array | undefined;
|
|
14
13
|
has(key: string): boolean;
|
|
15
14
|
set(key: string, value: Uint8Array): unknown;
|
|
16
15
|
delete(key: string): boolean;
|
|
16
|
+
deletePrefix(store: string, prefix: string): void;
|
|
17
17
|
}
|
|
18
18
|
export declare const rowKey: (store: string, key: string) => string;
|
|
19
|
+
export declare const rowPrefix: (store: string, prefix: string) => string;
|
|
19
20
|
export declare const signedTimestamp: (value: string) => bigint;
|
|
20
21
|
export type TokenRow = {
|
|
21
22
|
token: number[];
|
|
@@ -25,7 +26,7 @@ export type TokenRow = {
|
|
|
25
26
|
export declare const decodeTokenRow: (bytes: Uint8Array) => TokenRow;
|
|
26
27
|
export declare const encodeTokenRow: (row: TokenRow) => Uint8Array;
|
|
27
28
|
/** The caller supplies a real transaction covering all reads and writes. */
|
|
28
|
-
export declare const atomicCallbacks: (transaction: (change: (rows: AtomicRowView) => void) => Promise<void>) => AtomicStoreCallbacks;
|
|
29
|
+
export declare const atomicCallbacks: (transaction: (change: (rows: AtomicRows | AtomicRowView) => void) => Promise<void>) => AtomicStoreCallbacks;
|
|
29
30
|
/** Validate migration requirements before hydration or other storage I/O. */
|
|
30
31
|
export declare function assertStoreCallbacks(store: unknown): asserts store is JsStoreCallbacks;
|
|
31
32
|
//# sourceMappingURL=atomic-store.d.ts.map
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
export const rowKey = (store, key) => JSON.stringify([store, key]);
|
|
2
|
+
// Canonical row keys encode a JSON tuple. The closing quote and bracket end the key.
|
|
3
|
+
export const rowPrefix = (store, prefix) => rowKey(store, prefix).slice(0, -2);
|
|
2
4
|
const encode = (value) => new TextEncoder().encode(JSON.stringify(value));
|
|
3
5
|
const decode = (value) => JSON.parse(new TextDecoder().decode(value));
|
|
4
6
|
export const signedTimestamp = (value) => {
|
|
@@ -65,6 +67,38 @@ export const atomicCallbacks = (transaction) => ({
|
|
|
65
67
|
}
|
|
66
68
|
});
|
|
67
69
|
},
|
|
70
|
+
async commitSnapshot(name, state, entries, maintainIndex) {
|
|
71
|
+
const version = Uint8Array.from(state);
|
|
72
|
+
const prefix = `${name}:`;
|
|
73
|
+
const replacement = entries.map(([key, bytes]) => {
|
|
74
|
+
if (!key.startsWith(prefix))
|
|
75
|
+
throw new TypeError('snapshot MAC key must belong to its collection');
|
|
76
|
+
return [key, Uint8Array.from(bytes)];
|
|
77
|
+
});
|
|
78
|
+
await transaction(rows => {
|
|
79
|
+
if (rows instanceof Map) {
|
|
80
|
+
const encodedPrefix = rowPrefix('mutation_mac', prefix);
|
|
81
|
+
for (const key of rows.keys())
|
|
82
|
+
if (key.startsWith(encodedPrefix))
|
|
83
|
+
rows.delete(key);
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
rows.deletePrefix('mutation_mac', prefix);
|
|
87
|
+
}
|
|
88
|
+
for (const [key, bytes] of replacement)
|
|
89
|
+
rows.set(rowKey('mutation_mac', key), bytes);
|
|
90
|
+
rows.set(rowKey('sync_version', name), version);
|
|
91
|
+
if (maintainIndex) {
|
|
92
|
+
const index = readIndex(rows, 'mutation_mac_keys');
|
|
93
|
+
for (const key of index)
|
|
94
|
+
if (key.startsWith(prefix))
|
|
95
|
+
index.delete(key);
|
|
96
|
+
for (const [key] of replacement)
|
|
97
|
+
index.add(key);
|
|
98
|
+
rows.set(rowKey('meta', 'mutation_mac_keys'), encode([...index]));
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
},
|
|
68
102
|
touchTcTokenSenderTimestamp(jid, timestamp) {
|
|
69
103
|
const incoming = signedTimestamp(timestamp);
|
|
70
104
|
return transaction(rows => {
|
|
@@ -106,11 +140,12 @@ export function assertStoreCallbacks(store) {
|
|
|
106
140
|
'set',
|
|
107
141
|
'delete',
|
|
108
142
|
'commitPatch',
|
|
143
|
+
'commitSnapshot',
|
|
109
144
|
'touchTcTokenSenderTimestamp',
|
|
110
145
|
'storeReceivedTcToken'
|
|
111
146
|
]) {
|
|
112
147
|
if (typeof store[method] !== 'function')
|
|
113
|
-
throw new TypeError(`auth store requires ${method};
|
|
148
|
+
throw new TypeError(`auth store requires ${method}; implement the bridge storage callbacks or use useMemoryStore()`);
|
|
114
149
|
}
|
|
115
150
|
}
|
|
116
151
|
//# sourceMappingURL=atomic-store.js.map
|
|
@@ -6,6 +6,7 @@ import { type MediaType } from '../Defaults/index.js';
|
|
|
6
6
|
import type { AnyMediaMessageContent, AnyMessageContent, MessageContentGenerationOptions, MessageGenerationOptions, MessageGenerationOptionsFromContent, MessageUserReceipt, WAMessage, WAMessageContent, WAMessageKey } from '../Types/index.js';
|
|
7
7
|
import { WAProto } from '../Types/index.js';
|
|
8
8
|
import { proto } from '../WAProto/runtime.js';
|
|
9
|
+
import { extractMessageContent, getContentType, normalizeMessageContent } from '../Media/content.js';
|
|
9
10
|
import type { ILogger } from './logger.js';
|
|
10
11
|
import { type MediaDownloadOptions } from './messages-media-core.js';
|
|
11
12
|
type ExtractByKey<T, K extends PropertyKey> = T extends Record<K, unknown> ? T : never;
|
|
@@ -16,7 +17,7 @@ type ExtractByKey<T, K extends PropertyKey> = T extends Record<K, unknown> ? T :
|
|
|
16
17
|
*/
|
|
17
18
|
export declare const extractUrlFromText: (text: string) => string | undefined;
|
|
18
19
|
export declare const generateLinkPreviewIfRequired: (text: string, getUrlInfo: MessageGenerationOptions['getUrlInfo'], logger: MessageGenerationOptions['logger']) => Promise<import("../index.js").WAUrlInfo | undefined>;
|
|
19
|
-
export declare const prepareWAMessageMedia: (message: AnyMediaMessageContent, options: MessageContentGenerationOptions) => Promise<
|
|
20
|
+
export declare const prepareWAMessageMedia: (message: AnyMediaMessageContent, options: MessageContentGenerationOptions) => Promise<proto.Message>;
|
|
20
21
|
export declare const prepareDisappearingMessageSettingContent: (ephemeralExpiration?: number) => WAProto.Message;
|
|
21
22
|
/**
|
|
22
23
|
* Generate forwarded message content like WA does
|
|
@@ -34,20 +35,7 @@ type RuntimeLongOptions = {
|
|
|
34
35
|
export declare const generateWAMessageContent: (message: AnyMessageContent, options: MessageContentGenerationOptions & RuntimeRandomOptions) => Promise<WAProto.Message>;
|
|
35
36
|
export declare const generateWAMessageFromContent: (jid: string, message: WAMessageContent, options: MessageGenerationOptionsFromContent & RuntimeLongOptions) => WAMessage;
|
|
36
37
|
export declare const generateWAMessage: (jid: string, content: AnyMessageContent, options: MessageGenerationOptions & RuntimeRandomOptions & RuntimeLongOptions) => Promise<WAMessage>;
|
|
37
|
-
|
|
38
|
-
export declare const getContentType: (content: proto.IMessage | undefined) => keyof WAProto.IMessage | undefined;
|
|
39
|
-
/**
|
|
40
|
-
* Normalizes ephemeral, view once messages to regular message content
|
|
41
|
-
* Eg. image messages in ephemeral messages, in view once messages etc.
|
|
42
|
-
* @param content
|
|
43
|
-
* @returns
|
|
44
|
-
*/
|
|
45
|
-
export declare const normalizeMessageContent: (content: WAMessageContent | null | undefined) => WAMessageContent | undefined;
|
|
46
|
-
/**
|
|
47
|
-
* Extract the true message content from a message
|
|
48
|
-
* Eg. extracts the inner message from a disappearing message/view once message
|
|
49
|
-
*/
|
|
50
|
-
export declare const extractMessageContent: (content: WAMessageContent | undefined | null) => WAMessageContent | undefined;
|
|
38
|
+
export { extractMessageContent, getContentType, normalizeMessageContent };
|
|
51
39
|
/**
|
|
52
40
|
* Every field is optional, so upstream's `{ reuploadRequest, logger }` and this
|
|
53
41
|
* package's `{ waClient }` are both accepted.
|
|
@@ -170,5 +158,4 @@ export declare const updateMessageWithPollUpdate: (msg: Pick<WAMessage, 'pollUpd
|
|
|
170
158
|
export declare const updateMessageWithEventResponse: (msg: Pick<WAMessage, 'eventResponses'>, update: proto.IEventResponse) => void;
|
|
171
159
|
/** Checks whether the message contains one of the upstream media payloads. */
|
|
172
160
|
export declare const assertMediaContent: (content: proto.IMessage | null | undefined) => WAProto.Message.IAudioMessage | WAProto.Message.IDocumentMessage | WAProto.Message.IImageMessage | WAProto.Message.IStickerMessage | WAProto.Message.IVideoMessage;
|
|
173
|
-
export {};
|
|
174
161
|
//# sourceMappingURL=messages-core.d.ts.map
|
|
@@ -9,6 +9,7 @@ import { assertArgumentDomain } from './argument-domain.js';
|
|
|
9
9
|
import { Boom } from './boom.js';
|
|
10
10
|
import { getKeyAuthorPortable, randomBytes, sha256Sync, toNumber, unixTimestampSeconds, utf8Encode, hexEncode } from '../Runtime/bytes.js';
|
|
11
11
|
import { readableFromWeb } from '../Runtime/stream.js';
|
|
12
|
+
import { extractMessageContent, getContentType, normalizeMessageContent } from '../Media/content.js';
|
|
12
13
|
import { generateThumbnail, getAudioDuration, getAudioWaveform, getStream, toBuffer } from './messages-media-core.js';
|
|
13
14
|
const MIMETYPE_MAP = {
|
|
14
15
|
image: 'image/jpeg',
|
|
@@ -56,7 +57,31 @@ const assertColor = (color) => {
|
|
|
56
57
|
}
|
|
57
58
|
return parseInt(hex, 16);
|
|
58
59
|
};
|
|
60
|
+
const toAudioUploadContent = (audio) => {
|
|
61
|
+
if (typeof audio === 'object' && audio !== null && !BufferRuntime.isBuffer(audio) && 'media' in audio) {
|
|
62
|
+
const { media, ...rest } = audio;
|
|
63
|
+
return { audio: media, ...rest };
|
|
64
|
+
}
|
|
65
|
+
return { audio };
|
|
66
|
+
};
|
|
59
67
|
export const prepareWAMessageMedia = async (message, options) => {
|
|
68
|
+
if ('sticker' in message && message.sticker != null && 'audio' in message && message.audio != null) {
|
|
69
|
+
const { audio, ...stickerInput } = message;
|
|
70
|
+
const audioOptions = options.mediaTypeOverride ? { ...options, mediaTypeOverride: undefined } : options;
|
|
71
|
+
const [stickerObj, audioObj] = await Promise.all([
|
|
72
|
+
prepareSingleWAMessageMedia(stickerInput, options),
|
|
73
|
+
prepareSingleWAMessageMedia(toAudioUploadContent(audio), audioOptions)
|
|
74
|
+
]);
|
|
75
|
+
if (stickerObj.stickerMessage && audioObj.audioMessage) {
|
|
76
|
+
stickerObj.stickerMessage.audioMessage = audioObj.audioMessage;
|
|
77
|
+
}
|
|
78
|
+
return WAProto.Message.fromObject({
|
|
79
|
+
audioStickerMessage: { message: { stickerMessage: stickerObj.stickerMessage } }
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
return prepareSingleWAMessageMedia(message, options);
|
|
83
|
+
};
|
|
84
|
+
const prepareSingleWAMessageMedia = async (message, options) => {
|
|
60
85
|
const logger = options.logger;
|
|
61
86
|
let mediaType;
|
|
62
87
|
for (const key of MEDIA_KEYS) {
|
|
@@ -73,6 +98,9 @@ export const prepareWAMessageMedia = async (message, options) => {
|
|
|
73
98
|
media: messageRecord[mediaType]
|
|
74
99
|
};
|
|
75
100
|
delete uploadData[mediaType];
|
|
101
|
+
if (mediaType === 'sticker') {
|
|
102
|
+
delete uploadData.audio;
|
|
103
|
+
}
|
|
76
104
|
// check if cacheable + generate cache key
|
|
77
105
|
const cacheableKey = typeof uploadData.media === 'object' &&
|
|
78
106
|
'url' in uploadData.media &&
|
|
@@ -178,7 +206,7 @@ async function extractBuiltInMetadata(buffer, mediaType, uploadData, options) {
|
|
|
178
206
|
try {
|
|
179
207
|
const requiresThumbnailComputation = (mediaType === 'image' || mediaType === 'video') && typeof uploadData.jpegThumbnail === 'undefined';
|
|
180
208
|
const requiresDurationComputation = mediaType === 'audio' && typeof uploadData.seconds === 'undefined';
|
|
181
|
-
const requiresWaveformProcessing = mediaType === 'audio' && uploadData.ptt === true;
|
|
209
|
+
const requiresWaveformProcessing = mediaType === 'audio' && uploadData.ptt === true && uploadData.waveform === undefined;
|
|
182
210
|
const requiresAudioBackground = options.backgroundColor && mediaType === 'audio' && uploadData.ptt === true;
|
|
183
211
|
if (requiresThumbnailComputation) {
|
|
184
212
|
const { thumbnail, originalImageDimensions } = await generateThumbnail(buffer, mediaType, options);
|
|
@@ -267,6 +295,9 @@ export const generateForwardMessageContent = (message, forceForward) => {
|
|
|
267
295
|
else {
|
|
268
296
|
nested.contextInfo = contextInfo;
|
|
269
297
|
}
|
|
298
|
+
if (content.stickerMessage?.audioMessage) {
|
|
299
|
+
return { audioStickerMessage: { message: content } };
|
|
300
|
+
}
|
|
270
301
|
return content;
|
|
271
302
|
};
|
|
272
303
|
export const hasNonNullishProperty = (message, key) => {
|
|
@@ -538,14 +569,18 @@ export const generateWAMessageContent = async (message, options) => {
|
|
|
538
569
|
if (hasOptionalProperty(message, 'viewOnce') && !!message.viewOnce) {
|
|
539
570
|
m = { viewOnceMessage: { message: m } };
|
|
540
571
|
}
|
|
572
|
+
const resolveContextTarget = () => {
|
|
573
|
+
const targetContainer = normalizeMessageContent(m) ?? m;
|
|
574
|
+
const messageType = Object.keys(targetContainer)[0];
|
|
575
|
+
const target = messageType ? targetContainer[messageType] : undefined;
|
|
576
|
+
return target && typeof target === 'object' ? target : undefined;
|
|
577
|
+
};
|
|
541
578
|
if ((hasOptionalProperty(message, 'mentions') && message.mentions?.length) ||
|
|
542
579
|
(hasOptionalProperty(message, 'mentionAll') && message.mentionAll)) {
|
|
543
|
-
const
|
|
544
|
-
const key = m[messageType];
|
|
580
|
+
const target = resolveContextTarget();
|
|
545
581
|
// `contextInfo` is declared by the proto schema but isn't an own
|
|
546
582
|
// property on freshly-built messages — create-if-absent, then merge.
|
|
547
|
-
if (
|
|
548
|
-
const target = key;
|
|
583
|
+
if (target) {
|
|
549
584
|
const ci = (target.contextInfo ?? (target.contextInfo = {}));
|
|
550
585
|
if (message.mentions?.length) {
|
|
551
586
|
ci.mentionedJid = message.mentions;
|
|
@@ -566,18 +601,19 @@ export const generateWAMessageContent = async (message, options) => {
|
|
|
566
601
|
};
|
|
567
602
|
}
|
|
568
603
|
if (hasOptionalProperty(message, 'contextInfo') && !!message.contextInfo) {
|
|
569
|
-
const
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
604
|
+
const target = resolveContextTarget();
|
|
605
|
+
if (target) {
|
|
606
|
+
target.contextInfo = target.contextInfo
|
|
607
|
+
? Object.assign(target.contextInfo, message.contextInfo)
|
|
608
|
+
: message.contextInfo;
|
|
573
609
|
}
|
|
574
610
|
}
|
|
575
611
|
return WAProto.Message.create(m);
|
|
576
612
|
};
|
|
577
613
|
export const generateWAMessageFromContent = (jid, message, options) => {
|
|
578
|
-
const innerMessage = normalizeMessageContent(message);
|
|
579
614
|
const timestamp = unixTimestampSeconds(options.timestamp);
|
|
580
|
-
const { quoted, userJid } = options;
|
|
615
|
+
const { quoted, ephemeralExpiration, userJid } = options;
|
|
616
|
+
const innerMessage = quoted || ephemeralExpiration ? normalizeMessageContent(message) : message;
|
|
581
617
|
// Only the quote and ephemeral branches read the content key, and a plain
|
|
582
618
|
// send takes neither, so resolve it on demand instead of on every send.
|
|
583
619
|
let key;
|
|
@@ -611,7 +647,7 @@ export const generateWAMessageFromContent = (jid, message, options) => {
|
|
|
611
647
|
}
|
|
612
648
|
if (
|
|
613
649
|
// if we want to send a disappearing message
|
|
614
|
-
!!
|
|
650
|
+
!!ephemeralExpiration &&
|
|
615
651
|
// newsletters don't support ephemeral messages
|
|
616
652
|
!isJidNewsletter(jid)) {
|
|
617
653
|
const contentKey = key ?? getContentType(innerMessage);
|
|
@@ -621,7 +657,7 @@ export const generateWAMessageFromContent = (jid, message, options) => {
|
|
|
621
657
|
/* @ts-ignore */
|
|
622
658
|
innerMessage[contentKey].contextInfo = {
|
|
623
659
|
...innerMessage[contentKey].contextInfo,
|
|
624
|
-
expiration:
|
|
660
|
+
expiration: ephemeralExpiration || WA_DEFAULT_EPHEMERAL
|
|
625
661
|
//ephemeralSettingTimestamp: options.ephemeralOptions.eph_setting_ts?.toString()
|
|
626
662
|
};
|
|
627
663
|
}
|
|
@@ -659,123 +695,7 @@ export const generateWAMessage = async (jid, content, options) => {
|
|
|
659
695
|
: options;
|
|
660
696
|
return generateWAMessageFromContent(jid, await generateWAMessageContent(content, contentOptions), options);
|
|
661
697
|
};
|
|
662
|
-
|
|
663
|
-
* The content keys that carry almost every message on a live socket, settled by
|
|
664
|
-
* identity before the structural predicate runs. Every name here already
|
|
665
|
-
* satisfies that predicate, so this only shortcuts the substring scan; it never
|
|
666
|
-
* changes which key wins.
|
|
667
|
-
*/
|
|
668
|
-
const isCommonContentKey = (key) => {
|
|
669
|
-
switch (key) {
|
|
670
|
-
case 'conversation':
|
|
671
|
-
case 'extendedTextMessage':
|
|
672
|
-
case 'imageMessage':
|
|
673
|
-
case 'videoMessage':
|
|
674
|
-
case 'audioMessage':
|
|
675
|
-
case 'stickerMessage':
|
|
676
|
-
case 'documentMessage':
|
|
677
|
-
case 'reactionMessage':
|
|
678
|
-
case 'protocolMessage':
|
|
679
|
-
case 'pollCreationMessage':
|
|
680
|
-
return true;
|
|
681
|
-
default:
|
|
682
|
-
return false;
|
|
683
|
-
}
|
|
684
|
-
};
|
|
685
|
-
/** Get the key to access the true type of content */
|
|
686
|
-
export const getContentType = (content) => {
|
|
687
|
-
if (!content) {
|
|
688
|
-
return undefined;
|
|
689
|
-
}
|
|
690
|
-
// The answer stays positional (the first own key naming content wins), but
|
|
691
|
-
// the scan is an indexed loop with an early return instead of `Array.find`,
|
|
692
|
-
// so no closure is allocated and the common keys never reach `includes`.
|
|
693
|
-
//
|
|
694
|
-
// Deliberately still `Object.keys` and not `for..in`: a decoded
|
|
695
|
-
// `WAProto.Message` inherits a default for every field of the schema, so
|
|
696
|
-
// `for..in` would enumerate ~100 prototype keys per call (and would have to
|
|
697
|
-
// filter them back out with `hasOwn` to stay positional) where `Object.keys`
|
|
698
|
-
// yields only the handful that were actually set.
|
|
699
|
-
const keys = Object.keys(content);
|
|
700
|
-
for (let i = 0; i < keys.length; i++) {
|
|
701
|
-
const key = keys[i];
|
|
702
|
-
if (isCommonContentKey(key)) {
|
|
703
|
-
return key;
|
|
704
|
-
}
|
|
705
|
-
if (key.includes('Message') && key !== 'senderKeyDistributionMessage') {
|
|
706
|
-
return key;
|
|
707
|
-
}
|
|
708
|
-
}
|
|
709
|
-
return undefined;
|
|
710
|
-
};
|
|
711
|
-
const getFutureProofMessage = (message) => message?.ephemeralMessage ||
|
|
712
|
-
message?.viewOnceMessage ||
|
|
713
|
-
message?.documentWithCaptionMessage ||
|
|
714
|
-
message?.viewOnceMessageV2 ||
|
|
715
|
-
message?.viewOnceMessageV2Extension ||
|
|
716
|
-
message?.editedMessage ||
|
|
717
|
-
message?.associatedChildMessage ||
|
|
718
|
-
message?.groupStatusMessage ||
|
|
719
|
-
message?.groupStatusMessageV2;
|
|
720
|
-
const extractFromTemplateMessage = (msg) => {
|
|
721
|
-
if (msg.imageMessage) {
|
|
722
|
-
return { imageMessage: msg.imageMessage };
|
|
723
|
-
}
|
|
724
|
-
else if (msg.documentMessage) {
|
|
725
|
-
return { documentMessage: msg.documentMessage };
|
|
726
|
-
}
|
|
727
|
-
else if (msg.videoMessage) {
|
|
728
|
-
return { videoMessage: msg.videoMessage };
|
|
729
|
-
}
|
|
730
|
-
else if (msg.locationMessage) {
|
|
731
|
-
return { locationMessage: msg.locationMessage };
|
|
732
|
-
}
|
|
733
|
-
else {
|
|
734
|
-
return {
|
|
735
|
-
conversation: 'contentText' in msg ? msg.contentText : 'hydratedContentText' in msg ? msg.hydratedContentText : ''
|
|
736
|
-
};
|
|
737
|
-
}
|
|
738
|
-
};
|
|
739
|
-
/**
|
|
740
|
-
* Normalizes ephemeral, view once messages to regular message content
|
|
741
|
-
* Eg. image messages in ephemeral messages, in view once messages etc.
|
|
742
|
-
* @param content
|
|
743
|
-
* @returns
|
|
744
|
-
*/
|
|
745
|
-
export const normalizeMessageContent = (content) => {
|
|
746
|
-
if (!content) {
|
|
747
|
-
return undefined;
|
|
748
|
-
}
|
|
749
|
-
// set max iterations to prevent an infinite loop
|
|
750
|
-
for (let i = 0; i < 5; i++) {
|
|
751
|
-
const inner = getFutureProofMessage(content);
|
|
752
|
-
if (!inner) {
|
|
753
|
-
break;
|
|
754
|
-
}
|
|
755
|
-
content = inner.message;
|
|
756
|
-
}
|
|
757
|
-
return content;
|
|
758
|
-
};
|
|
759
|
-
/**
|
|
760
|
-
* Extract the true message content from a message
|
|
761
|
-
* Eg. extracts the inner message from a disappearing message/view once message
|
|
762
|
-
*/
|
|
763
|
-
export const extractMessageContent = (content) => {
|
|
764
|
-
content = normalizeMessageContent(content);
|
|
765
|
-
if (content?.buttonsMessage) {
|
|
766
|
-
return extractFromTemplateMessage(content.buttonsMessage);
|
|
767
|
-
}
|
|
768
|
-
if (content?.templateMessage?.hydratedFourRowTemplate) {
|
|
769
|
-
return extractFromTemplateMessage(content?.templateMessage?.hydratedFourRowTemplate);
|
|
770
|
-
}
|
|
771
|
-
if (content?.templateMessage?.hydratedTemplate) {
|
|
772
|
-
return extractFromTemplateMessage(content?.templateMessage?.hydratedTemplate);
|
|
773
|
-
}
|
|
774
|
-
if (content?.templateMessage?.fourRowTemplate) {
|
|
775
|
-
return extractFromTemplateMessage(content?.templateMessage?.fourRowTemplate);
|
|
776
|
-
}
|
|
777
|
-
return content;
|
|
778
|
-
};
|
|
698
|
+
export { extractMessageContent, getContentType, normalizeMessageContent };
|
|
779
699
|
export const MEDIA_DOWNLOAD_TYPES = ['buffer', 'stream'];
|
|
780
700
|
/**
|
|
781
701
|
* Downloads the given message. Throws an error if it's not a media message.
|
|
@@ -150,6 +150,7 @@ export const transactionalFileStore = async (folder, ordinary, syncDir, options
|
|
|
150
150
|
listKeys: admit(result.listKeys),
|
|
151
151
|
deletePrefix: admit(result.deletePrefix),
|
|
152
152
|
commitPatch: admit(result.commitPatch),
|
|
153
|
+
commitSnapshot: admit(result.commitSnapshot),
|
|
153
154
|
storeReceivedTcToken: admit(result.storeReceivedTcToken),
|
|
154
155
|
touchTcTokenSenderTimestamp: admit(result.touchTcTokenSenderTimestamp)
|
|
155
156
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { atomicCallbacks } from './atomic-store.js';
|
|
1
|
+
import { atomicCallbacks, rowKey, rowPrefix } from './atomic-store.js';
|
|
2
2
|
import { markNativeMemoryStore } from '../Compatibility/internal/native-memory-store.js';
|
|
3
3
|
/**
|
|
4
4
|
* Creates a purely in-memory authentication store.
|
|
@@ -50,6 +50,16 @@ export function useMemoryStore(options = {}) {
|
|
|
50
50
|
staged.set(rawKey, undefined);
|
|
51
51
|
writes.push([rawKey, undefined]);
|
|
52
52
|
return existed;
|
|
53
|
+
},
|
|
54
|
+
deletePrefix(store, prefix) {
|
|
55
|
+
const encodedPrefix = rowPrefix(store, prefix);
|
|
56
|
+
for (const key of staged.keys())
|
|
57
|
+
if (key.startsWith(encodedPrefix))
|
|
58
|
+
rows.delete(key);
|
|
59
|
+
for (const key of stores.get(store)?.keys() ?? []) {
|
|
60
|
+
if (key.startsWith(prefix) && !staged.has(rowKey(store, key)))
|
|
61
|
+
rows.delete(rowKey(store, key));
|
|
62
|
+
}
|
|
53
63
|
}
|
|
54
64
|
};
|
|
55
65
|
change(rows);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { proto } from './runtime.js';
|
|
1
2
|
export type ProtoFieldSchema = readonly [name: string, kind: number, reference: number, flags: number, oneof: string];
|
|
2
3
|
export type ProtoMessageSchema = readonly [path: string, fields: readonly ProtoFieldSchema[]];
|
|
3
4
|
export type ProtoEnumSchema = readonly [path: string, entries: readonly (string | number)[]];
|
|
@@ -18,8 +19,13 @@ export declare const PROTO_FIELD_FLAG: {
|
|
|
18
19
|
readonly map: 2;
|
|
19
20
|
readonly proto3Optional: 4;
|
|
20
21
|
readonly oneof: 8;
|
|
22
|
+
readonly bridgeAddition: 16;
|
|
21
23
|
};
|
|
22
|
-
export declare const
|
|
24
|
+
export declare const PROTO_INSTANCE_SCHEMA: unique symbol;
|
|
25
|
+
export declare const BASELINE_FUTURE_PROOF_FIELDS: readonly ["ephemeralMessage", "viewOnceMessage", "documentWithCaptionMessage", "viewOnceMessageV2", "viewOnceMessageV2Extension", "editedMessage", "associatedChildMessage", "groupStatusMessage", "groupStatusMessageV2"];
|
|
26
|
+
export declare const BRIDGE_FUTURE_PROOF_FIELDS: readonly ["newsletterAdminProfileMessage", "spoilerMessage", "newsletterAdminProfileStatusMessage", "botPlatformRegistrationSuccessMessage", "newsletterScheduledMessage", "acp2SettingMessage", "audioStickerMessage", "botGroupParticipantMessage"];
|
|
27
|
+
export declare const getOrderedFutureProofMessage: (message: proto.IMessage) => proto.Message.IFutureProofMessage | undefined;
|
|
28
|
+
export declare const PROTO_SCHEMA_SOURCE = "baileys@7.0.0-rc14:4bab5324186daf8de5ab592548ee80dfc753651667fa9411e0666837f90e4c8d+@oxidezap/whatsapp-rust-bridge@0.28.0:c5c7786509ff120044f0ca01d062efc6c118fa587a7d4bdae7b42a2590a43bea";
|
|
23
29
|
export declare const PROTO_MESSAGE_SCHEMAS: readonly ProtoMessageSchema[];
|
|
24
30
|
export declare const PROTO_ENUM_SCHEMAS: readonly ProtoEnumSchema[];
|
|
25
31
|
//# sourceMappingURL=compatibility-schema.d.ts.map
|