Featured image hiding (#24)

* Featured image hiding

This makes sure the Featured Image on the front page obeys user hiding.

* Optimized

Took the `hidden=1` check out of the `WHERE` clause.

* proper anti join

Co-authored-by: liamwhite <liamwhite@users.noreply.github.com>
This commit is contained in:
SomewhatDamaged 2020-01-27 10:04:30 +11:00 committed by liamwhite
parent f558e76cc8
commit c972f00cdc

View file

@ -71,6 +71,7 @@ defmodule PhilomenaWeb.ActivityController do
featured_image = featured_image =
Image Image
|> join(:inner, [i], f in ImageFeature, on: [image_id: i.id]) |> join(:inner, [i], f in ImageFeature, on: [image_id: i.id])
|> filter_hidden(user, conn.params["hidden"])
|> order_by([i, f], desc: f.created_at) |> order_by([i, f], desc: f.created_at)
|> limit(1) |> limit(1)
|> preload([:tags]) |> preload([:tags])
@ -116,4 +117,17 @@ defmodule PhilomenaWeb.ActivityController do
layout_class: "layout--wide" layout_class: "layout--wide"
) )
end end
def filter_hidden(featured_image, nil, _hidden) do
featured_image
end
def filter_hidden(featured_image, _user, "1") do
featured_image
end
def filter_hidden(featured_image, user, _hidden) do
featured_image
|> where([i], fragment("NOT EXISTS(SELECT 1 FROM image_hides WHERE image_id = ? AND user_id = ?)", i.id, ^user.id))
end
end end