From eea83214cba86d7e74f6020ee0fdbce9a4372583 Mon Sep 17 00:00:00 2001 From: Cosmin Stejerean Date: Fri, 30 Dec 2022 14:03:11 -0800 Subject: [PATCH] Option to show/hide boosts for a followed user (#317) --- activities/models/post_interaction.py | 8 +++---- api/views/accounts.py | 4 ++-- static/css/style.css | 29 +++++++++++++++++++++++--- templates/identity/_view_menu.html | 14 +++++++++++-- users/migrations/0008_follow_boosts.py | 18 ++++++++++++++++ users/models/follow.py | 13 ++++++++++-- users/services/identity.py | 23 +++++++++++++------- users/views/identity.py | 4 ++++ 8 files changed, 92 insertions(+), 21 deletions(-) create mode 100644 users/migrations/0008_follow_boosts.py diff --git a/activities/models/post_interaction.py b/activities/models/post_interaction.py index cce88ab..fa85245 100644 --- a/activities/models/post_interaction.py +++ b/activities/models/post_interaction.py @@ -32,9 +32,9 @@ class PostInteractionStates(StateGraph): interaction = await instance.afetch_full() # Boost: send a copy to all people who follow this user if interaction.type == interaction.Types.boost: - async for follow in interaction.identity.inbound_follows.select_related( - "source", "target" - ): + async for follow in interaction.identity.inbound_follows.filter( + boosts=True + ).select_related("source", "target"): if follow.source.local or follow.target.local: await FanOut.objects.acreate( type=FanOut.Types.interaction, @@ -294,7 +294,7 @@ class PostInteraction(StatorModel): # Boosts (announces) go to everyone who follows locally if interaction.type == cls.Types.boost: for follow in Follow.objects.filter( - target=interaction.identity, source__local=True + target=interaction.identity, source__local=True, boosts=True ): TimelineEvent.add_post_interaction(follow.source, interaction) # Likes go to just the author of the post diff --git a/api/views/accounts.py b/api/views/accounts.py index 3c6fab3..61d8590 100644 --- a/api/views/accounts.py +++ b/api/views/accounts.py @@ -175,12 +175,12 @@ def account_statuses( @api_router.post("/v1/accounts/{id}/follow", response=schemas.Relationship) @identity_required -def account_follow(request, id: str): +def account_follow(request, id: str, reblogs: bool = True): identity = get_object_or_404( Identity.objects.exclude(restriction=Identity.Restriction.blocked), pk=id ) service = IdentityService(identity) - service.follow_from(request.identity) + service.follow_from(request.identity, boosts=reblogs) return service.mastodon_json_relationship(request.identity) diff --git a/static/css/style.css b/static/css/style.css index 7b03cb9..05e66bb 100644 --- a/static/css/style.css +++ b/static/css/style.css @@ -595,6 +595,8 @@ fieldset legend { .right-column form, form.inline { padding: 0; + margin: 0; + display:inline; } div.follow-profile { @@ -604,11 +606,11 @@ div.follow-profile { text-align: center; } -div.follow-profile.has-reverse { +.follow-profile.has-reverse { margin-top: 0; } -div.follow-profile .reverse-follow { +.follow-profile .reverse-follow { display: block; margin: 0 0 5px 0; } @@ -644,6 +646,7 @@ div.follow-profile .actions menu { top: 43px; } + div.follow-profile .actions menu.enabled { display: block; min-width: 160px; @@ -658,7 +661,27 @@ div.follow-profile .actions menu a { color: var(--color-text-dull); } -div.follow-profile .actions menu a i { +.follow-profile .actions menu button { + background: none !important; + border: none; + cursor: pointer; + text-align: left; + display: block; + font-size: 15px; + padding: 4px 10px; + color: var(--color-text-dull); +} + +.follow-profile .actions menu button i { + margin-right: 4px; + width: 16px; +} + +.follow-profile .actions button:hover { + color: var(--color-text-main); +} + +.follow-profile .actions menu a i { margin-right: 4px; width: 16px; } diff --git a/templates/identity/_view_menu.html b/templates/identity/_view_menu.html index 960b376..ae05f84 100644 --- a/templates/identity/_view_menu.html +++ b/templates/identity/_view_menu.html @@ -1,6 +1,4 @@ -
-