gramjs icon indicating copy to clipboard operation
gramjs copied to clipboard

Telegram entity classes are lost after message serialization

Open migh000 opened this issue 4 years ago • 3 comments

Telegram entity classes are lost after message serialization

/// get one message with bold in text
  const chanId = 123 // insert yours
  const offset = 456 // insert yours
  const result = await client.client.invoke(new Api.messages.GetHistory({
    peer: chanId,
    limit: 1,
    offsetId: offset
  }));

  console.log(message, JSON.parse(JSON.stringify(message))) // printing both plain and stringified version

in the console (excerpts):

// when doing console.log()
entities: [
    {
      CONSTRUCTOR_ID: 3177253833,
      SUBCLASS_OF_ID: 3479443932,
      className: 'MessageEntityBold',
      classType: 'constructor',
      offset: 19,
      length: 7
    },
    {
      CONSTRUCTOR_ID: 3177253833,
      SUBCLASS_OF_ID: 3479443932,
      className: 'MessageEntityBold',
      classType: 'constructor',
      offset: 35,
      length: 7
    }
  ],

// when doing JSON.parse(JSON.stringify())
  entities: [ { offset: 19, length: 7 }, { offset: 35, length: 7 } ],

As a result, className: 'MessageEntityBold', is lost forever.

migh000 avatar Mar 28 '22 10:03 migh000

ah you're right,

I don't think the other info (constructor id , subclass id , class type) are relevant so I'm only going to add the class name for now

painor avatar Mar 28 '22 10:03 painor

Should be fixed in https://github.com/gram-js/gramjs/commit/6fc7ea29b72b8386be86be3b4d50020d31942ec3 Please test and close this issue if it's working now.

painor avatar Mar 28 '22 14:03 painor

Tested, looks fine, many thanks!

migh000 avatar Apr 07 '22 11:04 migh000