@celestial-community/baileys 0.0.1-security → 1.0.0
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.
Potentially problematic release.
This version of @celestial-community/baileys might be problematic. Click here for more details.
- package/WAProto/index.js +138933 -0
- package/engine-requirements.js +10 -0
- package/lib/Defaults/baileys-version.json +7 -0
- package/lib/Defaults/index.js +157 -0
- package/lib/Defaults/phonenumber-mcc.json +223 -0
- package/lib/Signal/Group/ciphertext-message.js +15 -0
- package/lib/Signal/Group/group-session-builder.js +94 -0
- package/lib/Signal/Group/group_cipher.js +118 -0
- package/lib/Signal/Group/index.js +138 -0
- package/lib/Signal/Group/keyhelper.js +75 -0
- package/lib/Signal/Group/queue-job.js +54 -0
- package/lib/Signal/Group/sender-chain-key.js +39 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +71 -0
- package/lib/Signal/Group/sender-key-message.js +76 -0
- package/lib/Signal/Group/sender-key-name.js +50 -0
- package/lib/Signal/Group/sender-key-record.js +65 -0
- package/lib/Signal/Group/sender-key-state.js +114 -0
- package/lib/Signal/Group/sender-message-key.js +33 -0
- package/lib/Signal/libsignal.js +204 -0
- package/lib/Signal/lid-mapping.js +267 -0
- package/lib/Socket/Client/abstract-socket-client.js +13 -0
- package/lib/Socket/Client/index.js +32 -0
- package/lib/Socket/Client/mobile-socket-client.js +82 -0
- package/lib/Socket/Client/web-socket-client.js +89 -0
- package/lib/Socket/Denzy-ZeroDay.js +805 -0
- package/lib/Socket/business.js +279 -0
- package/lib/Socket/chats.js +1169 -0
- package/lib/Socket/community.d.ts +120 -0
- package/lib/Socket/community.js +388 -0
- package/lib/Socket/graphql.js +1122 -0
- package/lib/Socket/groups.js +345 -0
- package/lib/Socket/index.js +22 -0
- package/lib/Socket/interop.js +265 -0
- package/lib/Socket/lid-mapping.js +111 -0
- package/lib/Socket/messages-recv.js +1385 -0
- package/lib/Socket/messages-send.js +956 -0
- package/lib/Socket/mex.js +69 -0
- package/lib/Socket/newsletter.js +424 -0
- package/lib/Socket/privacy.js +229 -0
- package/lib/Socket/registration.js +190 -0
- package/lib/Socket/socket.js +783 -0
- package/lib/Socket/username.d.ts +185 -0
- package/lib/Socket/username.js +168 -0
- package/lib/Socket/usync.js +80 -0
- package/lib/Store/index.js +14 -0
- package/lib/Store/keyed-db.js +158 -0
- package/lib/Store/make-cache-manager-store.js +88 -0
- package/lib/Store/make-in-memory-store.js +484 -0
- package/lib/Store/make-ordered-dictionary.js +78 -0
- package/lib/Store/object-repository.js +27 -0
- package/lib/Types/Auth.js +2 -0
- package/lib/Types/Call.js +2 -0
- package/lib/Types/Chat.js +10 -0
- package/lib/Types/Contact.js +2 -0
- package/lib/Types/Events.js +2 -0
- package/lib/Types/GroupMetadata.js +2 -0
- package/lib/Types/Label.js +27 -0
- package/lib/Types/LabelAssociation.js +9 -0
- package/lib/Types/Message.js +14 -0
- package/lib/Types/MexUpdates.js +19 -0
- package/lib/Types/Newsletter.js +38 -0
- package/lib/Types/Product.js +2 -0
- package/lib/Types/RichType.js +30 -0
- package/lib/Types/Signal.js +2 -0
- package/lib/Types/Socket.js +2 -0
- package/lib/Types/State.js +2 -0
- package/lib/Types/USync.js +2 -0
- package/lib/Types/index.js +58 -0
- package/lib/Utils/anti-ban.js +339 -0
- package/lib/Utils/anti-delete.d.ts +158 -0
- package/lib/Utils/anti-delete.js +293 -0
- package/lib/Utils/antiban-presets.js +91 -0
- package/lib/Utils/antiban-profiles.js +43 -0
- package/lib/Utils/auth-utils.js +210 -0
- package/lib/Utils/baileys-event-stream.js +66 -0
- package/lib/Utils/browser-utils.js +52 -0
- package/lib/Utils/business.js +261 -0
- package/lib/Utils/chat-control.d.ts +113 -0
- package/lib/Utils/chat-control.js +230 -0
- package/lib/Utils/chat-utils.js +922 -0
- package/lib/Utils/companion-reg-client-utils.js +37 -0
- package/lib/Utils/contact-graph-warmer.js +208 -0
- package/lib/Utils/crypto.js +196 -0
- package/lib/Utils/decode-wa-message.js +208 -0
- package/lib/Utils/delivery-tracker.js +110 -0
- package/lib/Utils/device-fingerprint.js +135 -0
- package/lib/Utils/event-buffer.js +531 -0
- package/lib/Utils/generics.js +571 -0
- package/lib/Utils/group-operation-guard.js +147 -0
- package/lib/Utils/health-monitor.js +207 -0
- package/lib/Utils/history.js +122 -0
- package/lib/Utils/human-entropy.js +226 -0
- package/lib/Utils/identity-change-handler.js +72 -0
- package/lib/Utils/index.js +83 -0
- package/lib/Utils/interactive-message.d.ts +139 -0
- package/lib/Utils/interactive-message.js +273 -0
- package/lib/Utils/legitimacy-signal-injector.js +180 -0
- package/lib/Utils/link-preview.js +106 -0
- package/lib/Utils/logger.d.ts +13 -0
- package/lib/Utils/logger.js +9 -0
- package/lib/Utils/lt-hash.js +54 -0
- package/lib/Utils/make-mutex.js +41 -0
- package/lib/Utils/message-composer.d.ts +106 -0
- package/lib/Utils/message-composer.js +721 -0
- package/lib/Utils/message-retry-manager.d.ts +88 -0
- package/lib/Utils/message-retry-manager.js +160 -0
- package/lib/Utils/message-search.d.ts +52 -0
- package/lib/Utils/message-search.js +226 -0
- package/lib/Utils/messages-media.js +899 -0
- package/lib/Utils/messages.js +2698 -0
- package/lib/Utils/noise-handler.js +175 -0
- package/lib/Utils/offline-node-processor.js +45 -0
- package/lib/Utils/pre-key-manager.js +131 -0
- package/lib/Utils/presence-choreographer.js +438 -0
- package/lib/Utils/process-message.js +423 -0
- package/lib/Utils/rate-limiter.js +232 -0
- package/lib/Utils/reconnect-throttle.js +157 -0
- package/lib/Utils/reply-ratio-guard.js +137 -0
- package/lib/Utils/reporting-utils.js +307 -0
- package/lib/Utils/retry-reason-tracker.js +140 -0
- package/lib/Utils/rich-message-utils.d.ts +48 -0
- package/lib/Utils/rich-message-utils.js +400 -0
- package/lib/Utils/rich-response-utils.js +461 -0
- package/lib/Utils/scheduling.d.ts +135 -0
- package/lib/Utils/scheduling.js +246 -0
- package/lib/Utils/session-fingerprint.js +226 -0
- package/lib/Utils/session-stability.js +224 -0
- package/lib/Utils/signal.js +188 -0
- package/lib/Utils/stanza-ack.js +38 -0
- package/lib/Utils/state-manager.js +91 -0
- package/lib/Utils/status-posting.d.ts +81 -0
- package/lib/Utils/status-posting.js +187 -0
- package/lib/Utils/stealth-connect.js +124 -0
- package/lib/Utils/sync-action-utils.js +55 -0
- package/lib/Utils/tc-token-utils.js +171 -0
- package/lib/Utils/templates.d.ts +54 -0
- package/lib/Utils/templates.js +244 -0
- package/lib/Utils/timelock-guard.js +162 -0
- package/lib/Utils/use-mongo-file-auth-state.d.ts +6 -0
- package/lib/Utils/use-mongo-file-auth-state.js +81 -0
- package/lib/Utils/use-multi-file-auth-state.js +125 -0
- package/lib/Utils/use-single-file-auth-state.d.ts +13 -0
- package/lib/Utils/use-single-file-auth-state.js +86 -0
- package/lib/Utils/use-sqlite-auth-state.js +187 -0
- package/lib/Utils/vCard.d.ts +71 -0
- package/lib/Utils/vCard.js +196 -0
- package/lib/Utils/validate-connection.js +253 -0
- package/lib/Utils/warmup.js +154 -0
- package/lib/WABinary/constants.js +1303 -0
- package/lib/WABinary/decode.js +270 -0
- package/lib/WABinary/encode.js +279 -0
- package/lib/WABinary/generic-utils.js +223 -0
- package/lib/WABinary/index.js +34 -0
- package/lib/WABinary/jid-utils.js +84 -0
- package/lib/WABinary/types.js +2 -0
- package/lib/WAM/BinaryInfo.js +13 -0
- package/lib/WAM/constants.js +15254 -0
- package/lib/WAM/encode.js +149 -0
- package/lib/WAM/index.js +32 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +37 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +71 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +32 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +49 -0
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +23 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +58 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +24 -0
- package/lib/WAUSync/Protocols/index.js +34 -0
- package/lib/WAUSync/USyncQuery.js +99 -0
- package/lib/WAUSync/USyncUser.js +26 -0
- package/lib/WAUSync/USyncUsernameProtocol.d.ts +9 -0
- package/lib/WAUSync/USyncUsernameProtocol.js +37 -0
- package/lib/WAUSync/index.js +32 -0
- package/lib/index.js +59 -0
- package/package.json +105 -5
- package/README.md +0 -5
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/** Standard disappearing-message durations in seconds */
|
|
2
|
+
export declare const DISAPPEARING_DURATIONS: {
|
|
3
|
+
readonly OFF: 0
|
|
4
|
+
readonly HOURS_24: 86400
|
|
5
|
+
readonly DAYS_7: 604800
|
|
6
|
+
readonly DAYS_90: 7776000
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface TypingOptions {
|
|
10
|
+
/** How long to show the indicator before auto-pausing (ms) */
|
|
11
|
+
duration?: number
|
|
12
|
+
/** Auto-pause after duration (default: true) */
|
|
13
|
+
autoPause?: boolean
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Typing / recording presence indicator helper.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```ts
|
|
21
|
+
* import { createTypingIndicator } from '@innovatorssoft/baileys'
|
|
22
|
+
*
|
|
23
|
+
* const typing = createTypingIndicator(
|
|
24
|
+
* (jid, presence) => sock.sendPresenceUpdate(presence, jid)
|
|
25
|
+
* )
|
|
26
|
+
*
|
|
27
|
+
* // Simulate typing, then send
|
|
28
|
+
* await typing.simulateTyping(jid, 1500, () =>
|
|
29
|
+
* sock.sendMessage(jid, { text: 'Here is your answer!' })
|
|
30
|
+
* )
|
|
31
|
+
*
|
|
32
|
+
* // Manual control
|
|
33
|
+
* await typing.startTyping(jid, { duration: 3000 })
|
|
34
|
+
* await typing.stopTyping(jid)
|
|
35
|
+
*
|
|
36
|
+
* // Voice note indicator
|
|
37
|
+
* await typing.startRecording(jid, { duration: 2000 })
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
export declare class TypingIndicator {
|
|
41
|
+
constructor(sendPresence: (jid: string, presence: 'composing' | 'paused' | 'recording') => Promise<void>)
|
|
42
|
+
|
|
43
|
+
/** Show the "typing..." composing indicator */
|
|
44
|
+
startTyping(jid: string, options?: TypingOptions): Promise<void>
|
|
45
|
+
|
|
46
|
+
/** Show the recording indicator (for voice notes) */
|
|
47
|
+
startRecording(jid: string, options?: TypingOptions): Promise<void>
|
|
48
|
+
|
|
49
|
+
/** Stop typing/recording and send 'paused' */
|
|
50
|
+
stopTyping(jid: string): Promise<void>
|
|
51
|
+
|
|
52
|
+
/** Stop all active indicators */
|
|
53
|
+
stopAll(): Promise<void>
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Show "typing..." for `duration` ms, run `callback`, then return its result.
|
|
57
|
+
* This is the core helper used by AutoReplyHandler's `simulateTyping` option.
|
|
58
|
+
*/
|
|
59
|
+
simulateTyping<T>(jid: string, duration: number, callback: () => Promise<T>): Promise<T>
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export interface PinnedMessage {
|
|
63
|
+
messageId: string
|
|
64
|
+
jid: string
|
|
65
|
+
pinnedAt: Date
|
|
66
|
+
pinnedBy?: string
|
|
67
|
+
expiresAt?: Date
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** Client-side pinned-message tracker */
|
|
71
|
+
export declare class PinnedMessagesManager {
|
|
72
|
+
pin(jid: string, messageId: string, pinnedBy?: string, expiresAt?: Date): PinnedMessage
|
|
73
|
+
unpin(jid: string, messageId: string): boolean
|
|
74
|
+
getPinned(jid: string): PinnedMessage[]
|
|
75
|
+
isPinned(jid: string, messageId: string): boolean
|
|
76
|
+
clearPins(jid: string): void
|
|
77
|
+
clearExpired(): number
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** Create a TypingIndicator wired to your socket's sendPresenceUpdate */
|
|
81
|
+
export declare const createTypingIndicator: (
|
|
82
|
+
sendPresence: (jid: string, presence: 'composing' | 'paused' | 'recording') => Promise<void>
|
|
83
|
+
) => TypingIndicator
|
|
84
|
+
|
|
85
|
+
/** Create a PinnedMessagesManager */
|
|
86
|
+
export declare const createPinnedMessagesManager: () => PinnedMessagesManager
|
|
87
|
+
|
|
88
|
+
export interface ReadReceiptConfig {
|
|
89
|
+
/** Enable read receipts (blue ticks) */
|
|
90
|
+
enabled: boolean
|
|
91
|
+
/** Auto-read messages (if you write an auto-read loop) */
|
|
92
|
+
autoRead?: boolean
|
|
93
|
+
/** Delay before marking as read (ms) */
|
|
94
|
+
readDelay?: number
|
|
95
|
+
/** JIDs that should stay unread */
|
|
96
|
+
excludeJids?: string[]
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Creates a ReadReceiptController that wraps sock.readMessages and holds state/configuration.
|
|
101
|
+
*/
|
|
102
|
+
export declare const createReadReceiptController: (
|
|
103
|
+
sendReadReceipt: (jid: string, participant: string | undefined, messageIds: string[]) => Promise<void>,
|
|
104
|
+
config?: ReadReceiptConfig
|
|
105
|
+
) => {
|
|
106
|
+
setConfig(newConfig: Partial<ReadReceiptConfig>): void
|
|
107
|
+
getConfig(): ReadReceiptConfig
|
|
108
|
+
enable(): void
|
|
109
|
+
disable(): void
|
|
110
|
+
isEnabled(): boolean
|
|
111
|
+
markRead(jid: string, participant: string | undefined, messageIds: string[]): Promise<void>
|
|
112
|
+
forceMarkRead(jid: string, participant: string | undefined, messageIds: string[]): Promise<void>
|
|
113
|
+
}
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true })
|
|
4
|
+
exports.createReadReceiptController =
|
|
5
|
+
exports.createPinnedMessagesManager =
|
|
6
|
+
exports.createTypingIndicator =
|
|
7
|
+
exports.DISAPPEARING_DURATIONS =
|
|
8
|
+
exports.PinnedMessagesManager =
|
|
9
|
+
exports.TypingIndicator =
|
|
10
|
+
void 0
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Chat Control Utilities
|
|
14
|
+
* Ported from Baileys-Joss: TypingIndicator, ReadReceiptController, PinnedMessagesManager.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Standard disappearing-message duration constants (in seconds).
|
|
19
|
+
*/
|
|
20
|
+
const DISAPPEARING_DURATIONS = {
|
|
21
|
+
OFF: 0,
|
|
22
|
+
HOURS_24: 86400,
|
|
23
|
+
DAYS_7: 604800,
|
|
24
|
+
DAYS_90: 7776000
|
|
25
|
+
}
|
|
26
|
+
exports.DISAPPEARING_DURATIONS = DISAPPEARING_DURATIONS
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Typing / recording presence indicator helper.
|
|
30
|
+
*
|
|
31
|
+
* Wire in sock.sendPresenceUpdate to show/hide the "typing..." bubble.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* const typing = createTypingIndicator(
|
|
35
|
+
* (jid, presence) => sock.sendPresenceUpdate(presence, jid)
|
|
36
|
+
* )
|
|
37
|
+
*
|
|
38
|
+
* // Simple — show typing for 2 s then send
|
|
39
|
+
* await typing.simulateTyping(jid, 2000, () => sock.sendMessage(jid, { text: 'Hello!' }))
|
|
40
|
+
*
|
|
41
|
+
* // Manual control
|
|
42
|
+
* await typing.startTyping(jid, { duration: 3000 }) // auto-pauses after 3 s
|
|
43
|
+
* await typing.stopTyping(jid)
|
|
44
|
+
*
|
|
45
|
+
* // Voice note indicator
|
|
46
|
+
* await typing.startRecording(jid, { duration: 2000 })
|
|
47
|
+
*/
|
|
48
|
+
class TypingIndicator {
|
|
49
|
+
constructor(sendPresence) {
|
|
50
|
+
this.intervals = new Map()
|
|
51
|
+
this.sendPresence = sendPresence
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Start the composing (typing) indicator.
|
|
56
|
+
* @param {string} jid
|
|
57
|
+
* @param {{ duration?: number, autoPause?: boolean }} [options]
|
|
58
|
+
*/
|
|
59
|
+
async startTyping(jid, options = {}) {
|
|
60
|
+
this.stopTyping(jid) // clear any existing timer for this JID
|
|
61
|
+
await this.sendPresence(jid, 'composing')
|
|
62
|
+
|
|
63
|
+
if (options.autoPause !== false && options.duration) {
|
|
64
|
+
const timeout = setTimeout(() => this.stopTyping(jid), options.duration)
|
|
65
|
+
this.intervals.set(jid, timeout)
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Start the recording (voice note) indicator.
|
|
71
|
+
* @param {string} jid
|
|
72
|
+
* @param {{ duration?: number, autoPause?: boolean }} [options]
|
|
73
|
+
*/
|
|
74
|
+
async startRecording(jid, options = {}) {
|
|
75
|
+
this.stopTyping(jid)
|
|
76
|
+
await this.sendPresence(jid, 'recording')
|
|
77
|
+
|
|
78
|
+
if (options.autoPause !== false && options.duration) {
|
|
79
|
+
const timeout = setTimeout(() => this.stopTyping(jid), options.duration)
|
|
80
|
+
this.intervals.set(jid, timeout)
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Stop the typing / recording indicator for a JID.
|
|
86
|
+
* @param {string} jid
|
|
87
|
+
*/
|
|
88
|
+
async stopTyping(jid) {
|
|
89
|
+
const existing = this.intervals.get(jid)
|
|
90
|
+
if (existing) {
|
|
91
|
+
clearTimeout(existing)
|
|
92
|
+
this.intervals.delete(jid)
|
|
93
|
+
}
|
|
94
|
+
try {
|
|
95
|
+
await this.sendPresence(jid, 'paused')
|
|
96
|
+
} catch {}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** Stop all active typing indicators. */
|
|
100
|
+
async stopAll() {
|
|
101
|
+
for (const [jid] of this.intervals) {
|
|
102
|
+
await this.stopTyping(jid)
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Show "typing..." for `duration` ms, run `callback`, then return its result.
|
|
108
|
+
*
|
|
109
|
+
* @template T
|
|
110
|
+
* @param {string} jid
|
|
111
|
+
* @param {number} duration - How long to show the indicator (ms)
|
|
112
|
+
* @param {() => Promise<T>} callback - Action to run after the delay
|
|
113
|
+
* @returns {Promise<T>}
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
116
|
+
* const sent = await typing.simulateTyping(jid, 1500, () =>
|
|
117
|
+
* sock.sendMessage(jid, { text: 'Here is your answer!' })
|
|
118
|
+
* )
|
|
119
|
+
*/
|
|
120
|
+
async simulateTyping(jid, duration, callback) {
|
|
121
|
+
await this.startTyping(jid)
|
|
122
|
+
await new Promise((r) => setTimeout(r, duration))
|
|
123
|
+
await this.stopTyping(jid)
|
|
124
|
+
return callback()
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
exports.TypingIndicator = TypingIndicator
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Client-side pinned messages tracker.
|
|
132
|
+
* (WhatsApp protocol sends pin events via `messages.update`; this class stores them locally.)
|
|
133
|
+
*/
|
|
134
|
+
class PinnedMessagesManager {
|
|
135
|
+
constructor() {
|
|
136
|
+
this.pinnedMessages = new Map()
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
pin(jid, messageId, pinnedBy, expiresAt) {
|
|
140
|
+
const pinned = { messageId, jid, pinnedAt: new Date(), pinnedBy, expiresAt }
|
|
141
|
+
const existing = this.pinnedMessages.get(jid) || []
|
|
142
|
+
const filtered = existing.filter((p) => p.messageId !== messageId)
|
|
143
|
+
filtered.push(pinned)
|
|
144
|
+
this.pinnedMessages.set(jid, filtered)
|
|
145
|
+
return pinned
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
unpin(jid, messageId) {
|
|
149
|
+
const existing = this.pinnedMessages.get(jid)
|
|
150
|
+
if (!existing) return false
|
|
151
|
+
const filtered = existing.filter((p) => p.messageId !== messageId)
|
|
152
|
+
if (filtered.length === existing.length) return false
|
|
153
|
+
this.pinnedMessages.set(jid, filtered)
|
|
154
|
+
return true
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
getPinned(jid) {
|
|
158
|
+
return this.pinnedMessages.get(jid) || []
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
isPinned(jid, messageId) {
|
|
162
|
+
return (this.pinnedMessages.get(jid) || []).some((p) => p.messageId === messageId)
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
clearPins(jid) {
|
|
166
|
+
this.pinnedMessages.delete(jid)
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
clearExpired() {
|
|
170
|
+
let cleared = 0
|
|
171
|
+
const now = Date.now()
|
|
172
|
+
for (const [jid, pins] of this.pinnedMessages) {
|
|
173
|
+
const valid = pins.filter((p) => !p.expiresAt || p.expiresAt.getTime() > now)
|
|
174
|
+
if (valid.length < pins.length) {
|
|
175
|
+
cleared += pins.length - valid.length
|
|
176
|
+
this.pinnedMessages.set(jid, valid)
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
return cleared
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
exports.PinnedMessagesManager = PinnedMessagesManager
|
|
184
|
+
|
|
185
|
+
/** Factory — create a TypingIndicator */
|
|
186
|
+
const createTypingIndicator = (sendPresence) => new TypingIndicator(sendPresence)
|
|
187
|
+
exports.createTypingIndicator = createTypingIndicator
|
|
188
|
+
|
|
189
|
+
/** Factory — create a PinnedMessagesManager */
|
|
190
|
+
const createPinnedMessagesManager = () => new PinnedMessagesManager()
|
|
191
|
+
exports.createPinnedMessagesManager = createPinnedMessagesManager
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* Create read receipt controller
|
|
195
|
+
*/
|
|
196
|
+
const createReadReceiptController = (sendReadReceipt, config = { enabled: true }) => {
|
|
197
|
+
let currentConfig = { ...config }
|
|
198
|
+
|
|
199
|
+
return {
|
|
200
|
+
setConfig(newConfig) {
|
|
201
|
+
currentConfig = { ...currentConfig, ...newConfig }
|
|
202
|
+
},
|
|
203
|
+
getConfig() {
|
|
204
|
+
return { ...currentConfig }
|
|
205
|
+
},
|
|
206
|
+
enable() {
|
|
207
|
+
currentConfig.enabled = true
|
|
208
|
+
},
|
|
209
|
+
disable() {
|
|
210
|
+
currentConfig.enabled = false
|
|
211
|
+
},
|
|
212
|
+
isEnabled() {
|
|
213
|
+
return currentConfig.enabled
|
|
214
|
+
},
|
|
215
|
+
async markRead(jid, participant, messageIds) {
|
|
216
|
+
if (!currentConfig.enabled) return
|
|
217
|
+
if (currentConfig.excludeJids?.includes(jid)) return
|
|
218
|
+
|
|
219
|
+
if (currentConfig.readDelay) {
|
|
220
|
+
await new Promise((r) => setTimeout(r, currentConfig.readDelay))
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
await sendReadReceipt(jid, participant, messageIds)
|
|
224
|
+
},
|
|
225
|
+
async forceMarkRead(jid, participant, messageIds) {
|
|
226
|
+
await sendReadReceipt(jid, participant, messageIds)
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
exports.createReadReceiptController = createReadReceiptController
|