@prototypevip/baileys 0.0.2 → 0.0.3

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.
@@ -380,6 +380,33 @@ export const makePrototypeStore = (config = {}) => {
380
380
 
381
381
  const presencesCache = {};
382
382
 
383
+ const makeMessagesStore = () =>
384
+ new Proxy(
385
+ makeOrderedDictionary((m) => {
386
+ const participant = m.key.participant
387
+ ? resolveJID(m.key.participant, store.signalRepository?.lidMapping)
388
+ : m.key.fromMe
389
+ ? "me"
390
+ : "";
391
+ return participant ? `${participant}:${m.key.id}` : m.key.id;
392
+ }),
393
+ {
394
+ get(target, prop) {
395
+ if (prop in target) return target[prop];
396
+ return target.get(prop);
397
+ },
398
+ set(target, prop, value) {
399
+ target.upsert(value);
400
+ return true;
401
+ },
402
+ deleteProperty(target, prop) {
403
+ const item = target.get(prop);
404
+ if (item) return target.remove(item);
405
+ return false;
406
+ },
407
+ },
408
+ );
409
+
383
410
  const store = {
384
411
  signalRepository: config.signalRepository,
385
412
  chats: new Proxy(chatsCache, {
@@ -389,34 +416,7 @@ export const makePrototypeStore = (config = {}) => {
389
416
  if (!target[jid]) {
390
417
  target[jid] = {
391
418
  id: jid,
392
- messages: new Proxy(
393
- makeOrderedDictionary((m) => {
394
- const participant = m.key.participant
395
- ? resolveJID(
396
- m.key.participant,
397
- store.signalRepository?.lidMapping,
398
- )
399
- : m.key.fromMe
400
- ? "me"
401
- : "";
402
- return participant ? `${participant}:${m.key.id}` : m.key.id;
403
- }),
404
- {
405
- get(target, prop) {
406
- if (prop in target) return target[prop];
407
- return target.get(prop);
408
- },
409
- set(target, prop, value) {
410
- target.upsert(value);
411
- return true;
412
- },
413
- deleteProperty(target, prop) {
414
- const item = target.get(prop);
415
- if (item) return target.remove(item);
416
- return false;
417
- },
418
- },
419
- ),
419
+ messages: makeMessagesStore(),
420
420
  get isGroup() {
421
421
  return jid.endsWith("@g.us");
422
422
  },
@@ -788,7 +788,7 @@ export const makePrototypeStore = (config = {}) => {
788
788
  store.signalRepository?.lidMapping,
789
789
  );
790
790
  if (chatsCache[jid]) {
791
- chatsCache[jid].messages = {};
791
+ chatsCache[jid].messages = makeMessagesStore();
792
792
  if (db)
793
793
  pendingUpdates.set(`del:m:${jid}`, {
794
794
  type: "delete",
@@ -954,5 +954,22 @@ export const makePrototypeStore = (config = {}) => {
954
954
  },
955
955
  };
956
956
 
957
+ store.close = () => {
958
+ if (flushInterval) clearInterval(flushInterval);
959
+ if (cleanInterval) clearInterval(cleanInterval);
960
+ try {
961
+ _flush();
962
+ } catch {
963
+ // ignore flush errors on close
964
+ }
965
+ if (db) {
966
+ try {
967
+ db.close();
968
+ } catch {
969
+ // ignore close errors
970
+ }
971
+ }
972
+ };
973
+
957
974
  return store;
958
975
  };
@@ -26,4 +26,5 @@ export * from "./cstoken-utils.js";
26
26
  export * from "./use-prototype-auth-state.js";
27
27
  export * from "./sticker-utils.js";
28
28
  export * from "./rich-message-utils.js";
29
+ export * from "./message-builder.js";
29
30
  export * from "./constants.js";