offset: ^((page - 1) * page_size)
)
end
+
+ def showing_reblogs?(%User{} = user, %User{} = target) do
+ target.id not in user.info.muted_reblogs
+ end
end
field(:blocks, {:array, :string}, default: [])
field(:domain_blocks, {:array, :string}, default: [])
field(:mutes, {:array, :string}, default: [])
+ field(:muted_reblogs, {:array, :string}, default: [])
field(:deactivated, :boolean, default: false)
field(:no_rich_text, :boolean, default: false)
field(:ap_enabled, :boolean, default: false)
moderator: is_moderator
}
end
+
+ def add_reblog_mute(info, id) do
+ params = %{muted_reblogs: info.muted_reblogs ++ [id]}
+
+ cast(info, params, [:muted_reblogs])
+ end
+
+ def remove_reblog_mute(info, id) do
+ params = %{muted_reblogs: List.delete(info.muted_reblogs, id)}
+
+ cast(info, params, [:muted_reblogs])
+ end
end
entire_thread_visible_for_user?(activity, user)
end
+ # filter out muted threads
+ def contain_muted_boosts(%Activity{data: %{"type" => "Announce"}} = activity, %User{} = user) do
+ id = User.get_by_ap_id(activity.actor).id
+ id not in user.info.muted_reblogs
+ end
+
+ def contain_muted_boosts(%Activity{} = _activity, %User{} = _user), do: true
+
# do post-processing on a specific activity
def contain_activity(%Activity{} = activity, %User{} = user) do
- contain_broken_threads(activity, user)
+ contain_broken_threads(activity, user) and contain_muted_boosts(activity, user)
end
# do post-processing on a timeline
{:account, nil} -> {:error, "Account not found"}
end
end
+
+ def hide_reblogs(user, id) do
+ if id not in user.info.muted_reblogs do
+ info_changeset = User.Info.add_reblog_mute(user.info, id)
+ changeset = Ecto.Changeset.change(user) |> Ecto.Changeset.put_embed(:info, info_changeset)
+ User.update_and_set_cache(changeset)
+ end
+ end
+
+ def show_reblogs(user, id) do
+ if id in user.info.muted_reblogs do
+ info_changeset = User.Info.remove_reblog_mute(user.info, id)
+ changeset = Ecto.Changeset.change(user) |> Ecto.Changeset.put_embed(:info, info_changeset)
+ User.update_and_set_cache(changeset)
+ end
+ end
end
def follow(%{assigns: %{user: follower}} = conn, %{"id" => id}) do
with %User{} = followed <- Repo.get(User, id),
+ false <- User.following?(follower, followed),
{:ok, follower, followed, _} <- CommonAPI.follow(follower, followed) do
conn
|> put_view(AccountView)
|> render("relationship.json", %{user: follower, target: followed})
else
+ true ->
+ case conn.params["reblogs"] do
+ true -> CommonAPI.show_reblogs(follower, id)
+ false -> CommonAPI.hide_reblogs(follower, id)
+ end
+
+ followed = Repo.get(User, id)
+
+ conn
+ |> put_view(AccountView)
+ |> render("relationship.json", %{user: follower, target: followed})
+
{:error, message} ->
conn
|> put_resp_content_type("application/json")
muting_notifications: false,
requested: requested,
domain_blocking: false,
- showing_reblogs: false,
+ showing_reblogs: User.showing_reblogs?(user, target),
endorsed: false
}
end