diff --git a/app/activitypub/util.py b/app/activitypub/util.py index 63c419e3..a094b19f 100644 --- a/app/activitypub/util.py +++ b/app/activitypub/util.py @@ -562,6 +562,7 @@ def actor_json_to_model(activity_json, address, server): ap_followers_url=activity_json['followers'], ap_inbox_url=activity_json['endpoints']['sharedInbox'], ap_outbox_url=activity_json['outbox'], + ap_featured_url=activity_json['featured'], ap_moderators_url=mods_url, ap_fetched_at=utcnow(), ap_domain=server, diff --git a/app/community/util.py b/app/community/util.py index b07e2c16..f96e915d 100644 --- a/app/community/util.py +++ b/app/community/util.py @@ -121,6 +121,18 @@ def retrieve_mods_and_backfill(community_id: int): if c.post_count > 0: c.last_active = Post.query.filter(Post.community_id == community_id).order_by(desc(Post.posted_at)).first().posted_at db.session.commit() + if community.ap_featured_url: + featured_request = get_request(community.ap_featured_url, headers={'Accept': 'application/activityjson'}) + if featured_request.status_code == 200: + featured_data = featured_request.json() + featured_request.close() + if featured_data['type'] == 'OrderedCollection' and 'orderedItems' in featured_data: + for item in featured_data['orderedItems']: + featured_id = item['id'] + p = Post.query.filter(Post.ap_id == featured_id).first() + if p: + p.sticky = True + db.session.commit() def community_url_exists(url) -> bool: diff --git a/app/models.py b/app/models.py index 10f792b2..3a82c5b9 100644 --- a/app/models.py +++ b/app/models.py @@ -266,6 +266,7 @@ class Community(db.Model): ap_deleted_at = db.Column(db.DateTime) ap_inbox_url = db.Column(db.String(255)) ap_outbox_url = db.Column(db.String(255)) + ap_featured_url = db.Column(db.String(255)) ap_moderators_url = db.Column(db.String(255)) ap_domain = db.Column(db.String(255)) diff --git a/migrations/versions/12d60b9d5417_ap_featured_url.py b/migrations/versions/12d60b9d5417_ap_featured_url.py new file mode 100644 index 00000000..9311d82e --- /dev/null +++ b/migrations/versions/12d60b9d5417_ap_featured_url.py @@ -0,0 +1,32 @@ +"""ap_featured_url + +Revision ID: 12d60b9d5417 +Revises: 81175e11c083 +Create Date: 2024-03-19 07:05:04.588051 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = '12d60b9d5417' +down_revision = '81175e11c083' +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + with op.batch_alter_table('community', schema=None) as batch_op: + batch_op.add_column(sa.Column('ap_featured_url', sa.String(length=255), nullable=True)) + + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + with op.batch_alter_table('community', schema=None) as batch_op: + batch_op.drop_column('ap_featured_url') + + # ### end Alembic commands ###