From: Roger Braun Date: Fri, 5 May 2017 14:07:44 +0000 (+0200) Subject: Handle incoming favorites, fetch potentially missing messages. X-Git-Url: https://git.squeep.com/?a=commitdiff_plain;h=fa2610c7959500c18b64d70828123a817de78864;p=akkoma Handle incoming favorites, fetch potentially missing messages. --- diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index d7b490088..82aed7ce4 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -41,7 +41,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do end end - def like(%User{ap_id: ap_id} = user, %Object{data: %{"id" => id}} = object) do + def like(%User{ap_id: ap_id} = user, %Object{data: %{"id" => id}} = object, local \\ true) do cond do # There's already a like here, so return the original activity. ap_id in (object.data["likes"] || []) -> @@ -59,7 +59,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do "context" => object.data["context"] } - {:ok, activity} = insert(data) + {:ok, activity} = insert(data, local) likes = [ap_id | (object.data["likes"] || [])] |> Enum.uniq diff --git a/lib/pleroma/web/ostatus/ostatus.ex b/lib/pleroma/web/ostatus/ostatus.ex index 3bed5a5d9..0a4361393 100644 --- a/lib/pleroma/web/ostatus/ostatus.ex +++ b/lib/pleroma/web/ostatus/ostatus.ex @@ -1,4 +1,6 @@ defmodule Pleroma.Web.OStatus do + @httpoison Application.get_env(:pleroma, :httpoison) + import Ecto.Query import Pleroma.Web.XML require Logger @@ -30,6 +32,8 @@ defmodule Pleroma.Web.OStatus do case verb do 'http://activitystrea.ms/schema/1.0/share' -> with {:ok, activity, retweeted_activity} <- handle_share(entry, doc), do: [activity, retweeted_activity] + 'http://activitystrea.ms/schema/1.0/favorite' -> + with {:ok, activity, favorited_activity} <- handle_favorite(entry, doc), do: [activity, favorited_activity] _ -> case object_type do 'http://activitystrea.ms/schema/1.0/note' -> @@ -63,6 +67,24 @@ defmodule Pleroma.Web.OStatus do end end + def make_favorite(_entry, doc, favorited_activity) do + with {:ok, actor} <- find_make_or_update_user(doc), + %Object{} = object <- Object.get_cached_by_ap_id(favorited_activity.data["object"]["id"]), + {:ok, activity, _object} = ActivityPub.like(actor, object, false) do + {:ok, activity} + end + end + + def handle_favorite(entry, doc) do + 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), + {:ok, activity} <- make_favorite(entry, doc, favorited_activity) do + {:ok, activity, favorited_activity} + else + e -> {:error, e} + end + end + def get_attachments(entry) do :xmerl_xpath.string('/entry/link[@rel="enclosure"]', entry) |> Enum.map(fn (enclosure) -> @@ -210,4 +232,30 @@ defmodule Pleroma.Web.OStatus do {:error, e} end end + + # Regex-based 'parsing' so we don't have to pull in a full html parser + # It's a hack anyway. Maybe revisit this in the future + @mastodon_regex ~r// + @gs_regex ~r// + def get_atom_url(body) do + cond do + Regex.match?(@mastodon_regex, body) -> + [[_, match]] = Regex.scan(@mastodon_regex, body) + {:ok, match} + Regex.match?(@gs_regex, body) -> + [[_, match]] = Regex.scan(@gs_regex, body) + {:ok, match} + true -> + Logger.debug(fn -> "Couldn't find atom link in #{inspect(body)}" end) + {:error, "Couldn't find the atom link"} + end + end + + def fetch_activity_from_html_url(url) do + with {:ok, %{body: body}} <- @httpoison.get(url), + {:ok, atom_url} <- get_atom_url(body), + {:ok, %{status_code: code, body: body}} when code in 200..299 <- @httpoison.get(atom_url) do + handle_incoming(body) + end + end end diff --git a/test/fixtures/favorite.xml b/test/fixtures/favorite.xml new file mode 100644 index 000000000..c32b4a403 --- /dev/null +++ b/test/fixtures/favorite.xml @@ -0,0 +1,65 @@ + + + GNU social + https://social.heldscal.la/api/statuses/user_timeline/23211.atom + lambadalambda timeline + Updates from lambadalambda on social.heldscal.la! + https://social.heldscal.la/avatar/23211-96-20170416114255.jpeg + 2017-05-05T09:12:53+00:00 + + http://activitystrea.ms/schema/1.0/person + https://social.heldscal.la/user/23211 + lambadalambda + Call me Deacon Blues. + + + + + + lambadalambda + Constance Variable + Call me Deacon Blues. + + Berlin + + + homepage + https://heldscal.la + true + + + + + + + + + + + + + tag:social.heldscal.la,2017-05-05:fave:23211:comment:2061643:2017-05-05T09:12:50+00:00 + Favorite + lambadalambda favorited something by moonman: @<a href="https://shitposter.club/user/9655" class="h-card mention" title="Solidarity for Pigs">neimzr4luzerz</a> @<a href="https://gs.smuglo.li/user/2326" class="h-card mention" title="Dolus_McHonest">dolus</a> childhood poring over Strong's concordance and a koine Greek dictionary, fast forward to 2017 and some fuckstick who translates japanese jackoff material tells me you just need to make it sound right in English + + http://activitystrea.ms/schema/1.0/favorite + 2017-05-05T09:12:50+00:00 + 2017-05-05T09:12:50+00:00 + + http://activitystrea.ms/schema/1.0/comment + tag:shitposter.club,2017-05-05:noticeId=2827873:objectType=comment + New comment by moonman + @<a href="https://shitposter.club/user/9655" class="h-card mention" title="Solidarity for Pigs">neimzr4luzerz</a> @<a href="https://gs.smuglo.li/user/2326" class="h-card mention" title="Dolus_McHonest">dolus</a> childhood poring over Strong's concordance and a koine Greek dictionary, fast forward to 2017 and some fuckstick who translates japanese jackoff material tells me you just need to make it sound right in English + + + + + + + tag:social.heldscal.la,2017-05-05:objectType=thread:nonce=55ead90125cd4bd4 + + + + + + diff --git a/test/fixtures/httpoison_mock/https___shitposter.club_api_statuses_show_2827873.atom.xml b/test/fixtures/httpoison_mock/https___shitposter.club_api_statuses_show_2827873.atom.xml new file mode 100644 index 000000000..26fdebb49 --- /dev/null +++ b/test/fixtures/httpoison_mock/https___shitposter.club_api_statuses_show_2827873.atom.xml @@ -0,0 +1,54 @@ + + http://activitystrea.ms/schema/1.0/comment + tag:shitposter.club,2017-05-05:noticeId=2827873:objectType=comment + New comment by moonman + @<a href="https://shitposter.club/user/9655" class="h-card mention" title="Solidarity for Pigs">neimzr4luzerz</a> @<a href="https://gs.smuglo.li/user/2326" class="h-card mention" title="Dolus_McHonest">dolus</a> childhood poring over Strong's concordance and a koine Greek dictionary, fast forward to 2017 and some fuckstick who translates japanese jackoff material tells me you just need to make it sound right in English + + + http://activitystrea.ms/schema/1.0/post + 2017-05-05T08:51:48+00:00 + 2017-05-05T08:51:48+00:00 + + http://activitystrea.ms/schema/1.0/person + https://shitposter.club/user/1 + moonman + EMAIL:shitposterclub@gmail.com XMPP: moon@talk.shitposter.club Matrix Ed25519 fingerprint: 2HuDUTEz3iFN5N3xl6PYp9xZW/EWhgbbt78SrFy4w8o + + + + + + moonman + Generic Enemy + EMAIL:shitposterclub@gmail.com XMPP: moon@talk.shitposter.club Matrix Ed25519 fingerprint: 2HuDUTEz3iFN5N3xl6PYp9xZW/EWhgbbt78SrFy4w8o + + The Moon + + + homepage + https://shitposter.club/moonman + true + + + + + + + + tag:shitposter.club,2017-05-05:objectType=thread:nonce=3c16e9c2681f6d26 + + + + + https://shitposter.club/api/statuses/user_timeline/1.atom + Generic Enemy + + + + https://shitposter.club/avatar/1-96-20170503024316.jpeg + 2017-05-05T11:43:58+00:00 + + + + + diff --git a/test/fixtures/httpoison_mock/https___shitposter.club_api_statuses_user_timeline_1.atom.xml b/test/fixtures/httpoison_mock/https___shitposter.club_api_statuses_user_timeline_1.atom.xml new file mode 100644 index 000000000..31df7c2a6 --- /dev/null +++ b/test/fixtures/httpoison_mock/https___shitposter.club_api_statuses_user_timeline_1.atom.xml @@ -0,0 +1,454 @@ + + + GNU social + https://shitposter.club/api/statuses/user_timeline/1.atom + moonman timeline + Updates from moonman on Shitposter Club! + https://shitposter.club/avatar/1-96-20170503024316.jpeg + 2017-05-05T13:24:09+00:00 + + http://activitystrea.ms/schema/1.0/person + https://shitposter.club/user/1 + moonman + EMAIL:shitposterclub@gmail.com XMPP: moon@talk.shitposter.club Matrix Ed25519 fingerprint: 2HuDUTEz3iFN5N3xl6PYp9xZW/EWhgbbt78SrFy4w8o + + + + + + moonman + Generic Enemy + EMAIL:shitposterclub@gmail.com XMPP: moon@talk.shitposter.club Matrix Ed25519 fingerprint: 2HuDUTEz3iFN5N3xl6PYp9xZW/EWhgbbt78SrFy4w8o + + The Moon + + + homepage + https://shitposter.club/moonman + true + + + + + + + + + + + + + + tag:shitposter.club,2017-05-05:subscription:1:person:23190:2017-05-05T11:43:58+00:00 + Generic Enemy (moonman)'s status on Friday, 05-May-2017 11:43:58 UTC + <a href="https://shitposter.club/moonman">Generic Enemy</a> started following <a href="https://noagendasocial.com/@Ma5on">Mason</a>. + + http://activitystrea.ms/schema/1.0/follow + 2017-05-05T11:43:58+00:00 + 2017-05-05T11:43:58+00:00 + + http://activitystrea.ms/schema/1.0/person + https://noagendasocial.com/users/Ma5on + Mason + + + + + + ma5on + Mason + + + tag:shitposter.club,2017-05-05:objectType=thread:nonce=abffa9c14a054d3b + + + + + + + tag:shitposter.club,2017-05-05:subscription:1:person:14357:2017-05-05T10:29:03+00:00 + Generic Enemy (moonman)'s status on Friday, 05-May-2017 10:29:03 UTC + <a href="https://shitposter.club/moonman">Generic Enemy</a> started following <a href="https://mastodon.cloud/@ohyran">Jens Reuterberg</a>. + + http://activitystrea.ms/schema/1.0/follow + 2017-05-05T10:29:03+00:00 + 2017-05-05T10:29:03+00:00 + + http://activitystrea.ms/schema/1.0/person + https://mastodon.cloud/users/ohyran + Jens Reuterberg + RPG-nerd, illustrator, Open Source enthusiast, KDE dude, designer and gay lefty. Might be a cliché - but we will soon find out! + + + + + + ohyran + Jens Reuterberg + RPG-nerd, illustrator, Open Source enthusiast, KDE dude, designer and gay lefty. Might be a cliché - but we will soon find out! + + + tag:shitposter.club,2017-05-05:objectType=thread:nonce=937151d4825a85bf + + + + + + + http://activitystrea.ms/schema/1.0/note + tag:shitposter.club,2017-05-05:noticeId=2828637:objectType=note + New note by moonman + basicall i would just rather have ppl say &quot;i like x and y&quot; than &quot;i'm a nerd&quot; the term can be retired. + + + http://activitystrea.ms/schema/1.0/post + 2017-05-05T10:24:54+00:00 + 2017-05-05T10:24:54+00:00 + + tag:shitposter.club,2017-05-05:objectType=thread:nonce=65992b0b9b5e6931 + + + + + + + http://activitystrea.ms/schema/1.0/comment + tag:shitposter.club,2017-05-05:noticeId=2828579:objectType=comment + New comment by moonman + @<a href="https://gs.smuglo.li/user/35497" class="h-card mention" title="Bokuro Bokusawa">boco</a> to be honest i've turned right around and been cruel to other people, i said i'd never do it but it happens again eventually. + + + http://activitystrea.ms/schema/1.0/post + 2017-05-05T10:20:33+00:00 + 2017-05-05T10:20:33+00:00 + + + + tag:shitposter.club,2017-05-05:objectType=thread:nonce=c997fc73d7f8a8f0 + + + + + + + + http://activitystrea.ms/schema/1.0/comment + tag:shitposter.club,2017-05-05:noticeId=2828554:objectType=comment + New comment by moonman + @<a href="https://mastodon.cloud/users/ohyran" class="h-card mention" title="Jens Reuterberg">ohyran</a> i won't ever get over bullying but i agree otherwise. i don't go to comic shops too often these days but i got dragged to one last year and the sheer diversity of people enjoying comics now compared to years ago was striking and it pleased me. and i noticed a couple years ago because of youtube i find things i truly enjoy watching, like in-depth videos about electronic parts, didn't exist 20 years ago. it's pretty great. + + + http://activitystrea.ms/schema/1.0/post + 2017-05-05T10:18:10+00:00 + 2017-05-05T10:18:10+00:00 + + + + tag:shitposter.club,2017-05-05:objectType=thread:nonce=efae3a23b6e05767 + + + + + + + + tag:shitposter.club,2017-05-05:fave:1:comment:2828502:2017-05-05T10:12:52+00:00 + Favorite + moonman favorited something by ohyran: <p><span class="h-card"><a href="https://shitposter.club/moonman" class="u-url mention">@<span>moonman</span></a></span> fair enough - that distinction makes it clearer...</p><p>On the other hand - those of us who did "pay the price" of being nerdy little kids in the 80's and 90's should strive to get past it anyway (mental health wise not "just get over it") and see the "nerd culture" thing as a blessing of sorts. We are in the optimal spot to do it. (not saying that that is something easy btw just that NOW is the best of time to start talking about it)</p> + + http://activitystrea.ms/schema/1.0/favorite + 2017-05-05T10:12:52+00:00 + 2017-05-05T10:12:52+00:00 + + http://activitystrea.ms/schema/1.0/comment + tag:mastodon.cloud,2017-05-05:objectId=6334570:objectType=Status + New comment by ohyran + <p><span class="h-card"><a href="https://shitposter.club/moonman" class="u-url mention">@<span>moonman</span></a></span> fair enough - that distinction makes it clearer...</p><p>On the other hand - those of us who did "pay the price" of being nerdy little kids in the 80's and 90's should strive to get past it anyway (mental health wise not "just get over it") and see the "nerd culture" thing as a blessing of sorts. We are in the optimal spot to do it. (not saying that that is something easy btw just that NOW is the best of time to start talking about it)</p> + + + + + + + tag:shitposter.club,2017-05-05:objectType=thread:nonce=efae3a23b6e05767 + + + + + + + http://activitystrea.ms/schema/1.0/note + tag:shitposter.club,2017-05-05:noticeId=2828496:objectType=note + New note by moonman + things are better now, a lot less kids in america get beaten up and called a fag. still too many. + + + http://activitystrea.ms/schema/1.0/post + 2017-05-05T10:11:31+00:00 + 2017-05-05T10:11:31+00:00 + + tag:shitposter.club,2017-05-05:objectType=thread:nonce=c997fc73d7f8a8f0 + + + + + + + http://activitystrea.ms/schema/1.0/comment + tag:shitposter.club,2017-05-05:noticeId=2828457:objectType=comment + New comment by moonman + @<a href="https://shitposter.club/user/21787" class="h-card mention" title="Yukari">cutscenes</a> @<a href="https://gs.smuglo.li/user/28250" class="h-card mention" title="Bricky">thatbrickster</a> @<a href="https://gs.smuglo.li/user/35497" class="h-card mention" title="Bokuro Bokusawa">boco</a> i never understood this because nerds had pocket protectors, which was a draftsman engineer thing and therefore smart, while geeks were people in carnivals who bit heads off small animals. + + + http://activitystrea.ms/schema/1.0/post + 2017-05-05T10:07:57+00:00 + 2017-05-05T10:07:57+00:00 + + + + tag:shitposter.club,2017-05-05:objectType=thread:nonce=efae3a23b6e05767 + + + + + + + + + + http://activitystrea.ms/schema/1.0/comment + tag:shitposter.club,2017-05-05:noticeId=2828435:objectType=comment + New comment by moonman + @<a href="https://mastodon.cloud/users/ohyran" class="h-card mention" title="Jens Reuterberg">ohyran</a> since i didn't specify i'm talking about people subjected to physical and psychological abuse and not people that are just mad that more people like comic books now. + + + http://activitystrea.ms/schema/1.0/post + 2017-05-05T10:05:07+00:00 + 2017-05-05T10:05:07+00:00 + + + + tag:shitposter.club,2017-05-05:objectType=thread:nonce=efae3a23b6e05767 + + + + + + + + http://activitystrea.ms/schema/1.0/note + tag:shitposter.club,2017-05-05:noticeId=2828326:objectType=note + New note by moonman + if you were a &quot;nerd&quot; before, like, 2001 you have permanent excuse to hate this kind of shit.   <a href="https://shitposter.club/file/b79fa5644be0d6f22679136e67b7bf45c9c4a74a55c32dd2d0cf15de4ddd5be5.gif" title="https://shitposter.club/file/b79fa5644be0d6f22679136e67b7bf45c9c4a74a55c32dd2d0cf15de4ddd5be5.gif" class="attachment" id="attachment-662105" rel="nofollow external">https://shitposter.club/attachment/662105</a> + + + http://activitystrea.ms/schema/1.0/post + 2017-05-05T09:47:42+00:00 + 2017-05-05T09:47:42+00:00 + + tag:shitposter.club,2017-05-05:objectType=thread:nonce=efae3a23b6e05767 + + + + + + + + http://activitystrea.ms/schema/1.0/note + tag:shitposter.club,2017-05-05:noticeId=2828250:objectType=note + New note by moonman + <a href="https://shitposter.club/file/1283e2d4dd8f96b8eeb5d9a16b318e210868aa11386cf0d593891e4c75c9126e.gif" title="https://shitposter.club/file/1283e2d4dd8f96b8eeb5d9a16b318e210868aa11386cf0d593891e4c75c9126e.gif" class="attachment" id="attachment-662098" rel="nofollow external">https://shitposter.club/attachment/662098</a> + + + http://activitystrea.ms/schema/1.0/post + 2017-05-05T09:39:06+00:00 + 2017-05-05T09:39:06+00:00 + + tag:shitposter.club,2017-05-05:objectType=thread:nonce=ea8ffae90546f0ab + + + + + + + + tag:shitposter.club,2017-05-05:fave:1:comment:2828161:2017-05-05T09:28:19+00:00 + Favorite + moonman favorited something by kro: @<a href="https://shitposter.club/user/1" class="h-card u-url p-nickname mention" title="Generic Enemy">moonman</a> Till Brooklyn? + + http://activitystrea.ms/schema/1.0/favorite + 2017-05-05T09:28:19+00:00 + 2017-05-05T09:28:19+00:00 + + http://activitystrea.ms/schema/1.0/comment + tag:gs.smuglo.li,2017-05-05:noticeId=2188587:objectType=comment + New comment by kro + @<a href="https://shitposter.club/user/1" class="h-card u-url p-nickname mention" title="Generic Enemy">moonman</a> Till Brooklyn? + + + + + + + tag:shitposter.club,2017-05-05:objectType=thread:nonce=d7aa6b5b057ca555 + + + + + + + tag:shitposter.club,2017-05-05:fave:1:comment:2828125:2017-05-05T09:24:56+00:00 + Favorite + moonman favorited something by hardbass2k8: this has obviously interesting implications in various places, for example:<br /> the nationalism of the nazis might not have been real, who would have thought?<br /> socialism is usually promoted to implementation by real douchebags!<br /> your local social justice people might want diversity but they don't want you, m/19, white, why?<br /> amateur soccer club, they want to be the best in the amateur league but actually they just get drunk after training and are 50% overweight.<br /> This is because humans are not capable of telepathy, so if you join a group it doesn't magically align every little bit of your being with the declared group goals.<br /> <br /> Even though you see unmanned group beliefs flying around from time to time, generally groups are created from a bunch of people. they are not a container for people, they are the people inside them.<br /> <br /> so if you see a group that appears to be cool don't think of it as cool because its goals are cool but because its members are cool. if they aren't, tough cookies. don't be the retard and end up on the camp watchtower. + + http://activitystrea.ms/schema/1.0/favorite + 2017-05-05T09:24:56+00:00 + 2017-05-05T09:24:56+00:00 + + http://activitystrea.ms/schema/1.0/comment + tag:shitposter.club,2017-05-05:noticeId=2828125:objectType=comment + New comment by hardbass2k8 + this has obviously interesting implications in various places, for example:<br /> the nationalism of the nazis might not have been real, who would have thought?<br /> socialism is usually promoted to implementation by real douchebags!<br /> your local social justice people might want diversity but they don't want you, m/19, white, why?<br /> amateur soccer club, they want to be the best in the amateur league but actually they just get drunk after training and are 50% overweight.<br /> This is because humans are not capable of telepathy, so if you join a group it doesn't magically align every little bit of your being with the declared group goals.<br /> <br /> Even though you see unmanned group beliefs flying around from time to time, generally groups are created from a bunch of people. they are not a container for people, they are the people inside them.<br /> <br /> so if you see a group that appears to be cool don't think of it as cool because its goals are cool but because its members are cool. if they aren't, tough cookies. don't be the retard and end up on the camp watchtower. + + + + + + + tag:shitposter.club,2017-05-05:objectType=thread:nonce=51b227fe92f6babf + + + + + + + http://activitystrea.ms/schema/1.0/note + tag:shitposter.club,2017-05-05:noticeId=2828128:objectType=note + New note by moonman + In a valid remake of They live, signs would say REBEL, and DON'T GET MARRIED AND HAVE KIDS + + + http://activitystrea.ms/schema/1.0/post + 2017-05-05T09:24:23+00:00 + 2017-05-05T09:24:23+00:00 + + tag:shitposter.club,2017-05-05:objectType=thread:nonce=b74397fa766b82c9 + + + + + + + http://activitystrea.ms/schema/1.0/note + tag:shitposter.club,2017-05-05:noticeId=2828104:objectType=note + New note by moonman + <a href="https://shitposter.club/file/4d34178bde99599f31a28928e1666fbd58448d8a22e94ed82222496e4a45cb07.gif" title="https://shitposter.club/file/4d34178bde99599f31a28928e1666fbd58448d8a22e94ed82222496e4a45cb07.gif" class="attachment" id="attachment-662049" rel="nofollow external">https://shitposter.club/attachment/662049</a> + + + http://activitystrea.ms/schema/1.0/post + 2017-05-05T09:21:01+00:00 + 2017-05-05T09:21:01+00:00 + + tag:shitposter.club,2017-05-05:objectType=thread:nonce=d7aa6b5b057ca555 + + + + + + + + http://activitystrea.ms/schema/1.0/note + tag:shitposter.club,2017-05-05:noticeId=2828102:objectType=note + New note by moonman + when ppl find out i haven't always been serious  <a href="https://shitposter.club/file/5859fa95875342cc65dba0d852f726db158ce28198c326d5f13d9de7c0d2c449.gif" title="https://shitposter.club/file/5859fa95875342cc65dba0d852f726db158ce28198c326d5f13d9de7c0d2c449.gif" class="attachment" id="attachment-662053" rel="nofollow external">https://shitposter.club/attachment/662053</a> + + + http://activitystrea.ms/schema/1.0/post + 2017-05-05T09:20:45+00:00 + 2017-05-05T09:20:45+00:00 + + tag:shitposter.club,2017-05-05:objectType=thread:nonce=0a025ac5a570b4ec + + + + + + + + http://activitystrea.ms/schema/1.0/comment + tag:shitposter.club,2017-05-05:noticeId=2828086:objectType=comment + New comment by moonman + @<a href="https://shitposter.club/user/9655" class="h-card mention" title="Solidarity for Pigs">neimzr4luzerz</a> @<a href="https://gs.smuglo.li/user/2326" class="h-card mention" title="Dolus_McHonest">dolus</a> @<a href="https://gs.smuglo.li/user/35497" class="h-card mention" title="Bokuro Bokusawa">boco</a> you are being too serious lol + + + http://activitystrea.ms/schema/1.0/post + 2017-05-05T09:17:19+00:00 + 2017-05-05T09:17:19+00:00 + + + + tag:shitposter.club,2017-05-05:objectType=thread:nonce=3c16e9c2681f6d26 + + + + + + + + + + http://activitystrea.ms/schema/1.0/note + tag:shitposter.club,2017-05-05:noticeId=2828085:objectType=note + New note by moonman + shitposter dot club  <a href="https://shitposter.club/file/9b084c7210b16abbf4d28594b924a07ef4a2a06f89d901a4c42fb1e243291263.gif" title="https://shitposter.club/file/9b084c7210b16abbf4d28594b924a07ef4a2a06f89d901a4c42fb1e243291263.gif" class="attachment" id="attachment-662047" rel="nofollow external">https://shitposter.club/attachment/662047</a> + + + http://activitystrea.ms/schema/1.0/post + 2017-05-05T09:16:50+00:00 + 2017-05-05T09:16:50+00:00 + + tag:shitposter.club,2017-05-05:objectType=thread:nonce=d1ae088a1b91e5e5 + + + + + + + + http://activitystrea.ms/schema/1.0/note + tag:shitposter.club,2017-05-05:noticeId=2828061:objectType=note + New note by moonman + even when i lie i tell the truth, is that so hard to understand? + + + http://activitystrea.ms/schema/1.0/post + 2017-05-05T09:15:07+00:00 + 2017-05-05T09:15:07+00:00 + + tag:shitposter.club,2017-05-05:objectType=thread:nonce=a516e4b8506b8ef5 + + + + + + + http://activitystrea.ms/schema/1.0/comment + tag:shitposter.club,2017-05-05:noticeId=2828052:objectType=comment + New comment by moonman + @<a href="https://shitposter.club/user/9591" class="h-card mention" title="warum hei&#xDF;en deutschl&#xE4;nder deutschl&#xE4;nder">hardbass2k8</a> history, anthropology. + + + http://activitystrea.ms/schema/1.0/post + 2017-05-05T09:14:22+00:00 + 2017-05-05T09:14:22+00:00 + + + + tag:shitposter.club,2017-05-05:objectType=thread:nonce=fe4d7f35b13403ba + + + + + + + diff --git a/test/fixtures/httpoison_mock/https___shitposter.club_notice_2827873.html b/test/fixtures/httpoison_mock/https___shitposter.club_notice_2827873.html new file mode 100644 index 000000000..54745ef3d --- /dev/null +++ b/test/fixtures/httpoison_mock/https___shitposter.club_notice_2827873.html @@ -0,0 +1,653 @@ + + + + Shitposter Club + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+
Please enable javascript to use this site.
+
+
+
+
+
+
+ +
+ + + + +
+ · + + OpenID
+
+
+ +
+
+
+
+

