diff --git a/activitypub.py b/activitypub.py index 0d4a5c2..15e64cb 100644 --- a/activitypub.py +++ b/activitypub.py @@ -569,6 +569,7 @@ class MicroblogPubBackend(Backend): ) return None + print(f"processing {create!r} and incrementing {in_reply_to}") creply = DB.activities.find_one_and_update( {"activity.object.id": in_reply_to}, {"$inc": {"meta.count_reply": 1, "meta.count_direct_reply": 1}}, diff --git a/app.py b/app.py index 55e3de7..dbec07f 100644 --- a/app.py +++ b/app.py @@ -2639,6 +2639,7 @@ def post_to_inbox(activity: ap.BaseActivity) -> None: if back.inbox_check_duplicate(MY_PERSON, activity.id): # The activity is already in the inbox app.logger.info(f"received duplicate activity {activity!r}, dropping it") + return back.save(Box.INBOX, activity) Tasks.process_new_activity(activity.id) @@ -2691,16 +2692,23 @@ def task_cache_attachments(): if actor.icon: MEDIA_CACHE.cache(actor.icon["url"], Kind.ACTOR_ICON) + obj = None if activity.has_type(ap.ActivityType.CREATE): - for attachment in activity.get_object()._data.get("attachment", []): - if ( - attachment.get("mediaType", "").startswith("image/") - or attachment.get("type") == ap.ActivityType.IMAGE.value - ): - try: - MEDIA_CACHE.cache_attachment2(attachment["url"], iri) - except ValueError: - app.logger.exception(f"failed to cache {attachment}") + # This means a `Create` triggered the task + obj = activity.get_object() + elif activity.has_type(ap.CREATE_TYPES): + # This means a `Announce` triggered the task + obj = activity + else: + app.logger.warning(f"Don't know what to do with {activity!r}") + return + + # Iter the attachments + for attachment in obj._data.get("attachment", []): + try: + MEDIA_CACHE.cache_attachment2(attachment, iri) + except ValueError: + app.logger.exception(f"failed to cache {attachment}") app.logger.info(f"attachments cached for {iri}") @@ -2725,6 +2733,7 @@ def task_cache_actor() -> str: activity = ap.fetch_remote_activity(iri) app.logger.info(f"activity={activity!r}") + # FIXME(tsileo): OG meta for Announce? if activity.has_type(ap.ActivityType.CREATE): Tasks.fetch_og_meta(iri) @@ -2766,6 +2775,10 @@ def task_cache_actor() -> str: app.logger.info(f"actor cached for {iri}") if also_cache_attachments and activity.has_type(ap.ActivityType.CREATE): Tasks.cache_attachments(iri) + elif also_cache_attachments and activity.has_type(ap.ActivityType.ANNOUNCE): + obj = activity.get_object() + Tasks.cache_attachments(obj.id) + Tasks.cache_actor(obj.id) except (ActivityGoneError, ActivityNotFoundError): DB.activities.update_one({"remote_id": iri}, {"$set": {"meta.deleted": True}}) @@ -3201,6 +3214,8 @@ def task_cleanup_part_2(): MEDIA_CACHE.fs.delete(grid_item._id) DB.activities.delete_one({"_id": data["_id"]}) + # FIXME(tsileo): cleanup cache from announces object + p.push({}, "/task/cleanup_part_3") return "OK" diff --git a/sass/base_theme.scss b/sass/base_theme.scss index ce16014..c4c67b2 100644 --- a/sass/base_theme.scss +++ b/sass/base_theme.scss @@ -246,6 +246,7 @@ a:hover { color: $color-light; margin-right:5px; border-radius:2px; + float: left; } .bar-item-no-hover:hover { cursor: default; diff --git a/templates/following.html b/templates/following.html index e5874a8..c850f88 100644 --- a/templates/following.html +++ b/templates/following.html @@ -10,7 +10,7 @@