diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex
index 7d065ae90..98471cf71 100644
--- a/lib/pleroma/user.ex
+++ b/lib/pleroma/user.ex
@@ -136,9 +136,13 @@ def following?(%User{} = follower, %User{} = followed) do
Enum.member?(follower.following, User.ap_followers(followed))
end
+ def get_by_ap_id(ap_id) do
+ Repo.get_by(User, ap_id: ap_id)
+ end
+
def get_cached_by_ap_id(ap_id) do
key = "ap_id:#{ap_id}"
- Cachex.get!(:user_cache, key, fallback: fn(_) -> Repo.get_by(User, ap_id: ap_id) end)
+ Cachex.get!(:user_cache, key, fallback: fn(_) -> get_by_ap_id(ap_id) end)
end
def get_cached_by_nickname(nickname) do
diff --git a/lib/pleroma/web/ostatus/ostatus.ex b/lib/pleroma/web/ostatus/ostatus.ex
index 3bcc858cf..1ac38bd8a 100644
--- a/lib/pleroma/web/ostatus/ostatus.ex
+++ b/lib/pleroma/web/ostatus/ostatus.ex
@@ -81,11 +81,11 @@ def make_favorite(entry, doc, favorited_activity) do
end
def get_or_try_fetching(entry) do
- Logger.debug("Trying to fetch entry")
+ Logger.debug("Trying to get entry from db")
with id when not is_nil(id) <- string_from_xpath("//activity:object[1]/id", entry),
%Activity{} = activity <- Activity.get_create_activity_by_object_ap_id(id) do
{:ok, activity}
- else _e ->
+ else e ->
Logger.debug("Couldn't get, will try to fetch")
with href when not is_nil(href) <- string_from_xpath("//activity:object[1]/link[@type=\"text/html\"]/@href", entry),
{:ok, [favorited_activity]} <- fetch_activity_from_html_url(href) do
@@ -126,7 +126,7 @@ def get_content(entry) do
base_content = string_from_xpath("//content", entry)
with scope when not is_nil(scope) <- string_from_xpath("//mastodon:scope", entry),
- cw when not is_nil(cw) <- string_from_xpath("//summary", entry) do
+ cw when not is_nil(cw) <- string_from_xpath("/*/summary", entry) do
"#{cw}
#{base_content}"
else _e -> base_content
end
@@ -297,7 +297,7 @@ def fetch_activity_from_html_url(url) do
with {:ok, %{body: body}} <- @httpoison.get(url, [], follow_redirect: true),
{:ok, atom_url} <- get_atom_url(body),
{:ok, %{status_code: code, body: body}} when code in 200..299 <- @httpoison.get(atom_url, [], follow_redirect: true) do
- Logger.debug("Got #{url}, handling...")
+ Logger.debug("Got document from #{url}, handling...")
handle_incoming(body)
else e -> Logger.debug("Couldn't get #{url}: #{inspect(e)}")
end
diff --git a/test/fixtures/cw_retweet.xml b/test/fixtures/cw_retweet.xml
new file mode 100644
index 000000000..c99a569d7
--- /dev/null
+++ b/test/fixtures/cw_retweet.xml
@@ -0,0 +1,68 @@
+
+
+ https://mastodon.social/users/lambadalambda.atom
+ Critical Value
+
+ 2017-04-16T21:47:25Z
+ https://files.mastodon.social/accounts/avatars/000/000/264/original/1429214160519.gif
+
+ https://mastodon.social/users/lambadalambda
+ http://activitystrea.ms/schema/1.0/person
+ https://mastodon.social/users/lambadalambda
+ lambadalambda
+ lambadalambda@mastodon.social
+
+
+
+ lambadalambda
+ Critical Value
+ public
+
+
+
+
+
+
+ tag:mastodon.social,2017-05-11:objectId=5647963:objectType=Status
+ 2017-05-11T10:23:15Z
+ 2017-05-11T10:23:15Z
+ lambadalambda shared a status by Skruyb@mamot.fr
+ http://activitystrea.ms/schema/1.0/activity
+ http://activitystrea.ms/schema/1.0/share
+
+ tag:mamot.fr,2017-05-10:objectId=1294943:objectType=Status
+ 2017-05-10T17:31:44Z
+ 2017-05-10T17:31:45Z
+ New status by Skruyb@mamot.fr
+
+ https://mamot.fr/users/Skruyb
+ http://activitystrea.ms/schema/1.0/person
+ https://mamot.fr/users/Skruyb
+ Skruyb
+ Skruyb@mamot.fr
+ <p>Fr and En.<br>Posts will disappear on a regular basis.</p>
+
+
+
+ Skruyb
+ The 7th Son
+ Fr and En.Posts will disappear on a regular basis.
+ public
+
+ http://activitystrea.ms/schema/1.0/comment
+ http://activitystrea.ms/schema/1.0/post
+ Hey.
+ <p><span class="h-card"><a href="https://mastodon.social/@lambadalambda">@<span>lambadalambda</span></a></span></p><p>Hey!!!</p>
+
+
+ public
+
+
+
+ <p><span class="h-card"><a href="https://mastodon.social/@lambadalambda">@<span>lambadalambda</span></a></span></p><p>Hey!!!</p>
+
+ public
+
+
+
+
diff --git a/test/fixtures/httpoison_mock/https___mamot.fr_users_Skruyb.atom b/test/fixtures/httpoison_mock/https___mamot.fr_users_Skruyb.atom
new file mode 100644
index 000000000..b5f3d923b
--- /dev/null
+++ b/test/fixtures/httpoison_mock/https___mamot.fr_users_Skruyb.atom
@@ -0,0 +1,342 @@
+
+
+ https://mamot.fr/users/Skruyb.atom
+ The 7th Son
+ Fr and En.
+Posts will disappear on a regular basis.
+ 2017-04-28T13:54:23Z
+ https://mamot.fr/system/accounts/avatars/000/026/213/original/d95dbcfc76f77f4c.jpg?1493230984
+
+ https://mamot.fr/users/Skruyb
+ http://activitystrea.ms/schema/1.0/person
+ https://mamot.fr/users/Skruyb
+ Skruyb
+ Skruyb@mamot.fr
+ <p>Fr and En.<br />Posts will disappear on a regular basis.</p>
+
+
+
+ Skruyb
+ The 7th Son
+ Fr and En.
+Posts will disappear on a regular basis.
+ public
+
+
+
+
+
+
+
+ tag:mamot.fr,2017-05-10:objectId=1299665:objectType=Status
+ 2017-05-10T20:06:59Z
+ 2017-05-10T20:06:59Z
+ New status by Skruyb
+ http://activitystrea.ms/schema/1.0/comment
+ http://activitystrea.ms/schema/1.0/post
+ <p><span class="h-card"><a href="https://pouets.ovh/@noName" class="u-url mention">@<span>noName</span></a></span></p><p>Pour comparer faut avoir tester... Ă wait!!! đ</p>
+
+
+ public
+
+
+
+
+
+ tag:mamot.fr,2017-05-10:objectId=1299185:objectType=Status
+ 2017-05-10T19:52:14Z
+ 2017-05-10T19:52:14Z
+ New status by Skruyb
+ http://activitystrea.ms/schema/1.0/comment
+ http://activitystrea.ms/schema/1.0/post
+ <p><span class="h-card"><a href="https://witches.town/@Dhveszak" class="u-url mention">@<span>Dhveszak</span></a></span></p><p>Toi!! Tu vises le ministĂšre de la propagande avoue!!!!!!!</p>
+
+
+ public
+
+
+
+
+
+ tag:mamot.fr,2017-05-10:objectId=1299019:objectType=Status
+ 2017-05-10T19:47:19Z
+ 2017-05-10T19:47:19Z
+ New status by Skruyb
+ http://activitystrea.ms/schema/1.0/note
+ http://activitystrea.ms/schema/1.0/post
+ <p>Facebook s'attaque aux sites internet "trompeurs"</p><p><a href="http://u.afp.com/4W4z" rel="nofollow noopener" target="_blank"><span class="invisible">http://</span><span class="">u.afp.com/4W4z</span><span class="invisible"></span></a></p><p>J'attends de voir que Facebook s'attaque Ă lui mĂȘme... rien qu'Ă lire leurs conditions gĂ©nĂ©rales d'utilisation, le respect de la vie privĂ©e...</p><p>CharitĂ© bien ordonnĂ©e... Parfois l'Ă©goĂŻsme aurait du bon.</p>
+
+ public
+
+
+
+
+ tag:mamot.fr,2017-05-10:objectId=1298889:objectType=Status
+ 2017-05-10T19:43:18Z
+ 2017-05-10T19:43:18Z
+ New status by Skruyb
+ http://activitystrea.ms/schema/1.0/comment
+ http://activitystrea.ms/schema/1.0/post
+ <p><span class="h-card"><a href="https://octodon.social/@Balise" class="u-url mention">@<span>Balise</span></a></span></p><p>Fait comme moi, annonce que tu fais dans le flou artistique et que seuls des esprits éclairés pourront en percevoir la beauté et apprécier. Globalement aprÚs ça, tout le monde trouve les photos cool :-p</p>
+
+
+ public
+
+
+
+
+
+ tag:mamot.fr,2017-05-10:objectId=1298728:objectType=Status
+ 2017-05-10T19:38:39Z
+ 2017-05-10T19:38:39Z
+ New status by Skruyb
+ http://activitystrea.ms/schema/1.0/comment
+ http://activitystrea.ms/schema/1.0/post
+ <p><span class="h-card"><a href="https://mastodon.social/@applecandy" class="u-url mention">@<span>applecandy</span></a></span></p><p>Lucky you!!!</p>
+
+
+ public
+
+
+
+
+
+ tag:mamot.fr,2017-05-10:objectId=1298431:objectType=Status
+ 2017-05-10T19:26:32Z
+ 2017-05-10T19:26:32Z
+ New status by Skruyb
+ http://activitystrea.ms/schema/1.0/note
+ http://activitystrea.ms/schema/1.0/post
+ <p>Est-ce que je suis le seul qui lorsqu'il commence Ă compter les arbres sur le bord de la route n'arrive pas Ă s'arrĂȘter de compter?</p>
+
+ public
+
+
+
+
+ tag:mamot.fr,2017-05-10:objectId=1298224:objectType=Status
+ 2017-05-10T19:18:17Z
+ 2017-05-10T19:18:17Z
+ New status by Skruyb
+ http://activitystrea.ms/schema/1.0/note
+ http://activitystrea.ms/schema/1.0/post
+ <p>Ca y est j'ai une nouvelle passion. Mettre les bouchons qui trainent par terre dans le bons sens avec mon pied đ</p>
+
+ public
+
+
+
+
+ tag:mamot.fr,2017-05-10:objectId=1297450:objectType=Status
+ 2017-05-10T18:53:37Z
+ 2017-05-10T18:53:37Z
+ New status by Skruyb
+ http://activitystrea.ms/schema/1.0/note
+ http://activitystrea.ms/schema/1.0/post
+ <p>Ok. On est capable d'envoyer des mecs dans l'espace, avoir des voitures autonomes, des trucs intelligents de partout mais pas tous les bùtiments accessibles aux personnes à mobilité réduite, les émissions sur le services publics avec une personne faisant la traduction pour les sourds et malentendants de maniÚre systématique...</p><p>J'ai du louper un truc dans l'ordre des priorités Oo</p>
+
+ public
+
+
+
+
+ tag:mamot.fr,2017-05-10:objectId=1297292:objectType=Status
+ 2017-05-10T18:48:17Z
+ 2017-05-10T18:48:17Z
+ New status by Skruyb
+ http://activitystrea.ms/schema/1.0/note
+ http://activitystrea.ms/schema/1.0/post
+ <p>J'ai comme envie de faire un truc mais je ne sais pas quoi mais pourtant c'est comme si je ressentais l'idĂ©e dans ma tĂȘte mais c'est pas clair...</p><p>Fuck!!! J'vais aller draguer Josiane Ă la compta ça va me changer les idĂ©es!!!</p>
+
+ public
+
+
+
+
+ tag:mamot.fr,2017-05-10:objectId=1296598:objectType=Status
+ 2017-05-10T18:25:11Z
+ 2017-05-10T18:25:11Z
+ New status by Skruyb
+ http://activitystrea.ms/schema/1.0/comment
+ http://activitystrea.ms/schema/1.0/post
+ <p><span class="h-card"><a href="https://mamot.fr/@Smeablog" class="u-url mention">@<span>Smeablog</span></a></span></p><p>Pas faux MDR!!!!</p>
+
+
+ public
+
+
+
+
+
+ tag:mamot.fr,2017-05-10:objectId=1296571:objectType=Status
+ 2017-05-10T18:24:13Z
+ 2017-05-10T18:24:13Z
+ New status by Skruyb
+ http://activitystrea.ms/schema/1.0/comment
+ http://activitystrea.ms/schema/1.0/post
+ <p><span class="h-card"><a href="https://mamot.fr/@Smeablog" class="u-url mention">@<span>Smeablog</span></a></span></p><p>Ca ne change pas la finalitĂ© malheureusement, ça ne m'ouvre pas ce Ă quoi je veux accĂ©der đ</p>
+
+
+ public
+
+
+
+
+
+ tag:mamot.fr,2017-05-10:objectId=1296475:objectType=Status
+ 2017-05-10T18:20:50Z
+ 2017-05-10T18:20:50Z
+ New status by Skruyb
+ http://activitystrea.ms/schema/1.0/note
+ http://activitystrea.ms/schema/1.0/post
+ <p>Arrrgghhhhhhh!!!!</p><p>Quand t'es sur le point de cliquer sur un lien dans le fil public global et que BOOM ça se met Ă jour... J'ose mĂȘme pas imaginer combien j'ai ouvert de pages web sans le vouloir!!!</p>
+
+ public
+
+
+
+
+ tag:mamot.fr,2017-05-10:objectId=1296426:objectType=Status
+ 2017-05-10T18:19:17Z
+ 2017-05-10T18:19:17Z
+ Skruyb shared a status by Isaluini@mastodon.social
+ http://activitystrea.ms/schema/1.0/activity
+ http://activitystrea.ms/schema/1.0/share
+
+ tag:mastodon.social,2017-05-10:objectId=5587049:objectType=Status
+ 2017-05-10T18:18:59Z
+ 2017-05-10T18:19:00Z
+ New status by Isaluini@mastodon.social
+
+ https://mastodon.social/users/Isaluini
+ http://activitystrea.ms/schema/1.0/person
+ https://mastodon.social/users/Isaluini
+ Isaluini
+ Isaluini@mastodon.social
+ <p>Adicciones: Escribir, diseñar, cine, cafĂ©, humor negro, mĂșsica y dibujar. | Jedi. Bueno, no. AlgĂșn dĂa (?) | Gratitude.</p>
+
+
+
+ Isaluini
+ Isa
+ Adicciones: Escribir, diseñar, cine, cafĂ©, humor negro, mĂșsica y dibujar. | Jedi. Bueno, no. AlgĂșn dĂa (?) | Gratitude.
+ public
+
+ http://activitystrea.ms/schema/1.0/note
+ http://activitystrea.ms/schema/1.0/post
+ <p>â« <br><a href="https://www.youtube.com/watch?v=pT68FS3YbQ4"><span class="invisible">https://www.</span><span class="ellipsis">youtube.com/watch?v=pT68FS3YbQ</span><span class="invisible">4</span></a></p>
+
+ public
+
+
+ <p>â« <br><a href="https://www.youtube.com/watch?v=pT68FS3YbQ4"><span class="invisible">https://www.</span><span class="ellipsis">youtube.com/watch?v=pT68FS3YbQ</span><span class="invisible">4</span></a></p>
+
+ public
+
+
+
+
+ tag:mamot.fr,2017-05-10:objectId=1295893:objectType=Status
+ 2017-05-10T18:01:51Z
+ 2017-05-10T18:01:51Z
+ New status by Skruyb
+ http://activitystrea.ms/schema/1.0/comment
+ http://activitystrea.ms/schema/1.0/post
+ <p><span class="h-card"><a href="https://mamot.fr/@Chat2Gouttieres" class="u-url mention">@<span>Chat2Gouttieres</span></a></span></p><p>Ah bah aprĂšs faut savoir mettre Ă profit ce savoir ^^</p>
+
+
+ public
+
+
+
+
+
+ tag:mamot.fr,2017-05-10:objectId=1295815:objectType=Status
+ 2017-05-10T18:00:02Z
+ 2017-05-10T18:00:02Z
+ New status by Skruyb
+ http://activitystrea.ms/schema/1.0/comment
+ http://activitystrea.ms/schema/1.0/post
+ <p><span class="h-card"><a href="https://mamot.fr/@Chat2Gouttieres" class="u-url mention">@<span>Chat2Gouttieres</span></a></span></p><p>Exactement. On a les jeux mais pas le pain encore.</p><p>Finalement on a rien inventé :-p</p>
+
+
+ public
+
+
+
+
+
+ tag:mamot.fr,2017-05-10:objectId=1295778:objectType=Status
+ 2017-05-10T17:58:52Z
+ 2017-05-10T17:58:52Z
+ New status by Skruyb
+ http://activitystrea.ms/schema/1.0/comment
+ http://activitystrea.ms/schema/1.0/post
+ <p><span class="h-card"><a href="https://mamot.fr/@Chat2Gouttieres" class="u-url mention">@<span>Chat2Gouttieres</span></a></span></p><p>C'est ça visiblement dans notre société dite moderne... "Créer l'illusion que" Oo.</p>
+
+
+ public
+
+
+
+
+
+ tag:mamot.fr,2017-05-10:objectId=1294943:objectType=Status
+ 2017-05-10T17:31:44Z
+ 2017-05-10T17:31:44Z
+ New status by Skruyb
+ http://activitystrea.ms/schema/1.0/comment
+ http://activitystrea.ms/schema/1.0/post
+ Hey.
+ <p><span class="h-card"><a href="https://mastodon.social/@lambadalambda" class="u-url mention">@<span>lambadalambda</span></a></span></p><p>Hey!!!</p>
+
+
+ public
+
+
+
+
+
+ tag:mamot.fr,2017-05-10:objectId=1294914:objectType=Status
+ 2017-05-10T17:30:40Z
+ 2017-05-10T17:30:40Z
+ New status by Skruyb
+ http://activitystrea.ms/schema/1.0/comment
+ http://activitystrea.ms/schema/1.0/post
+ <p><span class="h-card"><a href="https://mamot.fr/@EloClemTiti" class="u-url mention">@<span>EloClemTiti</span></a></span></p><p>J'ai souvent cette impression en effet đ</p>
+
+
+ public
+
+
+
+
+
+ tag:mamot.fr,2017-05-10:objectId=1294148:objectType=Status
+ 2017-05-10T17:02:01Z
+ 2017-05-10T17:02:01Z
+ New status by Skruyb
+ http://activitystrea.ms/schema/1.0/note
+ http://activitystrea.ms/schema/1.0/post
+ <p>Les gars, les boss veulent voir de l'avancement!! Une idée?</p><p>On fait comme d'habitude. On divise nos tùches en 25.000 tùches unitaires, on fout du vert au maximum et on crée l'illusion que ça a bien avancé!</p><p>Deal!!</p><p>Bob, tu choisis quel vert on utilise<br />Alice, t'es en charge de la typo<br />Moi, je m'occupe qu'on prend bien le dernier template ppt fournit par la comm interne.</p><p>Des winners qu'on est!!!! Des WI-NNERS!!!</p>
+
+ public
+
+
+
+
+ tag:mamot.fr,2017-05-10:objectId=1293995:objectType=Status
+ 2017-05-10T16:57:53Z
+ 2017-05-10T16:57:53Z
+ New status by Skruyb
+ http://activitystrea.ms/schema/1.0/comment
+ http://activitystrea.ms/schema/1.0/post
+ <p><span class="h-card"><a href="https://mastodon.social/@SauceHair" class="u-url mention">@<span>SauceHair</span></a></span></p><p>Cool!!</p><p>Bon courage.</p>
+
+
+ public
+
+
+
+
+
diff --git a/test/fixtures/httpoison_mock/skruyb@mamot.fr.atom b/test/fixtures/httpoison_mock/skruyb@mamot.fr.atom
new file mode 100644
index 000000000..1bbbc29f5
--- /dev/null
+++ b/test/fixtures/httpoison_mock/skruyb@mamot.fr.atom
@@ -0,0 +1,11 @@
+
+
+ acct:Skruyb@mamot.fr
+ https://mamot.fr/@Skruyb
+ https://mamot.fr/users/Skruyb
+
+
+
+
+
+
diff --git a/test/support/httpoison_mock.ex b/test/support/httpoison_mock.ex
index 0eff336ab..420d42a0d 100644
--- a/test/support/httpoison_mock.ex
+++ b/test/support/httpoison_mock.ex
@@ -135,6 +135,20 @@ def get("https://pawoo.net/users/pekorino.atom", _, _) do
}}
end
+ def get("https://mamot.fr/.well-known/webfinger", [Accept: "application/xrd+xml"], [params: [resource: "https://mamot.fr/users/Skruyb"]]) do
+ {:ok, %Response{
+ status_code: 200,
+ body: File.read!("test/fixtures/httpoison_mock/skruyb@mamot.fr.atom")
+ }}
+ end
+
+ def get("https://mamot.fr/users/Skruyb.atom", _, _) do
+ {:ok, %Response{
+ status_code: 200,
+ body: File.read!("test/fixtures/httpoison_mock/https___mamot.fr_users_Skruyb.atom")
+ }}
+ end
+
def get(url, body, headers) do
{:error, "Not implemented the mock response for get #{inspect(url)}, #{inspect(body)}, #{inspect(headers)}"}
end
diff --git a/test/web/ostatus/ostatus_test.exs b/test/web/ostatus/ostatus_test.exs
index e8f81aae6..e38a195d9 100644
--- a/test/web/ostatus/ostatus_test.exs
+++ b/test/web/ostatus/ostatus_test.exs
@@ -72,6 +72,13 @@ test "handle incoming notes - Mastodon, with CW" do
assert String.contains?(activity.data["object"]["content"], "technologic")
end
+ test "handle incoming retweets - Mastodon, with CW" do
+ incoming = File.read!("test/fixtures/cw_retweet.xml")
+ {:ok, [[activity, retweeted_activity]]} = OStatus.handle_incoming(incoming)
+
+ assert String.contains?(retweeted_activity.data["object"]["content"], "Hey.")
+ end
+
test "handle incoming notes - GS, subscription, reply" do
incoming = File.read!("test/fixtures/ostatus_incoming_reply.xml")
{:ok, [activity]} = OStatus.handle_incoming(incoming)
@@ -99,6 +106,7 @@ test "handle incoming retweets - GS, subscription" do
refute retweeted_activity.local
assert retweeted_activity.data["object"]["announcement_count"] == 1
assert String.contains?(retweeted_activity.data["object"]["content"], "mastodon")
+ refute String.contains?(retweeted_activity.data["object"]["content"], "Test account")
end
test "handle incoming retweets - GS, subscription - local message" do
@@ -138,6 +146,7 @@ test "handle incoming retweets - Mastodon, salmon" do
assert retweeted_activity.data["type"] == "Create"
assert retweeted_activity.data["actor"] == "https://pleroma.soykaf.com/users/lain"
refute retweeted_activity.local
+ refute String.contains?(retweeted_activity.data["object"]["content"], "Test account")
end
test "handle incoming favorites - GS, websub" do
@@ -192,8 +201,8 @@ test "handle incoming follows" do
assert activity.data["object"] == "https://pawoo.net/users/pekorino"
refute activity.local
- follower = User.get_cached_by_ap_id(activity.data["actor"])
- followed = User.get_cached_by_ap_id(activity.data["object"])
+ follower = User.get_by_ap_id(activity.data["actor"])
+ followed = User.get_by_ap_id(activity.data["object"])
assert User.following?(follower, followed)
end