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

Update messages-recv.ts #4

Closed
wants to merge 4 commits into from
Closed

Conversation

wkarts
Copy link
Owner

@wkarts wkarts commented Aug 16, 2024

Run yarn
  yarn
  shell: /usr/bin/bash -e {0}
  env:
    NODE_AUTH_TOKEN: ***
yarn install v1.[2](https://github.com/wkarts/Baileys/actions/runs/10419571902/job/28857896043#step:8:2)2.22
[1/4] Resolving packages...
[2/4] Fetching packages...
[[3](https://github.com/wkarts/Baileys/actions/runs/10419571902/job/28857896043#step:8:3)/4] Linking dependencies...
[[4](https://github.com/wkarts/Baileys/actions/runs/10419571902/job/28857896043#step:8:4)/4] Building fresh packages...
$ tsc
Error: src/Socket/messages-recv.ts(842,39): error TS234[5](https://github.com/wkarts/Baileys/actions/runs/10419571902/job/28857896043#step:8:5): Argument of type '{ historySyncOnDemandRequest: { chatJid: string | null | undefined; oldestMsgFromMe: boolean | null | undefined; oldestMsgId: string | null | undefined; oldestMsgTimestampMs: number | Long.Long; onDemandMsgCount: number; }; peerDataOperationRequestType: proto.Message.PeerDataOperationRequestType; }' is not assignable to parameter of type 'IPeerDataOperationRequestMessage'.
  The types of 'historySyncOnDemandRequest.oldestMsgTimestampMs' are incompatible between these types.
    Type 'number | Long' is not assignable to type 'number | Long | null | undefined'.
      Type 'Long' is not assignable to type 'number | Long | null | undefined'.
        Type 'Long' is missing the following properties from type 'Long': ge, eqz, le, rem, and [10](https://github.com/wkarts/Baileys/actions/runs/10419571902/job/28857896043#step:8:11) more.
error Command failed with exit code 2.
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
Error: Process completed with exit code 2.

O erro ocorre porque há uma incompatibilidade de tipos entre o que é esperado e o que está sendo passado como argumento para a função sendPeerDataOperationMessage.

Identificação do Problema

Na função fetchMessageHistory, a linha que define pdoMessage está assim:

const pdoMessage = {
    historySyncOnDemandRequest: {
        chatJid: oldestMsgKey.remoteJid,
        oldestMsgFromMe: oldestMsgKey.fromMe,
        oldestMsgId: oldestMsgKey.id,
        oldestMsgTimestampMs: oldestMsgTimestamp,
        onDemandMsgCount: count
    },
    peerDataOperationRequestType: proto.Message.PeerDataOperationRequestType.HISTORY_SYNC_ON_DEMAND
}

O problema está na linha:

oldestMsgTimestampMs: oldestMsgTimestamp,

Aqui, oldestMsgTimestamp é do tipo number | Long, mas o TypeScript está exigindo que ele seja do tipo number | Long | null | undefined.

Correção

Para resolver isso, podemos garantir que o tipo esteja compatível com o que é esperado. Uma maneira de fazer isso é explicitamente permitir que o valor seja null ou undefined usando uma conversão de tipo.

const pdoMessage = {
    historySyncOnDemandRequest: {
        chatJid: oldestMsgKey.remoteJid,
        oldestMsgFromMe: oldestMsgKey.fromMe,
        oldestMsgId: oldestMsgKey.id,
        oldestMsgTimestampMs: oldestMsgTimestamp as number | Long | null | undefined,
        onDemandMsgCount: count
    },
    peerDataOperationRequestType: proto.Message.PeerDataOperationRequestType.HISTORY_SYNC_ON_DEMAND
}

@wkarts
Copy link
Owner Author

wkarts commented Aug 16, 2024

Thanks for your contribution.

The next step is to wait for review and approval to merge it to main repository

The community can help reacting with a thumb up (:thumbsup:) for approval and rocket (:rocket:) for who has tested it.

To test this PR you can run the following command below:

# NPM
npm install @wkarts/baileys@wkarts/Baileys#master-oficial-save-16082024
# YARN v2
yarn add @wkarts/baileys@wkarts/Baileys#master-oficial-save-16082024

@wkarts wkarts closed this Aug 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant