diff options
author | lain <lain@soykaf.club> | 2019-10-25 17:08:01 +0000 |
---|---|---|
committer | lain <lain@soykaf.club> | 2019-10-25 17:08:01 +0000 |
commit | a43b899e94c499a9b5cb1a072fe4b96f0f02696f (patch) | |
tree | 82488bc1f7dd70959a879f2e42760fe1c23ee309 /lib/pleroma/notification.ex | |
parent | 9b26d1608f5ddd64a146dec3c41b029c1b7a4198 (diff) | |
parent | 948d0d3b0b2a2eb72a0db41abebd9ad976dfdbf7 (diff) | |
download | pleroma-1.1.3.tar.gz |
Merge branch 'release/1.1.3' into 'stable'v1.1.3
1.1.3 release
See merge request pleroma/pleroma!1884
Diffstat (limited to 'lib/pleroma/notification.ex')
-rw-r--r-- | lib/pleroma/notification.ex | 72 |
1 files changed, 40 insertions, 32 deletions
diff --git a/lib/pleroma/notification.ex b/lib/pleroma/notification.ex index d94ae5971..ed39958a8 100644 --- a/lib/pleroma/notification.ex +++ b/lib/pleroma/notification.ex @@ -34,41 +34,49 @@ defmodule Pleroma.Notification do end def for_user_query(user, opts \\ []) do - query = - Notification - |> where(user_id: ^user.id) - |> where( - [n, a], + Notification + |> where(user_id: ^user.id) + |> where( + [n, a], + fragment( + "? not in (SELECT ap_id FROM users WHERE info->'deactivated' @> 'true')", + a.actor + ) + ) + |> join(:inner, [n], activity in assoc(n, :activity)) + |> join(:left, [n, a], object in Object, + on: fragment( - "? not in (SELECT ap_id FROM users WHERE info->'deactivated' @> 'true')", - a.actor + "(?->>'id') = COALESCE((? -> 'object'::text) ->> 'id'::text)", + object.data, + a.data ) - ) - |> join(:inner, [n], activity in assoc(n, :activity)) - |> join(:left, [n, a], object in Object, - on: - fragment( - "(?->>'id') = COALESCE((? -> 'object'::text) ->> 'id'::text)", - object.data, - a.data - ) - ) - |> preload([n, a, o], activity: {a, object: o}) + ) + |> preload([n, a, o], activity: {a, object: o}) + |> exclude_muted(user, opts) + |> exclude_blocked(user) + end - if opts[:with_muted] do - query - else - where(query, [n, a], a.actor not in ^user.info.muted_notifications) - |> where([n, a], a.actor not in ^user.info.blocks) - |> where( - [n, a], - fragment("substring(? from '.*://([^/]*)')", a.actor) not in ^user.info.domain_blocks - ) - |> join(:left, [n, a], tm in Pleroma.ThreadMute, - on: tm.user_id == ^user.id and tm.context == fragment("?->>'context'", a.data) - ) - |> where([n, a, o, tm], is_nil(tm.user_id)) - end + defp exclude_blocked(query, user) do + query + |> where([n, a], a.actor not in ^user.info.blocks) + |> where( + [n, a], + fragment("substring(? from '.*://([^/]*)')", a.actor) not in ^user.info.domain_blocks + ) + end + + defp exclude_muted(query, _, %{with_muted: true}) do + query + end + + defp exclude_muted(query, user, _opts) do + query + |> where([n, a], a.actor not in ^user.info.muted_notifications) + |> join(:left, [n, a], tm in Pleroma.ThreadMute, + on: tm.user_id == ^user.id and tm.context == fragment("?->>'context'", a.data) + ) + |> where([n, a, o, tm], is_nil(tm.user_id)) end def for_user(user, opts \\ %{}) do |