From b4adcd8c87025ef45cd8b0e6a2fbcaab8d4c9178 Mon Sep 17 00:00:00 2001 From: Mayel de Borniol Date: Mon, 14 Oct 2024 18:55:24 +0100 Subject: [PATCH] https://github.com/bonfire-networks/bonfire-app/issues/1038 --- .../instance/members/instances_live.ex | 59 +++++++++++++++++++ .../instance/members/instances_live.sface | 58 ++++++++++++++++++ .../instance_sidebar_settings_nav_live.sface | 11 ++-- lib/live_handlers/users_live_handler.ex | 12 ++++ .../settings/instance_settings_live.sface | 7 ++- 5 files changed, 139 insertions(+), 8 deletions(-) create mode 100644 lib/components/settings/instance/members/instances_live.ex create mode 100644 lib/components/settings/instance/members/instances_live.sface diff --git a/lib/components/settings/instance/members/instances_live.ex b/lib/components/settings/instance/members/instances_live.ex new file mode 100644 index 00000000..3b33c313 --- /dev/null +++ b/lib/components/settings/instance/members/instances_live.ex @@ -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 diff --git a/lib/components/settings/instance/members/instances_live.sface b/lib/components/settings/instance/members/instances_live.sface new file mode 100644 index 00000000..253f60bb --- /dev/null +++ b/lib/components/settings/instance/members/instances_live.sface @@ -0,0 +1,58 @@ +
+
+
+ +
{display_hostname}
+ + +
+
+ + +
\ No newline at end of file diff --git a/lib/components/settings/nav_sidebar/instance_sidebar_settings_nav_live.sface b/lib/components/settings/nav_sidebar/instance_sidebar_settings_nav_live.sface index 6398e42c..43b14cff 100644 --- a/lib/components/settings/nav_sidebar/instance_sidebar_settings_nav_live.sface +++ b/lib/components/settings/nav_sidebar/instance_sidebar_settings_nav_live.sface @@ -147,19 +147,18 @@
  • - {l("Known remote instances")} - +
  • diff --git a/lib/live_handlers/users_live_handler.ex b/lib/live_handlers/users_live_handler.ex index 29483ce0..546878ed 100755 --- a/lib/live_handlers/users_live_handler.ex +++ b/lib/live_handlers/users_live_handler.ex @@ -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) diff --git a/lib/views/settings/instance_settings_live.sface b/lib/views/settings/instance_settings_live.sface index af2fca1d..afb2e1aa 100644 --- a/lib/views/settings/instance_settings_live.sface +++ b/lib/views/settings/instance_settings_live.sface @@ -97,9 +97,12 @@ --> {#match "members"} - + {#match "remote_users"} - + + {#match "remote_instances"} + + {!-- {#match "instance_silenced"} {#match "instance_ghosted"}