gramjs icon indicating copy to clipboard operation
gramjs copied to clipboard

Why ID format is different at few methods?

Open Psychosynthesis opened this issue 6 months ago • 0 comments

Why does the ID format returned by different methods differ?

This seems like nonsense, but...

const channels = await client.getDialogs();
const subscribedChannels = channels.map((chnl) => {
  const entity = chnl.entity;
  if (
    chnl.isChannel &&
    entity &&
    entity.className === "Channel" &&
    !entity.left
  ) {
    console.log('channel entity.id is: ', entity.id.toJSNumber()); // number like 1012360397 (10-diget format)
}});

And if I get the IDs from a message that comes as a parameter to the event handler function, i got OTHER id-format:

async function listenMessageEvent(params: NewMessageEvent) {
  const { chatId } = params.message;
  console.log(chatId.toJSNumber()); // !!!!! It's like -1001012360397 (same, but has "-100" at start);
}

Okay, I suspect that somewhere inside Gram.js there is a conversion and negative values ​​are encoded apparently by the most significant bits of the number, which is why this situation occurs...

But should this concern the client working with the lib?

Why aren't IDs formatted in a single format by calling toString()? By the way, it doesn't matter which method I use, toString() and toJSNumber() give the same format :\

Am I doing something wrong? What's the problem with returning one format?

Psychosynthesis avatar Apr 02 '25 13:04 Psychosynthesis