Fix message entity parsing and serialization

This commit is contained in:
Dan 2022-08-28 20:32:43 +02:00
parent f6e0e58f86
commit ed008dd3bb
6 changed files with 6 additions and 6 deletions

View File

@ -159,7 +159,7 @@ class SendMessage:
entities=[
types.MessageEntity._parse(None, entity, {})
for entity in entities
],
] if entities else None,
client=self
)

View File

@ -155,7 +155,7 @@ class SendPoll:
),
correct_answers=[bytes([correct_option_id])] if correct_option_id is not None else None,
solution=solution,
solution_entities=solution_entities
solution_entities=solution_entities or []
),
message="",
silent=disable_notification,

View File

@ -149,7 +149,7 @@ class HTML:
return {
"message": utils.remove_surrogates(parser.text),
"entities": sorted(entities, key=lambda e: e.offset)
"entities": sorted(entities, key=lambda e: e.offset) or None
}
@staticmethod

View File

@ -49,7 +49,7 @@ class Parser:
return await self.html.parse(text)
if mode == enums.ParseMode.DISABLED:
return {"message": text, "entities": []}
return {"message": text, "entities": None}
raise ValueError(f'Invalid parse mode "{mode}"')

View File

@ -52,5 +52,5 @@ class TermsOfService(Object):
entities=[
types.MessageEntity._parse(None, entity, {})
for entity in terms_of_service.entities
]
] if terms_of_service.entities else None
)

View File

@ -349,7 +349,7 @@ async def parse_text_entities(
for entity in entities:
entity._client = client
text, entities = text, [await entity.write() for entity in entities]
text, entities = text, [await entity.write() for entity in entities] or None
else:
text, entities = (await client.parser.parse(text, parse_mode)).values()