This commit is contained in:
tusooa 2022-11-07 11:58:41 -05:00
parent 5b302d8b76
commit 7379f1417b
No known key found for this signature in database
GPG key ID: 7B467EDE43A08224
4 changed files with 36 additions and 13 deletions

View file

@ -27,16 +27,20 @@ def import_object(
|> strip_recipients(opts) |> strip_recipients(opts)
create_data = create_data =
Utils.make_create_data(%{ Utils.make_create_data(
%{
actor: user, actor: user,
published: published, published: published,
object: fixed_object, object: fixed_object,
to: [], to: [],
context: context context: context
}, %{}) },
%{}
)
|> Utils.lazy_put_activity_defaults() |> Utils.lazy_put_activity_defaults()
with {:ok, activity, _meta} <- Pipeline.common_pipeline(create_data, local: true, importing: true) do with {:ok, activity, _meta} <-
Pipeline.common_pipeline(create_data, local: true, importing: true) do
# This is to meant to be executed in the oban queue, we only care if it succeeds, # This is to meant to be executed in the oban queue, we only care if it succeeds,
# so don't query for and put in the object here. # so don't query for and put in the object here.
{:ok, activity} {:ok, activity}
@ -69,6 +73,7 @@ defp rewrite_actor(object, user) do
defp strip_recipients(object, opts) do defp strip_recipients(object, opts) do
keep_unlisted = opts[:keep_unlisted] || false keep_unlisted = opts[:keep_unlisted] || false
orig_is_public = Visibility.is_public?(object) and not Visibility.is_local_public?(object) orig_is_public = Visibility.is_public?(object) and not Visibility.is_local_public?(object)
unlisted_ccs = unlisted_ccs =
if keep_unlisted and orig_is_public do if keep_unlisted and orig_is_public do
[Pleroma.Constants.as_public()] [Pleroma.Constants.as_public()]

View file

@ -43,7 +43,10 @@ def fix_object_defaults(data, meta) do
|> cast_and_filter_recipients("cc", follower_collection) |> cast_and_filter_recipients("cc", follower_collection)
|> cast_and_filter_recipients("bto", follower_collection) |> cast_and_filter_recipients("bto", follower_collection)
|> cast_and_filter_recipients("bcc", follower_collection) |> cast_and_filter_recipients("bcc", follower_collection)
|> dont_apply_when_importing(& Transmogrifier.fix_implicit_addressing(&1, follower_collection), meta) |> dont_apply_when_importing(
&Transmogrifier.fix_implicit_addressing(&1, follower_collection),
meta
)
end end
def fix_activity_addressing(activity, meta \\ []) do def fix_activity_addressing(activity, meta \\ []) do
@ -54,7 +57,10 @@ def fix_activity_addressing(activity, meta \\ []) do
|> cast_and_filter_recipients("cc", follower_collection) |> cast_and_filter_recipients("cc", follower_collection)
|> cast_and_filter_recipients("bto", follower_collection) |> cast_and_filter_recipients("bto", follower_collection)
|> cast_and_filter_recipients("bcc", follower_collection) |> cast_and_filter_recipients("bcc", follower_collection)
|> dont_apply_when_importing(& Transmogrifier.fix_implicit_addressing(&1, follower_collection), meta) |> dont_apply_when_importing(
&Transmogrifier.fix_implicit_addressing(&1, follower_collection),
meta
)
end end
def fix_actor(data) do def fix_actor(data) do

View file

@ -67,7 +67,10 @@ defp fix_addressing(data, object, meta) do
|> CommonFixes.cast_and_filter_recipients("cc", follower_collection, object["cc"]) |> CommonFixes.cast_and_filter_recipients("cc", follower_collection, object["cc"])
|> CommonFixes.cast_and_filter_recipients("bto", follower_collection, object["bto"]) |> CommonFixes.cast_and_filter_recipients("bto", follower_collection, object["bto"])
|> CommonFixes.cast_and_filter_recipients("bcc", follower_collection, object["bcc"]) |> CommonFixes.cast_and_filter_recipients("bcc", follower_collection, object["bcc"])
|> CommonFixes.dont_apply_when_importing(& Transmogrifier.fix_implicit_addressing(&1, follower_collection), meta) |> CommonFixes.dont_apply_when_importing(
&Transmogrifier.fix_implicit_addressing(&1, follower_collection),
meta
)
end end
def fix(data, meta) do def fix(data, meta) do

View file

@ -53,7 +53,13 @@ test "it keeps inReplyTo and context" do
user = insert(:user) user = insert(:user)
user2 = insert(:user) user2 = insert(:user)
{:ok, replied_to_activity} = CommonAPI.post(user2, %{status: "mew"}) {:ok, replied_to_activity} = CommonAPI.post(user2, %{status: "mew"})
{:ok, activity} = CommonAPI.post(user, %{status: "mew @#{user2.nickname}", in_reply_to_id: replied_to_activity})
{:ok, activity} =
CommonAPI.post(user, %{
status: "mew @#{user2.nickname}",
in_reply_to_id: replied_to_activity
})
assert user2.ap_id in activity.recipients assert user2.ap_id in activity.recipients
{:ok, activity_for_import} = Transmogrifier.prepare_outgoing(activity.data) {:ok, activity_for_import} = Transmogrifier.prepare_outgoing(activity.data)
@ -76,7 +82,10 @@ test "it keeps public and unlisted posts unlisted with keep_unlisted option" do
{:ok, activity_for_import} = Transmogrifier.prepare_outgoing(activity.data) {:ok, activity_for_import} = Transmogrifier.prepare_outgoing(activity.data)
importing_user = insert(:user) importing_user = insert(:user)
assert {:ok, imported_activity} = Importer.import_one(activity_for_import, importing_user, keep_unlisted: true)
assert {:ok, imported_activity} =
Importer.import_one(activity_for_import, importing_user, keep_unlisted: true)
imported_activity = Activity.normalize(imported_activity) imported_activity = Activity.normalize(imported_activity)
if yn do if yn do