Fix highlighting Telegram users without usernames
This commit is contained in:
@@ -53,17 +53,15 @@ class MatrixParser(HTMLParser):
|
|||||||
mention = self.mention_regex.match(url)
|
mention = self.mention_regex.match(url)
|
||||||
if mention:
|
if mention:
|
||||||
mxid = mention.group(1)
|
mxid = mention.group(1)
|
||||||
user = (pu.Puppet.get_by_mxid(mxid, create=False)
|
user = (pu.Puppet.get_by_mxid(mxid)
|
||||||
or u.User.get_by_mxid(mxid, create=False))
|
or u.User.get_by_mxid(mxid, create=False))
|
||||||
if not user:
|
if not user:
|
||||||
return None, None
|
return None, None
|
||||||
if user.username:
|
if user.username:
|
||||||
entity_type = MessageEntityMention
|
return MessageEntityMention, f"@{user.username}"
|
||||||
url = f"@{user.username}"
|
|
||||||
else:
|
else:
|
||||||
entity_type = MessageEntityMentionName
|
args["user_id"] = InputUser(user.tgid, 0)
|
||||||
args["user_id"] = user.tgid
|
return InputMessageEntityMentionName, user.displayname or None
|
||||||
return entity_type, url
|
|
||||||
|
|
||||||
room = self.room_regex.match(url)
|
room = self.room_regex.match(url)
|
||||||
if room:
|
if room:
|
||||||
|
|||||||
@@ -580,13 +580,22 @@ class Portal:
|
|||||||
message["body"] = f"<{sender.displayname}> {message['body']}"
|
message["body"] = f"<{sender.displayname}> {message['body']}"
|
||||||
return type
|
return type
|
||||||
|
|
||||||
def _handle_matrix_text(self, client, message, reply_to):
|
async def _handle_matrix_text(self, client, message, reply_to):
|
||||||
if "format" in message and message["format"] == "org.matrix.custom.html":
|
is_formatted = ("format" in message
|
||||||
|
and message["format"] == "org.matrix.custom.html"
|
||||||
|
and "formatted_body" in message)
|
||||||
|
if is_formatted:
|
||||||
message, entities = formatter.matrix_to_telegram(message["formatted_body"])
|
message, entities = formatter.matrix_to_telegram(message["formatted_body"])
|
||||||
return client.send_message(self.peer, message, entities=entities, reply_to=reply_to)
|
|
||||||
|
# TODO remove this crap
|
||||||
|
for entity in entities:
|
||||||
|
if isinstance(entity, InputMessageEntityMentionName):
|
||||||
|
entity.user_id = await client.get_input_entity(entity.user_id.user_id)
|
||||||
|
|
||||||
|
return await client.send_message(self.peer, message, entities=entities, reply_to=reply_to)
|
||||||
else:
|
else:
|
||||||
message = formatter.matrix_text_to_telegram(message["body"])
|
message = formatter.matrix_text_to_telegram(message["body"])
|
||||||
return client.send_message(self.peer, message, reply_to=reply_to)
|
return await client.send_message(self.peer, message, reply_to=reply_to)
|
||||||
|
|
||||||
async def _handle_matrix_file(self, client, message, reply_to):
|
async def _handle_matrix_file(self, client, message, reply_to):
|
||||||
file = await self.main_intent.download_file(message["url"])
|
file = await self.main_intent.download_file(message["url"])
|
||||||
|
|||||||
Reference in New Issue
Block a user