forked from AkkomaGang/akkoma
Use inReplyTo to find context.
This commit is contained in:
parent
33c803d6da
commit
018a1a390f
3 changed files with 57 additions and 7 deletions
|
@ -44,13 +44,19 @@ def handle_note(entry, doc \\ nil) do
|
|||
|
||||
[author] = :xmerl_xpath.string('//author[1]', doc)
|
||||
{:ok, actor} = find_make_or_update_user(author)
|
||||
inReplyTo = string_from_xpath("/entry/thr:in-reply-to[1]/@ref", entry)
|
||||
|
||||
context = (string_from_xpath("/entry/ostatus:conversation[1]", entry) || "") |> String.trim
|
||||
context = if String.length(context) > 0 do
|
||||
context
|
||||
else
|
||||
ActivityPub.generate_context_id
|
||||
end
|
||||
|
||||
context = with %{data: %{"context" => context}} <- Object.get_cached_by_ap_id(inReplyTo) do
|
||||
context
|
||||
else _e ->
|
||||
if String.length(context) > 0 do
|
||||
context
|
||||
else
|
||||
ActivityPub.generate_context_id
|
||||
end
|
||||
end
|
||||
|
||||
to = [
|
||||
"https://www.w3.org/ns/activitystreams#Public"
|
||||
|
@ -74,8 +80,6 @@ def handle_note(entry, doc \\ nil) do
|
|||
"actor" => actor.ap_id
|
||||
}
|
||||
|
||||
inReplyTo = string_from_xpath("/entry/thr:in-reply-to[1]/@ref", entry)
|
||||
|
||||
object = if inReplyTo do
|
||||
Map.put(object, "inReplyTo", inReplyTo)
|
||||
else
|
||||
|
|
29
test/fixtures/incoming_reply_mastodon.xml
vendored
Normal file
29
test/fixtures/incoming_reply_mastodon.xml
vendored
Normal file
|
@ -0,0 +1,29 @@
|
|||
<?xml version="1.0"?>
|
||||
<entry 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>tag:mastodon.social,2017-05-02:objectId=4901603:objectType=Status</id>
|
||||
<published>2017-05-02T18:33:06Z</published>
|
||||
<updated>2017-05-02T18:33:06Z</updated>
|
||||
<title>New status by lambadalambda</title>
|
||||
<author>
|
||||
<id>https://mastodon.social/users/lambadalambda</id>
|
||||
<activity:object-type>http://activitystrea.ms/schema/1.0/person</activity:object-type>
|
||||
<uri>https://mastodon.social/users/lambadalambda</uri>
|
||||
<name>lambadalambda</name>
|
||||
<email>lambadalambda@mastodon.social</email>
|
||||
<link rel="alternate" type="text/html" href="https://mastodon.social/@lambadalambda"/>
|
||||
<link rel="avatar" type="image/gif" media:width="120" media:height="120" href="https://files.mastodon.social/accounts/avatars/000/000/264/original/1429214160519.gif"/>
|
||||
<link rel="header" type="" media:width="700" media:height="335" href="/headers/original/missing.png"/>
|
||||
<poco:preferredUsername>lambadalambda</poco:preferredUsername>
|
||||
<poco:displayName>Critical Value</poco:displayName>
|
||||
<mastodon:scope>public</mastodon:scope>
|
||||
</author>
|
||||
<activity:object-type>http://activitystrea.ms/schema/1.0/comment</activity:object-type>
|
||||
<activity:verb>http://activitystrea.ms/schema/1.0/post</activity:verb>
|
||||
<content type="html" xml:lang="el"><p><span class="h-card"><a href="https://pleroma.soykaf.com/users/lain" class="u-url mention">@<span>lain</span></a></span> hey</p></content>
|
||||
<link rel="mentioned" ostatus:object-type="http://activitystrea.ms/schema/1.0/person" href="https://pleroma.soykaf.com/users/lain"/>
|
||||
<link rel="mentioned" ostatus:object-type="http://activitystrea.ms/schema/1.0/collection" href="http://activityschema.org/collection/public"/>
|
||||
<mastodon:scope>public</mastodon:scope>
|
||||
<link rel="alternate" type="text/html" href="https://mastodon.social/users/lambadalambda/updates/2224923"/>
|
||||
<link rel="self" type="application/atom+xml" href="https://mastodon.social/users/lambadalambda/updates/2224923.atom"/>
|
||||
<thr:in-reply-to ref="https://pleroma.soykaf.com/objects/c237d966-ac75-4fe3-a87a-d89d71a3a7a4" href=""/>
|
||||
</entry>
|
|
@ -2,6 +2,7 @@ defmodule Pleroma.Web.OStatusTest do
|
|||
use Pleroma.DataCase
|
||||
alias Pleroma.Web.OStatus
|
||||
alias Pleroma.Web.XML
|
||||
alias Pleroma.{Object, Repo}
|
||||
|
||||
test "don't insert create notes twice" do
|
||||
incoming = File.read!("test/fixtures/incoming_note_activity.xml")
|
||||
|
@ -32,6 +33,22 @@ test "handle incoming notes - GS, subscription" do
|
|||
assert activity.data["object"]["content"] == "Will it blend?"
|
||||
end
|
||||
|
||||
test "handle incoming notes - Mastodon, salmon, reply" do
|
||||
# It uses the context of the replied to object
|
||||
Repo.insert!(%Object{
|
||||
data: %{
|
||||
"id" => "https://pleroma.soykaf.com/objects/c237d966-ac75-4fe3-a87a-d89d71a3a7a4",
|
||||
"context" => "2hu"
|
||||
}})
|
||||
incoming = File.read!("test/fixtures/incoming_reply_mastodon.xml")
|
||||
{:ok, [activity]} = OStatus.handle_incoming(incoming)
|
||||
|
||||
assert activity.data["type"] == "Create"
|
||||
assert activity.data["object"]["type"] == "Note"
|
||||
assert activity.data["object"]["actor"] == "https://mastodon.social/users/lambadalambda"
|
||||
assert activity.data["context"] == "2hu"
|
||||
end
|
||||
|
||||
test "handle incoming notes - GS, subscription, reply" do
|
||||
incoming = File.read!("test/fixtures/ostatus_incoming_reply.xml")
|
||||
{:ok, [activity]} = OStatus.handle_incoming(incoming)
|
||||
|
|
Loading…
Reference in a new issue