Skip to content

Commit

Permalink
fix: getUnreadMessages
Browse files Browse the repository at this point in the history
  • Loading branch information
jonalan7 committed May 22, 2023
1 parent 9105c06 commit 9f6b6bd
Show file tree
Hide file tree
Showing 10 changed files with 10 additions and 62 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,7 @@ const status = await client.getStatus('[email protected]');
const user = await client.getNumberProfile('[email protected]');

// Retrieve all unread message
const messages = await client.getAllUnreadMessages();
const messages = await client.getUnreadMessages();

// Retrieve profile fic (as url)
const url = await client.getProfilePicFromServer('[email protected]');
Expand Down
1 change: 0 additions & 1 deletion src/api/layers/retriever.layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,6 @@ export class RetrieverLayer extends SenderLayer {
return await this.page.evaluate(() => WAPI.isBeta());
}

//PRO
/**
* Retrieves all undread Messages
*/
Expand Down
18 changes: 0 additions & 18 deletions src/lib/wapi/functions/get-all-unread-messages.js

This file was deleted.

10 changes: 0 additions & 10 deletions src/lib/wapi/functions/get-chats-with-new-messages.js

This file was deleted.

24 changes: 8 additions & 16 deletions src/lib/wapi/functions/get-unread-messages.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,19 @@
export async function getUnreadMessages(undread = true) {
let arr = [];
const arr = [];
let chats;

// console.log('.....................', typeof undread);

if (undread === true) {
if (undread) {
chats = await Store.Chat.filter((e) => e.unreadCount > 0);
} else {
chats = await Store.Chat.filter((e) => e.unreadCount <= 0);
}

for (let i in chats) {
let f = Number(i);
if (!isNaN(f)) {
let t = chats[i].msgs._models.slice(-chats[i].unreadCount);
for (let r in t) {
let h = Number(r);
if (!isNaN(h)) {
let message = await WAPI.processMessageObj(t[r], true, true);
if (message) {
arr.push(message);
}
}
for (const chat of chats) {
const t = chat.msgs._models.slice(-chat.unreadCount);
for (const messageObj of t) {
const message = await WAPI.processMessageObj(messageObj, true, true);
if (message) {
arr.push(message);
}
}
}
Expand Down
3 changes: 0 additions & 3 deletions src/lib/wapi/functions/has-unread-messages.js

This file was deleted.

3 changes: 0 additions & 3 deletions src/lib/wapi/functions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,10 @@ export { getAllContacts } from './get-all-contacts';
export { getAllGroupMetadata } from './get-all-group-metadata';
export { getAllGroups } from './get-all-groups';
export { getAllMessagesInChat } from './get-all-messages-in-chat';
export { getAllUnreadMessages } from './get-all-unread-messages';
export { getBatteryLevel } from './get-battery-level';
export { getChat } from './get-chat';
export { getChatById } from './get-chat-by-id';
export { getChatByName } from './get-chat-by-name';
export { getAllChatsWithNewMessages } from './get-chats-with-new-messages';
export { getCommonGroups } from './get-common-groups';
export { getContact } from './get-contact';
export { getGroupAdmins } from './get-group-admins';
Expand All @@ -32,7 +30,6 @@ export { getNumberProfile } from './get-number-profile';
export { getProfilePicFromServer } from './get-profile-pic-from-server';
export { getStatus } from './get-status';
export { getUnreadMessages } from './get-unread-messages';
export { hasUndreadMessages } from './has-unread-messages';
export { isConnected } from './is-connected';
export { isLoggedIn } from './is-logged-in';
export { leaveGroup } from './leave-group';
Expand Down
6 changes: 0 additions & 6 deletions src/lib/wapi/wapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,10 @@ import {
getAllChatIds,
getAllChats,
getAllChatsWithMessages,
getAllChatsWithNewMessages,
getAllContacts,
getAllGroupMetadata,
getAllGroups,
getAllMessagesInChat,
getAllUnreadMessages,
getBatteryLevel,
getChat,
getChatById,
Expand All @@ -41,7 +39,6 @@ import {
getProfilePicFromServer,
getStatus,
getUnreadMessages,
hasUndreadMessages,
isConnected,
isLoggedIn,
leaveGroup,
Expand Down Expand Up @@ -313,10 +310,7 @@ if (typeof window.WAPI === 'undefined') {
window.WAPI.getMyContacts = getMyContacts;
window.WAPI.getContact = getContact;
window.WAPI.getAllChats = getAllChats;
window.WAPI.haveNewMsg = hasUndreadMessages;
window.WAPI.getAllChatsWithNewMsg = getAllChatsWithNewMessages;
window.WAPI.getAllChatIds = getAllChatIds;
window.WAPI.getAllUnreadMessages = getAllUnreadMessages;
window.WAPI.getAllChatsWithMessages = getAllChatsWithMessages;
window.WAPI.getAllGroups = getAllGroups;
window.WAPI.getChat = getChat;
Expand Down
1 change: 0 additions & 1 deletion src/types/WAPI.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ interface WAPI {
limit: number
) => Message[];

getAllUnreadMessages: () => PartialMessage[];
getBatteryLevel: () => number;
getBlockList: () => Contact[];
getBusinessProfilesProducts: (to: string) => any;
Expand Down
4 changes: 1 addition & 3 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ async function start(client) {
// client.onMessage((message) => {
// console.log(message);
// });
// const allMessages = await client.loadAndGetAllMessagesInChat(
// '[email protected]'
// );
// const allMessages = await client.getAllUnreadMessages();
// console.log(allMessages);
}

0 comments on commit 9f6b6bd

Please sign in to comment.