feat: Deleting posts
This commit is contained in:
parent
1bd8ce9c6b
commit
b49925b830
5 changed files with 53 additions and 4 deletions
|
|
@ -12,7 +12,7 @@
|
||||||
- [x] My posts
|
- [x] My posts
|
||||||
- [x] Posts from accounts you follow
|
- [x] Posts from accounts you follow
|
||||||
- [x] Show the actor avatar and display name
|
- [x] Show the actor avatar and display name
|
||||||
- [ ] Deleting posts
|
- [x] Deleting posts
|
||||||
- [x] Profile
|
- [x] Profile
|
||||||
- [x] Name field (for display name)
|
- [x] Name field (for display name)
|
||||||
- [x] Bust actor cache when you update your profile
|
- [x] Bust actor cache when you update your profile
|
||||||
|
|
@ -31,6 +31,7 @@
|
||||||
- [ ] DMs
|
- [ ] DMs
|
||||||
- [ ] Support authenticated fetch of outbox (by allowed domains / servers)
|
- [ ] Support authenticated fetch of outbox (by allowed domains / servers)
|
||||||
- [ ] Followers-only posts (or maybe this is handled because we only send posts to followers? but we also include public in the TO field?)
|
- [ ] Followers-only posts (or maybe this is handled because we only send posts to followers? but we also include public in the TO field?)
|
||||||
|
- [ ] Check the domain of the public key against the domain of the object being CRUDed
|
||||||
|
|
||||||
## UX
|
## UX
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -58,6 +58,21 @@ defmodule Postland.Activities do
|
||||||
|> broadcast_to_followers(activity)
|
|> broadcast_to_followers(activity)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def delete_post(post) do
|
||||||
|
activity =
|
||||||
|
%{
|
||||||
|
"@context" => "https://www.w3.org/ns/activitystreams",
|
||||||
|
"id" => url(~p"/activities/#{Ecto.UUID.autogenerate()}"),
|
||||||
|
"type" => "Delete",
|
||||||
|
"actor" => Postland.my_actor_id(),
|
||||||
|
"object" => post.id
|
||||||
|
}
|
||||||
|
|
||||||
|
post
|
||||||
|
|> Repo.delete()
|
||||||
|
|> broadcast_to_followers(activity)
|
||||||
|
end
|
||||||
|
|
||||||
def broadcast_to_followers({:ok, _} = result, activity) do
|
def broadcast_to_followers({:ok, _} = result, activity) do
|
||||||
my_actor_id = Postland.my_actor_id()
|
my_actor_id = Postland.my_actor_id()
|
||||||
private_key = Postland.Accounts.solo_user().private_key
|
private_key = Postland.Accounts.solo_user().private_key
|
||||||
|
|
@ -65,8 +80,6 @@ defmodule Postland.Activities do
|
||||||
Postland.Follows.all_followers()
|
Postland.Follows.all_followers()
|
||||||
|> Enum.map(fn %{follower: follower} ->
|
|> Enum.map(fn %{follower: follower} ->
|
||||||
inbox = Postland.Actors.inbox(follower)
|
inbox = Postland.Actors.inbox(follower)
|
||||||
dbg(follower)
|
|
||||||
dbg(inbox)
|
|
||||||
|
|
||||||
case inbox do
|
case inbox do
|
||||||
nil ->
|
nil ->
|
||||||
|
|
|
||||||
11
lib/postland/objects.ex
Normal file
11
lib/postland/objects.ex
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
defmodule Postland.Objects do
|
||||||
|
alias Postland.Object
|
||||||
|
alias Postland.Repo
|
||||||
|
|
||||||
|
import Ecto.Query
|
||||||
|
|
||||||
|
def get_by_id(id) do
|
||||||
|
from(o in Object, where: o.id == ^id)
|
||||||
|
|> Repo.one()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -115,6 +115,15 @@ defmodule PostlandWeb.CoreComponents do
|
||||||
<%= {:safe, Postland.Timeline.html_content(@post)} %>
|
<%= {:safe, Postland.Timeline.html_content(@post)} %>
|
||||||
</div>
|
</div>
|
||||||
<div class="px-4 py-4 sm:px-6">
|
<div class="px-4 py-4 sm:px-6">
|
||||||
|
<a
|
||||||
|
:if={@author["id"] == Postland.my_actor_id()}
|
||||||
|
href="#"
|
||||||
|
phx-click="delete_post"
|
||||||
|
phx-value-post-dom-id={@post_dom_id}
|
||||||
|
phx-value-post-id={@post.id}
|
||||||
|
>
|
||||||
|
<.icon name="hero-trash" />
|
||||||
|
</a>
|
||||||
<!-- Content goes here -->
|
<!-- Content goes here -->
|
||||||
<!-- We use less vertical padding on card footers at all sizes than on headers or body sections -->
|
<!-- We use less vertical padding on card footers at all sizes than on headers or body sections -->
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,15 @@
|
||||||
defmodule PostlandWeb.TimelineLive do
|
defmodule PostlandWeb.TimelineLive do
|
||||||
use PostlandWeb, :live_view
|
use PostlandWeb, :live_view
|
||||||
|
|
||||||
|
alias Postland.Activities
|
||||||
|
alias Postland.Objects
|
||||||
|
|
||||||
def render(assigns) do
|
def render(assigns) do
|
||||||
~H"""
|
~H"""
|
||||||
<.post_form post_content={@post} />
|
<.post_form post_content={@post} />
|
||||||
<div id="timeline-posts" phx-update="stream">
|
<div id="timeline-posts" phx-update="stream">
|
||||||
<div :for={{id, post} <- @streams.posts} id={id} class="mt-10">
|
<div :for={{id, post} <- @streams.posts} id={id} class="mt-10">
|
||||||
<.post_card post={post} />
|
<.post_card post={post} post_dom_id={id} />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
"""
|
"""
|
||||||
|
|
@ -37,6 +40,18 @@ defmodule PostlandWeb.TimelineLive do
|
||||||
{:noreply, socket}
|
{:noreply, socket}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def handle_event("delete_post", %{"post-id" => id, "post-dom-id" => dom_id}, socket) do
|
||||||
|
post = Objects.get_by_id(id)
|
||||||
|
|
||||||
|
case Activities.delete_post(post) do
|
||||||
|
{:ok, _} ->
|
||||||
|
{:noreply, socket |> stream_delete_by_dom_id(:posts, dom_id)}
|
||||||
|
|
||||||
|
_ ->
|
||||||
|
{:noreply, socket |> put_flash(:error, "An unexpected error has occurred.")}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def handle_event("change_post", %{"post" => post}, socket) do
|
def handle_event("change_post", %{"post" => post}, socket) do
|
||||||
{:noreply, socket |> assign(:post, post)}
|
{:noreply, socket |> assign(:post, post)}
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue