Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Added deleteOldChats #1884

Closed
wants to merge 20 commits into from
Closed
27 changes: 27 additions & 0 deletions src/lib/wapi/wapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,33 @@ if (typeof window.WAPI === 'undefined') {
return window.Debug.VERSION;
};

/**
* @param NumberChatsDelete Number of chats that will be deleted
*/
//Add Marcelo 21/10/2023
window.WAPI.deleteOldChats = async function (NumberChatsDelete) {
const options = {
onlyWithUnreadMessage: false,
onlyUsers: true,
};

try {
const chats = await window.WAPI.chat.list(options);
chats.reverse();
const numChatsToDelete = Math.min(NumberChatsDelete, chats.length);

for (let i = 0; i < numChatsToDelete; i++) {
await window.WAPI.chat
.delete(chats[i].id._serialized)
.then((_) => true)
.catch((_) => false);
}
} catch (e) {
console.error('Erro:', e);
return e;
}
};

/**
* @param id The id of the conversation
* @param archive boolean true => archive, false => unarchive
Expand Down
Loading