diff --git a/alembic/versions/2022_12_12_1926-9b404c47970a_add_option_to_hide_announces_from_actor.py b/alembic/versions/2022_12_12_1926-9b404c47970a_add_option_to_hide_announces_from_actor.py new file mode 100644 index 0000000..059129c --- /dev/null +++ b/alembic/versions/2022_12_12_1926-9b404c47970a_add_option_to_hide_announces_from_actor.py @@ -0,0 +1,32 @@ +"""Add option to hide announces from actor + +Revision ID: 9b404c47970a +Revises: fadfd359ce78 +Create Date: 2022-12-12 19:26:36.912763+00:00 + +""" +import sqlalchemy as sa + +from alembic import op + +# revision identifiers, used by Alembic. +revision = '9b404c47970a' +down_revision = 'fadfd359ce78' +branch_labels = None +depends_on = None + + +def upgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + with op.batch_alter_table('actor', schema=None) as batch_op: + batch_op.add_column(sa.Column('are_announces_hidden_from_stream', sa.Boolean(), server_default='0', nullable=False)) + + # ### end Alembic commands ### + + +def downgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + with op.batch_alter_table('actor', schema=None) as batch_op: + batch_op.drop_column('are_announces_hidden_from_stream') + + # ### end Alembic commands ### diff --git a/app/admin.py b/app/admin.py index 17a06cb..7d8b776 100644 --- a/app/admin.py +++ b/app/admin.py @@ -959,6 +959,34 @@ async def admin_actions_unblock( return RedirectResponse(redirect_url, status_code=302) +@router.post("/actions/hide_announces") +async def admin_actions_hide_announces( + request: Request, + ap_actor_id: str = Form(), + redirect_url: str = Form(), + csrf_check: None = Depends(verify_csrf_token), + db_session: AsyncSession = Depends(get_db_session), +) -> RedirectResponse: + actor = await fetch_actor(db_session, ap_actor_id) + actor.are_announces_hidden_from_stream = True + await db_session.commit() + return RedirectResponse(redirect_url, status_code=302) + + +@router.post("/actions/show_announces") +async def admin_actions_show_announces( + request: Request, + ap_actor_id: str = Form(), + redirect_url: str = Form(), + csrf_check: None = Depends(verify_csrf_token), + db_session: AsyncSession = Depends(get_db_session), +) -> RedirectResponse: + actor = await fetch_actor(db_session, ap_actor_id) + actor.are_announces_hidden_from_stream = False + await db_session.commit() + return RedirectResponse(redirect_url, status_code=302) + + @router.post("/actions/delete") async def admin_actions_delete( request: Request, diff --git a/app/boxes.py b/app/boxes.py index 7438623..ff37f15 100644 --- a/app/boxes.py +++ b/app/boxes.py @@ -2205,7 +2205,10 @@ async def _handle_announce_activity( db_session.add(announced_inbox_object) await db_session.flush() announce_activity.relates_to_inbox_object_id = announced_inbox_object.id - announce_activity.is_hidden_from_stream = not is_from_following + announce_activity.is_hidden_from_stream = ( + not is_from_following + or announce_activity.actor.are_announces_hidden_from_stream + ) async def _handle_like_activity( diff --git a/app/models.py b/app/models.py index 13b1b0b..2d9468c 100644 --- a/app/models.py +++ b/app/models.py @@ -54,6 +54,10 @@ class Actor(Base, BaseActor): is_blocked = Column(Boolean, nullable=False, default=False, server_default="0") is_deleted = Column(Boolean, nullable=False, default=False, server_default="0") + are_announces_hidden_from_stream = Column( + Boolean, nullable=False, default=False, server_default="0" + ) + @property def is_from_db(self) -> bool: return True diff --git a/app/templates/utils.html b/app/templates/utils.html index 32bbcc9..d88a881 100644 --- a/app/templates/utils.html +++ b/app/templates/utils.html @@ -32,6 +32,29 @@ {% endblock %} {% endmacro %} +{% macro admin_hide_shares_button(actor) %} +{% block admin_hide_shares_button scoped %} +
+{% endblock %} +{% endmacro %} + +{% macro admin_show_shares_button(actor) %} +{% block admin_show_shares_button scoped %} + +{% endblock %} +{% endmacro %} + + {% macro admin_follow_button(actor) %} {% block admin_follow_button scoped %}