{note["content"]}
{note["content"]}
-diff --git a/lib/aether_web/live/timeline_live.ex b/lib/aether_web/live/timeline_live.ex index 1b701fb..6586ba7 100644 --- a/lib/aether_web/live/timeline_live.ex +++ b/lib/aether_web/live/timeline_live.ex @@ -7,23 +7,18 @@ defmodule AetherWeb.TimelineLive do alias Tribes.Nostr @impl true - def mount(params, session, socket) do - tribe_id = resolve_tribe_id(params, session) - scope = load_scope(socket.assigns.current_user, tribe_id) - - {:ok, notes} = Nostr.list_notes(limit: 100) - notes = filter_notes(notes, scope) + def mount(_params, _session, socket) do + feed = load_feed() + notes = load_notes(feed.member_pubkeys) profile_cache = load_profile_cache(notes) note_ids = notes |> Enum.map(& &1["id"]) |> MapSet.new() socket = socket |> assign(:page_title, "Aether") - |> assign(:tribe_id, tribe_id) - |> assign(:tribe, scope.tribe) - |> assign(:can_view_tribe?, scope.can_view?) - |> assign(:is_tribe_member?, scope.member?) - |> assign(:tribe_member_pubkeys, scope.member_pubkeys) + |> assign(:current_scope, socket.assigns[:current_scope]) + |> assign(:tribe, feed.tribe) + |> assign(:tribe_member_pubkeys, feed.member_pubkeys) |> assign(:profile_cache, profile_cache) |> assign(:note_ids, note_ids) |> assign(:note_count, MapSet.size(note_ids)) @@ -32,7 +27,7 @@ defmodule AetherWeb.TimelineLive do |> stream(:notes, notes) if connected?(socket) do - {:ok, ref} = Nostr.subscribe_notes(self(), "aether", limit: 100) + {:ok, ref} = subscribe_notes(feed.member_pubkeys) {:ok, assign(socket, :subscription_ref, ref)} else {:ok, socket} @@ -40,31 +35,6 @@ defmodule AetherWeb.TimelineLive do end @impl true - def handle_event("join_tribe", %{"join" => %{"invite_code" => invite_code}}, socket) do - cond do - is_nil(socket.assigns.current_user) -> - {:noreply, put_flash(socket, :error, "Sign in to join tribes")} - - is_nil(socket.assigns.tribe) -> - {:noreply, put_flash(socket, :error, "No tribe selected")} - - true -> - opts = - case String.trim(invite_code || "") do - "" -> [] - code -> [invite_code: code] - end - - case Communities.join_tribe(socket.assigns.current_user, socket.assigns.tribe.id, opts) do - {:ok, _membership} -> - {:noreply, socket |> refresh_scope() |> put_flash(:info, "Joined tribe")} - - {:error, _reason} -> - {:noreply, put_flash(socket, :error, "Unable to join tribe")} - end - end - end - def handle_event("post", %{"note" => %{"content" => content}}, socket) do content = String.trim(content) @@ -75,25 +45,12 @@ defmodule AetherWeb.TimelineLive do content == "" -> {:noreply, put_flash(socket, :error, "Post cannot be empty")} - not can_post_to_scope?(socket) -> - {:noreply, put_flash(socket, :error, "Join this tribe to post")} - true -> case socket.assigns[:session_privkey] do privkey when is_binary(privkey) -> case Nostr.publish_note(content, socket.assigns.current_user.pubkey_hex, privkey) do {:ok, event} -> - if note_in_scope?(event, socket.assigns.tribe_member_pubkeys) do - note_ids = MapSet.put(socket.assigns.note_ids, event["id"]) - - {:noreply, - socket - |> assign(:note_ids, note_ids) - |> assign(:note_count, MapSet.size(note_ids)) - |> stream_insert(:notes, event, at: 0)} - else - {:noreply, put_flash(socket, :info, "Posted outside current tribe scope")} - end + handle_published_note(socket, event) {:error, reason} -> {:noreply, put_flash(socket, :error, "Failed to publish: #{inspect(reason)}")} @@ -107,8 +64,7 @@ defmodule AetherWeb.TimelineLive do @impl true def handle_info({:parrhesia, :event, _ref, _sub_id, %{"kind" => 1} = event}, socket) do - if note_in_scope?(event, socket.assigns.tribe_member_pubkeys) and - socket.assigns.can_view_tribe? do + if note_in_scope?(event, socket.assigns.tribe_member_pubkeys) do profile_cache = maybe_put_profile(socket.assigns.profile_cache, event["pubkey"]) if MapSet.member?(socket.assigns.note_ids, event["id"]) do @@ -144,178 +100,165 @@ defmodule AetherWeb.TimelineLive do @impl true def render(assigns) do ~H""" -
+ Local feed +
++ {timeline_description(@tribe)} +
+- You are viewing this tribe as a guest. -
-{note["content"]}
{note["content"]}
-