forked from AkkomaGang/akkoma
Handle duplicates.
This commit is contained in:
parent
62607f37dc
commit
18edc299b2
2 changed files with 15 additions and 6 deletions
|
@ -3,7 +3,7 @@ defmodule Pleroma.Web.OStatus do
|
||||||
import Pleroma.Web.XML
|
import Pleroma.Web.XML
|
||||||
require Logger
|
require Logger
|
||||||
|
|
||||||
alias Pleroma.{Repo, User, Web}
|
alias Pleroma.{Repo, User, Web, Object}
|
||||||
alias Pleroma.Web.ActivityPub.ActivityPub
|
alias Pleroma.Web.ActivityPub.ActivityPub
|
||||||
alias Pleroma.Web.{WebFinger, Websub}
|
alias Pleroma.Web.{WebFinger, Websub}
|
||||||
|
|
||||||
|
@ -28,11 +28,9 @@ def handle_incoming(xml_string) do
|
||||||
|
|
||||||
case object_type do
|
case object_type do
|
||||||
'http://activitystrea.ms/schema/1.0/note' ->
|
'http://activitystrea.ms/schema/1.0/note' ->
|
||||||
{:ok, activity} = handle_note(entry, doc)
|
with {:ok, activity} <- handle_note(entry, doc), do: activity
|
||||||
activity
|
|
||||||
'http://activitystrea.ms/schema/1.0/comment' ->
|
'http://activitystrea.ms/schema/1.0/comment' ->
|
||||||
{:ok, activity} = handle_note(entry, doc)
|
with {:ok, activity} <- handle_note(entry, doc), do: activity
|
||||||
activity
|
|
||||||
_ ->
|
_ ->
|
||||||
Logger.error("Couldn't parse incoming document")
|
Logger.error("Couldn't parse incoming document")
|
||||||
nil
|
nil
|
||||||
|
@ -86,7 +84,12 @@ def handle_note(entry, doc \\ nil) do
|
||||||
object
|
object
|
||||||
end
|
end
|
||||||
|
|
||||||
ActivityPub.create(to, actor, context, object, %{}, date)
|
# TODO: Bail out sooner and use transaction.
|
||||||
|
if Object.get_by_ap_id(id) do
|
||||||
|
{:error, "duplicate activity"}
|
||||||
|
else
|
||||||
|
ActivityPub.create(to, actor, context, object, %{}, date)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def find_or_make_user(uri) do
|
def find_or_make_user(uri) do
|
||||||
|
|
|
@ -2,6 +2,12 @@ defmodule Pleroma.Web.OStatusTest do
|
||||||
use Pleroma.DataCase
|
use Pleroma.DataCase
|
||||||
alias Pleroma.Web.OStatus
|
alias Pleroma.Web.OStatus
|
||||||
|
|
||||||
|
test "don't insert create notes twice" do
|
||||||
|
incoming = File.read!("test/fixtures/incoming_note_activity.xml")
|
||||||
|
{:ok, [_activity]} = OStatus.handle_incoming(incoming)
|
||||||
|
assert {:ok, [{:error, "duplicate activity"}]} == OStatus.handle_incoming(incoming)
|
||||||
|
end
|
||||||
|
|
||||||
test "handle incoming note - GS, Salmon" do
|
test "handle incoming note - GS, Salmon" do
|
||||||
incoming = File.read!("test/fixtures/incoming_note_activity.xml")
|
incoming = File.read!("test/fixtures/incoming_note_activity.xml")
|
||||||
{:ok, [activity]} = OStatus.handle_incoming(incoming)
|
{:ok, [activity]} = OStatus.handle_incoming(incoming)
|
||||||
|
|
Loading…
Reference in a new issue