This commit is contained in:
Mirai Kumiko 2025-06-30 14:33:13 +02:00
parent c531beadb7
commit dc25c926ba
Signed by: miraikumiko
GPG key ID: 3F178B1B5E0CB278
5 changed files with 33 additions and 13 deletions

View file

@ -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

View file

@ -95,13 +95,13 @@
</div>
<div class="flex items-center space-x-2 text-sm text-gray-500">
<%= 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 %>
<span>{format_note_datetime_diff(note.inserted_at)}</span>