From 29a00fbfd97cf6480613b4b1d77a6cba2b2099aa Mon Sep 17 00:00:00 2001 From: Edgard Date: Sat, 4 Jun 2022 17:47:44 -0300 Subject: [PATCH] fix: Fixed compatibility with WhatsApp Web >= 2.2220.8 --- src/blocklist/functions/all.ts | 2 +- src/chat/events/registerLiveLocationUpdateEvent.ts | 2 +- src/chat/events/registerPresenceChange.ts | 5 +++-- src/chat/functions/list.ts | 2 +- src/group/functions/getParticipants.ts | 2 +- src/labels/functions/getAllLabels.ts | 2 +- src/status/functions/sendRawStatus.ts | 2 +- src/whatsapp/collections/Collection.ts | 8 ++------ 8 files changed, 11 insertions(+), 14 deletions(-) diff --git a/src/blocklist/functions/all.ts b/src/blocklist/functions/all.ts index 6ee87b1d59..5050e81818 100644 --- a/src/blocklist/functions/all.ts +++ b/src/blocklist/functions/all.ts @@ -17,5 +17,5 @@ import { BlocklistStore, Wid } from '../../whatsapp'; export function all(): Wid[] { - return BlocklistStore.models.map((b) => b.id); + return BlocklistStore.getModelsArray().map((b) => b.id); } diff --git a/src/chat/events/registerLiveLocationUpdateEvent.ts b/src/chat/events/registerLiveLocationUpdateEvent.ts index 43ba457c9b..95dd959200 100644 --- a/src/chat/events/registerLiveLocationUpdateEvent.ts +++ b/src/chat/events/registerLiveLocationUpdateEvent.ts @@ -105,7 +105,7 @@ function registerLiveLocationUpdateEvent() { * Start for all active chats */ ChatStore.once('collection_has_synced', () => { - const chats = ChatStore.models.slice(0, config.liveLocationLimit); + const chats = ChatStore.getModelsArray().slice(0, config.liveLocationLimit); chats.forEach((chat) => { LiveLocationStore.update(chat.id) .then((liveLocation) => { diff --git a/src/chat/events/registerPresenceChange.ts b/src/chat/events/registerPresenceChange.ts index ead6f0767f..56ffe8646f 100644 --- a/src/chat/events/registerPresenceChange.ts +++ b/src/chat/events/registerPresenceChange.ts @@ -32,7 +32,7 @@ internalEv.on('conn.main_ready', () => { function register() { PresenceStore.on('change:chatstate.type', (chatstate: ChatstateModel) => { // Search precense model from chatstate - const presence = PresenceStore.models.find( + const presence = PresenceStore.getModelsArray().find( (m) => m.chatstate === chatstate ); @@ -58,7 +58,8 @@ function register() { } if (presence.isGroup) { - data.participants = presence.chatstates.models + data.participants = presence.chatstates + .getModelsArray() .filter((c) => !!c.type) .map((c) => { const contact = ContactStore.get(c.id); diff --git a/src/chat/functions/list.ts b/src/chat/functions/list.ts index 45540f8824..4ca3a84103 100644 --- a/src/chat/functions/list.ts +++ b/src/chat/functions/list.ts @@ -40,7 +40,7 @@ export interface ChatListOptions { * @category Chat */ export async function list(options: ChatListOptions): Promise { - let models = ChatStore.models; + let models = ChatStore.getModelsArray(); if (options.onlyUsers) { models = models.filter((c) => c.isUser); diff --git a/src/group/functions/getParticipants.ts b/src/group/functions/getParticipants.ts index 7baf3c11a4..7b819a5fa4 100644 --- a/src/group/functions/getParticipants.ts +++ b/src/group/functions/getParticipants.ts @@ -27,5 +27,5 @@ import { ensureGroup } from './'; */ export async function getParticipants(groupId: string | Wid) { const groupChat = await ensureGroup(groupId); - return groupChat.groupMetadata!.participants.models; + return groupChat.groupMetadata!.participants.getModelsArray(); } diff --git a/src/labels/functions/getAllLabels.ts b/src/labels/functions/getAllLabels.ts index d61324e7da..a976b7f0a8 100644 --- a/src/labels/functions/getAllLabels.ts +++ b/src/labels/functions/getAllLabels.ts @@ -19,7 +19,7 @@ import { LabelModel, LabelStore } from '../../whatsapp'; import { Label } from '..'; export async function getAllLabels(): Promise { - const labels = LabelStore.models; + const labels = LabelStore.getModelsArray(); return labels.map((e: LabelModel) => { return { id: e.id!, diff --git a/src/status/functions/sendRawStatus.ts b/src/status/functions/sendRawStatus.ts index 7df3679adc..aabbd6ea7e 100644 --- a/src/status/functions/sendRawStatus.ts +++ b/src/status/functions/sendRawStatus.ts @@ -81,7 +81,7 @@ webpack.onInjected(() => { return await func(...args); } - const myContacts = ContactStore.models + const myContacts = ContactStore.getModelsArray() .filter((c) => c.isMyContact && !c.isContactBlocked) .map((c) => c.id); diff --git a/src/whatsapp/collections/Collection.ts b/src/whatsapp/collections/Collection.ts index 224cb75e65..b0bcf0c48e 100644 --- a/src/whatsapp/collections/Collection.ts +++ b/src/whatsapp/collections/Collection.ts @@ -50,6 +50,8 @@ export declare class Collection extends EventEmitter { constructor(e?: any, t?: { parent: any }); + get length(): number; + add(value: A | WritableProperties, options?: Option): A; set(value: A, options?: Option): A; @@ -70,12 +72,6 @@ export declare class Collection extends EventEmitter { at(position: number): M | undefined; - get length(): number; - - get isCollection(): boolean; - - get models(): M[]; - serialize(): any[]; toJSON(): any[];