forked from AkkomaGang/akkoma
Merge branch 'features/profile-fields-emojo' into 'develop'
user: Add support for custom emojis in profile fields See merge request pleroma/pleroma!2741
This commit is contained in:
commit
8f9ee694ed
2 changed files with 38 additions and 4 deletions
|
@ -530,11 +530,21 @@ defp parse_fields(value) do
|
||||||
end
|
end
|
||||||
|
|
||||||
defp put_emoji(changeset) do
|
defp put_emoji(changeset) do
|
||||||
bio = get_change(changeset, :bio)
|
emojified_fields = [:bio, :name, :raw_fields]
|
||||||
name = get_change(changeset, :name)
|
|
||||||
|
if Enum.any?(changeset.changes, fn {k, _} -> k in emojified_fields end) do
|
||||||
|
bio = Emoji.Formatter.get_emoji_map(get_field(changeset, :bio))
|
||||||
|
name = Emoji.Formatter.get_emoji_map(get_field(changeset, :name))
|
||||||
|
|
||||||
|
emoji = Map.merge(bio, name)
|
||||||
|
|
||||||
|
emoji =
|
||||||
|
changeset
|
||||||
|
|> get_field(:raw_fields)
|
||||||
|
|> Enum.reduce(emoji, fn x, acc ->
|
||||||
|
Map.merge(acc, Emoji.Formatter.get_emoji_map(x["name"] <> x["value"]))
|
||||||
|
end)
|
||||||
|
|
||||||
if bio || name do
|
|
||||||
emoji = Map.merge(Emoji.Formatter.get_emoji_map(bio), Emoji.Formatter.get_emoji_map(name))
|
|
||||||
put_change(changeset, :emoji, emoji)
|
put_change(changeset, :emoji, emoji)
|
||||||
else
|
else
|
||||||
changeset
|
changeset
|
||||||
|
|
|
@ -351,6 +351,30 @@ test "update fields", %{conn: conn} do
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "emojis in fields labels", %{conn: conn} do
|
||||||
|
fields = [
|
||||||
|
%{"name" => ":firefox:", "value" => "is best 2hu"},
|
||||||
|
%{"name" => "they wins", "value" => ":blank:"}
|
||||||
|
]
|
||||||
|
|
||||||
|
account_data =
|
||||||
|
conn
|
||||||
|
|> patch("/api/v1/accounts/update_credentials", %{"fields_attributes" => fields})
|
||||||
|
|> json_response_and_validate_schema(200)
|
||||||
|
|
||||||
|
assert account_data["fields"] == [
|
||||||
|
%{"name" => ":firefox:", "value" => "is best 2hu"},
|
||||||
|
%{"name" => "they wins", "value" => ":blank:"}
|
||||||
|
]
|
||||||
|
|
||||||
|
assert account_data["source"]["fields"] == [
|
||||||
|
%{"name" => ":firefox:", "value" => "is best 2hu"},
|
||||||
|
%{"name" => "they wins", "value" => ":blank:"}
|
||||||
|
]
|
||||||
|
|
||||||
|
assert [%{"shortcode" => "blank"}, %{"shortcode" => "firefox"}] = account_data["emojis"]
|
||||||
|
end
|
||||||
|
|
||||||
test "update fields via x-www-form-urlencoded", %{conn: conn} do
|
test "update fields via x-www-form-urlencoded", %{conn: conn} do
|
||||||
fields =
|
fields =
|
||||||
[
|
[
|
||||||
|
|
Loading…
Reference in a new issue