mirror of
https://github.com/philomena-dev/philomena.git
synced 2025-01-20 06:37:59 +01:00
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:
parent
f558e76cc8
commit
c972f00cdc
1 changed files with 14 additions and 0 deletions
|
@ -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
|
||||||
|
|
Loading…
Reference in a new issue