aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorHaelwenn <contact+git.pleroma.social@hacktivis.me>2021-03-23 09:27:03 +0000
committerHaelwenn <contact+git.pleroma.social@hacktivis.me>2021-03-23 09:27:03 +0000
commitc09844d3d250feccce08cf06d6f2f326daf897a7 (patch)
treee82f7305c6362dc41d0a3d6119759cc2d491b822 /lib
parent572363793f27895903a8c156fd614ec5c7493cd1 (diff)
parentd3660b24d37862bb58cf309c582cfe7432fd7bb6 (diff)
downloadpleroma-c09844d3d250feccce08cf06d6f2f326daf897a7.tar.gz
Merge branch 'fix/copy-emoji-summary' into 'develop'
Copy emoji in the subject from parent post See merge request pleroma/pleroma!3378
Diffstat (limited to 'lib')
-rw-r--r--lib/pleroma/web/common_api/activity_draft.ex27
1 files changed, 27 insertions, 0 deletions
diff --git a/lib/pleroma/web/common_api/activity_draft.ex b/lib/pleroma/web/common_api/activity_draft.ex
index 8668b600e..80a9fa7bb 100644
--- a/lib/pleroma/web/common_api/activity_draft.ex
+++ b/lib/pleroma/web/common_api/activity_draft.ex
@@ -5,6 +5,7 @@
defmodule Pleroma.Web.CommonAPI.ActivityDraft do
alias Pleroma.Activity
alias Pleroma.Conversation.Participation
+ alias Pleroma.Object
alias Pleroma.Web.CommonAPI
alias Pleroma.Web.CommonAPI.Utils
@@ -186,6 +187,32 @@ defmodule Pleroma.Web.CommonAPI.ActivityDraft do
defp object(draft) do
emoji = Map.merge(Pleroma.Emoji.Formatter.get_emoji_map(draft.full_payload), draft.emoji)
+ # Sometimes people create posts with subject containing emoji,
+ # since subjects are usually copied this will result in a broken
+ # subject when someone replies from an instance that does not have
+ # the emoji or has it under different shortcode. This is an attempt
+ # to mitigate this by copying emoji from inReplyTo if they are present
+ # in the subject.
+ summary_emoji =
+ with %Activity{} <- draft.in_reply_to,
+ %Object{data: %{"tag" => [_ | _] = tag}} <- Object.normalize(draft.in_reply_to) do
+ Enum.reduce(tag, %{}, fn
+ %{"type" => "Emoji", "name" => name, "icon" => %{"url" => url}}, acc ->
+ if String.contains?(draft.summary, name) do
+ Map.put(acc, name, url)
+ else
+ acc
+ end
+
+ _, acc ->
+ acc
+ end)
+ else
+ _ -> %{}
+ end
+
+ emoji = Map.merge(emoji, summary_emoji)
+
object =
Utils.make_note_data(draft)
|> Map.put("emoji", emoji)