aboutsummaryrefslogtreecommitdiff
path: root/lib/pleroma/web
diff options
context:
space:
mode:
authorMaksim Pechnikov <parallel588@gmail.com>2019-12-05 15:46:27 +0300
committerMaksim Pechnikov <parallel588@gmail.com>2019-12-05 15:46:27 +0300
commit3fe7a1fd35a9ca81b158eff6dbcc25ca48cbf96d (patch)
tree9a275a71ab8eeb19ce1e02d0b6ba64fe309f3d79 /lib/pleroma/web
parenta36607c27e6a50aeca450570f7b8e4c9c0233bb1 (diff)
parent228bf4d214abe3bb62c52128d3bc145e396b174d (diff)
downloadpleroma-3fe7a1fd35a9ca81b158eff6dbcc25ca48cbf96d.tar.gz
Merge branch 'develop' into issue/1342
Diffstat (limited to 'lib/pleroma/web')
-rw-r--r--lib/pleroma/web/activity_pub/activity_pub.ex37
-rw-r--r--lib/pleroma/web/activity_pub/transmogrifier.ex20
-rw-r--r--lib/pleroma/web/activity_pub/visibility.ex1
-rw-r--r--lib/pleroma/web/common_api/utils.ex13
-rw-r--r--lib/pleroma/web/mastodon_api/controllers/account_controller.ex1
-rw-r--r--lib/pleroma/web/mastodon_api/views/account_view.ex7
-rw-r--r--lib/pleroma/web/mastodon_api/views/notification_view.ex38
-rw-r--r--lib/pleroma/web/push/impl.ex2
8 files changed, 89 insertions, 30 deletions
diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex
index f25314ff6..d6a425d8b 100644
--- a/lib/pleroma/web/activity_pub/activity_pub.ex
+++ b/lib/pleroma/web/activity_pub/activity_pub.ex
@@ -541,6 +541,30 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
end
end
+ def move(%User{} = origin, %User{} = target, local \\ true) do
+ params = %{
+ "type" => "Move",
+ "actor" => origin.ap_id,
+ "object" => origin.ap_id,
+ "target" => target.ap_id
+ }
+
+ with true <- origin.ap_id in target.also_known_as,
+ {:ok, activity} <- insert(params, local) do
+ maybe_federate(activity)
+
+ BackgroundWorker.enqueue("move_following", %{
+ "origin_id" => origin.id,
+ "target_id" => target.id
+ })
+
+ {:ok, activity}
+ else
+ false -> {:error, "Target account must have the origin in `alsoKnownAs`"}
+ err -> err
+ end
+ end
+
defp fetch_activities_for_context_query(context, opts) do
public = [Pleroma.Constants.as_public()]
@@ -1171,7 +1195,8 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
name: data["name"],
follower_address: data["followers"],
following_address: data["following"],
- bio: data["summary"]
+ bio: data["summary"],
+ also_known_as: Map.get(data, "alsoKnownAs", [])
}
# nickname can be nil because of virtual actors
@@ -1233,13 +1258,13 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
end
end
- defp collection_private(data) do
- if is_map(data["first"]) and
- data["first"]["type"] in ["CollectionPage", "OrderedCollectionPage"] do
+ defp collection_private(%{"first" => first}) do
+ if is_map(first) and
+ first["type"] in ["CollectionPage", "OrderedCollectionPage"] do
{:ok, false}
else
with {:ok, %{"type" => type}} when type in ["CollectionPage", "OrderedCollectionPage"] <-
- Fetcher.fetch_and_contain_remote_object_from_id(data["first"]) do
+ Fetcher.fetch_and_contain_remote_object_from_id(first) do
{:ok, false}
else
{:error, {:ok, %{status: code}}} when code in [401, 403] ->
@@ -1254,6 +1279,8 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
end
end
+ defp collection_private(_data), do: {:ok, true}
+
def user_data_from_user_object(data) do
with {:ok, data} <- MRF.filter(data),
{:ok, data} <- object_to_user_data(data) do
diff --git a/lib/pleroma/web/activity_pub/transmogrifier.ex b/lib/pleroma/web/activity_pub/transmogrifier.ex
index 15612545b..ce95fb6ba 100644
--- a/lib/pleroma/web/activity_pub/transmogrifier.ex
+++ b/lib/pleroma/web/activity_pub/transmogrifier.ex
@@ -669,7 +669,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
update_data =
new_user_data
- |> Map.take([:avatar, :banner, :bio, :name])
+ |> Map.take([:avatar, :banner, :bio, :name, :also_known_as])
|> Map.put(:fields, fields)
|> Map.put(:locked, locked)
|> Map.put(:invisible, invisible)
@@ -857,6 +857,24 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
end
end
+ def handle_incoming(
+ %{
+ "type" => "Move",
+ "actor" => origin_actor,
+ "object" => origin_actor,
+ "target" => target_actor
+ },
+ _options
+ ) do
+ with %User{} = origin_user <- User.get_cached_by_ap_id(origin_actor),
+ {:ok, %User{} = target_user} <- User.get_or_fetch_by_ap_id(target_actor),
+ true <- origin_actor in target_user.also_known_as do
+ ActivityPub.move(origin_user, target_user, false)
+ else
+ _e -> :error
+ end
+ end
+
def handle_incoming(_, _), do: :error
@spec get_obj_helper(String.t(), Keyword.t()) :: {:ok, Object.t()} | nil
diff --git a/lib/pleroma/web/activity_pub/visibility.ex b/lib/pleroma/web/activity_pub/visibility.ex
index cd4097493..e172f6d3f 100644
--- a/lib/pleroma/web/activity_pub/visibility.ex
+++ b/lib/pleroma/web/activity_pub/visibility.ex
@@ -14,6 +14,7 @@ defmodule Pleroma.Web.ActivityPub.Visibility do
@spec is_public?(Object.t() | Activity.t() | map()) :: boolean()
def is_public?(%Object{data: %{"type" => "Tombstone"}}), do: false
def is_public?(%Object{data: data}), do: is_public?(data)
+ def is_public?(%Activity{data: %{"type" => "Move"}}), do: true
def is_public?(%Activity{data: data}), do: is_public?(data)
def is_public?(%{"directMessage" => true}), do: false
def is_public?(data), do: Utils.label_in_message?(Pleroma.Constants.as_public(), data)
diff --git a/lib/pleroma/web/common_api/utils.ex b/lib/pleroma/web/common_api/utils.ex
index 88a5f434a..cbb64f8d2 100644
--- a/lib/pleroma/web/common_api/utils.ex
+++ b/lib/pleroma/web/common_api/utils.ex
@@ -451,6 +451,8 @@ defmodule Pleroma.Web.CommonAPI.Utils do
recipients ++ to
end
+ def maybe_notify_to_recipients(recipients, _), do: recipients
+
def maybe_notify_mentioned_recipients(
recipients,
%Activity{data: %{"to" => _to, "type" => type} = data} = activity
@@ -502,6 +504,17 @@ defmodule Pleroma.Web.CommonAPI.Utils do
def maybe_notify_subscribers(recipients, _), do: recipients
+ def maybe_notify_followers(recipients, %Activity{data: %{"type" => "Move"}} = activity) do
+ with %User{} = user <- User.get_cached_by_ap_id(activity.actor) do
+ user
+ |> User.get_followers()
+ |> Enum.map(& &1.ap_id)
+ |> Enum.concat(recipients)
+ end
+ end
+
+ def maybe_notify_followers(recipients, _), do: recipients
+
def maybe_extract_mentions(%{"tag" => tag}) do
tag
|> Enum.filter(fn x -> is_map(x) && x["type"] == "Mention" end)
diff --git a/lib/pleroma/web/mastodon_api/controllers/account_controller.ex b/lib/pleroma/web/mastodon_api/controllers/account_controller.ex
index 5f2544640..a69423f60 100644
--- a/lib/pleroma/web/mastodon_api/controllers/account_controller.ex
+++ b/lib/pleroma/web/mastodon_api/controllers/account_controller.ex
@@ -152,6 +152,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountController do
:hide_favorites,
:show_role,
:skip_thread_containment,
+ :allow_following_move,
:discoverable
]
|> Enum.reduce(%{}, fn key, acc ->
diff --git a/lib/pleroma/web/mastodon_api/views/account_view.ex b/lib/pleroma/web/mastodon_api/views/account_view.ex
index 1068f8823..ec720e472 100644
--- a/lib/pleroma/web/mastodon_api/views/account_view.ex
+++ b/lib/pleroma/web/mastodon_api/views/account_view.ex
@@ -162,6 +162,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
|> maybe_put_chat_token(user, opts[:for], opts)
|> maybe_put_activation_status(user, opts[:for])
|> maybe_put_follow_requests_count(user, opts[:for])
+ |> maybe_put_allow_following_move(user, opts[:for])
|> maybe_put_unread_conversation_count(user, opts[:for])
end
@@ -238,6 +239,12 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
defp maybe_put_notification_settings(data, _, _), do: data
+ defp maybe_put_allow_following_move(data, %User{id: user_id} = user, %User{id: user_id}) do
+ Kernel.put_in(data, [:pleroma, :allow_following_move], user.allow_following_move)
+ end
+
+ defp maybe_put_allow_following_move(data, _, _), do: data
+
defp maybe_put_activation_status(data, user, %User{is_admin: true}) do
Kernel.put_in(data, [:pleroma, :deactivated], user.deactivated)
end
diff --git a/lib/pleroma/web/mastodon_api/views/notification_view.ex b/lib/pleroma/web/mastodon_api/views/notification_view.ex
index 5e3dbe728..ddd7f5318 100644
--- a/lib/pleroma/web/mastodon_api/views/notification_view.ex
+++ b/lib/pleroma/web/mastodon_api/views/notification_view.ex
@@ -37,32 +37,24 @@ defmodule Pleroma.Web.MastodonAPI.NotificationView do
}
case mastodon_type do
- "mention" ->
- response
- |> Map.merge(%{
- status: StatusView.render("show.json", %{activity: activity, for: user})
- })
-
- "favourite" ->
- response
- |> Map.merge(%{
- status: StatusView.render("show.json", %{activity: parent_activity, for: user})
- })
-
- "reblog" ->
- response
- |> Map.merge(%{
- status: StatusView.render("show.json", %{activity: parent_activity, for: user})
- })
-
- "follow" ->
- response
-
- _ ->
- nil
+ "mention" -> put_status(response, activity, user)
+ "favourite" -> put_status(response, parent_activity, user)
+ "reblog" -> put_status(response, parent_activity, user)
+ "move" -> put_target(response, activity, user)
+ "follow" -> response
+ _ -> nil
end
else
_ -> nil
end
end
+
+ defp put_status(response, activity, user) do
+ Map.put(response, :status, StatusView.render("show.json", %{activity: activity, for: user}))
+ end
+
+ defp put_target(response, activity, user) do
+ target = User.get_cached_by_ap_id(activity.data["target"])
+ Map.put(response, :target, AccountView.render("show.json", %{user: target, for: user}))
+ end
end
diff --git a/lib/pleroma/web/push/impl.ex b/lib/pleroma/web/push/impl.ex
index 53f93c1ed..34ec1d8d9 100644
--- a/lib/pleroma/web/push/impl.ex
+++ b/lib/pleroma/web/push/impl.ex
@@ -16,7 +16,7 @@ defmodule Pleroma.Web.Push.Impl do
require Logger
import Ecto.Query
- @types ["Create", "Follow", "Announce", "Like"]
+ @types ["Create", "Follow", "Announce", "Like", "Move"]
@doc "Performs sending notifications for user subscriptions"
@spec perform(Notification.t()) :: list(any) | :error