mirror of
https://codeberg.org/rimu/pyfedi
synced 2025-01-24 03:43:42 -08:00
Merge pull request 'Sticky Posts' (#109) from freamon/pyfedi:19 into main
Reviewed-on: https://codeberg.org/rimu/pyfedi/pulls/109
This commit is contained in:
commit
cfe4feb934
5 changed files with 64 additions and 0 deletions
|
@ -666,6 +666,24 @@ def process_inbox_request(request_json, activitypublog_id, ip_address):
|
||||||
target_ap_id = request_json['object']['object']['object'] # object object object!
|
target_ap_id = request_json['object']['object']['object'] # object object object!
|
||||||
post = undo_vote(activity_log, comment, post, target_ap_id, user)
|
post = undo_vote(activity_log, comment, post, target_ap_id, user)
|
||||||
activity_log.result = 'success'
|
activity_log.result = 'success'
|
||||||
|
elif request_json['object']['type'] == 'Add':
|
||||||
|
activity_log.activity_type = request_json['object']['type']
|
||||||
|
featured_url = Community.query.filter(Community.ap_public_url == request_json['actor']).first().ap_featured_url
|
||||||
|
if featured_url:
|
||||||
|
if 'target' in request_json['object'] and featured_url == request_json['object']['target']:
|
||||||
|
post = Post.query.filter(Post.ap_id == request_json['object']['object']).first()
|
||||||
|
if post:
|
||||||
|
post.sticky = True
|
||||||
|
activity_log.result = 'success'
|
||||||
|
elif request_json['object']['type'] == 'Remove':
|
||||||
|
activity_log.activity_type = request_json['object']['type']
|
||||||
|
featured_url = Community.query.filter(Community.ap_public_url == request_json['actor']).first().ap_featured_url
|
||||||
|
if featured_url:
|
||||||
|
if 'target' in request_json['object'] and featured_url == request_json['object']['target']:
|
||||||
|
post = Post.query.filter(Post.ap_id == request_json['object']['object']).first()
|
||||||
|
if post:
|
||||||
|
post.sticky = False
|
||||||
|
activity_log.result = 'success'
|
||||||
else:
|
else:
|
||||||
activity_log.exception_message = 'Invalid type for Announce'
|
activity_log.exception_message = 'Invalid type for Announce'
|
||||||
|
|
||||||
|
|
|
@ -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