Skip to content

Commit

Permalink
fix: Fixed getMessages for non multidevices (fix wppconnect-team/wppc…
Browse files Browse the repository at this point in the history
  • Loading branch information
edgardmessias committed Nov 6, 2021
1 parent bac1944 commit c43b2cb
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/chat/Chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,25 +216,29 @@ export class Chat extends Emittery<ChatEventTypes> {

let count = options.count || 20;
const direction = options.direction === 'after' ? 'after' : 'before';
const id = options.id || chat.lastReceivedKey!.toString();
const id = options.id || chat.lastReceivedKey?.toString();

// Fix for multidevice
if (count === -1 && Features.supportsFeature('MD_BACKEND')) {
count = Infinity;
}

if (!options.id) {
if (!options.id && id) {
count--;
}

const params: MsgFindQueryParams = MsgKey.fromString(id) as any;
const params: MsgFindQueryParams = id
? (MsgKey.fromString(id) as any)
: {
remote: chat.id,
};

params.count = count;
params.direction = direction;

const msgs = await msgFindQuery(direction, params);

if (!options.id) {
if (!options.id && id) {
const msg = MsgStore.get(id);
if (msg) {
msgs.push(msg.attributes);
Expand Down

0 comments on commit c43b2cb

Please sign in to comment.