Support actor update

This commit is contained in:
Thomas Sileo
2019-09-08 16:55:24 +02:00
parent cc89b0b584
commit 7f4be2cbc2
7 changed files with 55 additions and 5 deletions

View File

@@ -78,7 +78,7 @@ def _answer_key(choice: str) -> str:
return h.hexdigest()
def _actor_hash(actor: ap.ActivityType) -> str:
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")
h.update(actor.id.encode())
@@ -91,6 +91,12 @@ def _actor_hash(actor: ap.ActivityType) -> str:
h.update(key.key_id().encode())
if isinstance(actor.icon, dict) and "url" in actor.icon:
h.update(actor.icon["url"].encode())
if local:
# The local hash helps us detect when to send an Update
for item in actor.attachment:
h.update(item["name"].encode())
h.update(item["value"].encode())
h.update(("1" if actor.manuallyApprovesFollowers else "0").encode())
return h.hexdigest()

View File

@@ -8,8 +8,8 @@ from typing import Set
from little_boxes import activitypub as ap
from poussetaches import PousseTaches
from config import MEDIA_CACHE
from config import DISABLE_WEBMENTIONS
from config import MEDIA_CACHE
from utils import parse_datetime
p = PousseTaches(
@@ -102,6 +102,10 @@ class Tasks:
def finish_post_to_outbox(iri: str) -> None:
p.push(iri, "/task/finish_post_to_outbox")
@staticmethod
def send_actor_update() -> None:
p.push({}, "/task/send_actor_update", delay=2)
@staticmethod
def update_question_outbox(iri: str, open_for: int) -> None:
p.push(