From 4613997fe3f429d81c9a63ceeafd2c05bce6dec0 Mon Sep 17 00:00:00 2001 From: Alexey Shpakovsky Date: Thu, 10 Nov 2022 22:43:33 +0100 Subject: [PATCH] Add option to set image_url ("background image") for user While this option is not used anywhere in microblog.pub itself, some other servers do occasionally use it when showing remote profiles. Also, this image _can_ be used in microblog.pub - just add this: in the appropriate place of your template! --- app/activitypub.py | 6 ++++++ app/actor.py | 7 +++++++ app/config.py | 1 + 3 files changed, 14 insertions(+) diff --git a/app/activitypub.py b/app/activitypub.py index 61f1e8b..84440e6 100644 --- a/app/activitypub.py +++ b/app/activitypub.py @@ -154,6 +154,12 @@ if ALSO_KNOWN_AS: if MOVED_TO: ME["movedTo"] = MOVED_TO +if config.CONFIG.image_url: + ME["image"] = { + "mediaType": mimetypes.guess_type(config.CONFIG.image_url)[0], + "type": "Image", + "url": config.CONFIG.image_url, + } class NotAnObjectError(Exception): def __init__(self, url: str, resp: httpx.Response | None = None) -> None: diff --git a/app/actor.py b/app/actor.py index 05061c4..995de2b 100644 --- a/app/actor.py +++ b/app/actor.py @@ -88,6 +88,10 @@ class Actor: def icon_media_type(self) -> str | None: return self.ap_actor.get("icon", {}).get("mediaType") + @property + def image_url(self) -> str | None: + return self.ap_actor.get("image", {}).get("url") + @property def public_key_as_pem(self) -> str: return self.ap_actor["publicKey"]["publicKeyPem"] @@ -381,6 +385,9 @@ def _actor_hash(actor: Actor) -> bytes: if actor.icon_url: h.update(actor.icon_url.encode()) + if actor.image_url: + h.update(actor.image_url.encode()) + if actor.attachments: for a in actor.attachments: if a.get("type") != "PropertyValue": diff --git a/app/config.py b/app/config.py index 36ff073..0ce10c6 100644 --- a/app/config.py +++ b/app/config.py @@ -92,6 +92,7 @@ class Config(pydantic.BaseModel): summary: str https: bool icon_url: str + image_url: str secret: str debug: bool = False trusted_hosts: list[str] = ["127.0.0.1"]