Skip to content

Commit

Permalink
fix: Fixed getMessages function (fix #401)
Browse files Browse the repository at this point in the history
  • Loading branch information
edgardmessias committed Aug 18, 2021
1 parent 76a4217 commit 43ba3d4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/lib/wapi/functions/get-messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export async function getMessages(chatId, params = {}, serialize = true) {
remote: chatWid,
count: params.count,
owner: params.fromMe,
direction: direction,
};

// Caso tenha informado o ID da mensagem, a consulta se realizará a partir dela
Expand All @@ -61,7 +62,8 @@ export async function getMessages(chatId, params = {}, serialize = true) {
const msgKey = window.Store.MsgKey.fromString(params.id);
if (msgKey) {
queryData.id = msgKey.id;
queryData.owner = msgKey.fromMe;
queryData.fromMe = msgKey.fromMe;
queryData._serialized = msgKey._serialized;
}
} catch (error) {
queryData.id = params.id;
Expand All @@ -71,7 +73,16 @@ export async function getMessages(chatId, params = {}, serialize = true) {
queryData.count--;
}

const msgs = await Store.WapQuery.msgFindQuery(direction, queryData);
const msgs = await Store.msgFindQuery(direction, queryData);
console.log(msgs);

if (!Array.isArray(msgs)) {
const error = new Error(`Failed to fetch messages for ${chat.id}`);

Object.assign(error, msgs);

throw error;
}

const result = msgs
.map((m) => new Store.Msg.modelClass(m))
Expand Down
5 changes: 5 additions & 0 deletions src/lib/wapi/store/store-objects.js
Original file line number Diff line number Diff line change
Expand Up @@ -430,4 +430,9 @@ export const storeObjects = [
id: 'sendCreateGroup',
conditions: (module) => module.sendCreateGroup,
},
{
id: 'msgFindQuery',
conditions: (module) =>
module.msgFindQuery && module.msgFindByIds ? module.msgFindQuery : null,
},
];

0 comments on commit 43ba3d4

Please sign in to comment.