Fix for HubZilla actor caching

master
Thomas Sileo 2019-11-01 12:15:42 +01:00
rodzic 7c4e6732c9
commit 99bf6a4a01
1 zmienionych plików z 19 dodań i 1 usunięć

Wyświetl plik

@ -78,6 +78,24 @@ def _answer_key(choice: str) -> str:
return h.hexdigest()
def _actor_url(actor: ap.ActivityType) -> str:
if isinstance(actor.url, dict):
if actor.url.get("type") == ap.ActivityType.LINK.value:
return actor.url["href"]
raise ValueError(f"unkown actor url object type: {actor.url!r}")
elif isinstance(actor.url, str):
return actor.url
# Return the actor ID if we cannot get the URL
elif isinstance(actor.id, str):
return actor.id
else:
raise ValueError(f"invalid actor URL: {actor.url!r}")
def _actor_hash(actor: ap.ActivityType, local: bool = False) -> str:
"""Used to know when to update the meta actor cache, like an "actor version"."""
h = hashlib.new("sha1")
@ -85,7 +103,7 @@ def _actor_hash(actor: ap.ActivityType, local: bool = False) -> str:
h.update((actor.name or "").encode())
h.update((actor.preferredUsername or "").encode())
h.update((actor.summary or "").encode())
h.update((actor.url or "").encode())
h.update(_actor_url(actor).encode())
key = actor.get_key()
h.update(key.pubkey_pem.encode())
h.update(key.key_id().encode())