2019-07-23 12:20:34 +00:00
|
|
|
defmodule BackendWeb.SearchView do
|
|
|
|
use BackendWeb, :view
|
|
|
|
alias BackendWeb.SearchView
|
2019-07-23 14:08:43 +00:00
|
|
|
import Backend.Util
|
2019-07-23 12:20:34 +00:00
|
|
|
|
2019-07-26 22:30:11 +00:00
|
|
|
def render("index.json", %{hits: hits, next: next}) do
|
2019-07-23 12:20:34 +00:00
|
|
|
%{
|
2019-07-26 22:30:11 +00:00
|
|
|
results: render_many(hits, SearchView, "instance.json", as: :hit),
|
2019-07-23 12:20:34 +00:00
|
|
|
next: next
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2019-07-26 22:30:11 +00:00
|
|
|
def render("instance.json", %{hit: hit}) do
|
2019-07-23 14:08:43 +00:00
|
|
|
threshold = get_config(:personal_instance_threshold)
|
|
|
|
|
|
|
|
description =
|
2019-07-26 22:30:11 +00:00
|
|
|
if hit.user_count != nil and hit.user_count < threshold do
|
2019-07-23 14:08:43 +00:00
|
|
|
nil
|
|
|
|
else
|
2019-07-26 22:30:11 +00:00
|
|
|
hit.description
|
2019-07-23 14:08:43 +00:00
|
|
|
end
|
|
|
|
|
2019-07-23 12:20:34 +00:00
|
|
|
%{
|
2019-07-26 22:30:11 +00:00
|
|
|
name: hit.domain,
|
2019-07-23 14:08:43 +00:00
|
|
|
description: description,
|
2019-07-26 22:30:11 +00:00
|
|
|
userCount: hit.user_count,
|
|
|
|
type: hit.type
|
2019-07-23 12:20:34 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|