Skip to content

Commit

Permalink
fix: Fixed group metadata from chat list
Browse files Browse the repository at this point in the history
  • Loading branch information
edgardmessias committed Sep 17, 2022
1 parent b60a9b6 commit 8b1dea1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
10 changes: 8 additions & 2 deletions src/chat/functions/find.ts
Expand Up @@ -15,7 +15,7 @@
*/

import { assertWid } from '../../assert';
import { ChatModel, Wid } from '../../whatsapp';
import { ChatModel, GroupMetadataStore, Wid } from '../../whatsapp';
import { findChat } from '../../whatsapp/functions';

/**
Expand All @@ -27,5 +27,11 @@ import { findChat } from '../../whatsapp/functions';
*/
export async function find(chatId: string | Wid): Promise<ChatModel> {
const wid = assertWid(chatId);
return findChat(wid);
const chat = await findChat(wid);

if (chat.isGroup) {
await GroupMetadataStore.find(chat.id);
}

return chat;
}
13 changes: 12 additions & 1 deletion src/chat/functions/list.ts
Expand Up @@ -14,7 +14,12 @@
* limitations under the License.
*/

import { ChatModel, ChatStore, LabelStore } from '../../whatsapp';
import {
ChatModel,
ChatStore,
GroupMetadataStore,
LabelStore,
} from '../../whatsapp';

export interface ChatListOptions {
onlyGroups?: boolean;
Expand Down Expand Up @@ -80,5 +85,11 @@ export async function list(
models = models.filter((c) => c.labels?.some((id) => ids.includes(id)));
}

for (const chat of models) {
if (chat.isGroup) {
await GroupMetadataStore.find(chat.id);
}
}

return models;
}

0 comments on commit 8b1dea1

Please sign in to comment.