If a remote actor has no icon, we show our local default icon.
If we have no icon, we should allow remote instances to show their
default icon, instead of sending ours.
---
app/activitypub.py | 12 +++++++-----
app/config.py | 2 +-
app/main.py | 9 ++++++---
scripts/config_wizard.py | 5 +++--
4 files changed, 17 insertions(+), 11 deletions(-)
diff --git a/app/activitypub.py b/app/activitypub.py
index 170811d..3a96e8b 100644
--- a/app/activitypub.py
+++ b/app/activitypub.py
@@ -135,11 +135,6 @@ ME = {
"url": config.ID + "/", # XXX: the path is important for Mastodon compat
"manuallyApprovesFollowers": config.CONFIG.manually_approves_followers,
"attachment": _LOCAL_ACTOR_METADATA,
- "icon": {
- "mediaType": mimetypes.guess_type(config.CONFIG.icon_url)[0],
- "type": "Image",
- "url": config.CONFIG.icon_url,
- },
"publicKey": {
"id": f"{config.ID}#main-key",
"owner": config.ID,
@@ -148,6 +143,13 @@ ME = {
"tag": dedup_tags(_LOCAL_ACTOR_TAGS),
}
+if config.CONFIG.icon_url:
+ ME["icon"] = {
+ "mediaType": mimetypes.guess_type(config.CONFIG.icon_url)[0],
+ "type": "Image",
+ "url": config.CONFIG.icon_url,
+ }
+
if ALSO_KNOWN_AS:
ME["alsoKnownAs"] = [ALSO_KNOWN_AS]
diff --git a/app/config.py b/app/config.py
index 14bb913..447fb24 100644
--- a/app/config.py
+++ b/app/config.py
@@ -91,7 +91,7 @@ class Config(pydantic.BaseModel):
name: str
summary: str
https: bool
- icon_url: str
+ icon_url: str | None = None
image_url: str | None = None
secret: str
debug: bool = False
diff --git a/app/main.py b/app/main.py
index 814c650..2d5f0a7 100644
--- a/app/main.py
+++ b/app/main.py
@@ -1431,7 +1431,7 @@ async def json_feed(
],
}
)
- return {
+ result = {
"version": "https://jsonfeed.org/version/1",
"title": f"{LOCAL_ACTOR.display_name}'s microblog'",
"home_page_url": LOCAL_ACTOR.url,
@@ -1439,10 +1439,12 @@ async def json_feed(
"author": {
"name": LOCAL_ACTOR.display_name,
"url": LOCAL_ACTOR.url,
- "avatar": LOCAL_ACTOR.icon_url,
},
"items": data,
}
+ if LOCAL_ACTOR.icon_url:
+ result["author"]["avatar"] = LOCAL_ACTOR.icon_url
+ return result
async def _gen_rss_feed(
@@ -1454,7 +1456,8 @@ async def _gen_rss_feed(
fg.description(f"{LOCAL_ACTOR.display_name}'s microblog")
fg.author({"name": LOCAL_ACTOR.display_name})
fg.link(href=LOCAL_ACTOR.url, rel="alternate")
- fg.logo(LOCAL_ACTOR.icon_url)
+ if LOCAL_ACTOR.icon_url:
+ fg.logo(LOCAL_ACTOR.icon_url)
fg.language("en")
outbox_objects = await _get_outbox_for_feed(db_session)
diff --git a/scripts/config_wizard.py b/scripts/config_wizard.py
index 22119e6..912d726 100644
--- a/scripts/config_wizard.py
+++ b/scripts/config_wizard.py
@@ -75,9 +75,10 @@ def main() -> None:
proto = "http"
print("Note that you can put your icon/avatar in the static/ directory")
- dat["icon_url"] = prompt(
+ if icon_url := prompt(
"icon URL: ", default=f'{proto}://{dat["domain"]}/static/nopic.png'
- )
+ ):
+ dat["icon_url"] = icon_url
dat["secret"] = os.urandom(16).hex()
with config_file.open("w") as f:
--
2.35.1
Hey, that makes sense.
I wonder if having `null`/`None` as the `icon` would a better option?
Did you look at how other software are handling this (and have you tested with at least Mastodon)?
I am afraid it could break federation with some software expecting the `icon` key to be there.
Thanks!
On 2022-11-18 11:29 AM, Thomas Sileo wrote:
> I wonder if having `null`/`None` as the `icon` would a better option?
> Did you look at how other software are handling this (and have you tested with at least Mastodon)?
>
> I am afraid it could break federation with some software expecting the `icon` key to be there.
A reasonable concern!
Microblog.pub instances seem to show the local nopic.png (not the
Mastodon default icon) on mastodon.social users who haven't set an icon.
Fetching the Mastodon actor JSON manually confirms that the "icon" key
is missing entirely for no-icon users, and present for users with an
icon set. So I think this patch's behavior matches what Mastodon does.
I've been running it on @noc@doof.net for the past several days, and
have been successfully federating with mastodon.social in that time,
including a lot of test interactions between a no-icon Microblog.pub
actor and a custom-icon Mastodon actor.
I looked at the ActivityPub/ActivityStreams spec, and I think it intends
for the "icon" property to be optional, but it doesn't seem to
explicitly state that.
Thanks,
Kevin