Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Featured image hiding #24

Merged
merged 3 commits into from
Jan 26, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 14 additions & 0 deletions lib/philomena_web/controllers/activity_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ defmodule PhilomenaWeb.ActivityController do
featured_image =
Image
|> 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)
|> limit(1)
|> preload([:tags])
Expand Down Expand Up @@ -116,4 +117,17 @@ defmodule PhilomenaWeb.ActivityController do
layout_class: "layout--wide"
)
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