mirror of
https://git.pleroma.social/pleroma/pleroma.git
synced 2025-04-08 12:04:10 +00:00
Transmogrifier: Also accept mitra emoji likes.
This commit is contained in:
parent
fc7ca2ccf4
commit
e19ca7606d
4 changed files with 163 additions and 1 deletions
|
@ -495,12 +495,23 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
|
|||
defp handle_incoming_normalized(
|
||||
%{
|
||||
"type" => "Like",
|
||||
"_misskey_reaction" => reaction
|
||||
"content" => _
|
||||
} = data,
|
||||
options
|
||||
) do
|
||||
data
|
||||
|> Map.put("type", "EmojiReact")
|
||||
|> handle_incoming_normalized(options)
|
||||
end
|
||||
|
||||
defp handle_incoming_normalized(
|
||||
%{
|
||||
"type" => "Like",
|
||||
"_misskey_reaction" => reaction
|
||||
} = data,
|
||||
options
|
||||
) do
|
||||
data
|
||||
|> Map.put("content", @misskey_reactions[reaction] || reaction)
|
||||
|> handle_incoming_normalized(options)
|
||||
end
|
||||
|
|
54
test/fixtures/misskey-custom-emoji-like.json
vendored
Normal file
54
test/fixtures/misskey-custom-emoji-like.json
vendored
Normal file
|
@ -0,0 +1,54 @@
|
|||
{
|
||||
"@context": [
|
||||
"https://www.w3.org/ns/activitystreams",
|
||||
"https://w3id.org/security/v1",
|
||||
{
|
||||
"Emoji": "toot:Emoji",
|
||||
"Hashtag": "as:Hashtag",
|
||||
"PropertyValue": "schema:PropertyValue",
|
||||
"_misskey_content": "misskey:_misskey_content",
|
||||
"_misskey_quote": "misskey:_misskey_quote",
|
||||
"_misskey_reaction": "misskey:_misskey_reaction",
|
||||
"_misskey_summary": "misskey:_misskey_summary",
|
||||
"_misskey_votes": "misskey:_misskey_votes",
|
||||
"backgroundUrl": "sharkey:backgroundUrl",
|
||||
"discoverable": "toot:discoverable",
|
||||
"featured": "toot:featured",
|
||||
"fedibird": "http://fedibird.com/ns#",
|
||||
"firefish": "https://joinfirefish.org/ns#",
|
||||
"isCat": "misskey:isCat",
|
||||
"listenbrainz": "sharkey:listenbrainz",
|
||||
"manuallyApprovesFollowers": "as:manuallyApprovesFollowers",
|
||||
"misskey": "https://misskey-hub.net/ns#",
|
||||
"quoteUri": "fedibird:quoteUri",
|
||||
"quoteUrl": "as:quoteUrl",
|
||||
"schema": "http://schema.org#",
|
||||
"sensitive": "as:sensitive",
|
||||
"sharkey": "https://joinsharkey.org/ns#",
|
||||
"speakAsCat": "firefish:speakAsCat",
|
||||
"toot": "http://joinmastodon.org/ns#",
|
||||
"value": "schema:value",
|
||||
"vcard": "http://www.w3.org/2006/vcard/ns#"
|
||||
}
|
||||
],
|
||||
"_misskey_reaction": ":blobwtfnotlikethis:",
|
||||
"actor": "https://mai.waifuism.life/users/9otxaeemjqy70001",
|
||||
"content": ":blobwtfnotlikethis:",
|
||||
"id": "https://mai.waifuism.life/likes/9q2xifhrdnb0001b",
|
||||
"object": "https://bungle.online/notes/9q2xi2sy4k",
|
||||
"tag": [
|
||||
{
|
||||
"icon": {
|
||||
"mediaType": "image/png",
|
||||
"type": "Image",
|
||||
"url": "https://mai.waifuism.life/files/1b0510f2-1fb4-43f5-a399-10053bbd8f0f"
|
||||
},
|
||||
"id": "https://mai.waifuism.life/emojis/blobwtfnotlikethis",
|
||||
"name": ":blobwtfnotlikethis:",
|
||||
"type": "Emoji",
|
||||
"updated": "2024-02-07T02:21:46.497Z"
|
||||
}
|
||||
],
|
||||
"type": "Like"
|
||||
}
|
||||
|
46
test/fixtures/mitra-custom-emoji-like.json
vendored
Normal file
46
test/fixtures/mitra-custom-emoji-like.json
vendored
Normal file
|
@ -0,0 +1,46 @@
|
|||
{
|
||||
"@context": [
|
||||
"https://www.w3.org/ns/activitystreams",
|
||||
"https://w3id.org/security/v1",
|
||||
"https://w3id.org/security/data-integrity/v1",
|
||||
{
|
||||
"Emoji": "toot:Emoji",
|
||||
"Hashtag": "as:Hashtag",
|
||||
"sensitive": "as:sensitive",
|
||||
"toot": "http://joinmastodon.org/ns#"
|
||||
}
|
||||
],
|
||||
"actor": "https://mitra.social/users/silverpill",
|
||||
"cc": [],
|
||||
"content": ":ablobcatheartsqueeze:",
|
||||
"id": "https://mitra.social/activities/like/0195a89a-a3a0-ead4-3a1c-aa6311397cfd",
|
||||
"object": "https://framapiaf.org/users/peertube/statuses/114182703352270287",
|
||||
"proof": {
|
||||
"created": "2025-03-18T09:34:21.610678375Z",
|
||||
"cryptosuite": "eddsa-jcs-2022",
|
||||
"proofPurpose": "assertionMethod",
|
||||
"proofValue": "z5AvpwkXQGFpTneRVDNeF48Jo9qYG6PgrE5HaPPpQNdNyc31ULMN4Vxd4aFXELo4Rk5Y9hd9nDy254xP8v5uGGWp1",
|
||||
"type": "DataIntegrityProof",
|
||||
"verificationMethod": "https://mitra.social/users/silverpill#ed25519-key"
|
||||
},
|
||||
"tag": [
|
||||
{
|
||||
"attributedTo": "https://mitra.social/actor",
|
||||
"icon": {
|
||||
"mediaType": "image/png",
|
||||
"type": "Image",
|
||||
"url": "https://mitra.social/media/a08e153441b25e512ab1b2e8922f5d8cd928322c8b79958cd48297ac722a4117.png"
|
||||
},
|
||||
"id": "https://mitra.social/objects/emojis/ablobcatheartsqueeze",
|
||||
"name": ":ablobcatheartsqueeze:",
|
||||
"type": "Emoji",
|
||||
"updated": "1970-01-01T00:00:00Z"
|
||||
}
|
||||
],
|
||||
"to": [
|
||||
"https://framapiaf.org/users/peertube",
|
||||
"https://www.w3.org/ns/activitystreams#Public"
|
||||
],
|
||||
"type": "Like"
|
||||
}
|
||||
|
|
@ -6,6 +6,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.LikeHandlingTest do
|
|||
use Pleroma.DataCase, async: true
|
||||
|
||||
alias Pleroma.Activity
|
||||
alias Pleroma.Object
|
||||
alias Pleroma.Web.ActivityPub.Transmogrifier
|
||||
alias Pleroma.Web.CommonAPI
|
||||
|
||||
|
@ -75,4 +76,54 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.LikeHandlingTest do
|
|||
assert activity_data["object"] == activity.data["object"]
|
||||
assert activity_data["content"] == "⭐"
|
||||
end
|
||||
|
||||
test "it works for misskey likes with custom emoji" do
|
||||
user = insert(:user)
|
||||
|
||||
{:ok, activity} = CommonAPI.post(user, %{status: "hello"})
|
||||
|
||||
data =
|
||||
File.read!("test/fixtures/misskey-custom-emoji-like.json")
|
||||
|> Jason.decode!()
|
||||
|> Map.put("object", activity.data["object"])
|
||||
|
||||
_actor = insert(:user, ap_id: data["actor"], local: false)
|
||||
|
||||
{:ok, %Activity{data: activity_data, local: false}} = Transmogrifier.handle_incoming(data)
|
||||
|
||||
assert activity_data["actor"] == data["actor"]
|
||||
assert activity_data["type"] == "EmojiReact"
|
||||
assert activity_data["id"] == data["id"]
|
||||
assert activity_data["object"] == activity.data["object"]
|
||||
assert activity_data["content"] == ":blobwtfnotlikethis:"
|
||||
|
||||
assert [["blobwtfnotlikethis", _, _]] =
|
||||
Object.get_by_ap_id(activity.data["object"])
|
||||
|> Object.get_emoji_reactions()
|
||||
end
|
||||
|
||||
test "it works for mitra likes with custom emoji" do
|
||||
user = insert(:user)
|
||||
|
||||
{:ok, activity} = CommonAPI.post(user, %{status: "hello"})
|
||||
|
||||
data =
|
||||
File.read!("test/fixtures/mitra-custom-emoji-like.json")
|
||||
|> Jason.decode!()
|
||||
|> Map.put("object", activity.data["object"])
|
||||
|
||||
_actor = insert(:user, ap_id: data["actor"], local: false)
|
||||
|
||||
{:ok, %Activity{data: activity_data, local: false}} = Transmogrifier.handle_incoming(data)
|
||||
|
||||
assert activity_data["actor"] == data["actor"]
|
||||
assert activity_data["type"] == "EmojiReact"
|
||||
assert activity_data["id"] == data["id"]
|
||||
assert activity_data["object"] == activity.data["object"]
|
||||
assert activity_data["content"] == ":ablobcatheartsqueeze:"
|
||||
|
||||
assert [["ablobcatheartsqueeze", _, _]] =
|
||||
Object.get_by_ap_id(activity.data["object"])
|
||||
|> Object.get_emoji_reactions()
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue