move Model.username() to Web

pull/530/head
Ryan Barrett 2023-06-04 16:10:37 -07:00
rodzic 71dadc2ba5
commit 9a75d10f54
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 6BE31FDF4776E9D4
2 zmienionych plików z 21 dodań i 23 usunięć

Wyświetl plik

@ -195,29 +195,6 @@ class User(StringIdModel, metaclass=ProtocolUserMeta):
return self.readable_or_key_id()
def username(self):
"""Returns the user's preferred username.
Uses stored representative h-card if available, falls back to id.
TODO(#512): move to Web
Returns: str
"""
id = self.key.id()
if self.actor_as2 and self.direct:
for url in [u.get('value') if isinstance(u, dict) else u
for u in util.get_list(self.actor_as2, 'url')]:
if url and url.startswith('acct:'):
urluser, urldomain = util.parse_acct_uri(url)
if urldomain == id:
logger.info(f'Found custom username: {urluser}')
return urluser
logger.info(f'Defaulting username to key id {id}')
return id
def web_url(self):
"""Returns this user's web URL aka web_url, eg 'https://foo.com/'.

21
web.py
Wyświetl plik

@ -88,6 +88,27 @@ class Web(User, Protocol):
url += f'/{rest}'
return url
def username(self):
"""Returns the user's preferred username.
Uses stored representative h-card if available, falls back to id.
Returns: str
"""
id = self.key.id()
if self.actor_as2 and self.direct:
for url in [u.get('value') if isinstance(u, dict) else u
for u in util.get_list(self.actor_as2, 'url')]:
if url and url.startswith('acct:'):
urluser, urldomain = util.parse_acct_uri(url)
if urldomain == id:
logger.info(f'Found custom username: {urluser}')
return urluser
logger.info(f'Defaulting username to key id {id}')
return id
def verify(self):
"""Fetches site a couple ways to check for redirects and h-card.