zerobias / telegram-mtproto

Telegram client api (MTProto) library
MIT License
617 stars 136 forks source link

messages.getHistory: Not all messages returned when limit = 5 for inputPeerChannel #195

Closed abdhass closed 5 years ago

abdhass commented 6 years ago

Issue

From the examples folder, if you run the chat history with a limit of 5 this happens:

2:19 [undefined] msg 1 22:19 [undefined] msg 2 15:13 [undefined] msg 3 15:9 [undefined] msg 4 13:44 [undefined] msg 5 22:19 [undefined] msg 2 << repeats from here 15:13 [undefined] msg 3 15:9 [undefined] msg 4 13:44 [undefined] msg 5

Seems like messages.getHistory doesnt offset from the max_id

in this case, the maximum messages in the telegram group i was querying is 32.

To test this:

Be in a channel you can test this issue. npm install

Uncomment chat and chathistory lines in examples/index.js

`const run = async () => {`
  const first_name = await login()
  // const res = await searchUsers()
  // await updateProfile(first_name)
  const chat = await getChat()`
  await chatHistory(chat)
}

Update to dev:false in examples/init.js const server = { webogram: true, dev: false }

In chat-history.js change the limit to 5 const limit = 5 run node examples/index.js

After logging in, choose a channel.

Im actually having this problem in my own app, but thought id test it in a new clone of this repo and the problem is there too.

Any advice appreciated. Thanks!

ismenc commented 6 years ago

Excuse i ask here @abdhass, did you get messages.getHistory to work in channels? I only get CODE#400 PEER_ID_INVALID sending stuff like this:

peer: {
        "_": "inputPeerChannel",
        "channel_id": 1245892652,
        "access_hash": "2078923260725999679"
    },
limit: 3

is there any format mistake?

abdhass commented 6 years ago

Yes I did @ismenc Try this... taken from the examples folder

peer: {
        _          : 'inputPeerChannel',
        channel_id : chat.id,
        access_hash: chat.access_hash
      },
      max_id: offset,
      offset: -full.length,
      limit
ismenc commented 6 years ago

Thanks m8. After some time i realized the problem was i was using readHistory instead of getHistory. Sad life  >.<