diff --git a/lib/pleroma/object/fetcher.ex b/lib/pleroma/object/fetcher.ex
index 5e064fd87..9436e2730 100644
--- a/lib/pleroma/object/fetcher.ex
+++ b/lib/pleroma/object/fetcher.ex
@@ -10,7 +10,6 @@ defmodule Pleroma.Object.Fetcher do
alias Pleroma.Signature
alias Pleroma.Web.ActivityPub.InternalFetchActor
alias Pleroma.Web.ActivityPub.Transmogrifier
- alias Pleroma.Web.OStatus
require Logger
require Pleroma.Constants
@@ -87,15 +86,8 @@ defmodule Pleroma.Object.Fetcher do
{:fetch_object, %Object{} = object} ->
{:ok, object}
- _e ->
- # Only fallback when receiving a fetch/normalization error with ActivityPub
- Logger.info("Couldn't get object via AP, trying out OStatus fetching...")
-
- # FIXME: OStatus Object Containment?
- case OStatus.fetch_activity_from_url(id) do
- {:ok, [activity | _]} -> {:ok, Object.normalize(activity, false)}
- e -> e
- end
+ e ->
+ e
end
end
diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex
index cef011c68..ec705b8f6 100644
--- a/lib/pleroma/user.ex
+++ b/lib/pleroma/user.ex
@@ -26,7 +26,6 @@ defmodule Pleroma.User do
alias Pleroma.Web.CommonAPI
alias Pleroma.Web.CommonAPI.Utils, as: CommonUtils
alias Pleroma.Web.OAuth
- alias Pleroma.Web.OStatus
alias Pleroma.Web.RelMe
alias Pleroma.Workers.BackgroundWorker
@@ -609,12 +608,7 @@ defmodule Pleroma.User do
Cachex.fetch!(:user_cache, key, fn -> user_info(user) end)
end
- def fetch_by_nickname(nickname) do
- case ActivityPub.make_user_from_nickname(nickname) do
- {:ok, user} -> {:ok, user}
- _ -> OStatus.make_user(nickname)
- end
- end
+ def fetch_by_nickname(nickname), do: ActivityPub.make_user_from_nickname(nickname)
def get_or_fetch_by_nickname(nickname) do
with %User{} = user <- get_by_nickname(nickname) do
@@ -1241,18 +1235,7 @@ defmodule Pleroma.User do
def html_filter_policy(_), do: Pleroma.Config.get([:markup, :scrub_policy])
- def fetch_by_ap_id(ap_id) do
- case ActivityPub.make_user_from_ap_id(ap_id) do
- {:ok, user} ->
- {:ok, user}
-
- _ ->
- case OStatus.make_user(ap_id) do
- {:ok, user} -> {:ok, user}
- _ -> {:error, "Could not fetch by AP id"}
- end
- end
- end
+ def fetch_by_ap_id(ap_id), do: ActivityPub.make_user_from_ap_id(ap_id)
def get_or_fetch_by_ap_id(ap_id) do
user = get_cached_by_ap_id(ap_id)
@@ -1307,11 +1290,6 @@ defmodule Pleroma.User do
{:ok, key}
end
- # OStatus Magic Key
- def public_key_from_info(%{magic_key: magic_key}) when not is_nil(magic_key) do
- {:ok, Pleroma.Web.Salmon.decode_key(magic_key)}
- end
-
def public_key_from_info(_), do: {:error, "not found key"}
def get_public_key_for_ap_id(ap_id) do
diff --git a/lib/pleroma/web/federator/federator.ex b/lib/pleroma/web/federator/federator.ex
index 8c83f9aea..e8a56ebd7 100644
--- a/lib/pleroma/web/federator/federator.ex
+++ b/lib/pleroma/web/federator/federator.ex
@@ -10,7 +10,6 @@ defmodule Pleroma.Web.Federator do
alias Pleroma.Web.ActivityPub.Transmogrifier
alias Pleroma.Web.ActivityPub.Utils
alias Pleroma.Web.Federator.Publisher
- alias Pleroma.Web.OStatus
alias Pleroma.Workers.PublisherWorker
alias Pleroma.Workers.ReceiverWorker
diff --git a/lib/pleroma/web/ostatus/activity_representer.ex b/lib/pleroma/web/ostatus/activity_representer.ex
deleted file mode 100644
index 8e55b9f0b..000000000
--- a/lib/pleroma/web/ostatus/activity_representer.ex
+++ /dev/null
@@ -1,313 +0,0 @@
-# Pleroma: A lightweight social networking server
-# Copyright © 2017-2019 Pleroma Authors
-# SPDX-License-Identifier: AGPL-3.0-only
-
-defmodule Pleroma.Web.OStatus.ActivityRepresenter do
- alias Pleroma.Activity
- alias Pleroma.Object
- alias Pleroma.User
- alias Pleroma.Web.OStatus.UserRepresenter
-
- require Logger
- require Pleroma.Constants
-
- defp get_href(id) do
- with %Object{data: %{"external_url" => external_url}} <- Object.get_cached_by_ap_id(id) do
- external_url
- else
- _e -> id
- end
- end
-
- defp get_in_reply_to(activity) do
- with %Object{data: %{"inReplyTo" => in_reply_to}} <- Object.normalize(activity) do
- [
- {:"thr:in-reply-to",
- [ref: to_charlist(in_reply_to), href: to_charlist(get_href(in_reply_to))], []}
- ]
- else
- _ ->
- []
- end
- end
-
- defp get_mentions(to) do
- Enum.map(to, fn id ->
- cond do
- # Special handling for the AP/Ostatus public collections
- Pleroma.Constants.as_public() == id ->
- {:link,
- [
- rel: "mentioned",
- "ostatus:object-type": "http://activitystrea.ms/schema/1.0/collection",
- href: "http://activityschema.org/collection/public"
- ], []}
-
- # Ostatus doesn't handle follower collections, ignore these.
- Regex.match?(~r/^#{Pleroma.Web.base_url()}.+followers$/, id) ->
- []
-
- true ->
- {:link,
- [
- rel: "mentioned",
- "ostatus:object-type": "http://activitystrea.ms/schema/1.0/person",
- href: id
- ], []}
- end
- end)
- end
-
- defp get_links(%{local: true}, %{"id" => object_id}) do
- h = fn str -> [to_charlist(str)] end
-
- [
- {:link, [type: ['application/atom+xml'], href: h.(object_id), rel: 'self'], []},
- {:link, [type: ['text/html'], href: h.(object_id), rel: 'alternate'], []}
- ]
- end
-
- defp get_links(%{local: false}, %{"external_url" => external_url}) do
- h = fn str -> [to_charlist(str)] end
-
- [
- {:link, [type: ['text/html'], href: h.(external_url), rel: 'alternate'], []}
- ]
- end
-
- defp get_links(_activity, _object_data), do: []
-
- defp get_emoji_links(emojis) do
- Enum.map(emojis, fn {emoji, file} ->
- {:link, [name: to_charlist(emoji), rel: 'emoji', href: to_charlist(file)], []}
- end)
- end
-
- def to_simple_form(activity, user, with_author \\ false)
-
- def to_simple_form(%{data: %{"type" => "Create"}} = activity, user, with_author) do
- h = fn str -> [to_charlist(str)] end
-
- object = Object.normalize(activity)
-
- updated_at = object.data["published"]
- inserted_at = object.data["published"]
-
- attachments =
- Enum.map(object.data["attachment"] || [], fn attachment ->
- url = hd(attachment["url"])
-
- {:link,
- [rel: 'enclosure', href: to_charlist(url["href"]), type: to_charlist(url["mediaType"])],
- []}
- end)
-
- in_reply_to = get_in_reply_to(activity)
- author = if with_author, do: [{:author, UserRepresenter.to_simple_form(user)}], else: []
- mentions = activity.recipients |> get_mentions
-
- categories =
- (object.data["tag"] || [])
- |> Enum.map(fn tag ->
- if is_binary(tag) do
- {:category, [term: to_charlist(tag)], []}
- else
- nil
- end
- end)
- |> Enum.filter(& &1)
-
- emoji_links = get_emoji_links(object.data["emoji"] || %{})
-
- summary =
- if object.data["summary"] do
- [{:summary, [], h.(object.data["summary"])}]
- else
- []
- end
-
- [
- {:"activity:object-type", ['http://activitystrea.ms/schema/1.0/note']},
- {:"activity:verb", ['http://activitystrea.ms/schema/1.0/post']},
- # For notes, federate the object id.
- {:id, h.(object.data["id"])},
- {:title, ['New note by #{user.nickname}']},
- {:content, [type: 'html'], h.(object.data["content"] |> String.replace(~r/[\n\r]/, ""))},
- {:published, h.(inserted_at)},
- {:updated, h.(updated_at)},
- {:"ostatus:conversation", [ref: h.(activity.data["context"])],
- h.(activity.data["context"])},
- {:link, [ref: h.(activity.data["context"]), rel: 'ostatus:conversation'], []}
- ] ++
- summary ++
- get_links(activity, object.data) ++
- categories ++ attachments ++ in_reply_to ++ author ++ mentions ++ emoji_links
- end
-
- def to_simple_form(%{data: %{"type" => "Like"}} = activity, user, with_author) do
- h = fn str -> [to_charlist(str)] end
-
- updated_at = activity.data["published"]
- inserted_at = activity.data["published"]
-
- author = if with_author, do: [{:author, UserRepresenter.to_simple_form(user)}], else: []
- mentions = activity.recipients |> get_mentions
-
- [
- {:"activity:verb", ['http://activitystrea.ms/schema/1.0/favorite']},
- {:id, h.(activity.data["id"])},
- {:title, ['New favorite by #{user.nickname}']},
- {:content, [type: 'html'], ['#{user.nickname} favorited something']},
- {:published, h.(inserted_at)},
- {:updated, h.(updated_at)},
- {:"activity:object",
- [
- {:"activity:object-type", ['http://activitystrea.ms/schema/1.0/note']},
- # For notes, federate the object id.
- {:id, h.(activity.data["object"])}
- ]},
- {:"ostatus:conversation", [ref: h.(activity.data["context"])],
- h.(activity.data["context"])},
- {:link, [ref: h.(activity.data["context"]), rel: 'ostatus:conversation'], []},
- {:link, [rel: 'self', type: ['application/atom+xml'], href: h.(activity.data["id"])], []},
- {:"thr:in-reply-to", [ref: to_charlist(activity.data["object"])], []}
- ] ++ author ++ mentions
- end
-
- def to_simple_form(%{data: %{"type" => "Announce"}} = activity, user, with_author) do
- h = fn str -> [to_charlist(str)] end
-
- updated_at = activity.data["published"]
- inserted_at = activity.data["published"]
-
- author = if with_author, do: [{:author, UserRepresenter.to_simple_form(user)}], else: []
-
- retweeted_activity = Activity.get_create_by_object_ap_id(activity.data["object"])
- retweeted_object = Object.normalize(retweeted_activity)
- retweeted_user = User.get_cached_by_ap_id(retweeted_activity.data["actor"])
-
- retweeted_xml = to_simple_form(retweeted_activity, retweeted_user, true)
-
- mentions =
- ([retweeted_user.ap_id] ++ activity.recipients)
- |> Enum.uniq()
- |> get_mentions()
-
- [
- {:"activity:object-type", ['http://activitystrea.ms/schema/1.0/activity']},
- {:"activity:verb", ['http://activitystrea.ms/schema/1.0/share']},
- {:id, h.(activity.data["id"])},
- {:title, ['#{user.nickname} repeated a notice']},
- {:content, [type: 'html'], ['RT #{retweeted_object.data["content"]}']},
- {:published, h.(inserted_at)},
- {:updated, h.(updated_at)},
- {:"ostatus:conversation", [ref: h.(activity.data["context"])],
- h.(activity.data["context"])},
- {:link, [ref: h.(activity.data["context"]), rel: 'ostatus:conversation'], []},
- {:link, [rel: 'self', type: ['application/atom+xml'], href: h.(activity.data["id"])], []},
- {:"activity:object", retweeted_xml}
- ] ++ mentions ++ author
- end
-
- def to_simple_form(%{data: %{"type" => "Follow"}} = activity, user, with_author) do
- h = fn str -> [to_charlist(str)] end
-
- updated_at = activity.data["published"]
- inserted_at = activity.data["published"]
-
- author = if with_author, do: [{:author, UserRepresenter.to_simple_form(user)}], else: []
-
- mentions = (activity.recipients || []) |> get_mentions
-
- [
- {:"activity:object-type", ['http://activitystrea.ms/schema/1.0/activity']},
- {:"activity:verb", ['http://activitystrea.ms/schema/1.0/follow']},
- {:id, h.(activity.data["id"])},
- {:title, ['#{user.nickname} started following #{activity.data["object"]}']},
- {:content, [type: 'html'],
- ['#{user.nickname} started following #{activity.data["object"]}']},
- {:published, h.(inserted_at)},
- {:updated, h.(updated_at)},
- {:"activity:object",
- [
- {:"activity:object-type", ['http://activitystrea.ms/schema/1.0/person']},
- {:id, h.(activity.data["object"])},
- {:uri, h.(activity.data["object"])}
- ]},
- {:link, [rel: 'self', type: ['application/atom+xml'], href: h.(activity.data["id"])], []}
- ] ++ mentions ++ author
- end
-
- # Only undos of follow for now. Will need to get redone once there are more
- def to_simple_form(
- %{data: %{"type" => "Undo", "object" => %{"type" => "Follow"} = follow_activity}} =
- activity,
- user,
- with_author
- ) do
- h = fn str -> [to_charlist(str)] end
-
- updated_at = activity.data["published"]
- inserted_at = activity.data["published"]
-
- author = if with_author, do: [{:author, UserRepresenter.to_simple_form(user)}], else: []
-
- mentions = (activity.recipients || []) |> get_mentions
- follow_activity = Activity.normalize(follow_activity)
-
- [
- {:"activity:object-type", ['http://activitystrea.ms/schema/1.0/activity']},
- {:"activity:verb", ['http://activitystrea.ms/schema/1.0/unfollow']},
- {:id, h.(activity.data["id"])},
- {:title, ['#{user.nickname} stopped following #{follow_activity.data["object"]}']},
- {:content, [type: 'html'],
- ['#{user.nickname} stopped following #{follow_activity.data["object"]}']},
- {:published, h.(inserted_at)},
- {:updated, h.(updated_at)},
- {:"activity:object",
- [
- {:"activity:object-type", ['http://activitystrea.ms/schema/1.0/person']},
- {:id, h.(follow_activity.data["object"])},
- {:uri, h.(follow_activity.data["object"])}
- ]},
- {:link, [rel: 'self', type: ['application/atom+xml'], href: h.(activity.data["id"])], []}
- ] ++ mentions ++ author
- end
-
- def to_simple_form(%{data: %{"type" => "Delete"}} = activity, user, with_author) do
- h = fn str -> [to_charlist(str)] end
-
- updated_at = activity.data["published"]
- inserted_at = activity.data["published"]
-
- author = if with_author, do: [{:author, UserRepresenter.to_simple_form(user)}], else: []
-
- [
- {:"activity:object-type", ['http://activitystrea.ms/schema/1.0/activity']},
- {:"activity:verb", ['http://activitystrea.ms/schema/1.0/delete']},
- {:id, h.(activity.data["object"])},
- {:title, ['An object was deleted']},
- {:content, [type: 'html'], ['An object was deleted']},
- {:published, h.(inserted_at)},
- {:updated, h.(updated_at)}
- ] ++ author
- end
-
- def to_simple_form(_, _, _), do: nil
-
- def wrap_with_entry(simple_form) do
- [
- {
- :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:ostatus": 'http://ostatus.org/schema/1.0'
- ],
- simple_form
- }
- ]
- end
-end
diff --git a/lib/pleroma/web/ostatus/feed_representer.ex b/lib/pleroma/web/ostatus/feed_representer.ex
deleted file mode 100644
index fa7f7b564..000000000
--- a/lib/pleroma/web/ostatus/feed_representer.ex
+++ /dev/null
@@ -1,64 +0,0 @@
-# Pleroma: A lightweight social networking server
-# Copyright © 2017-2019 Pleroma Authors
-# SPDX-License-Identifier: AGPL-3.0-only
-
-defmodule Pleroma.Web.OStatus.FeedRepresenter do
- alias Pleroma.User
- alias Pleroma.Web.MediaProxy
- alias Pleroma.Web.OStatus
- alias Pleroma.Web.OStatus.ActivityRepresenter
- alias Pleroma.Web.OStatus.UserRepresenter
-
- def to_simple_form(user, activities, _users) do
- most_recent_update =
- (List.first(activities) || user).updated_at
- |> NaiveDateTime.to_iso8601()
-
- h = fn str -> [to_charlist(str)] end
-
- last_activity = List.last(activities)
-
- entries =
- activities
- |> Enum.map(fn activity ->
- {:entry, ActivityRepresenter.to_simple_form(activity, user)}
- end)
- |> Enum.filter(fn {_, form} -> form end)
-
- [
- {
- :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:ostatus": 'http://ostatus.org/schema/1.0'
- ],
- [
- {:id, h.(OStatus.feed_path(user))},
- {:title, ['#{user.nickname}\'s timeline']},
- {:updated, h.(most_recent_update)},
- {:logo, [to_charlist(User.avatar_url(user) |> MediaProxy.url())]},
- {:link, [rel: 'self', href: h.(OStatus.feed_path(user)), type: 'application/atom+xml'],
- []},
- {:author, UserRepresenter.to_simple_form(user)}
- ] ++
- if last_activity do
- [
- {:link,
- [
- rel: 'next',
- href:
- to_charlist(OStatus.feed_path(user)) ++
- '?max_id=' ++ to_charlist(last_activity.id),
- type: 'application/atom+xml'
- ], []}
- ]
- else
- []
- end ++ entries
- }
- ]
- end
-end
diff --git a/lib/pleroma/web/ostatus/handlers/delete_handler.ex b/lib/pleroma/web/ostatus/handlers/delete_handler.ex
deleted file mode 100644
index ac2dc115c..000000000
--- a/lib/pleroma/web/ostatus/handlers/delete_handler.ex
+++ /dev/null
@@ -1,18 +0,0 @@
-# Pleroma: A lightweight social networking server
-# Copyright © 2017-2019 Pleroma Authors
-# SPDX-License-Identifier: AGPL-3.0-only
-
-defmodule Pleroma.Web.OStatus.DeleteHandler do
- require Logger
- alias Pleroma.Object
- alias Pleroma.Web.ActivityPub.ActivityPub
- alias Pleroma.Web.XML
-
- def handle_delete(entry, _doc \\ nil) do
- with id <- XML.string_from_xpath("//id", entry),
- %Object{} = object <- Object.normalize(id),
- {:ok, delete} <- ActivityPub.delete(object, local: false) do
- delete
- end
- end
-end
diff --git a/lib/pleroma/web/ostatus/handlers/follow_handler.ex b/lib/pleroma/web/ostatus/handlers/follow_handler.ex
deleted file mode 100644
index 24513972e..000000000
--- a/lib/pleroma/web/ostatus/handlers/follow_handler.ex
+++ /dev/null
@@ -1,26 +0,0 @@
-# Pleroma: A lightweight social networking server
-# Copyright © 2017-2019 Pleroma Authors
-# SPDX-License-Identifier: AGPL-3.0-only
-
-defmodule Pleroma.Web.OStatus.FollowHandler do
- alias Pleroma.User
- alias Pleroma.Web.ActivityPub.ActivityPub
- alias Pleroma.Web.OStatus
- alias Pleroma.Web.XML
-
- def handle(entry, doc) do
- with {:ok, actor} <- OStatus.find_make_or_update_actor(doc),
- id when not is_nil(id) <- XML.string_from_xpath("/entry/id", entry),
- followed_uri when not is_nil(followed_uri) <-
- XML.string_from_xpath("/entry/activity:object/id", entry),
- {:ok, followed} <- OStatus.find_or_make_user(followed_uri),
- {:locked, false} <- {:locked, followed.info.locked},
- {:ok, activity} <- ActivityPub.follow(actor, followed, id, false) do
- User.follow(actor, followed)
- {:ok, activity}
- else
- {:locked, true} ->
- {:error, "It's not possible to follow locked accounts over OStatus"}
- end
- end
-end
diff --git a/lib/pleroma/web/ostatus/handlers/note_handler.ex b/lib/pleroma/web/ostatus/handlers/note_handler.ex
deleted file mode 100644
index 7fae14f7b..000000000
--- a/lib/pleroma/web/ostatus/handlers/note_handler.ex
+++ /dev/null
@@ -1,168 +0,0 @@
-# Pleroma: A lightweight social networking server
-# Copyright © 2017-2019 Pleroma Authors
-# SPDX-License-Identifier: AGPL-3.0-only
-
-defmodule Pleroma.Web.OStatus.NoteHandler do
- require Logger
- require Pleroma.Constants
-
- alias Pleroma.Activity
- alias Pleroma.Object
- alias Pleroma.Web.ActivityPub.ActivityPub
- alias Pleroma.Web.ActivityPub.Utils
- alias Pleroma.Web.CommonAPI
- alias Pleroma.Web.Federator
- alias Pleroma.Web.OStatus
- alias Pleroma.Web.XML
-
- @doc """
- Get the context for this note. Uses this:
- 1. The context of the parent activity
- 2. The conversation reference in the ostatus xml
- 3. A newly generated context id.
- """
- def get_context(entry, in_reply_to) do
- context =
- (XML.string_from_xpath("//ostatus:conversation[1]", entry) ||
- XML.string_from_xpath("//ostatus:conversation[1]/@ref", entry) || "")
- |> String.trim()
-
- with %{data: %{"context" => context}} <- Object.get_cached_by_ap_id(in_reply_to) do
- context
- else
- _e ->
- if String.length(context) > 0 do
- context
- else
- Utils.generate_context_id()
- end
- end
- end
-
- def get_people_mentions(entry) do
- :xmerl_xpath.string(
- '//link[@rel="mentioned" and @ostatus:object-type="http://activitystrea.ms/schema/1.0/person"]',
- entry
- )
- |> Enum.map(fn person -> XML.string_from_xpath("@href", person) end)
- end
-
- def get_collection_mentions(entry) do
- transmogrify = fn
- "http://activityschema.org/collection/public" ->
- Pleroma.Constants.as_public()
-
- group ->
- group
- end
-
- :xmerl_xpath.string(
- '//link[@rel="mentioned" and @ostatus:object-type="http://activitystrea.ms/schema/1.0/collection"]',
- entry
- )
- |> Enum.map(fn collection -> XML.string_from_xpath("@href", collection) |> transmogrify.() end)
- end
-
- def get_mentions(entry) do
- (get_people_mentions(entry) ++ get_collection_mentions(entry))
- |> Enum.filter(& &1)
- end
-
- def get_emoji(entry) do
- try do
- :xmerl_xpath.string('//link[@rel="emoji"]', entry)
- |> Enum.reduce(%{}, fn emoji, acc ->
- Map.put(acc, XML.string_from_xpath("@name", emoji), XML.string_from_xpath("@href", emoji))
- end)
- rescue
- _e -> nil
- end
- end
-
- def make_to_list(actor, mentions) do
- [
- actor.follower_address
- ] ++ mentions
- end
-
- def add_external_url(note, entry) do
- url = XML.string_from_xpath("//link[@rel='alternate' and @type='text/html']/@href", entry)
- Map.put(note, "external_url", url)
- end
-
- def fetch_replied_to_activity(entry, in_reply_to, options \\ []) do
- with %Activity{} = activity <- Activity.get_create_by_object_ap_id(in_reply_to) do
- activity
- else
- _e ->
- with true <- Federator.allowed_incoming_reply_depth?(options[:depth]),
- in_reply_to_href when not is_nil(in_reply_to_href) <-
- XML.string_from_xpath("//thr:in-reply-to[1]/@href", entry),
- {:ok, [activity | _]} <- OStatus.fetch_activity_from_url(in_reply_to_href, options) do
- activity
- else
- _e -> nil
- end
- end
- end
-
- # TODO: Clean this up a bit.
- def handle_note(entry, doc \\ nil, options \\ []) do
- with id <- XML.string_from_xpath("//id", entry),
- activity when is_nil(activity) <- Activity.get_create_by_object_ap_id_with_object(id),
- [author] <- :xmerl_xpath.string('//author[1]', doc),
- {:ok, actor} <- OStatus.find_make_or_update_actor(author),
- content_html <- OStatus.get_content(entry),
- cw <- OStatus.get_cw(entry),
- in_reply_to <- XML.string_from_xpath("//thr:in-reply-to[1]/@ref", entry),
- options <- Keyword.put(options, :depth, (options[:depth] || 0) + 1),
- in_reply_to_activity <- fetch_replied_to_activity(entry, in_reply_to, options),
- in_reply_to_object <-
- (in_reply_to_activity && Object.normalize(in_reply_to_activity)) || nil,
- in_reply_to <- (in_reply_to_object && in_reply_to_object.data["id"]) || in_reply_to,
- attachments <- OStatus.get_attachments(entry),
- context <- get_context(entry, in_reply_to),
- tags <- OStatus.get_tags(entry),
- mentions <- get_mentions(entry),
- to <- make_to_list(actor, mentions),
- date <- XML.string_from_xpath("//published", entry),
- unlisted <- XML.string_from_xpath("//mastodon:scope", entry) == "unlisted",
- cc <- if(unlisted, do: [Pleroma.Constants.as_public()], else: []),
- note <-
- CommonAPI.Utils.make_note_data(
- actor.ap_id,
- to,
- context,
- content_html,
- attachments,
- in_reply_to_activity,
- [],
- cw
- ),
- note <- note |> Map.put("id", id) |> Map.put("tag", tags),
- note <- note |> Map.put("published", date),
- note <- note |> Map.put("emoji", get_emoji(entry)),
- note <- add_external_url(note, entry),
- note <- note |> Map.put("cc", cc),
- # TODO: Handle this case in make_note_data
- note <-
- if(
- in_reply_to && !in_reply_to_activity,
- do: note |> Map.put("inReplyTo", in_reply_to),
- else: note
- ) do
- ActivityPub.create(%{
- to: to,
- actor: actor,
- context: context,
- object: note,
- published: date,
- local: false,
- additional: %{"cc" => cc}
- })
- else
- %Activity{} = activity -> {:ok, activity}
- e -> {:error, e}
- end
- end
-end
diff --git a/lib/pleroma/web/ostatus/handlers/unfollow_handler.ex b/lib/pleroma/web/ostatus/handlers/unfollow_handler.ex
deleted file mode 100644
index 2062432e3..000000000
--- a/lib/pleroma/web/ostatus/handlers/unfollow_handler.ex
+++ /dev/null
@@ -1,22 +0,0 @@
-# Pleroma: A lightweight social networking server
-# Copyright © 2017-2019 Pleroma Authors
-# SPDX-License-Identifier: AGPL-3.0-only
-
-defmodule Pleroma.Web.OStatus.UnfollowHandler do
- alias Pleroma.User
- alias Pleroma.Web.ActivityPub.ActivityPub
- alias Pleroma.Web.OStatus
- alias Pleroma.Web.XML
-
- def handle(entry, doc) do
- with {:ok, actor} <- OStatus.find_make_or_update_actor(doc),
- id when not is_nil(id) <- XML.string_from_xpath("/entry/id", entry),
- followed_uri when not is_nil(followed_uri) <-
- XML.string_from_xpath("/entry/activity:object/id", entry),
- {:ok, followed} <- OStatus.find_or_make_user(followed_uri),
- {:ok, activity} <- ActivityPub.unfollow(actor, followed, id, false) do
- User.unfollow(actor, followed)
- {:ok, activity}
- end
- end
-end
diff --git a/lib/pleroma/web/ostatus/ostatus.ex b/lib/pleroma/web/ostatus/ostatus.ex
deleted file mode 100644
index a858759d3..000000000
--- a/lib/pleroma/web/ostatus/ostatus.ex
+++ /dev/null
@@ -1,388 +0,0 @@
-# Pleroma: A lightweight social networking server
-# Copyright © 2017-2019 Pleroma Authors
-# SPDX-License-Identifier: AGPL-3.0-only
-
-defmodule Pleroma.Web.OStatus do
- import Pleroma.Web.XML
- require Logger
-
- alias Pleroma.Activity
- alias Pleroma.HTTP
- alias Pleroma.Object
- alias Pleroma.User
- alias Pleroma.Web
- alias Pleroma.Web.ActivityPub.ActivityPub
- alias Pleroma.Web.ActivityPub.Transmogrifier
- alias Pleroma.Web.ActivityPub.Visibility
- alias Pleroma.Web.OStatus.DeleteHandler
- alias Pleroma.Web.OStatus.FollowHandler
- alias Pleroma.Web.OStatus.NoteHandler
- alias Pleroma.Web.OStatus.UnfollowHandler
- alias Pleroma.Web.WebFinger
-
- def is_representable?(%Activity{} = activity) do
- object = Object.normalize(activity)
-
- cond do
- is_nil(object) ->
- false
-
- Visibility.is_public?(activity) && object.data["type"] == "Note" ->
- true
-
- true ->
- false
- end
- end
-
- def feed_path(user), do: "#{user.ap_id}/feed.atom"
-
- def remote_follow_path, do: "#{Web.base_url()}/ostatus_subscribe?acct={uri}"
-
- def handle_incoming(xml_string, options \\ []) do
- with doc when doc != :error <- parse_document(xml_string) do
- with {:ok, actor_user} <- find_make_or_update_actor(doc),
- do: Pleroma.Instances.set_reachable(actor_user.ap_id)
-
- entries = :xmerl_xpath.string('//entry', doc)
-
- activities =
- Enum.map(entries, fn entry ->
- {:xmlObj, :string, object_type} =
- :xmerl_xpath.string('string(/entry/activity:object-type[1])', entry)
-
- {:xmlObj, :string, verb} = :xmerl_xpath.string('string(/entry/activity:verb[1])', entry)
- Logger.debug("Handling #{verb}")
-
- try 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' ->
- with {:ok, activity} <- FollowHandler.handle(entry, doc), do: activity
-
- 'http://activitystrea.ms/schema/1.0/unfollow' ->
- with {:ok, activity} <- UnfollowHandler.handle(entry, doc), do: activity
-
- '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' ->
- with {:ok, activity} <- NoteHandler.handle_note(entry, doc, options),
- do: activity
-
- 'http://activitystrea.ms/schema/1.0/comment' ->
- with {:ok, activity} <- NoteHandler.handle_note(entry, doc, options),
- do: activity
-
- _ ->
- Logger.error("Couldn't parse incoming document")
- nil
- end
- end
- rescue
- e ->
- Logger.error("Error occured while handling activity")
- Logger.error(xml_string)
- Logger.error(inspect(e))
- nil
- end
- end)
- |> Enum.filter(& &1)
-
- {:ok, activities}
- else
- _e -> {:error, []}
- end
- end
-
- def make_share(entry, doc, retweeted_activity) do
- with {:ok, actor} <- find_make_or_update_actor(doc),
- %Object{} = object <- Object.normalize(retweeted_activity),
- id when not is_nil(id) <- string_from_xpath("/entry/id", entry),
- {:ok, activity, _object} = ActivityPub.announce(actor, object, id, false) do
- {:ok, activity}
- end
- end
-
- def handle_share(entry, doc) do
- with {:ok, retweeted_activity} <- get_or_build_object(entry),
- {:ok, activity} <- make_share(entry, doc, retweeted_activity) do
- {:ok, activity, retweeted_activity}
- else
- e -> {:error, e}
- end
- end
-
- def make_favorite(entry, doc, favorited_activity) do
- with {:ok, actor} <- find_make_or_update_actor(doc),
- %Object{} = object <- Object.normalize(favorited_activity),
- id when not is_nil(id) <- string_from_xpath("/entry/id", entry),
- {:ok, activity, _object} = ActivityPub.like(actor, object, id, false) do
- {:ok, activity}
- end
- end
-
- def get_or_build_object(entry) do
- with {:ok, activity} <- get_or_try_fetching(entry) do
- {:ok, activity}
- else
- _e ->
- with [object] <- :xmerl_xpath.string('/entry/activity:object', entry) do
- NoteHandler.handle_note(object, object)
- end
- end
- end
-
- def get_or_try_fetching(entry) do
- 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_by_object_ap_id_with_object(id) do
- {:ok, activity}
- else
- _ ->
- 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_url(href) do
- {:ok, favorited_activity}
- else
- e -> Logger.debug("Couldn't find href: #{inspect(e)}")
- end
- end
- end
-
- def handle_favorite(entry, doc) do
- with {:ok, favorited_activity} <- get_or_try_fetching(entry),
- {: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 ->
- with href when not is_nil(href) <- string_from_xpath("/link/@href", enclosure),
- type when not is_nil(type) <- string_from_xpath("/link/@type", enclosure) do
- %{
- "type" => "Attachment",
- "url" => [
- %{
- "type" => "Link",
- "mediaType" => type,
- "href" => href
- }
- ]
- }
- end
- end)
- |> Enum.filter(& &1)
- end
-
- @doc """
- Gets the content from a an entry.
- """
- def get_content(entry) do
- string_from_xpath("//content", entry)
- end
-
- @doc """
- Get the cw that mastodon uses.
- """
- def get_cw(entry) do
- case string_from_xpath("/*/summary", entry) do
- cw when not is_nil(cw) -> cw
- _ -> nil
- end
- end
-
- def get_tags(entry) do
- :xmerl_xpath.string('//category', entry)
- |> Enum.map(fn category -> string_from_xpath("/category/@term", category) end)
- |> Enum.filter(& &1)
- |> Enum.map(&String.downcase/1)
- end
-
- def maybe_update(doc, user) do
- case string_from_xpath("//author[1]/ap_enabled", doc) do
- "true" ->
- Transmogrifier.upgrade_user_from_ap_id(user.ap_id)
-
- _ ->
- maybe_update_ostatus(doc, user)
- end
- end
-
- def maybe_update_ostatus(doc, user) do
- old_data = Map.take(user, [:bio, :avatar, :name])
-
- with false <- user.local,
- avatar <- make_avatar_object(doc),
- bio <- string_from_xpath("//author[1]/summary", doc),
- name <- string_from_xpath("//author[1]/poco:displayName", doc),
- new_data <- %{
- avatar: avatar || old_data.avatar,
- name: name || old_data.name,
- bio: bio || old_data.bio
- },
- false <- new_data == old_data do
- change = Ecto.Changeset.change(user, new_data)
- User.update_and_set_cache(change)
- else
- _ ->
- {:ok, user}
- end
- end
-
- def find_make_or_update_actor(doc) do
- uri = string_from_xpath("//author/uri[1]", doc)
-
- with {:ok, %User{} = user} <- find_or_make_user(uri),
- {:ap_enabled, false} <- {:ap_enabled, User.ap_enabled?(user)} do
- maybe_update(doc, user)
- else
- {:ap_enabled, true} ->
- {:error, :invalid_protocol}
-
- _ ->
- {:error, :unknown_user}
- end
- end
-
- @spec find_or_make_user(String.t()) :: {:ok, User.t()}
- def find_or_make_user(uri) do
- case User.get_by_ap_id(uri) do
- %User{} = user -> {:ok, user}
- _ -> make_user(uri)
- end
- end
-
- @spec make_user(String.t(), boolean()) :: {:ok, User.t()} | {:error, any()}
- def make_user(uri, update \\ false) do
- with {:ok, info} <- gather_user_info(uri) do
- with false <- update,
- %User{} = user <- User.get_cached_by_ap_id(info["uri"]) do
- {:ok, user}
- else
- _e -> User.insert_or_update_user(build_user_data(info))
- end
- end
- end
-
- defp build_user_data(info) do
- %{
- name: info["name"],
- nickname: info["nickname"] <> "@" <> info["host"],
- ap_id: info["uri"],
- info: info,
- avatar: info["avatar"],
- bio: info["bio"]
- }
- end
-
- # TODO: Just takes the first one for now.
- def make_avatar_object(author_doc, rel \\ "avatar") do
- href = string_from_xpath("//author[1]/link[@rel=\"#{rel}\"]/@href", author_doc)
- type = string_from_xpath("//author[1]/link[@rel=\"#{rel}\"]/@type", author_doc)
-
- if href do
- %{
- "type" => "Image",
- "url" => [%{"type" => "Link", "mediaType" => type, "href" => href}]
- }
- else
- nil
- end
- end
-
- @spec gather_user_info(String.t()) :: {:ok, map()} | {:error, any()}
- def gather_user_info(username) do
- with {:ok, webfinger_data} <- WebFinger.finger(username) do
- data =
- webfinger_data
- |> Map.put("fqn", username)
-
- {:ok, data}
- else
- e ->
- Logger.debug(fn -> "Couldn't gather info for #{username}" end)
- {: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//
- @gs_classic_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}
-
- Regex.match?(@gs_classic_regex, body) ->
- [[_, match]] = Regex.scan(@gs_classic_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_atom_url(url, options \\ []) do
- with true <- String.starts_with?(url, "http"),
- {:ok, %{body: body, status: code}} when code in 200..299 <-
- HTTP.get(url, [{:Accept, "application/atom+xml"}]) do
- Logger.debug("Got document from #{url}, handling...")
- handle_incoming(body, options)
- else
- e ->
- Logger.debug("Couldn't get #{url}: #{inspect(e)}")
- e
- end
- end
-
- def fetch_activity_from_html_url(url, options \\ []) do
- Logger.debug("Trying to fetch #{url}")
-
- with true <- String.starts_with?(url, "http"),
- {:ok, %{body: body}} <- HTTP.get(url, []),
- {:ok, atom_url} <- get_atom_url(body) do
- fetch_activity_from_atom_url(atom_url, options)
- else
- e ->
- Logger.debug("Couldn't get #{url}: #{inspect(e)}")
- e
- end
- end
-
- def fetch_activity_from_url(url, options \\ []) do
- with {:ok, [_ | _] = activities} <- fetch_activity_from_atom_url(url, options) do
- {:ok, activities}
- else
- _e -> fetch_activity_from_html_url(url, options)
- end
- rescue
- e ->
- Logger.debug("Couldn't get #{url}: #{inspect(e)}")
- {:error, "Couldn't get #{url}: #{inspect(e)}"}
- end
-end
diff --git a/lib/pleroma/web/ostatus/ostatus_controller.ex b/lib/pleroma/web/ostatus/ostatus_controller.ex
index 7466dd8ea..6958519de 100644
--- a/lib/pleroma/web/ostatus/ostatus_controller.ex
+++ b/lib/pleroma/web/ostatus/ostatus_controller.ex
@@ -13,11 +13,8 @@ defmodule Pleroma.Web.OStatus.OStatusController do
alias Pleroma.Web.ActivityPub.ObjectView
alias Pleroma.Web.ActivityPub.Visibility
alias Pleroma.Web.Endpoint
- alias Pleroma.Web.Federator
alias Pleroma.Web.Metadata.PlayerView
- alias Pleroma.Web.OStatus.ActivityRepresenter
alias Pleroma.Web.Router
- alias Pleroma.Web.XML
plug(
Pleroma.Plugs.RateLimiter,
@@ -151,23 +148,10 @@ defmodule Pleroma.Web.OStatus.OStatusController do
|> render("object.json", %{object: object})
end
- defp represent_activity(_conn, "activity+json", _, _) do
+ defp represent_activity(_conn, _, _, _) do
{:error, :not_found}
end
- defp represent_activity(conn, _, activity, user) do
- response =
- activity
- |> ActivityRepresenter.to_simple_form(user, true)
- |> ActivityRepresenter.wrap_with_entry()
- |> :xmerl.export_simple(:xmerl_xml)
- |> to_string
-
- conn
- |> put_resp_content_type("application/atom+xml")
- |> send_resp(200, response)
- end
-
def errors(conn, {:error, :not_found}) do
render_error(conn, :not_found, "Not found")
end
diff --git a/lib/pleroma/web/ostatus/user_representer.ex b/lib/pleroma/web/ostatus/user_representer.ex
deleted file mode 100644
index 852be6eb4..000000000
--- a/lib/pleroma/web/ostatus/user_representer.ex
+++ /dev/null
@@ -1,41 +0,0 @@
-# Pleroma: A lightweight social networking server
-# Copyright © 2017-2019 Pleroma Authors
-# SPDX-License-Identifier: AGPL-3.0-only
-
-defmodule Pleroma.Web.OStatus.UserRepresenter do
- alias Pleroma.User
-
- def to_simple_form(user) do
- ap_id = to_charlist(user.ap_id)
- nickname = to_charlist(user.nickname)
- name = to_charlist(user.name)
- bio = to_charlist(user.bio)
- avatar_url = to_charlist(User.avatar_url(user))
-
- banner =
- if banner_url = User.banner_url(user) do
- [{:link, [rel: 'header', href: banner_url], []}]
- else
- []
- end
-
- ap_enabled =
- if user.local do
- [{:ap_enabled, ['true']}]
- else
- []
- end
-
- [
- {:id, [ap_id]},
- {:"activity:object", ['http://activitystrea.ms/schema/1.0/person']},
- {:uri, [ap_id]},
- {:"poco:preferredUsername", [nickname]},
- {:"poco:displayName", [name]},
- {:"poco:note", [bio]},
- {:summary, [bio]},
- {:name, [nickname]},
- {:link, [rel: 'avatar', href: avatar_url], []}
- ] ++ banner ++ ap_enabled
- end
-end
diff --git a/test/web/activity_pub/transmogrifier_test.exs b/test/web/activity_pub/transmogrifier_test.exs
index 7823ff041..252d98a7a 100644
--- a/test/web/activity_pub/transmogrifier_test.exs
+++ b/test/web/activity_pub/transmogrifier_test.exs
@@ -13,7 +13,6 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
alias Pleroma.Web.ActivityPub.ActivityPub
alias Pleroma.Web.ActivityPub.Transmogrifier
alias Pleroma.Web.CommonAPI
- alias Pleroma.Web.OStatus
import Mock
import Pleroma.Factory
@@ -1180,32 +1179,6 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
assert modified["object"]["actor"] == modified["object"]["attributedTo"]
end
- test "it translates ostatus IDs to external URLs" do
- incoming = File.read!("test/fixtures/incoming_note_activity.xml")
- {:ok, [referent_activity]} = OStatus.handle_incoming(incoming)
-
- user = insert(:user)
-
- {:ok, activity, _} = CommonAPI.favorite(referent_activity.id, user)
- {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
-
- assert modified["object"] == "http://gs.example.org:4040/index.php/notice/29"
- end
-
- test "it translates ostatus reply_to IDs to external URLs" do
- incoming = File.read!("test/fixtures/incoming_note_activity.xml")
- {:ok, [referred_activity]} = OStatus.handle_incoming(incoming)
-
- user = insert(:user)
-
- {:ok, activity} =
- CommonAPI.post(user, %{"status" => "HI!", "in_reply_to_status_id" => referred_activity.id})
-
- {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
-
- assert modified["object"]["inReplyTo"] == "http://gs.example.org:4040/index.php/notice/29"
- end
-
test "it strips internal hashtag data" do
user = insert(:user)
diff --git a/test/web/mastodon_api/controllers/timeline_controller_test.exs b/test/web/mastodon_api/controllers/timeline_controller_test.exs
index fc45c25de..61b6cea75 100644
--- a/test/web/mastodon_api/controllers/timeline_controller_test.exs
+++ b/test/web/mastodon_api/controllers/timeline_controller_test.exs
@@ -11,7 +11,6 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do
alias Pleroma.Config
alias Pleroma.User
alias Pleroma.Web.CommonAPI
- alias Pleroma.Web.OStatus
clear_config([:instance, :public])
@@ -75,8 +74,7 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do
{:ok, _activity} = CommonAPI.post(following, %{"status" => "test"})
- {:ok, [_activity]} =
- OStatus.fetch_activity_from_url("https://shitposter.club/notice/2827873")
+ _activity = insert(:note_activity, local: false)
conn = get(conn, "/api/v1/timelines/public", %{"local" => "False"})
@@ -271,9 +269,6 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do
{:ok, activity} = CommonAPI.post(following, %{"status" => "test #2hu"})
- {:ok, [_activity]} =
- OStatus.fetch_activity_from_url("https://shitposter.club/notice/2827873")
-
nconn = get(conn, "/api/v1/timelines/tag/2hu")
assert [%{"id" => id}] = json_response(nconn, :ok)
diff --git a/test/web/mastodon_api/views/status_view_test.exs b/test/web/mastodon_api/views/status_view_test.exs
index 1d5a6e956..9375c5030 100644
--- a/test/web/mastodon_api/views/status_view_test.exs
+++ b/test/web/mastodon_api/views/status_view_test.exs
@@ -14,7 +14,6 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
alias Pleroma.Web.CommonAPI.Utils
alias Pleroma.Web.MastodonAPI.AccountView
alias Pleroma.Web.MastodonAPI.StatusView
- alias Pleroma.Web.OStatus
import Pleroma.Factory
import Tesla.Mock
@@ -229,19 +228,20 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
assert status.in_reply_to_id == to_string(note.id)
end
- test "contains mentions" do
- incoming = File.read!("test/fixtures/incoming_reply_mastodon.xml")
- # a user with this ap id might be in the cache.
- recipient = "https://pleroma.soykaf.com/users/lain"
- user = insert(:user, %{ap_id: recipient})
-
- {:ok, [activity]} = OStatus.handle_incoming(incoming)
-
- status = StatusView.render("show.json", %{activity: activity})
-
- assert status.mentions ==
- Enum.map([user], fn u -> AccountView.render("mention.json", %{user: u}) end)
- end
+ # XXX: fix this test
+ # test "contains mentions" do
+ # incoming = File.read!("test/fixtures/incoming_reply_mastodon.xml")
+ # # a user with this ap id might be in the cache.
+ # recipient = "https://pleroma.soykaf.com/users/lain"
+ # user = insert(:user, %{ap_id: recipient})
+ #
+ # {:ok, [activity]} = OStatus.handle_incoming(incoming)
+ #
+ # status = StatusView.render("show.json", %{activity: activity})
+ #
+ # assert status.mentions ==
+ # Enum.map([user], fn u -> AccountView.render("mention.json", %{user: u}) end)
+ # end
test "create mentions from the 'to' field" do
%User{ap_id: recipient_ap_id} = insert(:user)
diff --git a/test/web/ostatus/activity_representer_test.exs b/test/web/ostatus/activity_representer_test.exs
deleted file mode 100644
index a8d500890..000000000
--- a/test/web/ostatus/activity_representer_test.exs
+++ /dev/null
@@ -1,300 +0,0 @@
-# Pleroma: A lightweight social networking server
-# Copyright © 2017-2019 Pleroma Authors
-# SPDX-License-Identifier: AGPL-3.0-only
-
-defmodule Pleroma.Web.OStatus.ActivityRepresenterTest do
- use Pleroma.DataCase
-
- alias Pleroma.Activity
- alias Pleroma.Object
- alias Pleroma.User
- alias Pleroma.Web.ActivityPub.ActivityPub
- alias Pleroma.Web.OStatus
- alias Pleroma.Web.OStatus.ActivityRepresenter
-
- import Pleroma.Factory
- import Tesla.Mock
-
- setup do
- mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
- :ok
- end
-
- test "an external note activity" do
- incoming = File.read!("test/fixtures/mastodon-note-cw.xml")
- {:ok, [activity]} = OStatus.handle_incoming(incoming)
-
- user = User.get_cached_by_ap_id(activity.data["actor"])
-
- tuple = ActivityRepresenter.to_simple_form(activity, user)
-
- res = :xmerl.export_simple_content(tuple, :xmerl_xml) |> IO.iodata_to_binary()
-
- assert String.contains?(
- res,
- ~s{}
- )
- end
-
- test "a note activity" do
- note_activity = insert(:note_activity)
- object_data = Object.normalize(note_activity).data
-
- user = User.get_cached_by_ap_id(note_activity.data["actor"])
-
- expected = """
- http://activitystrea.ms/schema/1.0/note
- http://activitystrea.ms/schema/1.0/post
- #{object_data["id"]}
-
New note by #{user.nickname}
- #{object_data["content"]}
- #{object_data["published"]}
- #{object_data["published"]}
- #{note_activity.data["context"]}
-
- #{object_data["summary"]}
-
-
-
-
-
- """
-
- tuple = ActivityRepresenter.to_simple_form(note_activity, user)
-
- res = :xmerl.export_simple_content(tuple, :xmerl_xml) |> IO.iodata_to_binary()
-
- assert clean(res) == clean(expected)
- end
-
- test "a reply note" do
- user = insert(:user)
- note_object = insert(:note)
- _note = insert(:note_activity, %{note: note_object})
- object = insert(:note, %{data: %{"inReplyTo" => note_object.data["id"]}})
- answer = insert(:note_activity, %{note: object})
-
- Repo.update!(
- Object.change(note_object, %{data: Map.put(note_object.data, "external_url", "someurl")})
- )
-
- expected = """
- http://activitystrea.ms/schema/1.0/note
- http://activitystrea.ms/schema/1.0/post
- #{object.data["id"]}
- New note by #{user.nickname}
- #{object.data["content"]}
- #{object.data["published"]}
- #{object.data["published"]}
- #{answer.data["context"]}
-
- 2hu
-
-
-
-
-
-
- """
-
- tuple = ActivityRepresenter.to_simple_form(answer, user)
-
- res = :xmerl.export_simple_content(tuple, :xmerl_xml) |> IO.iodata_to_binary()
-
- assert clean(res) == clean(expected)
- end
-
- test "an announce activity" do
- note = insert(:note_activity)
- user = insert(:user)
- object = Object.normalize(note)
-
- {:ok, announce, _object} = ActivityPub.announce(user, object)
-
- announce = Activity.get_by_id(announce.id)
-
- note_user = User.get_cached_by_ap_id(note.data["actor"])
- note = Activity.get_by_id(note.id)
-
- note_xml =
- ActivityRepresenter.to_simple_form(note, note_user, true)
- |> :xmerl.export_simple_content(:xmerl_xml)
- |> to_string
-
- expected = """
- http://activitystrea.ms/schema/1.0/activity
- http://activitystrea.ms/schema/1.0/share
- #{announce.data["id"]}
- #{user.nickname} repeated a notice
- RT #{object.data["content"]}
- #{announce.data["published"]}
- #{announce.data["published"]}
- #{announce.data["context"]}
-
-
-
- #{note_xml}
-
-
-
- """
-
- announce_xml =
- ActivityRepresenter.to_simple_form(announce, user)
- |> :xmerl.export_simple_content(:xmerl_xml)
- |> to_string
-
- assert clean(expected) == clean(announce_xml)
- end
-
- test "a like activity" do
- note = insert(:note)
- user = insert(:user)
- {:ok, like, _note} = ActivityPub.like(user, note)
-
- tuple = ActivityRepresenter.to_simple_form(like, user)
- refute is_nil(tuple)
-
- res = :xmerl.export_simple_content(tuple, :xmerl_xml) |> IO.iodata_to_binary()
-
- expected = """
- http://activitystrea.ms/schema/1.0/favorite
- #{like.data["id"]}
- New favorite by #{user.nickname}
- #{user.nickname} favorited something
- #{like.data["published"]}
- #{like.data["published"]}
-
- http://activitystrea.ms/schema/1.0/note
- #{note.data["id"]}
-
- #{like.data["context"]}
-
-
-
-
-
- """
-
- assert clean(res) == clean(expected)
- end
-
- test "a follow activity" do
- follower = insert(:user)
- followed = insert(:user)
-
- {:ok, activity} =
- ActivityPub.insert(%{
- "type" => "Follow",
- "actor" => follower.ap_id,
- "object" => followed.ap_id,
- "to" => [followed.ap_id]
- })
-
- tuple = ActivityRepresenter.to_simple_form(activity, follower)
-
- refute is_nil(tuple)
-
- res = :xmerl.export_simple_content(tuple, :xmerl_xml) |> IO.iodata_to_binary()
-
- expected = """
- http://activitystrea.ms/schema/1.0/activity
- http://activitystrea.ms/schema/1.0/follow
- #{activity.data["id"]}
- #{follower.nickname} started following #{activity.data["object"]}
- #{follower.nickname} started following #{activity.data["object"]}
- #{activity.data["published"]}
- #{activity.data["published"]}
-
- http://activitystrea.ms/schema/1.0/person
- #{activity.data["object"]}
- #{activity.data["object"]}
-
-
-
- """
-
- assert clean(res) == clean(expected)
- end
-
- test "an unfollow activity" do
- follower = insert(:user)
- followed = insert(:user)
- {:ok, _activity} = ActivityPub.follow(follower, followed)
- {:ok, activity} = ActivityPub.unfollow(follower, followed)
-
- tuple = ActivityRepresenter.to_simple_form(activity, follower)
-
- refute is_nil(tuple)
-
- res = :xmerl.export_simple_content(tuple, :xmerl_xml) |> IO.iodata_to_binary()
-
- expected = """
- http://activitystrea.ms/schema/1.0/activity
- http://activitystrea.ms/schema/1.0/unfollow
- #{activity.data["id"]}
- #{follower.nickname} stopped following #{followed.ap_id}
- #{follower.nickname} stopped following #{followed.ap_id}
- #{activity.data["published"]}
- #{activity.data["published"]}
-
- http://activitystrea.ms/schema/1.0/person
- #{followed.ap_id}
- #{followed.ap_id}
-
-
-
- """
-
- assert clean(res) == clean(expected)
- end
-
- test "a delete" do
- user = insert(:user)
-
- activity = %Activity{
- data: %{
- "id" => "ap_id",
- "type" => "Delete",
- "actor" => user.ap_id,
- "object" => "some_id",
- "published" => "2017-06-18T12:00:18+00:00"
- }
- }
-
- tuple = ActivityRepresenter.to_simple_form(activity, nil)
-
- refute is_nil(tuple)
-
- res = :xmerl.export_simple_content(tuple, :xmerl_xml) |> IO.iodata_to_binary()
-
- expected = """
- http://activitystrea.ms/schema/1.0/activity
- http://activitystrea.ms/schema/1.0/delete
- #{activity.data["object"]}
- An object was deleted
- An object was deleted
- #{activity.data["published"]}
- #{activity.data["published"]}
- """
-
- assert clean(res) == clean(expected)
- end
-
- test "an unknown activity" do
- tuple = ActivityRepresenter.to_simple_form(%Activity{}, nil)
- assert is_nil(tuple)
- end
-
- defp clean(string) do
- String.replace(string, ~r/\s/, "")
- end
-end
diff --git a/test/web/ostatus/feed_representer_test.exs b/test/web/ostatus/feed_representer_test.exs
deleted file mode 100644
index d1cadf1e4..000000000
--- a/test/web/ostatus/feed_representer_test.exs
+++ /dev/null
@@ -1,59 +0,0 @@
-# Pleroma: A lightweight social networking server
-# Copyright © 2017-2019 Pleroma Authors
-# SPDX-License-Identifier: AGPL-3.0-only
-
-defmodule Pleroma.Web.OStatus.FeedRepresenterTest do
- use Pleroma.DataCase
- import Pleroma.Factory
- alias Pleroma.User
- alias Pleroma.Web.OStatus
- alias Pleroma.Web.OStatus.ActivityRepresenter
- alias Pleroma.Web.OStatus.FeedRepresenter
- alias Pleroma.Web.OStatus.UserRepresenter
-
- test "returns a feed of the last 20 items of the user" do
- note_activity = insert(:note_activity)
- user = User.get_cached_by_ap_id(note_activity.data["actor"])
-
- tuple = FeedRepresenter.to_simple_form(user, [note_activity], [user])
-
- most_recent_update =
- note_activity.updated_at
- |> NaiveDateTime.to_iso8601()
-
- res = :xmerl.export_simple_content(tuple, :xmerl_xml) |> to_string
-
- user_xml =
- UserRepresenter.to_simple_form(user)
- |> :xmerl.export_simple_content(:xmerl_xml)
-
- entry_xml =
- ActivityRepresenter.to_simple_form(note_activity, user)
- |> :xmerl.export_simple_content(:xmerl_xml)
-
- expected = """
-
- #{OStatus.feed_path(user)}
- #{user.nickname}'s timeline
- #{most_recent_update}
- #{User.avatar_url(user)}
-
-
-
-
- #{user_xml}
-
-
-
- #{entry_xml}
-
-
- """
-
- assert clean(res) == clean(expected)
- end
-
- defp clean(string) do
- String.replace(string, ~r/\s/, "")
- end
-end
diff --git a/test/web/ostatus/incoming_documents/delete_handling_test.exs b/test/web/ostatus/incoming_documents/delete_handling_test.exs
deleted file mode 100644
index cd0447af7..000000000
--- a/test/web/ostatus/incoming_documents/delete_handling_test.exs
+++ /dev/null
@@ -1,48 +0,0 @@
-# Pleroma: A lightweight social networking server
-# Copyright © 2017-2019 Pleroma Authors
-# SPDX-License-Identifier: AGPL-3.0-only
-
-defmodule Pleroma.Web.OStatus.DeleteHandlingTest do
- use Pleroma.DataCase
-
- import Pleroma.Factory
- import Tesla.Mock
-
- alias Pleroma.Activity
- alias Pleroma.Object
- alias Pleroma.Web.OStatus
-
- setup do
- mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
- :ok
- end
-
- describe "deletions" do
- test "it removes the mentioned activity" do
- note = insert(:note_activity)
- second_note = insert(:note_activity)
- object = Object.normalize(note)
- second_object = Object.normalize(second_note)
- user = insert(:user)
-
- {:ok, like, _object} = Pleroma.Web.ActivityPub.ActivityPub.like(user, object)
-
- incoming =
- File.read!("test/fixtures/delete.xml")
- |> String.replace(
- "tag:mastodon.sdf.org,2017-06-10:objectId=310513:objectType=Status",
- object.data["id"]
- )
-
- {:ok, [delete]} = OStatus.handle_incoming(incoming)
-
- refute Activity.get_by_id(note.id)
- refute Activity.get_by_id(like.id)
- assert Object.get_by_ap_id(object.data["id"]).data["type"] == "Tombstone"
- assert Activity.get_by_id(second_note.id)
- assert Object.get_by_ap_id(second_object.data["id"])
-
- assert delete.data["type"] == "Delete"
- end
- end
-end
diff --git a/test/web/ostatus/ostatus_controller_test.exs b/test/web/ostatus/ostatus_controller_test.exs
index b1af918d8..29804cfe1 100644
--- a/test/web/ostatus/ostatus_controller_test.exs
+++ b/test/web/ostatus/ostatus_controller_test.exs
@@ -11,7 +11,6 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do
alias Pleroma.Object
alias Pleroma.User
alias Pleroma.Web.CommonAPI
- alias Pleroma.Web.OStatus.ActivityRepresenter
setup_all do
Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
@@ -73,27 +72,6 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do
end
describe "GET object/2" do
- test "gets an object", %{conn: conn} do
- note_activity = insert(:note_activity)
- object = Object.normalize(note_activity)
- user = User.get_cached_by_ap_id(note_activity.data["actor"])
- [_, uuid] = hd(Regex.scan(~r/.+\/([\w-]+)$/, object.data["id"]))
- url = "/objects/#{uuid}"
-
- conn =
- conn
- |> put_req_header("accept", "application/xml")
- |> get(url)
-
- expected =
- ActivityRepresenter.to_simple_form(note_activity, user, true)
- |> ActivityRepresenter.wrap_with_entry()
- |> :xmerl.export_simple(:xmerl_xml)
- |> to_string
-
- assert response(conn, 200) == expected
- end
-
test "redirects to /notice/id for html format", %{conn: conn} do
note_activity = insert(:note_activity)
object = Object.normalize(note_activity)
diff --git a/test/web/ostatus/ostatus_test.exs b/test/web/ostatus/ostatus_test.exs
deleted file mode 100644
index bbecba189..000000000
--- a/test/web/ostatus/ostatus_test.exs
+++ /dev/null
@@ -1,591 +0,0 @@
-# Pleroma: A lightweight social networking server
-# Copyright © 2017-2019 Pleroma Authors
-# SPDX-License-Identifier: AGPL-3.0-only
-
-defmodule Pleroma.Web.OStatusTest do
- use Pleroma.DataCase
- alias Pleroma.Activity
- alias Pleroma.Instances
- alias Pleroma.Object
- alias Pleroma.Repo
- alias Pleroma.User
- alias Pleroma.Web.OStatus
- alias Pleroma.Web.XML
-
- import ExUnit.CaptureLog
- import Mock
- import Pleroma.Factory
-
- setup_all do
- Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
- :ok
- end
-
- 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, [activity]} == OStatus.handle_incoming(incoming)
- end
-
- test "handle incoming note - GS, Salmon" do
- incoming = File.read!("test/fixtures/incoming_note_activity.xml")
- {:ok, [activity]} = OStatus.handle_incoming(incoming)
- object = Object.normalize(activity)
-
- user = User.get_cached_by_ap_id(activity.data["actor"])
- assert user.info.note_count == 1
- assert activity.data["type"] == "Create"
- assert object.data["type"] == "Note"
-
- assert object.data["id"] == "tag:gs.example.org:4040,2017-04-23:noticeId=29:objectType=note"
-
- assert activity.data["published"] == "2017-04-23T14:51:03+00:00"
- assert object.data["published"] == "2017-04-23T14:51:03+00:00"
-
- assert activity.data["context"] ==
- "tag:gs.example.org:4040,2017-04-23:objectType=thread:nonce=f09e22f58abd5c7b"
-
- assert "http://pleroma.example.org:4000/users/lain3" in activity.data["to"]
- assert object.data["emoji"] == %{"marko" => "marko.png", "reimu" => "reimu.png"}
- assert activity.local == false
- end
-
- test "handle incoming notes - GS, subscription" do
- incoming = File.read!("test/fixtures/ostatus_incoming_post.xml")
- {:ok, [activity]} = OStatus.handle_incoming(incoming)
- object = Object.normalize(activity)
-
- assert activity.data["type"] == "Create"
- assert object.data["type"] == "Note"
- assert object.data["actor"] == "https://social.heldscal.la/user/23211"
- assert object.data["content"] == "Will it blend?"
- user = User.get_cached_by_ap_id(activity.data["actor"])
- assert User.ap_followers(user) in activity.data["to"]
- assert "https://www.w3.org/ns/activitystreams#Public" in activity.data["to"]
- end
-
- test "handle incoming notes with tags" do
- incoming = File.read!("test/fixtures/ostatus_incoming_post_tag.xml")
- {:ok, [activity]} = OStatus.handle_incoming(incoming)
- object = Object.normalize(activity)
-
- assert object.data["tag"] == ["nsfw"]
- assert "https://www.w3.org/ns/activitystreams#Public" in activity.data["to"]
- 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)
- object = Object.normalize(activity)
-
- assert activity.data["type"] == "Create"
- assert object.data["type"] == "Note"
- assert object.data["actor"] == "https://mastodon.social/users/lambadalambda"
- assert activity.data["context"] == "2hu"
- assert "https://www.w3.org/ns/activitystreams#Public" in activity.data["to"]
- end
-
- test "handle incoming notes - Mastodon, with CW" do
- incoming = File.read!("test/fixtures/mastodon-note-cw.xml")
- {:ok, [activity]} = OStatus.handle_incoming(incoming)
- object = Object.normalize(activity)
-
- assert activity.data["type"] == "Create"
- assert object.data["type"] == "Note"
- assert object.data["actor"] == "https://mastodon.social/users/lambadalambda"
- assert object.data["summary"] == "technologic"
- assert "https://www.w3.org/ns/activitystreams#Public" in activity.data["to"]
- end
-
- test "handle incoming unlisted messages, put public into cc" do
- incoming = File.read!("test/fixtures/mastodon-note-unlisted.xml")
- {:ok, [activity]} = OStatus.handle_incoming(incoming)
- object = Object.normalize(activity)
-
- refute "https://www.w3.org/ns/activitystreams#Public" in activity.data["to"]
- assert "https://www.w3.org/ns/activitystreams#Public" in activity.data["cc"]
- refute "https://www.w3.org/ns/activitystreams#Public" in object.data["to"]
- assert "https://www.w3.org/ns/activitystreams#Public" in object.data["cc"]
- 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)
- retweeted_object = Object.normalize(retweeted_activity)
-
- assert retweeted_object.data["summary"] == "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)
- object = Object.normalize(activity)
-
- assert activity.data["type"] == "Create"
- assert object.data["type"] == "Note"
- assert object.data["actor"] == "https://social.heldscal.la/user/23211"
-
- assert object.data["content"] ==
- "@shpbot why not indeed."
-
- assert object.data["inReplyTo"] ==
- "tag:gs.archae.me,2017-04-30:noticeId=778260:objectType=note"
-
- assert "https://www.w3.org/ns/activitystreams#Public" in activity.data["to"]
- end
-
- test "handle incoming retweets - GS, subscription" do
- incoming = File.read!("test/fixtures/share-gs.xml")
- {:ok, [[activity, retweeted_activity]]} = OStatus.handle_incoming(incoming)
-
- assert activity.data["type"] == "Announce"
- assert activity.data["actor"] == "https://social.heldscal.la/user/23211"
- assert activity.data["object"] == retweeted_activity.data["object"]
- assert "https://pleroma.soykaf.com/users/lain" in activity.data["to"]
- refute activity.local
-
- retweeted_activity = Activity.get_by_id(retweeted_activity.id)
- retweeted_object = Object.normalize(retweeted_activity)
- assert retweeted_activity.data["type"] == "Create"
- assert retweeted_activity.data["actor"] == "https://pleroma.soykaf.com/users/lain"
- refute retweeted_activity.local
- assert retweeted_object.data["announcement_count"] == 1
- assert String.contains?(retweeted_object.data["content"], "mastodon")
- refute String.contains?(retweeted_object.data["content"], "Test account")
- end
-
- test "handle incoming retweets - GS, subscription - local message" do
- incoming = File.read!("test/fixtures/share-gs-local.xml")
- note_activity = insert(:note_activity)
- object = Object.normalize(note_activity)
- user = User.get_cached_by_ap_id(note_activity.data["actor"])
-
- incoming =
- incoming
- |> String.replace("LOCAL_ID", object.data["id"])
- |> String.replace("LOCAL_USER", user.ap_id)
-
- {:ok, [[activity, retweeted_activity]]} = OStatus.handle_incoming(incoming)
-
- assert activity.data["type"] == "Announce"
- assert activity.data["actor"] == "https://social.heldscal.la/user/23211"
- assert activity.data["object"] == object.data["id"]
- assert user.ap_id in activity.data["to"]
- refute activity.local
-
- retweeted_activity = Activity.get_by_id(retweeted_activity.id)
- assert note_activity.id == retweeted_activity.id
- assert retweeted_activity.data["type"] == "Create"
- assert retweeted_activity.data["actor"] == user.ap_id
- assert retweeted_activity.local
- assert Object.normalize(retweeted_activity).data["announcement_count"] == 1
- end
-
- test "handle incoming retweets - Mastodon, salmon" do
- incoming = File.read!("test/fixtures/share.xml")
- {:ok, [[activity, retweeted_activity]]} = OStatus.handle_incoming(incoming)
- retweeted_object = Object.normalize(retweeted_activity)
-
- assert activity.data["type"] == "Announce"
- assert activity.data["actor"] == "https://mastodon.social/users/lambadalambda"
- assert activity.data["object"] == retweeted_activity.data["object"]
-
- assert activity.data["id"] ==
- "tag:mastodon.social,2017-05-03:objectId=4934452:objectType=Status"
-
- refute activity.local
- 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_object.data["content"], "Test account")
- end
-
- test "handle conversation references" do
- incoming = File.read!("test/fixtures/mastodon_conversation.xml")
- {:ok, [activity]} = OStatus.handle_incoming(incoming)
-
- assert activity.data["context"] ==
- "tag:mastodon.social,2017-08-28:objectId=7876885:objectType=Conversation"
- end
-
- test_with_mock "handle incoming replies, fetching replied-to activities if we don't have them",
- OStatus,
- [:passthrough],
- [] do
- incoming = File.read!("test/fixtures/incoming_note_activity_answer.xml")
- {:ok, [activity]} = OStatus.handle_incoming(incoming)
- object = Object.normalize(activity, false)
-
- assert activity.data["type"] == "Create"
- assert object.data["type"] == "Note"
-
- assert object.data["inReplyTo"] ==
- "http://pleroma.example.org:4000/objects/55bce8fc-b423-46b1-af71-3759ab4670bc"
-
- assert "http://pleroma.example.org:4000/users/lain5" in activity.data["to"]
-
- assert object.data["id"] == "tag:gs.example.org:4040,2017-04-25:noticeId=55:objectType=note"
-
- assert "https://www.w3.org/ns/activitystreams#Public" in activity.data["to"]
-
- assert called(OStatus.fetch_activity_from_url(object.data["inReplyTo"], :_))
- end
-
- test_with_mock "handle incoming replies, not fetching replied-to activities beyond max_replies_depth",
- OStatus,
- [:passthrough],
- [] do
- incoming = File.read!("test/fixtures/incoming_note_activity_answer.xml")
-
- with_mock Pleroma.Web.Federator,
- allowed_incoming_reply_depth?: fn _ -> false end do
- {:ok, [activity]} = OStatus.handle_incoming(incoming)
- object = Object.normalize(activity, false)
-
- refute called(OStatus.fetch_activity_from_url(object.data["inReplyTo"], :_))
- end
- end
-
- test "handle incoming follows" do
- incoming = File.read!("test/fixtures/follow.xml")
- {:ok, [activity]} = OStatus.handle_incoming(incoming)
- assert activity.data["type"] == "Follow"
-
- assert activity.data["id"] ==
- "tag:social.heldscal.la,2017-05-07:subscription:23211:person:44803:2017-05-07T09:54:48+00:00"
-
- assert activity.data["actor"] == "https://social.heldscal.la/user/23211"
- 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"])
-
- assert User.following?(follower, followed)
- end
-
- test "refuse following over OStatus if the followed's account is locked" do
- incoming = File.read!("test/fixtures/follow.xml")
- _user = insert(:user, info: %{locked: true}, ap_id: "https://pawoo.net/users/pekorino")
-
- {:ok, [{:error, "It's not possible to follow locked accounts over OStatus"}]} =
- OStatus.handle_incoming(incoming)
- end
-
- test "handle incoming unfollows with existing follow" do
- incoming_follow = File.read!("test/fixtures/follow.xml")
- {:ok, [_activity]} = OStatus.handle_incoming(incoming_follow)
-
- incoming = File.read!("test/fixtures/unfollow.xml")
- {:ok, [activity]} = OStatus.handle_incoming(incoming)
-
- assert activity.data["type"] == "Undo"
-
- assert activity.data["id"] ==
- "undo:tag:social.heldscal.la,2017-05-07:subscription:23211:person:44803:2017-05-07T09:54:48+00:00"
-
- assert activity.data["actor"] == "https://social.heldscal.la/user/23211"
- embedded_object = activity.data["object"]
- assert is_map(embedded_object)
- assert embedded_object["type"] == "Follow"
- assert embedded_object["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(embedded_object["object"])
-
- refute User.following?(follower, followed)
- end
-
- test "it clears `unreachable` federation status of the sender" do
- incoming_reaction_xml = File.read!("test/fixtures/share-gs.xml")
- doc = XML.parse_document(incoming_reaction_xml)
- actor_uri = XML.string_from_xpath("//author/uri[1]", doc)
- reacted_to_author_uri = XML.string_from_xpath("//author/uri[2]", doc)
-
- Instances.set_consistently_unreachable(actor_uri)
- Instances.set_consistently_unreachable(reacted_to_author_uri)
- refute Instances.reachable?(actor_uri)
- refute Instances.reachable?(reacted_to_author_uri)
-
- {:ok, _} = OStatus.handle_incoming(incoming_reaction_xml)
- assert Instances.reachable?(actor_uri)
- refute Instances.reachable?(reacted_to_author_uri)
- end
-
- describe "new remote user creation" do
- test "returns local users" do
- local_user = insert(:user)
- {:ok, user} = OStatus.find_or_make_user(local_user.ap_id)
-
- assert user == local_user
- end
-
- test "tries to use the information in poco fields" do
- uri = "https://social.heldscal.la/user/23211"
-
- {:ok, user} = OStatus.find_or_make_user(uri)
-
- user = User.get_cached_by_id(user.id)
- assert user.name == "Constance Variable"
- assert user.nickname == "lambadalambda@social.heldscal.la"
- assert user.local == false
- assert user.info.uri == uri
- assert user.ap_id == uri
- assert user.bio == "Call me Deacon Blues."
- assert user.avatar["type"] == "Image"
-
- {:ok, user_again} = OStatus.find_or_make_user(uri)
-
- assert user == user_again
- end
-
- test "find_or_make_user sets all the nessary input fields" do
- uri = "https://social.heldscal.la/user/23211"
- {:ok, user} = OStatus.find_or_make_user(uri)
-
- assert user.info ==
- %User.Info{
- id: user.info.id,
- ap_enabled: false,
- background: %{},
- banner: %{},
- blocks: [],
- deactivated: false,
- default_scope: "public",
- domain_blocks: [],
- follower_count: 0,
- is_admin: false,
- is_moderator: false,
- keys: nil,
- locked: false,
- no_rich_text: false,
- note_count: 0,
- settings: nil,
- source_data: %{},
- hub: "https://social.heldscal.la/main/push/hub",
- magic_key:
- "RSA.uzg6r1peZU0vXGADWxGJ0PE34WvmhjUmydbX5YYdOiXfODVLwCMi1umGoqUDm-mRu4vNEdFBVJU1CpFA7dKzWgIsqsa501i2XqElmEveXRLvNRWFB6nG03Q5OUY2as8eE54BJm0p20GkMfIJGwP6TSFb-ICp3QjzbatuSPJ6xCE=.AQAB",
- salmon: "https://social.heldscal.la/main/salmon/user/23211",
- topic: "https://social.heldscal.la/api/statuses/user_timeline/23211.atom",
- uri: "https://social.heldscal.la/user/23211"
- }
- end
-
- test "find_make_or_update_actor takes an author element and returns an updated user" do
- uri = "https://social.heldscal.la/user/23211"
-
- {:ok, user} = OStatus.find_or_make_user(uri)
- old_name = user.name
- old_bio = user.bio
- change = Ecto.Changeset.change(user, %{avatar: nil, bio: nil, name: nil})
-
- {:ok, user} = Repo.update(change)
- refute user.avatar
-
- doc = XML.parse_document(File.read!("test/fixtures/23211.atom"))
- [author] = :xmerl_xpath.string('//author[1]', doc)
- {:ok, user} = OStatus.find_make_or_update_actor(author)
- assert user.avatar["type"] == "Image"
- assert user.name == old_name
- assert user.bio == old_bio
-
- {:ok, user_again} = OStatus.find_make_or_update_actor(author)
- assert user_again == user
- end
-
- test "find_or_make_user disallows protocol downgrade" do
- user = insert(:user, %{local: true})
- {:ok, user} = OStatus.find_or_make_user(user.ap_id)
-
- assert User.ap_enabled?(user)
-
- user =
- insert(:user, %{
- ap_id: "https://social.heldscal.la/user/23211",
- info: %{ap_enabled: true},
- local: false
- })
-
- assert User.ap_enabled?(user)
-
- {:ok, user} = OStatus.find_or_make_user(user.ap_id)
- assert User.ap_enabled?(user)
- end
-
- test "find_make_or_update_actor disallows protocol downgrade" do
- user = insert(:user, %{local: true})
- {:ok, user} = OStatus.find_or_make_user(user.ap_id)
-
- assert User.ap_enabled?(user)
-
- user =
- insert(:user, %{
- ap_id: "https://social.heldscal.la/user/23211",
- info: %{ap_enabled: true},
- local: false
- })
-
- assert User.ap_enabled?(user)
-
- {:ok, user} = OStatus.find_or_make_user(user.ap_id)
- assert User.ap_enabled?(user)
-
- doc = XML.parse_document(File.read!("test/fixtures/23211.atom"))
- [author] = :xmerl_xpath.string('//author[1]', doc)
- {:error, :invalid_protocol} = OStatus.find_make_or_update_actor(author)
- end
- end
-
- describe "gathering user info from a user id" do
- test "it returns user info in a hash" do
- user = "shp@social.heldscal.la"
-
- # TODO: make test local
- {:ok, data} = OStatus.gather_user_info(user)
-
- expected = %{
- "hub" => "https://social.heldscal.la/main/push/hub",
- "magic_key" =>
- "RSA.wQ3i9UA0qmAxZ0WTIp4a-waZn_17Ez1pEEmqmqoooRsG1_BvpmOvLN0G2tEcWWxl2KOtdQMCiPptmQObeZeuj48mdsDZ4ArQinexY2hCCTcbV8Xpswpkb8K05RcKipdg07pnI7tAgQ0VWSZDImncL6YUGlG5YN8b5TjGOwk2VG8=.AQAB",
- "name" => "shp",
- "nickname" => "shp",
- "salmon" => "https://social.heldscal.la/main/salmon/user/29191",
- "subject" => "acct:shp@social.heldscal.la",
- "topic" => "https://social.heldscal.la/api/statuses/user_timeline/29191.atom",
- "uri" => "https://social.heldscal.la/user/29191",
- "host" => "social.heldscal.la",
- "fqn" => user,
- "bio" => "cofe",
- "avatar" => %{
- "type" => "Image",
- "url" => [
- %{
- "href" => "https://social.heldscal.la/avatar/29191-original-20170421154949.jpeg",
- "mediaType" => "image/jpeg",
- "type" => "Link"
- }
- ]
- },
- "subscribe_address" => "https://social.heldscal.la/main/ostatussub?profile={uri}",
- "ap_id" => nil
- }
-
- assert data == expected
- end
-
- test "it works with the uri" do
- user = "https://social.heldscal.la/user/29191"
-
- # TODO: make test local
- {:ok, data} = OStatus.gather_user_info(user)
-
- expected = %{
- "hub" => "https://social.heldscal.la/main/push/hub",
- "magic_key" =>
- "RSA.wQ3i9UA0qmAxZ0WTIp4a-waZn_17Ez1pEEmqmqoooRsG1_BvpmOvLN0G2tEcWWxl2KOtdQMCiPptmQObeZeuj48mdsDZ4ArQinexY2hCCTcbV8Xpswpkb8K05RcKipdg07pnI7tAgQ0VWSZDImncL6YUGlG5YN8b5TjGOwk2VG8=.AQAB",
- "name" => "shp",
- "nickname" => "shp",
- "salmon" => "https://social.heldscal.la/main/salmon/user/29191",
- "subject" => "https://social.heldscal.la/user/29191",
- "topic" => "https://social.heldscal.la/api/statuses/user_timeline/29191.atom",
- "uri" => "https://social.heldscal.la/user/29191",
- "host" => "social.heldscal.la",
- "fqn" => user,
- "bio" => "cofe",
- "avatar" => %{
- "type" => "Image",
- "url" => [
- %{
- "href" => "https://social.heldscal.la/avatar/29191-original-20170421154949.jpeg",
- "mediaType" => "image/jpeg",
- "type" => "Link"
- }
- ]
- },
- "subscribe_address" => "https://social.heldscal.la/main/ostatussub?profile={uri}",
- "ap_id" => nil
- }
-
- 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
- capture_log(fn ->
- url = "https://shitposter.club/notice/2827873"
- {:ok, [activity]} = OStatus.fetch_activity_from_url(url)
-
- assert activity.data["actor"] == "https://shitposter.club/user/1"
-
- assert activity.data["object"] ==
- "tag:shitposter.club,2017-05-05:noticeId=2827873:objectType=comment"
- end)
- end
-
- test "it works for atom notes, too" do
- url = "https://social.sakamoto.gq/objects/0ccc1a2c-66b0-4305-b23a-7f7f2b040056"
- {:ok, [activity]} = OStatus.fetch_activity_from_url(url)
- assert activity.data["actor"] == "https://social.sakamoto.gq/users/eal"
- assert activity.data["object"] == url
- end
- end
-
- test "it doesn't add nil in the to field" do
- incoming = File.read!("test/fixtures/nil_mention_entry.xml")
- {:ok, [activity]} = OStatus.handle_incoming(incoming)
-
- assert activity.data["to"] == [
- "http://localhost:4001/users/atarifrosch@social.stopwatchingus-heidelberg.de/followers",
- "https://www.w3.org/ns/activitystreams#Public"
- ]
- end
-
- describe "is_representable?" do
- test "Note objects are representable" do
- note_activity = insert(:note_activity)
-
- assert OStatus.is_representable?(note_activity)
- end
-
- test "Article objects are not representable" do
- note_activity = insert(:note_activity)
- note_object = Object.normalize(note_activity)
-
- note_data =
- note_object.data
- |> Map.put("type", "Article")
-
- Cachex.clear(:object_cache)
-
- cs = Object.change(note_object, %{data: note_data})
- {:ok, _article_object} = Repo.update(cs)
-
- # the underlying object is now an Article instead of a note, so this should fail
- refute OStatus.is_representable?(note_activity)
- end
- end
-
- describe "make_user/2" do
- test "creates new user" do
- {:ok, user} = OStatus.make_user("https://social.heldscal.la/user/23211")
-
- created_user =
- User
- |> Repo.get_by(ap_id: "https://social.heldscal.la/user/23211")
- |> Map.put(:last_digest_emailed_at, nil)
-
- assert user.info
- assert user == created_user
- end
- end
-end
diff --git a/test/web/ostatus/user_representer_test.exs b/test/web/ostatus/user_representer_test.exs
deleted file mode 100644
index e3863d2e9..000000000
--- a/test/web/ostatus/user_representer_test.exs
+++ /dev/null
@@ -1,38 +0,0 @@
-# Pleroma: A lightweight social networking server
-# Copyright © 2017-2018 Pleroma Authors
-# SPDX-License-Identifier: AGPL-3.0-only
-
-defmodule Pleroma.Web.OStatus.UserRepresenterTest do
- use Pleroma.DataCase
- alias Pleroma.Web.OStatus.UserRepresenter
-
- import Pleroma.Factory
- alias Pleroma.User
-
- test "returns a user with id, uri, name and link" do
- user = insert(:user, %{nickname: "レイン"})
- tuple = UserRepresenter.to_simple_form(user)
-
- res = :xmerl.export_simple_content(tuple, :xmerl_xml) |> to_string
-
- expected = """
- #{user.ap_id}
- http://activitystrea.ms/schema/1.0/person
- #{user.ap_id}
- #{user.nickname}
- #{user.name}
- #{user.bio}
- #{user.bio}
- #{user.nickname}
-
-
- true
- """
-
- assert clean(res) == clean(expected)
- end
-
- defp clean(string) do
- String.replace(string, ~r/\s/, "")
- end
-end
diff --git a/test/web/web_finger/web_finger_test.exs b/test/web/web_finger/web_finger_test.exs
index 696c1bd70..5aa8c73cf 100644
--- a/test/web/web_finger/web_finger_test.exs
+++ b/test/web/web_finger/web_finger_test.exs
@@ -45,19 +45,6 @@ defmodule Pleroma.Web.WebFingerTest do
assert {:error, %Jason.DecodeError{}} = WebFinger.finger(user)
end
- test "returns the info for an OStatus user" do
- user = "shp@social.heldscal.la"
-
- {:ok, data} = WebFinger.finger(user)
-
- assert data["magic_key"] ==
- "RSA.wQ3i9UA0qmAxZ0WTIp4a-waZn_17Ez1pEEmqmqoooRsG1_BvpmOvLN0G2tEcWWxl2KOtdQMCiPptmQObeZeuj48mdsDZ4ArQinexY2hCCTcbV8Xpswpkb8K05RcKipdg07pnI7tAgQ0VWSZDImncL6YUGlG5YN8b5TjGOwk2VG8=.AQAB"
-
- assert data["topic"] == "https://social.heldscal.la/api/statuses/user_timeline/29191.atom"
- assert data["subject"] == "acct:shp@social.heldscal.la"
- assert data["salmon"] == "https://social.heldscal.la/main/salmon/user/29191"
- end
-
test "returns the ActivityPub actor URI for an ActivityPub user" do
user = "framasoft@framatube.org"
@@ -72,20 +59,6 @@ defmodule Pleroma.Web.WebFingerTest do
assert data["ap_id"] == "https://gerzilla.de/channel/kaniini"
end
- test "returns the correctly for json ostatus users" do
- user = "winterdienst@gnusocial.de"
-
- {:ok, data} = WebFinger.finger(user)
-
- assert data["magic_key"] ==
- "RSA.qfYaxztz7ZELrE4v5WpJrPM99SKI3iv9Y3Tw6nfLGk-4CRljNYqV8IYX2FXjeucC_DKhPNnlF6fXyASpcSmA_qupX9WC66eVhFhZ5OuyBOeLvJ1C4x7Hi7Di8MNBxY3VdQuQR0tTaS_YAZCwASKp7H6XEid3EJpGt0EQZoNzRd8=.AQAB"
-
- assert data["topic"] == "https://gnusocial.de/api/statuses/user_timeline/249296.atom"
- assert data["subject"] == "acct:winterdienst@gnusocial.de"
- assert data["salmon"] == "https://gnusocial.de/main/salmon/user/249296"
- assert data["subscribe_address"] == "https://gnusocial.de/main/ostatussub?profile={uri}"
- end
-
test "it work for AP-only user" do
user = "kpherox@mstdn.jp"