diff --git a/app.py b/app.py index bf2f838..e3e17a3 100644 --- a/app.py +++ b/app.py @@ -818,9 +818,7 @@ def followers(): ) raw_followers, older_than, newer_than = paginated_query(DB.activities, q) - followers = [ - doc["meta"]["actor"] for doc in raw_followers if "actor" in doc.get("meta", {}) - ] + followers = [doc["meta"] for doc in raw_followers if "actor" in doc.get("meta", {})] return htmlify( render_template( "followers.html", @@ -857,7 +855,7 @@ def following(): following, older_than, newer_than = paginated_query(DB.activities, q) following = [ - (doc["remote_id"], doc["meta"]["object"]) + (doc["remote_id"], doc["meta"]) for doc in following if "remote_id" in doc and "object" in doc.get("meta", {}) ] diff --git a/core/migrations.py b/core/migrations.py index 49cf534..8d7bcd4 100644 --- a/core/migrations.py +++ b/core/migrations.py @@ -14,9 +14,11 @@ from core.meta import FollowStatus from core.meta import MetaKey from core.meta import _meta from core.meta import by_actor_id +from core.meta import by_object_id from core.meta import by_remote_id from core.meta import by_type from core.meta import in_inbox +from core.meta import in_outbox from core.meta import not_undo from core.meta import upsert from utils.migrations import Migration @@ -232,24 +234,6 @@ class _20190830_FollowFollowBackMigration(Migration): except Exception: logger.exception(f"failed to process activity {data!r}") - for data in find_activities({**by_type(ap.ActivityType.FOLLOW), **in_inbox()}): - try: - accept_query = { - **in_inbox(), - **by_type(ap.ActivityType.ACCEPT), - **by_actor_id(data["meta"]["actor_id"]), - **not_undo(), - } - raw_accept = DB.activities.find_one(accept_query) - if raw_accept: - DB.activities.update_many( - accept_query, - {"$set": {_meta(MetaKey.NOTIFICATION_FOLLOWS_BACK): True}}, - ) - - except Exception: - logger.exception(f"failed to process activity {data!r}") - DB.activities.update_many( { **by_type(ap.ActivityType.FOLLOW), @@ -258,3 +242,54 @@ class _20190830_FollowFollowBackMigration(Migration): }, {"$set": {"meta.follow_status": "waiting"}}, ) + + +class _20190901_FollowFollowBackMigrationFix(Migration): + """Add the new meta flags for tracking accepted/rejected status and following/follows back info.""" + + def migrate(self) -> None: + for data in find_activities({**by_type(ap.ActivityType.ACCEPT), **in_inbox()}): + try: + update_one_activity( + { + **by_type(ap.ActivityType.FOLLOW), + **by_remote_id(data["meta"]["object_id"]), + }, + upsert({MetaKey.FOLLOW_STATUS: FollowStatus.ACCEPTED.value}), + ) + # Check if we are following this actor + follow_query = { + **in_inbox(), + **by_type(ap.ActivityType.FOLLOW), + **by_object_id(data["meta"]["actor_id"]), + **not_undo(), + } + raw_follow = DB.activities.find_one(follow_query) + if raw_follow: + DB.activities.update_many( + follow_query, + {"$set": {_meta(MetaKey.NOTIFICATION_FOLLOWS_BACK): True}}, + ) + + except Exception: + logger.exception(f"failed to process activity {data!r}") + + for data in find_activities({**by_type(ap.ActivityType.FOLLOW), **in_outbox()}): + try: + print(data) + follow_query = { + **in_inbox(), + **by_type(ap.ActivityType.FOLLOW), + **by_actor_id(data["meta"]["object_id"]), + **not_undo(), + } + raw_accept = DB.activities.find_one(follow_query) + print(raw_accept) + if raw_accept: + DB.activities.update_many( + by_remote_id(data["remote_id"]), + {"$set": {_meta(MetaKey.NOTIFICATION_FOLLOWS_BACK): True}}, + ) + + except Exception: + logger.exception(f"failed to process activity {data!r}") diff --git a/templates/followers.html b/templates/followers.html index f1bba01..c01f880 100644 --- a/templates/followers.html +++ b/templates/followers.html @@ -8,10 +8,16 @@ {% include "header.html" %}