Skip to content

Commit

Permalink
https://github.com/bonfire-networks/bonfire-app/issues/1038
Browse files Browse the repository at this point in the history
  • Loading branch information
mayel committed Oct 14, 2024
1 parent dba22b2 commit b4adcd8
Show file tree
Hide file tree
Showing 5 changed files with 139 additions and 8 deletions.
59 changes: 59 additions & 0 deletions lib/components/settings/instance/members/instances_live.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
defmodule Bonfire.UI.Me.SettingsViewsLive.InstancesLive do
use Bonfire.UI.Common.Web, :stateful_component

prop ghosted_instance_wide?, :boolean, default: nil
prop silenced_instance_wide?, :boolean, default: nil

def update(assigns, socket) do
socket = assign(socket, assigns)

{:ok,
assign(
socket,
if(socket_connected?(socket),
do: list_instances(),
else: [instances: [], page_info: nil]
)
)}
end

def handle_event("load_more", attrs, socket) do
%{page_info: page_info, instances: instances} = list_instances(attrs)

{:noreply,
socket
|> assign(
loaded: true,
# instances: e(assigns(socket), :instances, []) ++ instances,
instances: instances,
page_info: page_info
)}
end

def list_instances(attrs \\ nil) do
%{edges: instances, page_info: page_info} =
Bonfire.Federate.ActivityPub.Instances.list_paginated(
skip_boundary_check: true,
paginate: input_to_atoms(attrs)
)

# TODO: implement `Bonfire.Boundaries.Blocks.LiveHandler.update_many` so we don't do n+1 on these!
instances =
Enum.map(instances, fn user ->
user
|> Map.put(
:ghosted_instance_wide?,
Bonfire.Boundaries.Blocks.is_blocked?(id(user), :ghost, :instance_wide)
)
|> Map.put(
:silenced_instance_wide?,
Bonfire.Boundaries.Blocks.is_blocked?(id(user), :silence, :instance_wide)
)
end)

%{
instances: instances,
page_info: page_info
}
end
end
58 changes: 58 additions & 0 deletions lib/components/settings/instance/members/instances_live.sface
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<div>
<div class="grid mb-2 px-4 md:px-0 md:grid-cols-2 gap-4 max-w-screen-md mx-auto w-full">
<div
:for={%{id: id, ap_base_uri: ap_base_uri, display_hostname: display_hostname} = instance <- @instances}
class="p-4 border rounded border-base-content/20 flex"
>
<!-- TODO: link to member directory in settings instead -->
<div>{display_hostname}</div>

<div class="dropdown dropdown-end">
<label
class="relative btn btn-circle btn-outline border-base-content/30 btn-sm"
tabindex="0"
id="user-profile-menu"
aria-haspopup="true"
aria-expanded="true"
>
<#Icon iconify="material-symbols:more-horiz" class="w-5 h-5" />
</label>
<ul
tabindex="0"
class="relative z-50 mt-3 p-0.5 menu shadow-xl bg-base-100 border rounded border-base-content/5 !block w-52 menu dropdown-content"
role="menu"
aria-orientation="vertical"
aria-labelledby="user-profile-menu"
>
<li><LinkLive to={"/users/instance/#{display_hostname}/#{id}"} class="grow">{l("View known users from instance")}</LinkLive></li>
<li><a href={ap_base_uri} target="_blank"><#Icon iconify="heroicons-solid:external-link" class="w-4 h-4" /> {l("Visit instance")}</a></li>
<li>
<StatelessComponent
module={maybe_component(Bonfire.Boundaries.Web.BlockButtonLive, @__context__)}
object={instance}
parent_id="instances"
type={:block}
hide_icon
is_local_user={false}
open_btn_wrapper_class="w-full"
label={display_hostname}
open_btn_label={if @ghosted_instance_wide? && @silenced_instance_wide? do
l("Unblock")
else
l("Block")
end}
class="text-error"
/>
</li></ul>
</div>
</div>
</div>

<Bonfire.UI.Common.LoadMoreLive
:if={@page_info}
live_handler={__MODULE__}
target={@myself}
page_info={@page_info}
hide_guest_fallback
/>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -147,19 +147,18 @@
</LinkLive>
</li>
<li>
<a
href={~p"/known_instances"}
<LinkLive
to={~p"/settings/instance/remote_instances"}
class={
"!px-4 !py-2",
"bg-base-content/10": @selected_tab == "known_instances"
"bg-base-content/10": @selected_tab == "remote_instances"
}
target="_blank"
>
<span class={
"text-sm text-base-content/80 font-normal",
"text-base-content": @selected_tab == "known_instances"
"text-base-content": @selected_tab == "remote_instances"
}>{l("Known remote instances")}</span>
</a>
</LinkLive>
</li>
</ul>
</details>
Expand Down
12 changes: 12 additions & 0 deletions lib/live_handlers/users_live_handler.ex
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,18 @@ defmodule Bonfire.Me.Users.LiveHandler do
)
end

def handle_event("delete_user", %{"object_id" => delete}, socket) do
if Bonfire.Me.Accounts.is_admin?(assigns(socket)[:__context__]) do
after_delete(
Bonfire.Me.DeleteWorker.enqueue_delete(delete),
"/settings/deleted/user/#{id(delete)}",
socket
)
else
error("Not allowed")
end
end

def handle_event("delete_account", %{"password" => password}, socket) do
delete = current_account_auth!(socket, password)

Expand Down
7 changes: 5 additions & 2 deletions lib/views/settings/instance_settings_live.sface
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,12 @@

</div> -->
{#match "members"}
<Bonfire.UI.Me.SettingsViewsLive.InstanceMembersLive id={:instance_members} />
<Bonfire.UI.Me.SettingsViewsLive.InstanceMembersLive id="instance_members" />
{#match "remote_users"}
<Bonfire.UI.Me.SettingsViewsLive.InstanceMembersLive id={:remote_users} show={:remote} />
<Bonfire.UI.Me.SettingsViewsLive.InstanceMembersLive id="remote_users" show={:remote} />
{#match "remote_instances"}
<Bonfire.UI.Me.SettingsViewsLive.InstancesLive id="remote_instances" />

{!-- {#match "instance_silenced"}
<Bonfire.Boundaries.Web.BlocksLive scope={:instance_wide} id="blocks" selected_tab="silenced" name={l "Ghosted instance-wide"} />
{#match "instance_ghosted"}
Expand Down

0 comments on commit b4adcd8

Please sign in to comment.