+ +

+
+
+
+
+ +
+
+
    + + +
  1. + +
    + Generic Enemy (moonman)'s status on Friday, 05-May-2017 08:51:48 UTC + + Generic Enemy +Generic Enemy + +
    +
    @neimzr4luzerz @dolus childhood poring over Strong's concordance and a koine Greek dictionary, fast forward to 2017 and some fuckstick who translates japanese jackoff material tells me you just need to make it sound right in English
    + +
    +
  2. +
+ +
+ + + + + + + + + + + + + + + + + + +
+ +
+ + + + + diff --git a/test/fixtures/httpoison_mock/https___shitposter.club_user_1.xml b/test/fixtures/httpoison_mock/https___shitposter.club_user_1.xml new file mode 100644 index 000000000..bf54c80c8 --- /dev/null +++ b/test/fixtures/httpoison_mock/https___shitposter.club_user_1.xml @@ -0,0 +1,20 @@ + + + https://shitposter.club/user/1 + acct:moonman@shitposter.club + https://shitposter.club/moonman + https://shitposter.club/index.php/user/1 + https://shitposter.club/index.php/moonman + + + + + + + + + + + + + diff --git a/test/support/httpoison_mock.ex b/test/support/httpoison_mock.ex index 0cb3b2691..733abced2 100644 --- a/test/support/httpoison_mock.ex +++ b/test/support/httpoison_mock.ex @@ -38,6 +38,13 @@ defmodule HTTPoisonMock do }} end + def get("https://shitposter.club/.well-known/webfinger", [Accept: "application/xrd+xml"], [params: [resource: "https://shitposter.club/user/1"]]) do + {:ok, %Response{ + status_code: 200, + body: File.read!("test/fixtures/httpoison_mock/https___shitposter.club_user_1.xml") + }} + end + def get("http://gs.example.org/.well-known/webfinger", [Accept: "application/xrd+xml"], [params: [resource: "http://gs.example.org:4040/index.php/user/1"], follow_redirect: true]) do {:ok, %Response{ status_code: 200, @@ -87,6 +94,27 @@ defmodule HTTPoisonMock do }} end + def get("https://shitposter.club/notice/2827873", _body, _headers) do + {:ok, %Response{ + status_code: 200, + body: File.read!("test/fixtures/httpoison_mock/https___shitposter.club_notice_2827873.html") + }} + end + + def get("https://shitposter.club/api/statuses/show/2827873.atom", _body, _headers) do + {:ok, %Response{ + status_code: 200, + body: File.read!("test/fixtures/httpoison_mock/https___shitposter.club_api_statuses_show_2827873.atom.xml") + }} + end + + def get("https://shitposter.club/api/statuses/user_timeline/1.atom", _body, _headers) do + {:ok, %Response{ + status_code: 200, + body: File.read!("test/fixtures/httpoison_mock/https___shitposter.club_api_statuses_user_timeline_1.atom.xml") + }} + end + def get(url, body, headers) do {:error, "Not implemented the mock response for get #{inspect(url)}"} end diff --git a/test/web/ostatus/ostatus_test.exs b/test/web/ostatus/ostatus_test.exs index e85d7677c..7f168ee54 100644 --- a/test/web/ostatus/ostatus_test.exs +++ b/test/web/ostatus/ostatus_test.exs @@ -96,6 +96,20 @@ defmodule Pleroma.Web.OStatusTest do refute retweeted_activity.local end + test "handle incoming favorites - GS, websub" do + incoming = File.read!("test/fixtures/favorite.xml") + {:ok, [[activity, retweeted_activity]]} = OStatus.handle_incoming(incoming) + + assert activity.data["type"] == "Like" + assert activity.data["actor"] == "https://social.heldscal.la/user/23211" + assert activity.data["object"] == retweeted_activity.data["object"]["id"] + refute activity.local + assert retweeted_activity.data["type"] == "Create" + assert retweeted_activity.data["actor"] == "https://shitposter.club/user/1" + assert retweeted_activity.data["object"]["id"] == "tag:shitposter.club,2017-05-05:noticeId=2827873:objectType=comment" + refute retweeted_activity.local + end + test "handle incoming replies" do incoming = File.read!("test/fixtures/incoming_note_activity_answer.xml") {:ok, [activity]} = OStatus.handle_incoming(incoming) @@ -191,4 +205,14 @@ defmodule Pleroma.Web.OStatusTest do assert data == expected end end + + describe "fetching a status by it's HTML url" do + test "it builds a missing status from an html url" do + url = "https://shitposter.club/notice/2827873" + {:ok, [activity] } = OStatus.fetch_activity_from_html_url(url) + + assert activity.data["actor"] == "https://shitposter.club/user/1" + assert activity.data["object"]["id"] == "tag:shitposter.club,2017-05-05:noticeId=2827873:objectType=comment" + end + end end