CommonAPI: add emoji to user source data on update
This commit is contained in:
parent
8c0c930041
commit
f9d13558c8
4 changed files with 56 additions and 1 deletions
|
|
@ -1,5 +1,5 @@
|
|||
defmodule Pleroma.Web.CommonAPI do
|
||||
alias Pleroma.{Repo, Activity, Object}
|
||||
alias Pleroma.{User, Repo, Activity, Object}
|
||||
alias Pleroma.Web.ActivityPub.ActivityPub
|
||||
alias Pleroma.Formatter
|
||||
|
||||
|
|
@ -118,6 +118,18 @@ defmodule Pleroma.Web.CommonAPI do
|
|||
end
|
||||
|
||||
def update(user) do
|
||||
user =
|
||||
with emoji <- emoji_from_profile(user),
|
||||
source_data <- (user.info["source_data"] || %{}) |> Map.put("tag", emoji),
|
||||
new_info <- Map.put(user.info, "source_data", source_data),
|
||||
change <- User.info_changeset(user, %{info: new_info}),
|
||||
{:ok, user} <- User.update_and_set_cache(change) do
|
||||
user
|
||||
else
|
||||
_e ->
|
||||
user
|
||||
end
|
||||
|
||||
ActivityPub.update(%{
|
||||
local: true,
|
||||
to: [user.follower_address],
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
defmodule Pleroma.Web.CommonAPI.Utils do
|
||||
alias Pleroma.{Repo, Object, Formatter, Activity}
|
||||
alias Pleroma.Web.ActivityPub.Utils
|
||||
alias Pleroma.Web.Endpoint
|
||||
alias Pleroma.User
|
||||
alias Calendar.Strftime
|
||||
alias Comeonin.Pbkdf2
|
||||
|
|
@ -196,4 +197,15 @@ defmodule Pleroma.Web.CommonAPI.Utils do
|
|||
_ -> {:error, "Invalid password."}
|
||||
end
|
||||
end
|
||||
|
||||
def emoji_from_profile(%{info: info} = user) do
|
||||
(Formatter.get_emoji(user.bio) ++ Formatter.get_emoji(user.name))
|
||||
|> Enum.map(fn {shortcode, url} ->
|
||||
%{
|
||||
"type" => "Emoji",
|
||||
"icon" => %{"url" => "#{Endpoint.url()}#{url}"},
|
||||
"name" => ":#{shortcode}:"
|
||||
}
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue