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
|
|
|
|
|
|
|
def render("index.json", %{instances: instances, next: next}) do
|
|
|
|
%{
|
|
|
|
results: render_many(instances, SearchView, "instance.json", as: :instance),
|
|
|
|
next: next
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def render("instance.json", %{instance: instance}) do
|
2019-07-23 14:08:43 +00:00
|
|
|
threshold = get_config(:personal_instance_threshold)
|
|
|
|
|
|
|
|
description =
|
|
|
|
if instance.user_count != nil and instance.user_count < threshold do
|
|
|
|
nil
|
|
|
|
else
|
|
|
|
instance.description
|
|
|
|
end
|
|
|
|
|
2019-07-23 12:20:34 +00:00
|
|
|
%{
|
|
|
|
name: instance.domain,
|
2019-07-23 14:08:43 +00:00
|
|
|
description: description,
|
2019-07-24 15:51:44 +00:00
|
|
|
userCount: instance.user_count,
|
|
|
|
type: instance.type
|
2019-07-23 12:20:34 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|