forked from AkkomaGang/akkoma
ActivityPub: Basic EmojiReactions.
This commit is contained in:
parent
ba5e14be05
commit
6e1ec4c5da
3 changed files with 42 additions and 0 deletions
|
@ -312,6 +312,16 @@ def update(%{to: to, cc: cc, actor: actor, object: object} = params) do
|
|||
end
|
||||
end
|
||||
|
||||
def react_with_emoji(user, object, emoji, options \\ []) do
|
||||
with local <- Keyword.get(options, :local, true),
|
||||
activity_id <- Keyword.get(options, :activity_id, nil),
|
||||
is_emoji?(emoji),
|
||||
reaction_data <- make_emoji_reaction_data(user, object, emoji, activity_id),
|
||||
{:ok, activity} <- insert(reaction_data, local) do
|
||||
{:ok, activity, object}
|
||||
end
|
||||
end
|
||||
|
||||
# TODO: This is weird, maybe we shouldn't check here if we can make the activity.
|
||||
def like(
|
||||
%User{ap_id: ap_id} = user,
|
||||
|
|
|
@ -296,6 +296,16 @@ def get_object_likes(%{data: %{"id" => id}}) do
|
|||
Repo.all(query)
|
||||
end
|
||||
|
||||
def is_emoji?(emoji) do
|
||||
String.length(emoji) == 1
|
||||
end
|
||||
|
||||
def make_emoji_reaction_data(user, object, emoji, activity_id) do
|
||||
make_like_data(user, object, activity_id)
|
||||
|> Map.put("type", "EmojiReaction")
|
||||
|> Map.put("content", emoji)
|
||||
end
|
||||
|
||||
def make_like_data(
|
||||
%User{ap_id: ap_id} = actor,
|
||||
%{data: %{"actor" => object_actor_id, "id" => id}} = object,
|
||||
|
|
|
@ -675,6 +675,28 @@ test "returns reblogs for users for whom reblogs have not been muted" do
|
|||
end
|
||||
end
|
||||
|
||||
describe "react to an object" do
|
||||
test "adds an emoji reaction activity to the db" do
|
||||
user = insert(:user)
|
||||
reactor = insert(:user)
|
||||
{:ok, activity} = CommonAPI.post(user, %{"status" => "YASSSS queen slay"})
|
||||
assert object = Object.normalize(activity)
|
||||
|
||||
{:ok, reaction_activity, object} = ActivityPub.react_with_emoji(reactor, object, "🔥")
|
||||
|
||||
assert reaction_activity
|
||||
|
||||
assert reaction_activity.data["actor"] == reactor.ap_id
|
||||
assert reaction_activity.data["type"] == "EmojiReaction"
|
||||
assert reaction_activity.data["content"] == "🔥"
|
||||
assert reaction_activity.data["object"] == object.data["id"]
|
||||
assert reaction_activity.data["to"] == [User.ap_followers(reactor), activity.data["actor"]]
|
||||
assert reaction_activity.data["context"] == object.data["context"]
|
||||
# assert object.data["reaction_count"] == 1
|
||||
# assert object.data["reactions"] == [user.ap_id]
|
||||
end
|
||||
end
|
||||
|
||||
describe "like an object" do
|
||||
test "adds a like activity to the db" do
|
||||
note_activity = insert(:note_activity)
|
||||
|
|
Loading…
Reference in a new issue