Переглянути джерело

Merge branch 'develop' into issue/941

tags/v1.1.4
Maksim Pechnikov 5 роки тому
джерело
коміт
d3d1704e84
4 змінених файлів з 68 додано та 9 видалено
  1. +13
    -1
      lib/pleroma/emoji.ex
  2. +2
    -1
      lib/pleroma/web/activity_pub/utils.ex
  3. +10
    -7
      lib/pleroma/web/common_api/common_api.ex
  4. +43
    -0
      test/web/activity_pub/utils_test.exs

+ 13
- 1
lib/pleroma/emoji.ex Переглянути файл

@@ -97,10 +97,22 @@ defmodule Pleroma.Emoji do
# There was some other error
Logger.error("Could not access the custom emoji directory #{emoji_dir_path}: #{e}")

{:ok, packs} ->
{:ok, results} ->
grouped = Enum.group_by(results, &File.dir?/1)
packs = grouped[true] || []
files = grouped[false] || []

# Print the packs we've found
Logger.info("Found emoji packs: #{Enum.join(packs, ", ")}")

if not Enum.empty?(files) do
Logger.warn(
"Found files in the emoji folder. These will be ignored, please move them to a subdirectory\nFound files: #{
Enum.join(files, ", ")
}"
)
end

emojis =
Enum.flat_map(
packs,


+ 2
- 1
lib/pleroma/web/activity_pub/utils.ex Переглянути файл

@@ -794,10 +794,11 @@ defmodule Pleroma.Web.ActivityPub.Utils do
query =
from(
[activity, object: object] in Activity.with_preloaded_object(Activity),
where: fragment("(?)->>'type' = 'Create'", activity.data),
where: fragment("(?)->>'actor' = ?", activity.data, ^actor),
where:
fragment(
"(?)->'inReplyTo' = ?",
"(?)->>'inReplyTo' = ?",
object.data,
^to_string(id)
),


+ 10
- 7
lib/pleroma/web/common_api/common_api.ex Переглянути файл

@@ -132,13 +132,16 @@ defmodule Pleroma.Web.CommonAPI do
Enum.map(choices, fn index ->
answer_data = make_answer_data(user, object, Enum.at(options, index)["name"])

ActivityPub.create(%{
to: answer_data["to"],
actor: user,
context: object.data["context"],
object: answer_data,
additional: %{"cc" => answer_data["cc"]}
})
{:ok, activity} =
ActivityPub.create(%{
to: answer_data["to"],
actor: user,
context: object.data["context"],
object: answer_data,
additional: %{"cc" => answer_data["cc"]}
})

activity
end)

object = Object.get_cached_by_ap_id(object.data["id"])


+ 43
- 0
test/web/activity_pub/utils_test.exs Переглянути файл

@@ -1,6 +1,7 @@
defmodule Pleroma.Web.ActivityPub.UtilsTest do
use Pleroma.DataCase
alias Pleroma.Activity
alias Pleroma.Object
alias Pleroma.User
alias Pleroma.Web.ActivityPub.ActivityPub
alias Pleroma.Web.ActivityPub.Utils
@@ -204,4 +205,46 @@ defmodule Pleroma.Web.ActivityPub.UtilsTest do
]
}
end

describe "get_existing_votes" do
test "fetches existing votes" do
user = insert(:user)
other_user = insert(:user)

{:ok, activity} =
CommonAPI.post(user, %{
"status" => "How do I pronounce LaTeX?",
"poll" => %{
"options" => ["laytekh", "lahtekh", "latex"],
"expires_in" => 20,
"multiple" => true
}
})

object = Object.normalize(activity)
{:ok, votes, object} = CommonAPI.vote(other_user, object, [0, 1])
assert Enum.sort(Utils.get_existing_votes(other_user.ap_id, object)) == Enum.sort(votes)
end

test "fetches only Create activities" do
user = insert(:user)
other_user = insert(:user)

{:ok, activity} =
CommonAPI.post(user, %{
"status" => "Are we living in a society?",
"poll" => %{
"options" => ["yes", "no"],
"expires_in" => 20
}
})

object = Object.normalize(activity)
{:ok, [vote], object} = CommonAPI.vote(other_user, object, [0])
vote_object = Object.normalize(vote)
{:ok, _activity, _object} = ActivityPub.like(user, vote_object)
[fetched_vote] = Utils.get_existing_votes(other_user.ap_id, object)
assert fetched_vote.id == vote.id
end
end
end

Завантаження…
Відмінити
Зберегти