Copy emoji in the subject from parent post
Sometimes people put emoji in the subject, which results in the subject looking broken if someone replies to it from a server that does not have the said emoji under the same shortcode. This patch solves the problem by extending the emoji set available in the summary to that of the parent post.
This commit is contained in:
parent
572363793f
commit
d3660b24d3
4 changed files with 111 additions and 0 deletions
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue