@violetix/baileys 0.5.4 → 0.5.5
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/lib/Socket/chats.js +28 -0
- package/package.json +1 -1
package/lib/Socket/chats.js
CHANGED
|
@@ -953,7 +953,35 @@ export const makeChatsSocket = (config) => {
|
|
|
953
953
|
const executeInitQueries = async () => {
|
|
954
954
|
await Promise.all([fetchProps(), fetchBlocklist(), fetchPrivacySettings()]);
|
|
955
955
|
};
|
|
956
|
+
/**
|
|
957
|
+
* WhatsApp redelivers a message whose ack was lost — the ack goes out after the stanza is
|
|
958
|
+
* processed, so a transport drop in between leaves the server believing nobody took it. The
|
|
959
|
+
* redelivery is indistinguishable from a new message at the stanza level, so the same key.id
|
|
960
|
+
* reached the host twice and every plugin answered twice ("double response" after a reconnect).
|
|
961
|
+
*
|
|
962
|
+
* Per socket, not process-wide: two bots in the same group must each process the group message.
|
|
963
|
+
* Bounded because ids are never reused but this runs for the life of a long-lived socket.
|
|
964
|
+
*/
|
|
965
|
+
const seenMessageIds = new Set();
|
|
966
|
+
const SEEN_MESSAGE_LIMIT = 1000;
|
|
967
|
+
const isRepeatMessage = id => {
|
|
968
|
+
if (!id) {
|
|
969
|
+
return false;
|
|
970
|
+
}
|
|
971
|
+
if (seenMessageIds.has(id)) {
|
|
972
|
+
return true;
|
|
973
|
+
}
|
|
974
|
+
seenMessageIds.add(id);
|
|
975
|
+
if (seenMessageIds.size > SEEN_MESSAGE_LIMIT) {
|
|
976
|
+
seenMessageIds.delete(seenMessageIds.values().next().value);
|
|
977
|
+
}
|
|
978
|
+
return false;
|
|
979
|
+
};
|
|
956
980
|
const upsertMessage = ev.createBufferedFunction(async (msg, type) => {
|
|
981
|
+
if (isRepeatMessage(msg.key?.id)) {
|
|
982
|
+
logger.debug({ msgId: msg.key?.id, type }, 'dropped redelivered message');
|
|
983
|
+
return;
|
|
984
|
+
}
|
|
957
985
|
ev.emit('messages.upsert', { messages: [msg], type });
|
|
958
986
|
if (!!msg.pushName) {
|
|
959
987
|
let jid = msg.key.fromMe ? authState.creds.me?.id : msg.key.participant || msg.key.remoteJid;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@violetix/baileys",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.5",
|
|
4
4
|
"description": "Enhanced Baileys v7 with fixes for newsletter media uploads, plus support for interactive messages, albums, and additional message types.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|