Add basic incoming deletions.
This commit is contained in:
parent
558ab6e74e
commit
f226f46a09
|
@ -15,9 +15,13 @@ def get_by_ap_id(ap_id) do
|
||||||
where: fragment("(?)->>'id' = ?", activity.data, ^to_string(ap_id)))
|
where: fragment("(?)->>'id' = ?", activity.data, ^to_string(ap_id)))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def all_by_object_ap_id_q(ap_id) do
|
||||||
|
from activity in Activity,
|
||||||
|
where: fragment("(?)->'object'->>'id' = ?", activity.data, ^to_string(ap_id))
|
||||||
|
end
|
||||||
|
|
||||||
def all_by_object_ap_id(ap_id) do
|
def all_by_object_ap_id(ap_id) do
|
||||||
Repo.all(from activity in Activity,
|
Repo.all(all_by_object_ap_id_q(ap_id))
|
||||||
where: fragment("(?)->'object'->>'id' = ?", activity.data, ^to_string(ap_id)))
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_create_activity_by_object_ap_id(ap_id) do
|
def get_create_activity_by_object_ap_id(ap_id) do
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
defmodule Pleroma.Web.OStatus.DeleteHandler do
|
||||||
|
require Logger
|
||||||
|
alias Pleroma.Web.{XML, OStatus}
|
||||||
|
alias Pleroma.{Activity, Object, Repo}
|
||||||
|
|
||||||
|
def handle_delete(entry, doc \\ nil) do
|
||||||
|
with id <- XML.string_from_xpath("//id", entry),
|
||||||
|
object when not is_nil(object) <- Object.get_by_ap_id(id) do
|
||||||
|
Repo.delete(object)
|
||||||
|
Repo.delete_all(Activity.all_by_object_ap_id_q(id))
|
||||||
|
nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -9,7 +9,7 @@ defmodule Pleroma.Web.OStatus do
|
||||||
alias Pleroma.Web.ActivityPub.ActivityPub
|
alias Pleroma.Web.ActivityPub.ActivityPub
|
||||||
alias Pleroma.Web.ActivityPub.Utils
|
alias Pleroma.Web.ActivityPub.Utils
|
||||||
alias Pleroma.Web.{WebFinger, Websub}
|
alias Pleroma.Web.{WebFinger, Websub}
|
||||||
alias Pleroma.Web.OStatus.{FollowHandler, NoteHandler}
|
alias Pleroma.Web.OStatus.{FollowHandler, NoteHandler, DeleteHandler}
|
||||||
|
|
||||||
def feed_path(user) do
|
def feed_path(user) do
|
||||||
"#{user.ap_id}/feed.atom"
|
"#{user.ap_id}/feed.atom"
|
||||||
|
@ -34,6 +34,8 @@ def handle_incoming(xml_string) do
|
||||||
|
|
||||||
try do
|
try do
|
||||||
case verb do
|
case verb do
|
||||||
|
'http://activitystrea.ms/schema/1.0/delete' ->
|
||||||
|
with {:ok, activity} <- DeleteHandler.handle_delete(entry, doc), do: activity
|
||||||
'http://activitystrea.ms/schema/1.0/follow' ->
|
'http://activitystrea.ms/schema/1.0/follow' ->
|
||||||
with {:ok, activity} <- FollowHandler.handle(entry, doc), do: activity
|
with {:ok, activity} <- FollowHandler.handle(entry, doc), do: activity
|
||||||
'http://activitystrea.ms/schema/1.0/share' ->
|
'http://activitystrea.ms/schema/1.0/share' ->
|
||||||
|
|
|
@ -0,0 +1,39 @@
|
||||||
|
<?xml version="1.0"?>
|
||||||
|
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:thr="http://purl.org/syndication/thread/1.0" xmlns:activity="http://activitystrea.ms/spec/1.0/" xmlns:poco="http://portablecontacts.net/spec/1.0" xmlns:media="http://purl.org/syndication/atommedia" xmlns:ostatus="http://ostatus.org/schema/1.0" xmlns:mastodon="http://mastodon.social/schema/1.0">
|
||||||
|
<id>https://mastodon.sdf.org/users/snowdusk.atom</id>
|
||||||
|
<title>snowdusk</title>
|
||||||
|
<subtitle>Amateur live performance DJ/radio DJ on SDF's underground Internet radio http://aNONradio.net (LIVE Sat Sun Mon Tue 23:00-24:00 UTC) - http://snowdusk.sdf.org</subtitle>
|
||||||
|
<updated>2017-06-17T04:14:34Z</updated>
|
||||||
|
<logo>https://mastodon.sdf.org/system/accounts/avatars/000/000/002/original/405a7652d5f60449.jpg?1497672873</logo>
|
||||||
|
<author>
|
||||||
|
<id>https://mastodon.sdf.org/users/snowdusk</id>
|
||||||
|
<activity:object-type>http://activitystrea.ms/schema/1.0/person</activity:object-type>
|
||||||
|
<uri>https://mastodon.sdf.org/users/snowdusk</uri>
|
||||||
|
<name>snowdusk</name>
|
||||||
|
<email>snowdusk@mastodon.sdf.org</email>
|
||||||
|
<summary type="html"><p>Amateur live performance DJ/radio DJ on SDF&apos;s underground Internet radio <a href="http://anonradio.net/" rel="nofollow noopener" target="_blank"><span class="invisible">http://</span><span class="">anonradio.net/</span><span class="invisible"></span></a> (LIVE Sat Sun Mon Tue 23:00-24:00 UTC) - <a href="http://snowdusk.sdf.org/" rel="nofollow noopener" target="_blank"><span class="invisible">http://</span><span class="">snowdusk.sdf.org/</span><span class="invisible"></span></a></p></summary>
|
||||||
|
<link rel="alternate" type="text/html" href="https://mastodon.sdf.org/@snowdusk"/>
|
||||||
|
<link rel="avatar" type="image/jpeg" media:width="120" media:height="120" href="https://mastodon.sdf.org/system/accounts/avatars/000/000/002/original/405a7652d5f60449.jpg?1497672873"/>
|
||||||
|
<link rel="header" type="image/jpeg" media:width="700" media:height="335" href="https://mastodon.sdf.org/system/accounts/headers/000/000/002/original/f1e9b0fb21b4e5a0.jpeg?1495793472"/>
|
||||||
|
<poco:preferredUsername>snowdusk</poco:preferredUsername>
|
||||||
|
<poco:displayName>snowdusk</poco:displayName>
|
||||||
|
<poco:note>Amateur live performance DJ/radio DJ on SDF's underground Internet radio http://aNONradio.net (LIVE Sat Sun Mon Tue 23:00-24:00 UTC) - http://snowdusk.sdf.org</poco:note>
|
||||||
|
<mastodon:scope>public</mastodon:scope>
|
||||||
|
</author>
|
||||||
|
<link rel="alternate" type="text/html" href="https://mastodon.sdf.org/@snowdusk"/>
|
||||||
|
<link rel="self" type="application/atom+xml" href="https://mastodon.sdf.org/users/snowdusk.atom"/>
|
||||||
|
<link rel="next" type="application/atom+xml" href="https://mastodon.sdf.org/users/snowdusk.atom?max_id=7592"/>
|
||||||
|
<link rel="hub" href="https://mastodon.sdf.org/api/push"/>
|
||||||
|
<link rel="salmon" href="https://mastodon.sdf.org/api/salmon/2"/>
|
||||||
|
<entry>
|
||||||
|
<id>tag:mastodon.sdf.org,2017-06-10:objectId=310513:objectType=Status</id>
|
||||||
|
<published>2017-06-10T22:02:31Z</published>
|
||||||
|
<updated>2017-06-10T22:02:31Z</updated>
|
||||||
|
<title>snowdusk deleted status</title>
|
||||||
|
<activity:object-type>http://activitystrea.ms/schema/1.0/activity</activity:object-type>
|
||||||
|
<activity:verb>http://activitystrea.ms/schema/1.0/delete</activity:verb>
|
||||||
|
<content>Deleted status</content>
|
||||||
|
<link rel="alternate" type="text/html" href="https://mastodon.sdf.org/users/snowdusk/updates/7782"/>
|
||||||
|
<link rel="self" type="application/atom+xml" href="https://mastodon.sdf.org/users/snowdusk/updates/7782.atom"/>
|
||||||
|
</entry>
|
||||||
|
</feed>
|
|
@ -0,0 +1,23 @@
|
||||||
|
defmodule Pleroma.Web.OStatus.DeleteHandlingTest do
|
||||||
|
use Pleroma.DataCase
|
||||||
|
|
||||||
|
import Pleroma.Factory
|
||||||
|
alias Pleroma.{Repo, Activity, Object}
|
||||||
|
alias Pleroma.Web.OStatus
|
||||||
|
|
||||||
|
describe "deletions" do
|
||||||
|
test "it removes the mentioned activity" do
|
||||||
|
note = insert(:note_activity)
|
||||||
|
second_note = insert(:note_activity)
|
||||||
|
|
||||||
|
incoming = File.read!("test/fixtures/delete.xml")
|
||||||
|
|> String.replace("tag:mastodon.sdf.org,2017-06-10:objectId=310513:objectType=Status", note.data["object"]["id"])
|
||||||
|
{:ok, []} = OStatus.handle_incoming(incoming)
|
||||||
|
|
||||||
|
refute Repo.get(Activity, note.id)
|
||||||
|
refute Object.get_by_ap_id(note.data["object"]["id"])
|
||||||
|
assert Repo.get(Activity, second_note.id)
|
||||||
|
assert Object.get_by_ap_id(second_note.data["object"]["id"])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue