mirror of
https://codeberg.org/rimu/pyfedi
synced 2025-01-23 19:36:56 -08:00
Checked featured url for sticky posts #16
This commit is contained in:
parent
84d8198a67
commit
136cb64a69
4 changed files with 46 additions and 0 deletions
|
@ -562,6 +562,7 @@ def actor_json_to_model(activity_json, address, server):
|
||||||
ap_followers_url=activity_json['followers'],
|
ap_followers_url=activity_json['followers'],
|
||||||
ap_inbox_url=activity_json['endpoints']['sharedInbox'],
|
ap_inbox_url=activity_json['endpoints']['sharedInbox'],
|
||||||
ap_outbox_url=activity_json['outbox'],
|
ap_outbox_url=activity_json['outbox'],
|
||||||
|
ap_featured_url=activity_json['featured'],
|
||||||
ap_moderators_url=mods_url,
|
ap_moderators_url=mods_url,
|
||||||
ap_fetched_at=utcnow(),
|
ap_fetched_at=utcnow(),
|
||||||
ap_domain=server,
|
ap_domain=server,
|
||||||
|
|
|
@ -121,6 +121,18 @@ def retrieve_mods_and_backfill(community_id: int):
|
||||||
if c.post_count > 0:
|
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
|
c.last_active = Post.query.filter(Post.community_id == community_id).order_by(desc(Post.posted_at)).first().posted_at
|
||||||
db.session.commit()
|
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:
|
def community_url_exists(url) -> bool:
|
||||||
|
|
|
@ -266,6 +266,7 @@ class Community(db.Model):
|
||||||
ap_deleted_at = db.Column(db.DateTime)
|
ap_deleted_at = db.Column(db.DateTime)
|
||||||
ap_inbox_url = db.Column(db.String(255))
|
ap_inbox_url = db.Column(db.String(255))
|
||||||
ap_outbox_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_moderators_url = db.Column(db.String(255))
|
||||||
ap_domain = db.Column(db.String(255))
|
ap_domain = db.Column(db.String(255))
|
||||||
|
|
||||||
|
|
32
migrations/versions/12d60b9d5417_ap_featured_url.py
Normal file
32
migrations/versions/12d60b9d5417_ap_featured_url.py
Normal file
|
@ -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 ###
|
Loading…
Add table
Reference in a new issue