Merge branch 'develop' into issue/941

This commit is contained in:
Maksim Pechnikov 2019-06-04 15:06:58 +03:00
commit d3d1704e84
4 changed files with 68 additions and 9 deletions

View File

@ -97,10 +97,22 @@ defp load do
# There was some other error # There was some other error
Logger.error("Could not access the custom emoji directory #{emoji_dir_path}: #{e}") 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 # Print the packs we've found
Logger.info("Found emoji packs: #{Enum.join(packs, ", ")}") 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 = emojis =
Enum.flat_map( Enum.flat_map(
packs, packs,

View File

@ -794,10 +794,11 @@ def get_existing_votes(actor, %{data: %{"id" => id}}) do
query = query =
from( from(
[activity, object: object] in Activity.with_preloaded_object(Activity), [activity, object: object] in Activity.with_preloaded_object(Activity),
where: fragment("(?)->>'type' = 'Create'", activity.data),
where: fragment("(?)->>'actor' = ?", activity.data, ^actor), where: fragment("(?)->>'actor' = ?", activity.data, ^actor),
where: where:
fragment( fragment(
"(?)->'inReplyTo' = ?", "(?)->>'inReplyTo' = ?",
object.data, object.data,
^to_string(id) ^to_string(id)
), ),

View File

@ -132,6 +132,7 @@ def vote(user, object, choices) do
Enum.map(choices, fn index -> Enum.map(choices, fn index ->
answer_data = make_answer_data(user, object, Enum.at(options, index)["name"]) answer_data = make_answer_data(user, object, Enum.at(options, index)["name"])
{:ok, activity} =
ActivityPub.create(%{ ActivityPub.create(%{
to: answer_data["to"], to: answer_data["to"],
actor: user, actor: user,
@ -139,6 +140,8 @@ def vote(user, object, choices) do
object: answer_data, object: answer_data,
additional: %{"cc" => answer_data["cc"]} additional: %{"cc" => answer_data["cc"]}
}) })
activity
end) end)
object = Object.get_cached_by_ap_id(object.data["id"]) object = Object.get_cached_by_ap_id(object.data["id"])

View File

@ -1,6 +1,7 @@
defmodule Pleroma.Web.ActivityPub.UtilsTest do defmodule Pleroma.Web.ActivityPub.UtilsTest do
use Pleroma.DataCase use Pleroma.DataCase
alias Pleroma.Activity alias Pleroma.Activity
alias Pleroma.Object
alias Pleroma.User alias Pleroma.User
alias Pleroma.Web.ActivityPub.ActivityPub alias Pleroma.Web.ActivityPub.ActivityPub
alias Pleroma.Web.ActivityPub.Utils alias Pleroma.Web.ActivityPub.Utils
@ -204,4 +205,46 @@ test "make_json_ld_header/0" do
] ]
} }
end 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 end