don't show personal instances

This commit is contained in:
Tao Bror Bojlén 2019-07-19 14:21:16 +03:00
parent 3af099e70b
commit 898d0ff268
No known key found for this signature in database
GPG Key ID: C6EC7AAB905F9E6F
4 changed files with 49 additions and 18 deletions

View File

@ -1,5 +1,6 @@
defmodule Backend.Api do
alias Backend.{Crawl, Edge, Instance, Repo}
import Backend.Util
import Ecto.Query
@spec list_instances() :: [Instance.t()]
@ -18,18 +19,27 @@ defmodule Backend.Api do
@doc """
Returns a list of instances that
* have a user count (required to give the instance a size on the graph)
* the user count is > the threshold
* have x and y coordinates
"""
@spec list_nodes() :: [Instance.t()]
def list_nodes() do
user_threshold = get_config(:personal_instance_threshold)
Instance
|> where([i], not is_nil(i.x) and not is_nil(i.y) and not is_nil(i.user_count))
|> where(
[i],
not is_nil(i.x) and not is_nil(i.y) and not is_nil(i.user_count) and
i.user_count >= ^user_threshold
)
|> select([c], [:domain, :user_count, :x, :y])
|> Repo.all()
end
@spec list_edges() :: [Edge.t()]
def list_edges() do
user_threshold = get_config(:personal_instance_threshold)
Edge
|> join(:inner, [e], i1 in Instance, on: e.source_domain == i1.domain)
|> join(:inner, [e], i2 in Instance, on: e.target_domain == i2.domain)
@ -37,7 +47,8 @@ defmodule Backend.Api do
|> where(
[e, i1, i2],
not is_nil(i1.x) and not is_nil(i1.y) and
not is_nil(i2.x) and not is_nil(i2.y)
not is_nil(i2.x) and not is_nil(i2.y) and
i1.user_count >= ^user_threshold and i2.user_count >= ^user_threshold
)
|> Repo.all()
end

View File

@ -1,6 +1,7 @@
defmodule BackendWeb.InstanceView do
use BackendWeb, :view
alias BackendWeb.InstanceView
import Backend.Util
require Logger
def render("index.json", %{instances: instances}) do
@ -16,6 +17,8 @@ defmodule BackendWeb.InstanceView do
end
def render("instance_detail.json", %{instance: instance, crawl: crawl}) do
user_threshold = get_config(:personal_instance_threshold)
[status, last_updated] =
case crawl do
nil ->
@ -28,17 +31,26 @@ defmodule BackendWeb.InstanceView do
end
end
%{
name: instance.domain,
description: instance.description,
version: instance.version,
userCount: instance.user_count,
insularity: instance.insularity,
statusCount: instance.status_count,
domainCount: length(instance.peers),
peers: render_many(instance.peers, InstanceView, "instance.json"),
lastUpdated: last_updated,
status: status
}
cond do
instance.user_count < user_threshold ->
%{
name: instance.domain,
status: "personal instance"
}
true ->
%{
name: instance.domain,
description: instance.description,
version: instance.version,
userCount: instance.user_count,
insularity: instance.insularity,
statusCount: instance.status_count,
domainCount: length(instance.peers),
peers: render_many(instance.peers, InstanceView, "instance.json"),
lastUpdated: last_updated,
status: status
}
end
end
end

View File

@ -38,6 +38,7 @@ class Cytoscape extends React.Component<ICytoscapeProps> {
...n,
data: {
...n.data,
fontSize: Math.min(Math.max(n.data.size * 10, 6), 50),
size: Math.min(Math.max(n.data.size * 20, 1), 100)
}
}))
@ -47,6 +48,8 @@ class Cytoscape extends React.Component<ICytoscapeProps> {
layout: {
name: "preset"
},
maxZoom: 2,
minZoom: 0.03,
selectionType: "single"
});
@ -72,7 +75,12 @@ class Cytoscape extends React.Component<ICytoscapeProps> {
})
.selector("node[label]")
.style({
color: DEFAULT_NODE_COLOR
color: "black",
"font-size": "data(fontSize)",
"min-zoomed-font-size": 20,
"text-background-color": DEFAULT_NODE_COLOR,
"text-background-opacity": 0.5,
"text-background-padding": "5px"
})
.update();

View File

@ -108,7 +108,7 @@ class SidebarImpl extends React.Component<ISidebarProps, ISidebarState> {
return this.renderLoadingState();
} else if (!this.props.instanceDetails) {
return this.renderEmptyState();
} else if (this.props.instanceDetails.status.toLowerCase().indexOf("personalinstance") > -1) {
} else if (this.props.instanceDetails.status.toLowerCase().indexOf("personal instance") > -1) {
return this.renderPersonalInstanceErrorState();
} else if (this.props.instanceDetails.status !== "success") {
return this.renderMissingDataState();
@ -346,8 +346,8 @@ class SidebarImpl extends React.Component<ISidebarProps, ISidebarState> {
title="No data"
description="This instance has fewer than 10 users. It was not crawled in order to protect their privacy, but if it's your instance you can opt in."
action={
<AnchorButton icon={IconNames.CONFIRM} href="https://cursed.technology/@tao" target="_blank">
Message @tao to opt in
<AnchorButton icon={IconNames.CONFIRM} href="https://cursed.technology/@fediversespace" target="_blank">
Message @fediversespace to opt in
</AnchorButton>
}
/>