Browse Source

CommonAPI: Support emoji reactions.

fix/admin-api-grouped-reports-closed-reports
lain 4 years ago
parent
commit
b770ed1d99
2 changed files with 24 additions and 0 deletions
  1. +10
    -0
      lib/pleroma/web/common_api/common_api.ex
  2. +14
    -0
      test/web/common_api/common_api_test.exs

+ 10
- 0
lib/pleroma/web/common_api/common_api.ex View File

@@ -123,6 +123,16 @@ defmodule Pleroma.Web.CommonAPI do
end
end

def react_with_emoji(id, user, emoji) do
with %Activity{} = activity <- Activity.get_by_id(id),
object <- Object.normalize(activity) do
ActivityPub.react_with_emoji(user, object, emoji)
else
_ ->
{:error, dgettext("errors", "Could not add reaction emoji")}
end
end

def vote(user, object, choices) do
with "Question" <- object.data["type"],
{:author, false} <- {:author, object.data["actor"] == user.ap_id},


+ 14
- 0
test/web/common_api/common_api_test.exs View File

@@ -222,6 +222,20 @@ defmodule Pleroma.Web.CommonAPITest do
end

describe "reactions" do
test "reacting to a status with an emoji" do
user = insert(:user)
other_user = insert(:user)

{:ok, activity} = CommonAPI.post(other_user, %{"status" => "cofe"})

{:ok, reaction, _} = CommonAPI.react_with_emoji(activity.id, user, "👍")

assert reaction.data["actor"] == user.ap_id
assert reaction.data["content"] == "👍"

# TODO: test error case.
end

test "repeating a status" do
user = insert(:user)
other_user = insert(:user)


Loading…
Cancel
Save