diff --git a/README.md b/README.md index cd007ea..2eafa4d 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ - [x] Post formatting - [x] Deleting posts - [x] Sending posts w/ images -- [ ] Making posts with CWs +- [x] Making posts with CWs - [ ] Making polls - [ ] Followers-only posts (or maybe this is handled because we only send posts to followers? but we also include public in the TO field?) - [] Sending posts with videos @@ -39,11 +39,11 @@ - [x] Your posts show up in timeline - [x] Posts from accounts you follow show up in timeline - [x] Show the actor avatar and display name -- [ ] Receiving posts w/ images +- [x] Receiving posts w/ images - [ ] Receiving posts w/ videos - [ ] Liking posts - [ ] Unliking posts -- [ ] Displaying CW posts behind CW +- [x] Displaying CW posts behind CW - [ ] Displaying polls - [ ] Voting in polls diff --git a/lib/postland/activities.ex b/lib/postland/activities.ex index 655a973..b0c758f 100644 --- a/lib/postland/activities.ex +++ b/lib/postland/activities.ex @@ -9,7 +9,7 @@ defmodule Postland.Activities do alias Postland.Repo alias Postland.Follows - def record_markdown_post(markdown, attachments) do + def record_markdown_post(markdown, cw, attachments) do id = Ecto.UUID.autogenerate() html = Earmark.as_html!(markdown) @@ -21,6 +21,22 @@ defmodule Postland.Activities do # CW posts have a summary field which is the warning itself, a content # field (like a non-CW post) that is the body, and a "sensitive" => true field + note = + %{ + "id" => url(~p"/activities/#{id}"), + "type" => "Note", + "published" => DateTime.utc_now() |> DateTime.to_iso8601(), + "attributedTo" => Postland.my_actor_id(), + "mediaType" => "text/html", + "content" => html, + "to" => ["https://www.w3.org/ns/activitystreams#Public"], + "cc" => [ + "#{Postland.my_actor_id()}/followers" + ], + "attachment" => attachments + } + |> maybe_add_cw(cw) + activity = %{ "@context" => [ @@ -38,19 +54,7 @@ defmodule Postland.Activities do "id" => url(~p"/activities/#{id}"), "type" => "Create", "actor" => Postland.my_actor_id(), - "object" => %{ - "id" => url(~p"/activities/#{id}"), - "type" => "Note", - "published" => DateTime.utc_now() |> DateTime.to_iso8601(), - "attributedTo" => Postland.my_actor_id(), - "mediaType" => "text/html", - "content" => html, - "to" => ["https://www.w3.org/ns/activitystreams#Public"], - "cc" => [ - "#{Postland.my_actor_id()}/followers" - ], - "attachment" => attachments - } + "object" => note } activity @@ -59,6 +63,10 @@ defmodule Postland.Activities do |> broadcast_to_followers(activity) end + defp maybe_add_cw(note, nil), do: note + defp maybe_add_cw(note, ""), do: note + defp maybe_add_cw(note, cw), do: Map.merge(note, %{"sensitive" => true, "summary" => cw}) + def delete_post(post) do activity = %{ diff --git a/lib/postland/timeline.ex b/lib/postland/timeline.ex index 112f36e..5f6842e 100644 --- a/lib/postland/timeline.ex +++ b/lib/postland/timeline.ex @@ -17,6 +17,12 @@ defmodule Postland.Timeline do # TODO: Filter down to just image/* and video/* MIME types end + def cw(activity) do + activity.data + |> Map.get("items") + |> Enum.find_value(fn item -> item["sensitive"] && item["summary"] end) + end + def attribution(activity) do Postland.Actors.actor(get_from_html_item(activity, "attributedTo")) end diff --git a/lib/postland_web/components/core_components.ex b/lib/postland_web/components/core_components.ex index 122ed25..dab06f7 100644 --- a/lib/postland_web/components/core_components.ex +++ b/lib/postland_web/components/core_components.ex @@ -87,6 +87,16 @@ defmodule PostlandWeb.CoreComponents do