From 28bed96e404e477f9517215c37101e88543581c1 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Thu, 4 Jul 2019 22:32:30 +0300 Subject: [PATCH] Fix displayname not updating for some users Users who the bridge only saw via logged in users with the target user in their contact lists wouldn't get their displayname updated due to an invalid condition in the update_displayname function. --- mautrix_telegram/portal.py | 2 +- mautrix_telegram/puppet.py | 12 +++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/mautrix_telegram/portal.py b/mautrix_telegram/portal.py index 5558867a..60e9aff9 100644 --- a/mautrix_telegram/portal.py +++ b/mautrix_telegram/portal.py @@ -1774,7 +1774,7 @@ class Portal: return if sender and not sender.displayname: - self.log.debug(f"Telegram user {sender.tgid} sent a message, but doesn't have a" + self.log.debug(f"Telegram user {sender.tgid} sent a message, but doesn't have a " "displayname, updating info...") entity = await source.client.get_entity(PeerUser(sender.tgid)) await sender.update_info(source, entity) diff --git a/mautrix_telegram/puppet.py b/mautrix_telegram/puppet.py index b715ada0..9cdac8fe 100644 --- a/mautrix_telegram/puppet.py +++ b/mautrix_telegram/puppet.py @@ -363,11 +363,13 @@ class Puppet: ) -> bool: if self.disable_updates: return False - is_main_source = (source.is_relaybot or (self.displayname_source is not None - and self.displayname_source == source.tgid)) - # No phone -> not in contact list -> can't set custom name -> name is trustworthy - is_trustworthy_source = isinstance(info, User) and info.phone is None - if not is_main_source and not is_trustworthy_source: + allow_source = (source.is_relaybot + or self.displayname_source == source.tgid + # No displayname source, so just trust anything + or self.displayname_source is None + # No phone -> not in contact list -> can't set custom name + or (isinstance(info, User) and info.phone is None)) + if not allow_source: return False elif isinstance(info, UpdateUserName): info = await source.client.get_entity(PeerUser(self.tgid))