diff --git a/lib/nulla/models/note.ex b/lib/nulla/models/note.ex index a054b87..9eb9468 100644 --- a/lib/nulla/models/note.ex +++ b/lib/nulla/models/note.ex @@ -12,6 +12,7 @@ defmodule Nulla.Models.Note do field :inReplyTo, :string field :published, :utc_datetime field :url, :string + field :visibility, :string field :to, {:array, :string} field :cc, {:array, :string} field :sensitive, :boolean, default: false @@ -28,9 +29,11 @@ defmodule Nulla.Models.Note do def changeset(note, attrs) do note |> cast(attrs, [ + :id, :inReplyTo, :published, :url, + :visibility, :to, :cc, :sensitive, @@ -41,12 +44,12 @@ defmodule Nulla.Models.Note do |> validate_required([:published, :url, :to, :cc, :content, :language, :actor_id]) end - def create_note(attrs, visibility) - when is_map(attrs) and visibility in ["public", "unlisted", "followers", "private"] do + def create_note(attrs) when is_map(attrs) do id = Map.get(attrs, :id, Snowflake.next_id()) actor_id = Map.get(attrs, :actor_id) actor = Actor.get_actor(id: actor_id) published = Map.get(attrs, :published, DateTime.utc_now()) + visibility = Map.get(attrs, :visibility, "public") url = case Map.get(attrs, :url) do @@ -82,15 +85,21 @@ defmodule Nulla.Models.Note do cc = [] {to, cc} + + _ -> + raise ArgumentError, "Invalid visibility: #{visibility}" end + attrs = + attrs + |> Map.put(:id, id) + |> Map.put(:published, published) + |> Map.put(:url, url) + |> Map.put(:to, to) + |> Map.put(:cc, cc) + %__MODULE__{} |> changeset(attrs) - |> put_change(:id, id) - |> put_change(:published, published) - |> put_change(:url, url) - |> put_change(:to, to) - |> put_change(:cc, cc) |> Repo.insert() end diff --git a/lib/nulla_web/components/templates/actor/show.html.heex b/lib/nulla_web/components/templates/actor/show.html.heex index d7a2d21..6f667cd 100644 --- a/lib/nulla_web/components/templates/actor/show.html.heex +++ b/lib/nulla_web/components/templates/actor/show.html.heex @@ -95,13 +95,13 @@
<%= case note.visibility do %> - <% :public -> %> + <% "public" -> %> <.icon name="hero-globe-americas" class="h-5 w-5" /> - <% :unlisted -> %> + <% "unlisted" -> %> <.icon name="hero-moon" class="h-5 w-5" /> - <% :followers -> %> + <% "followers" -> %> <.icon name="hero-lock-closed" class="h-5 w-5" /> - <% :private -> %> + <% "private" -> %> <.icon name="hero-at-symbol" class="h-5 w-5" /> <% end %> {format_note_datetime_diff(note.inserted_at)} diff --git a/priv/repo/migrations/20250615131431_create_notes.exs b/priv/repo/migrations/20250615131431_create_notes.exs index 3115275..2513289 100644 --- a/priv/repo/migrations/20250615131431_create_notes.exs +++ b/priv/repo/migrations/20250615131431_create_notes.exs @@ -7,6 +7,7 @@ defmodule Nulla.Repo.Migrations.CreateNotes do add :inReplyTo, :string add :published, :utc_datetime add :url, :string + add :visibility, :string add :to, {:array, :string} add :cc, {:array, :string} add :sensitive, :boolean, default: false diff --git a/test/nulla/http_signature_test.exs b/test/nulla/http_signature_test.exs index 2983a17..afab9df 100644 --- a/test/nulla/http_signature_test.exs +++ b/test/nulla/http_signature_test.exs @@ -5,6 +5,7 @@ defmodule Nulla.HTTPSignatureTest do import Nulla.Fixtures.Data alias Nulla.HTTPSignature alias Nulla.Snowflake + alias Nulla.Models.User alias Nulla.Models.Actor setup do @@ -15,6 +16,7 @@ defmodule Nulla.HTTPSignatureTest do test "make_headers/3 creates valid signature headers and verify/2 validates them" do actor = Actor.get_actor(preferredUsername: "test") target_actor = Actor.get_actor(preferredUsername: "test2") + user = User.get_user(id: actor.id) follow_activity = %{ "@context" => "https://www.w3.org/ns/activitystreams", @@ -25,7 +27,14 @@ defmodule Nulla.HTTPSignatureTest do } body = Jason.encode!(follow_activity) - headers = HTTPSignature.make_headers(body, target_actor.inbox, actor) + + headers = + HTTPSignature.make_headers( + body, + target_actor.inbox, + actor.publicKey["id"], + user.privateKeyPem + ) conn = conn(:post, "/users/test2/inbox", body) diff --git a/test/support/fixtures/data.ex b/test/support/fixtures/data.ex index 8e40b58..d2944ab 100644 --- a/test/support/fixtures/data.ex +++ b/test/support/fixtures/data.ex @@ -48,7 +48,8 @@ defmodule Nulla.Fixtures.Data do actor_url: actor.url, content: "Hello World from Nulla!", language: "en", - actor_id: actor.id + actor_id: actor.id, + visibility: "public" }) {publicKeyPem, privateKeyPem} = KeyGen.gen()