Skip to content

Commit

Permalink
fix: loadAllEarlierMessages e retorno da loadAndGetAllMessagesInChat
Browse files Browse the repository at this point in the history
  • Loading branch information
Felipe Escher committed Aug 16, 2022
1 parent f6005fd commit 4e2a198
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/lib/wapi/functions/load-all-earlier-chat-messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMNNNNMMNNNMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
*/
export async function loadAllEarlierMessages(id, done) {
const found = WAPI.getChat(id);
const found = window.WAPI.getChat(id);
while (!found.msgs.msgLoadState.noEarlierMsgs) {
console.log('Loading...');
await found.loadEarlierMsgs();
await window.Store.ConversationMsgs.loadEarlierMsgs(found);
}
console.log('done');
return true;
Expand Down
35 changes: 26 additions & 9 deletions src/lib/wapi/functions/load-and-get-all-messages-in-chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,31 @@ MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMNMMNMNMMMNMMNNMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMNNNNMMNNNMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
*/
export async function loadAllEarlierMessages(id, done) {
const found = WAPI.getChat(id);
while (!found.msgs.msgLoadState.noEarlierMsgs) {
console.log('Loading...');
await window.Store.ConversationMsgs.loadEarlierMsgs(found);
}
console.log('done');
return true;
export async function loadAndGetAllMessagesInChat(
id,
includeMe,
includeNotifications
) {
return window.WAPI.loadAllEarlierMessages(id).then(() => {
const chat = window.WAPI.getChat(id);
let output = [];
const messages = chat.msgs._models;

for (const i in messages) {
if (i === 'remove') {
continue;
}
const messageObj = messages[i];

let message = WAPI.processMessageObj(
messageObj,
includeMe,
includeNotifications
);
if (message) output.push(message);
}
return output;
});
}

/**
Expand All @@ -69,6 +86,6 @@ export async function loadAllEarlierMessages(id, done) {
* @param {Funciton} done Optional callback
*/
export function asyncLoadAllEarlierMessages(id, done) {
loadAllEarlierMessages(id);
loadAndGetAllMessagesInChat(id);
done();
}

0 comments on commit 4e2a198

Please sign in to comment.