forked from AkkomaGang/akkoma
refactor filtering mechanism
This commit is contained in:
parent
aa71139e4a
commit
15b21d1983
3 changed files with 17 additions and 8 deletions
|
@ -679,6 +679,18 @@ defp restrict_pinned(query, %{"pinned" => "true", "pinned_activity_ids" => ids})
|
||||||
|
|
||||||
defp restrict_pinned(query, _), do: query
|
defp restrict_pinned(query, _), do: query
|
||||||
|
|
||||||
|
defp restrict_muted_reblogs(query, %{"muting_user" => %User{info: info}}) do
|
||||||
|
muted_reblogs = info.muted_reblogs || []
|
||||||
|
|
||||||
|
from(
|
||||||
|
activity in query,
|
||||||
|
where: fragment("not ?->>'type' = 'Announce'", activity.data),
|
||||||
|
where: fragment("not ? = ANY(?)", activity.actor, ^muted_reblogs)
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
defp restrict_muted_reblogs(query, _), do: query
|
||||||
|
|
||||||
def fetch_activities_query(recipients, opts \\ %{}) do
|
def fetch_activities_query(recipients, opts \\ %{}) do
|
||||||
base_query =
|
base_query =
|
||||||
from(
|
from(
|
||||||
|
@ -706,6 +718,7 @@ def fetch_activities_query(recipients, opts \\ %{}) do
|
||||||
|> restrict_replies(opts)
|
|> restrict_replies(opts)
|
||||||
|> restrict_reblogs(opts)
|
|> restrict_reblogs(opts)
|
||||||
|> restrict_pinned(opts)
|
|> restrict_pinned(opts)
|
||||||
|
|> restrict_muted_reblogs(opts)
|
||||||
end
|
end
|
||||||
|
|
||||||
def fetch_activities(recipients, opts \\ %{}) do
|
def fetch_activities(recipients, opts \\ %{}) do
|
||||||
|
@ -951,17 +964,11 @@ def contain_broken_threads(%Activity{} = activity, %User{} = user) do
|
||||||
entire_thread_visible_for_user?(activity, user)
|
entire_thread_visible_for_user?(activity, user)
|
||||||
end
|
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
|
def contain_muted_boosts(%Activity{} = _activity, %User{} = _user), do: true
|
||||||
|
|
||||||
# do post-processing on a specific activity
|
# do post-processing on a specific activity
|
||||||
def contain_activity(%Activity{} = activity, %User{} = user) do
|
def contain_activity(%Activity{} = activity, %User{} = user) do
|
||||||
contain_broken_threads(activity, user) and contain_muted_boosts(activity, user)
|
contain_broken_threads(activity, user)
|
||||||
end
|
end
|
||||||
|
|
||||||
# do post-processing on a timeline
|
# do post-processing on a timeline
|
||||||
|
|
|
@ -735,7 +735,7 @@ def follow(%{assigns: %{user: follower}} = conn, %{"id" => id}) do
|
||||||
false -> CommonAPI.hide_reblogs(follower, id)
|
false -> CommonAPI.hide_reblogs(follower, id)
|
||||||
end
|
end
|
||||||
|
|
||||||
followed = Repo.get(User, id)
|
followed = User.get_cached_by_id(id)
|
||||||
|
|
||||||
conn
|
conn
|
||||||
|> put_view(AccountView)
|
|> put_view(AccountView)
|
||||||
|
|
|
@ -200,10 +200,12 @@ def push_to_socket(topics, topic, %Activity{data: %{"type" => "Announce"}} = ite
|
||||||
user = User.get_cached_by_ap_id(socket.assigns[:user].ap_id)
|
user = User.get_cached_by_ap_id(socket.assigns[:user].ap_id)
|
||||||
blocks = user.info.blocks || []
|
blocks = user.info.blocks || []
|
||||||
mutes = user.info.mutes || []
|
mutes = user.info.mutes || []
|
||||||
|
reblog_mutes = user.info.reblog_mutes || []
|
||||||
|
|
||||||
parent = Object.normalize(item.data["object"])
|
parent = Object.normalize(item.data["object"])
|
||||||
|
|
||||||
unless is_nil(parent) or item.actor in blocks or item.actor in mutes or
|
unless is_nil(parent) or item.actor in blocks or item.actor in mutes or
|
||||||
|
item.actor in reblog_mutes or
|
||||||
not ActivityPub.contain_activity(item, user) or parent.data["actor"] in blocks or
|
not ActivityPub.contain_activity(item, user) or parent.data["actor"] in blocks or
|
||||||
parent.data["actor"] in mutes do
|
parent.data["actor"] in mutes do
|
||||||
send(socket.transport_pid, {:text, represent_update(item, user)})
|
send(socket.transport_pid, {:text, represent_update(item, user)})
|
||||||
|
|
Loading…
Reference in a new issue