forked from AkkomaGang/akkoma
profile emojis in User.emoji instead of source_data
This commit is contained in:
parent
62656ab259
commit
9172d719cc
20 changed files with 103 additions and 158 deletions
|
@ -38,22 +38,14 @@ def demojify(text) do
|
||||||
|
|
||||||
def demojify(text, nil), do: text
|
def demojify(text, nil), do: text
|
||||||
|
|
||||||
@doc "Outputs a list of the emoji-shortcodes in a text"
|
|
||||||
def get_emoji(text) when is_binary(text) do
|
|
||||||
Enum.filter(Emoji.get_all(), fn {emoji, %Emoji{}} ->
|
|
||||||
String.contains?(text, ":#{emoji}:")
|
|
||||||
end)
|
|
||||||
end
|
|
||||||
|
|
||||||
def get_emoji(_), do: []
|
|
||||||
|
|
||||||
@doc "Outputs a list of the emoji-Maps in a text"
|
@doc "Outputs a list of the emoji-Maps in a text"
|
||||||
def get_emoji_map(text) when is_binary(text) do
|
def get_emoji_map(text) when is_binary(text) do
|
||||||
get_emoji(text)
|
Emoji.get_all()
|
||||||
|
|> Enum.filter(fn {emoji, %Emoji{}} -> String.contains?(text, ":#{emoji}:") end)
|
||||||
|> Enum.reduce(%{}, fn {name, %Emoji{file: file}}, acc ->
|
|> Enum.reduce(%{}, fn {name, %Emoji{file: file}}, acc ->
|
||||||
Map.put(acc, name, "#{Pleroma.Web.Endpoint.static_url()}#{file}")
|
Map.put(acc, name, "#{Pleroma.Web.Endpoint.static_url()}#{file}")
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_emoji_map(_), do: []
|
def get_emoji_map(_), do: %{}
|
||||||
end
|
end
|
||||||
|
|
|
@ -15,6 +15,7 @@ defmodule Pleroma.User do
|
||||||
alias Pleroma.Config
|
alias Pleroma.Config
|
||||||
alias Pleroma.Conversation.Participation
|
alias Pleroma.Conversation.Participation
|
||||||
alias Pleroma.Delivery
|
alias Pleroma.Delivery
|
||||||
|
alias Pleroma.Emoji
|
||||||
alias Pleroma.FollowingRelationship
|
alias Pleroma.FollowingRelationship
|
||||||
alias Pleroma.Formatter
|
alias Pleroma.Formatter
|
||||||
alias Pleroma.HTML
|
alias Pleroma.HTML
|
||||||
|
@ -124,7 +125,7 @@ defmodule Pleroma.User do
|
||||||
field(:pinned_activities, {:array, :string}, default: [])
|
field(:pinned_activities, {:array, :string}, default: [])
|
||||||
field(:email_notifications, :map, default: %{"digest" => false})
|
field(:email_notifications, :map, default: %{"digest" => false})
|
||||||
field(:mascot, :map, default: nil)
|
field(:mascot, :map, default: nil)
|
||||||
field(:emoji, {:array, :map}, default: [])
|
field(:emoji, :map, default: %{})
|
||||||
field(:pleroma_settings_store, :map, default: %{})
|
field(:pleroma_settings_store, :map, default: %{})
|
||||||
field(:fields, {:array, :map}, default: [])
|
field(:fields, {:array, :map}, default: [])
|
||||||
field(:raw_fields, {:array, :map}, default: [])
|
field(:raw_fields, {:array, :map}, default: [])
|
||||||
|
@ -368,6 +369,7 @@ def remote_user_creation(params) do
|
||||||
[
|
[
|
||||||
:bio,
|
:bio,
|
||||||
:name,
|
:name,
|
||||||
|
:emoji,
|
||||||
:ap_id,
|
:ap_id,
|
||||||
:inbox,
|
:inbox,
|
||||||
:shared_inbox,
|
:shared_inbox,
|
||||||
|
@ -413,6 +415,7 @@ def update_changeset(struct, params \\ %{}) do
|
||||||
[
|
[
|
||||||
:bio,
|
:bio,
|
||||||
:name,
|
:name,
|
||||||
|
:emoji,
|
||||||
:avatar,
|
:avatar,
|
||||||
:public_key,
|
:public_key,
|
||||||
:inbox,
|
:inbox,
|
||||||
|
@ -443,6 +446,7 @@ def update_changeset(struct, params \\ %{}) do
|
||||||
|> validate_length(:bio, max: bio_limit)
|
|> validate_length(:bio, max: bio_limit)
|
||||||
|> validate_length(:name, min: 1, max: name_limit)
|
|> validate_length(:name, min: 1, max: name_limit)
|
||||||
|> put_fields()
|
|> put_fields()
|
||||||
|
|> put_emoji()
|
||||||
|> put_change_if_present(:bio, &{:ok, parse_bio(&1, struct)})
|
|> put_change_if_present(:bio, &{:ok, parse_bio(&1, struct)})
|
||||||
|> put_change_if_present(:avatar, &put_upload(&1, :avatar))
|
|> put_change_if_present(:avatar, &put_upload(&1, :avatar))
|
||||||
|> put_change_if_present(:banner, &put_upload(&1, :banner))
|
|> put_change_if_present(:banner, &put_upload(&1, :banner))
|
||||||
|
@ -478,6 +482,18 @@ defp parse_fields(value) do
|
||||||
|> elem(0)
|
|> elem(0)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defp put_emoji(changeset) do
|
||||||
|
bio = get_change(changeset, :bio)
|
||||||
|
name = get_change(changeset, :name)
|
||||||
|
|
||||||
|
if bio || name do
|
||||||
|
emoji = Map.merge(Emoji.Formatter.get_emoji_map(bio), Emoji.Formatter.get_emoji_map(name))
|
||||||
|
put_change(changeset, :emoji, emoji)
|
||||||
|
else
|
||||||
|
changeset
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
defp put_change_if_present(changeset, map_field, value_function) do
|
defp put_change_if_present(changeset, map_field, value_function) do
|
||||||
if value = get_change(changeset, map_field) do
|
if value = get_change(changeset, map_field) do
|
||||||
with {:ok, new_value} <- value_function.(value) do
|
with {:ok, new_value} <- value_function.(value) do
|
||||||
|
@ -511,6 +527,7 @@ def upgrade_changeset(struct, params \\ %{}, remote? \\ false) do
|
||||||
[
|
[
|
||||||
:bio,
|
:bio,
|
||||||
:name,
|
:name,
|
||||||
|
:emoji,
|
||||||
:follower_address,
|
:follower_address,
|
||||||
:following_address,
|
:following_address,
|
||||||
:public_key,
|
:public_key,
|
||||||
|
@ -618,7 +635,7 @@ def register_changeset(struct, params \\ %{}, opts \\ []) do
|
||||||
|
|
||||||
struct
|
struct
|
||||||
|> confirmation_changeset(need_confirmation: need_confirmation?)
|
|> confirmation_changeset(need_confirmation: need_confirmation?)
|
||||||
|> cast(params, [:bio, :email, :name, :nickname, :password, :password_confirmation])
|
|> cast(params, [:bio, :email, :name, :nickname, :password, :password_confirmation, :emoji])
|
||||||
|> validate_required([:name, :nickname, :password, :password_confirmation])
|
|> validate_required([:name, :nickname, :password, :password_confirmation])
|
||||||
|> validate_confirmation(:password)
|
|> validate_confirmation(:password)
|
||||||
|> unique_constraint(:email)
|
|> unique_constraint(:email)
|
||||||
|
@ -1969,12 +1986,6 @@ def update_background(user, background) do
|
||||||
|> update_and_set_cache()
|
|> update_and_set_cache()
|
||||||
end
|
end
|
||||||
|
|
||||||
def update_source_data(user, source_data) do
|
|
||||||
user
|
|
||||||
|> cast(%{source_data: source_data}, [:source_data])
|
|
||||||
|> update_and_set_cache()
|
|
||||||
end
|
|
||||||
|
|
||||||
def roles(%{is_moderator: is_moderator, is_admin: is_admin}) do
|
def roles(%{is_moderator: is_moderator, is_admin: is_admin}) do
|
||||||
%{
|
%{
|
||||||
admin: is_admin,
|
admin: is_admin,
|
||||||
|
|
|
@ -1427,6 +1427,14 @@ defp object_to_user_data(data) do
|
||||||
|> Enum.filter(fn %{"type" => t} -> t == "PropertyValue" end)
|
|> Enum.filter(fn %{"type" => t} -> t == "PropertyValue" end)
|
||||||
|> Enum.map(fn fields -> Map.take(fields, ["name", "value"]) end)
|
|> Enum.map(fn fields -> Map.take(fields, ["name", "value"]) end)
|
||||||
|
|
||||||
|
emojis =
|
||||||
|
data
|
||||||
|
|> Map.get("tag", [])
|
||||||
|
|> Enum.filter(fn %{"type" => t} -> t == "Emoji" end)
|
||||||
|
|> Enum.reduce(%{}, fn %{"icon" => %{"url" => url}, "name" => name}, acc ->
|
||||||
|
Map.put(acc, String.trim(name, ":"), url)
|
||||||
|
end)
|
||||||
|
|
||||||
locked = data["manuallyApprovesFollowers"] || false
|
locked = data["manuallyApprovesFollowers"] || false
|
||||||
data = Transmogrifier.maybe_fix_user_object(data)
|
data = Transmogrifier.maybe_fix_user_object(data)
|
||||||
discoverable = data["discoverable"] || false
|
discoverable = data["discoverable"] || false
|
||||||
|
@ -1454,6 +1462,7 @@ defp object_to_user_data(data) do
|
||||||
source_data: data,
|
source_data: data,
|
||||||
banner: banner,
|
banner: banner,
|
||||||
fields: fields,
|
fields: fields,
|
||||||
|
emoji: emojis,
|
||||||
locked: locked,
|
locked: locked,
|
||||||
discoverable: discoverable,
|
discoverable: discoverable,
|
||||||
invisible: invisible,
|
invisible: invisible,
|
||||||
|
|
|
@ -1129,7 +1129,7 @@ defp build_mention_tag(%{ap_id: ap_id, nickname: nickname} = _) do
|
||||||
|
|
||||||
def take_emoji_tags(%User{emoji: emoji}) do
|
def take_emoji_tags(%User{emoji: emoji}) do
|
||||||
emoji
|
emoji
|
||||||
|> Enum.flat_map(&Map.to_list/1)
|
|> Map.to_list()
|
||||||
|> Enum.map(&build_emoji_tag/1)
|
|> Enum.map(&build_emoji_tag/1)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -103,7 +103,7 @@ def render("user.json", %{user: user}) do
|
||||||
},
|
},
|
||||||
"endpoints" => endpoints,
|
"endpoints" => endpoints,
|
||||||
"attachment" => fields,
|
"attachment" => fields,
|
||||||
"tag" => (user.source_data["tag"] || []) ++ emoji_tags,
|
"tag" => emoji_tags,
|
||||||
"discoverable" => user.discoverable
|
"discoverable" => user.discoverable
|
||||||
}
|
}
|
||||||
|> Map.merge(maybe_make_image(&User.avatar_url/2, "icon", user))
|
|> Map.merge(maybe_make_image(&User.avatar_url/2, "icon", user))
|
||||||
|
|
|
@ -332,26 +332,6 @@ defp maybe_create_activity_expiration({:ok, activity}, %NaiveDateTime{} = expire
|
||||||
|
|
||||||
defp maybe_create_activity_expiration(result, _), do: result
|
defp maybe_create_activity_expiration(result, _), do: result
|
||||||
|
|
||||||
# Updates the emojis for a user based on their profile
|
|
||||||
def update(user) do
|
|
||||||
emoji = emoji_from_profile(user)
|
|
||||||
source_data = Map.put(user.source_data, "tag", emoji)
|
|
||||||
|
|
||||||
user =
|
|
||||||
case User.update_source_data(user, source_data) do
|
|
||||||
{:ok, user} -> user
|
|
||||||
_ -> user
|
|
||||||
end
|
|
||||||
|
|
||||||
ActivityPub.update(%{
|
|
||||||
local: true,
|
|
||||||
to: [Pleroma.Constants.as_public(), user.follower_address],
|
|
||||||
cc: [],
|
|
||||||
actor: user.ap_id,
|
|
||||||
object: Pleroma.Web.ActivityPub.UserView.render("user.json", %{user: user})
|
|
||||||
})
|
|
||||||
end
|
|
||||||
|
|
||||||
def pin(id_or_ap_id, %{ap_id: user_ap_id} = user) do
|
def pin(id_or_ap_id, %{ap_id: user_ap_id} = user) do
|
||||||
with %Activity{
|
with %Activity{
|
||||||
actor: ^user_ap_id,
|
actor: ^user_ap_id,
|
||||||
|
|
|
@ -10,7 +10,6 @@ defmodule Pleroma.Web.CommonAPI.Utils do
|
||||||
alias Pleroma.Activity
|
alias Pleroma.Activity
|
||||||
alias Pleroma.Config
|
alias Pleroma.Config
|
||||||
alias Pleroma.Conversation.Participation
|
alias Pleroma.Conversation.Participation
|
||||||
alias Pleroma.Emoji
|
|
||||||
alias Pleroma.Formatter
|
alias Pleroma.Formatter
|
||||||
alias Pleroma.Object
|
alias Pleroma.Object
|
||||||
alias Pleroma.Plugs.AuthenticationPlug
|
alias Pleroma.Plugs.AuthenticationPlug
|
||||||
|
@ -18,7 +17,6 @@ defmodule Pleroma.Web.CommonAPI.Utils do
|
||||||
alias Pleroma.User
|
alias Pleroma.User
|
||||||
alias Pleroma.Web.ActivityPub.Utils
|
alias Pleroma.Web.ActivityPub.Utils
|
||||||
alias Pleroma.Web.ActivityPub.Visibility
|
alias Pleroma.Web.ActivityPub.Visibility
|
||||||
alias Pleroma.Web.Endpoint
|
|
||||||
alias Pleroma.Web.MediaProxy
|
alias Pleroma.Web.MediaProxy
|
||||||
|
|
||||||
require Logger
|
require Logger
|
||||||
|
@ -175,7 +173,7 @@ def make_poll_data(%{"poll" => %{"options" => options, "expires_in" => expires_i
|
||||||
"replies" => %{"type" => "Collection", "totalItems" => 0}
|
"replies" => %{"type" => "Collection", "totalItems" => 0}
|
||||||
}
|
}
|
||||||
|
|
||||||
{note, Map.merge(emoji, Emoji.Formatter.get_emoji_map(option))}
|
{note, Map.merge(emoji, Pleroma.Emoji.Formatter.get_emoji_map(option))}
|
||||||
end)
|
end)
|
||||||
|
|
||||||
end_time =
|
end_time =
|
||||||
|
@ -431,19 +429,6 @@ def confirm_current_password(user, password) do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def emoji_from_profile(%User{bio: bio, name: name}) do
|
|
||||||
[bio, name]
|
|
||||||
|> Enum.map(&Emoji.Formatter.get_emoji/1)
|
|
||||||
|> Enum.concat()
|
|
||||||
|> Enum.map(fn {shortcode, %Emoji{file: path}} ->
|
|
||||||
%{
|
|
||||||
"type" => "Emoji",
|
|
||||||
"icon" => %{"type" => "Image", "url" => "#{Endpoint.url()}#{path}"},
|
|
||||||
"name" => ":#{shortcode}:"
|
|
||||||
}
|
|
||||||
end)
|
|
||||||
end
|
|
||||||
|
|
||||||
def maybe_notify_to_recipients(
|
def maybe_notify_to_recipients(
|
||||||
recipients,
|
recipients,
|
||||||
%Activity{data: %{"to" => to, "type" => _type}} = _activity
|
%Activity{data: %{"to" => to, "type" => _type}} = _activity
|
||||||
|
|
|
@ -140,9 +140,7 @@ def verify_credentials(%{assigns: %{user: user}} = conn, _) do
|
||||||
end
|
end
|
||||||
|
|
||||||
@doc "PATCH /api/v1/accounts/update_credentials"
|
@doc "PATCH /api/v1/accounts/update_credentials"
|
||||||
def update_credentials(%{assigns: %{user: original_user}} = conn, params) do
|
def update_credentials(%{assigns: %{user: user}} = conn, params) do
|
||||||
user = original_user
|
|
||||||
|
|
||||||
user_params =
|
user_params =
|
||||||
[
|
[
|
||||||
:no_rich_text,
|
:no_rich_text,
|
||||||
|
@ -178,8 +176,6 @@ def update_credentials(%{assigns: %{user: original_user}} = conn, params) do
|
||||||
changeset = User.update_changeset(user, user_params)
|
changeset = User.update_changeset(user, user_params)
|
||||||
|
|
||||||
with {:ok, user} <- User.update_and_set_cache(changeset) do
|
with {:ok, user} <- User.update_and_set_cache(changeset) do
|
||||||
if original_user != user, do: CommonAPI.update(user)
|
|
||||||
|
|
||||||
render(conn, "show.json", user: user, for: user, with_pleroma_settings: true)
|
render(conn, "show.json", user: user, for: user, with_pleroma_settings: true)
|
||||||
else
|
else
|
||||||
_e -> render_error(conn, :forbidden, "Invalid request")
|
_e -> render_error(conn, :forbidden, "Invalid request")
|
||||||
|
|
|
@ -180,13 +180,11 @@ defp do_render("show.json", %{user: user} = opts) do
|
||||||
bot = user.actor_type in ["Application", "Service"]
|
bot = user.actor_type in ["Application", "Service"]
|
||||||
|
|
||||||
emojis =
|
emojis =
|
||||||
(user.source_data["tag"] || [])
|
Enum.map(user.emoji, fn {shortcode, url} ->
|
||||||
|> Enum.filter(fn %{"type" => t} -> t == "Emoji" end)
|
|
||||||
|> Enum.map(fn %{"icon" => %{"url" => url}, "name" => name} ->
|
|
||||||
%{
|
%{
|
||||||
"shortcode" => String.trim(name, ":"),
|
"shortcode" => shortcode,
|
||||||
"url" => MediaProxy.url(url),
|
"url" => url,
|
||||||
"static_url" => MediaProxy.url(url),
|
"static_url" => url,
|
||||||
"visible_in_picker" => false
|
"visible_in_picker" => false
|
||||||
}
|
}
|
||||||
end)
|
end)
|
||||||
|
|
|
@ -13,7 +13,6 @@ defmodule Pleroma.Web.PleromaAPI.AccountController do
|
||||||
alias Pleroma.Plugs.RateLimiter
|
alias Pleroma.Plugs.RateLimiter
|
||||||
alias Pleroma.User
|
alias Pleroma.User
|
||||||
alias Pleroma.Web.ActivityPub.ActivityPub
|
alias Pleroma.Web.ActivityPub.ActivityPub
|
||||||
alias Pleroma.Web.CommonAPI
|
|
||||||
alias Pleroma.Web.MastodonAPI.StatusView
|
alias Pleroma.Web.MastodonAPI.StatusView
|
||||||
|
|
||||||
require Pleroma.Constants
|
require Pleroma.Constants
|
||||||
|
@ -58,38 +57,32 @@ def confirmation_resend(conn, params) do
|
||||||
|
|
||||||
@doc "PATCH /api/v1/pleroma/accounts/update_avatar"
|
@doc "PATCH /api/v1/pleroma/accounts/update_avatar"
|
||||||
def update_avatar(%{assigns: %{user: user}} = conn, %{"img" => ""}) do
|
def update_avatar(%{assigns: %{user: user}} = conn, %{"img" => ""}) do
|
||||||
{:ok, user} =
|
{:ok, _user} =
|
||||||
user
|
user
|
||||||
|> Changeset.change(%{avatar: nil})
|
|> Changeset.change(%{avatar: nil})
|
||||||
|> User.update_and_set_cache()
|
|> User.update_and_set_cache()
|
||||||
|
|
||||||
CommonAPI.update(user)
|
|
||||||
|
|
||||||
json(conn, %{url: nil})
|
json(conn, %{url: nil})
|
||||||
end
|
end
|
||||||
|
|
||||||
def update_avatar(%{assigns: %{user: user}} = conn, params) do
|
def update_avatar(%{assigns: %{user: user}} = conn, params) do
|
||||||
{:ok, %{data: data}} = ActivityPub.upload(params, type: :avatar)
|
{:ok, %{data: data}} = ActivityPub.upload(params, type: :avatar)
|
||||||
{:ok, user} = user |> Changeset.change(%{avatar: data}) |> User.update_and_set_cache()
|
{:ok, _user} = user |> Changeset.change(%{avatar: data}) |> User.update_and_set_cache()
|
||||||
%{"url" => [%{"href" => href} | _]} = data
|
%{"url" => [%{"href" => href} | _]} = data
|
||||||
|
|
||||||
CommonAPI.update(user)
|
|
||||||
|
|
||||||
json(conn, %{url: href})
|
json(conn, %{url: href})
|
||||||
end
|
end
|
||||||
|
|
||||||
@doc "PATCH /api/v1/pleroma/accounts/update_banner"
|
@doc "PATCH /api/v1/pleroma/accounts/update_banner"
|
||||||
def update_banner(%{assigns: %{user: user}} = conn, %{"banner" => ""}) do
|
def update_banner(%{assigns: %{user: user}} = conn, %{"banner" => ""}) do
|
||||||
with {:ok, user} <- User.update_banner(user, %{}) do
|
with {:ok, _user} <- User.update_banner(user, %{}) do
|
||||||
CommonAPI.update(user)
|
|
||||||
json(conn, %{url: nil})
|
json(conn, %{url: nil})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def update_banner(%{assigns: %{user: user}} = conn, params) do
|
def update_banner(%{assigns: %{user: user}} = conn, params) do
|
||||||
with {:ok, object} <- ActivityPub.upload(%{"img" => params["banner"]}, type: :banner),
|
with {:ok, object} <- ActivityPub.upload(%{"img" => params["banner"]}, type: :banner),
|
||||||
{:ok, user} <- User.update_banner(user, object.data) do
|
{:ok, _user} <- User.update_banner(user, object.data) do
|
||||||
CommonAPI.update(user)
|
|
||||||
%{"url" => [%{"href" => href} | _]} = object.data
|
%{"url" => [%{"href" => href} | _]} = object.data
|
||||||
|
|
||||||
json(conn, %{url: href})
|
json(conn, %{url: href})
|
||||||
|
|
|
@ -18,15 +18,6 @@ defmodule Pleroma.Web.StaticFE.StaticFEView do
|
||||||
|
|
||||||
@media_types ["image", "audio", "video"]
|
@media_types ["image", "audio", "video"]
|
||||||
|
|
||||||
def emoji_for_user(%User{} = user) do
|
|
||||||
user.source_data
|
|
||||||
|> Map.get("tag", [])
|
|
||||||
|> Enum.filter(fn %{"type" => t} -> t == "Emoji" end)
|
|
||||||
|> Enum.map(fn %{"icon" => %{"url" => url}, "name" => name} ->
|
|
||||||
{String.trim(name, ":"), url}
|
|
||||||
end)
|
|
||||||
end
|
|
||||||
|
|
||||||
def fetch_media_type(%{"mediaType" => mediaType}) do
|
def fetch_media_type(%{"mediaType" => mediaType}) do
|
||||||
Utils.fetch_media_type(@media_types, mediaType)
|
Utils.fetch_media_type(@media_types, mediaType)
|
||||||
end
|
end
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
<img src="<%= User.avatar_url(@user) |> MediaProxy.url %>" width="48" height="48" alt="">
|
<img src="<%= User.avatar_url(@user) |> MediaProxy.url %>" width="48" height="48" alt="">
|
||||||
</div>
|
</div>
|
||||||
<span class="display-name">
|
<span class="display-name">
|
||||||
<bdi><%= raw (@user.name |> Formatter.emojify(emoji_for_user(@user))) %></bdi>
|
<bdi><%= raw Formatter.emojify(@user.name, @user.emoji) %></bdi>
|
||||||
<span class="nickname"><%= @user.nickname %></span>
|
<span class="nickname"><%= @user.nickname %></span>
|
||||||
</span>
|
</span>
|
||||||
</a>
|
</a>
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
<input type="hidden" name="profile" value="">
|
<input type="hidden" name="profile" value="">
|
||||||
<button type="submit" class="collapse">Remote follow</button>
|
<button type="submit" class="collapse">Remote follow</button>
|
||||||
</form>
|
</form>
|
||||||
<%= raw Formatter.emojify(@user.name, emoji_for_user(@user)) %> |
|
<%= raw Formatter.emojify(@user.name, @user.emoji) %> |
|
||||||
<%= link "@#{@user.nickname}@#{Endpoint.host()}", to: (@user.uri || @user.ap_id) %>
|
<%= link "@#{@user.nickname}@#{Endpoint.host()}", to: (@user.uri || @user.ap_id) %>
|
||||||
</h3>
|
</h3>
|
||||||
<p><%= raw @user.bio %></p>
|
<p><%= raw @user.bio %></p>
|
||||||
|
|
35
priv/repo/migrations/20200406100225_users_add_emoji.exs
Normal file
35
priv/repo/migrations/20200406100225_users_add_emoji.exs
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
defmodule Pleroma.Repo.Migrations.UsersPopulateEmoji do
|
||||||
|
use Ecto.Migration
|
||||||
|
|
||||||
|
import Ecto.Query
|
||||||
|
|
||||||
|
alias Pleroma.User
|
||||||
|
alias Pleroma.Repo
|
||||||
|
|
||||||
|
def up do
|
||||||
|
execute("ALTER TABLE users ALTER COLUMN emoji SET DEFAULT '{}'::jsonb")
|
||||||
|
execute("UPDATE users SET emoji = DEFAULT WHERE emoji = '[]'::jsonb")
|
||||||
|
|
||||||
|
from(u in User)
|
||||||
|
|> select([u], struct(u, [:id, :ap_id, :source_data]))
|
||||||
|
|> Repo.stream()
|
||||||
|
|> Enum.each(fn user ->
|
||||||
|
emoji =
|
||||||
|
user.source_data
|
||||||
|
|> Map.get("tag", [])
|
||||||
|
|> Enum.filter(fn %{"type" => t} -> t == "Emoji" end)
|
||||||
|
|> Enum.reduce(%{}, fn %{"icon" => %{"url" => url}, "name" => name}, acc ->
|
||||||
|
Map.put(acc, String.trim(name, ":"), url)
|
||||||
|
end)
|
||||||
|
|
||||||
|
user
|
||||||
|
|> Ecto.Changeset.cast(%{emoji: emoji}, [:emoji])
|
||||||
|
|> Repo.update()
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
|
def down do
|
||||||
|
execute("ALTER TABLE users ALTER COLUMN emoji SET DEFAULT '[]'::jsonb")
|
||||||
|
execute("UPDATE users SET emoji = DEFAULT WHERE emoji = '{}'::jsonb")
|
||||||
|
end
|
||||||
|
end
|
|
@ -3,7 +3,6 @@
|
||||||
# SPDX-License-Identifier: AGPL-3.0-only
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
defmodule Pleroma.Emoji.FormatterTest do
|
defmodule Pleroma.Emoji.FormatterTest do
|
||||||
alias Pleroma.Emoji
|
|
||||||
alias Pleroma.Emoji.Formatter
|
alias Pleroma.Emoji.Formatter
|
||||||
use Pleroma.DataCase
|
use Pleroma.DataCase
|
||||||
|
|
||||||
|
@ -32,30 +31,19 @@ test "it does not add XSS emoji" do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "get_emoji" do
|
describe "get_emoji_map" do
|
||||||
test "it returns the emoji used in the text" do
|
test "it returns the emoji used in the text" do
|
||||||
text = "I love :firefox:"
|
assert Formatter.get_emoji_map("I love :firefox:") == %{
|
||||||
|
"firefox" => "http://localhost:4001/emoji/Firefox.gif"
|
||||||
assert Formatter.get_emoji(text) == [
|
}
|
||||||
{"firefox",
|
|
||||||
%Emoji{
|
|
||||||
code: "firefox",
|
|
||||||
file: "/emoji/Firefox.gif",
|
|
||||||
tags: ["Gif", "Fun"],
|
|
||||||
safe_code: "firefox",
|
|
||||||
safe_file: "/emoji/Firefox.gif"
|
|
||||||
}}
|
|
||||||
]
|
|
||||||
end
|
end
|
||||||
|
|
||||||
test "it returns a nice empty result when no emojis are present" do
|
test "it returns a nice empty result when no emojis are present" do
|
||||||
text = "I love moominamma"
|
assert Formatter.get_emoji_map("I love moominamma") == %{}
|
||||||
assert Formatter.get_emoji(text) == []
|
|
||||||
end
|
end
|
||||||
|
|
||||||
test "it doesn't die when text is absent" do
|
test "it doesn't die when text is absent" do
|
||||||
text = nil
|
assert Formatter.get_emoji_map(nil) == %{}
|
||||||
assert Formatter.get_emoji(text) == []
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -2182,4 +2182,18 @@ test "sets `replies` collection with a limited number of self-replies" do
|
||||||
Transmogrifier.set_replies(object.data)["replies"]
|
Transmogrifier.set_replies(object.data)["replies"]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "take_emoji_tags/1" do
|
||||||
|
user = insert(:user, %{emoji: %{"firefox" => "https://example.org/firefox.png"}})
|
||||||
|
|
||||||
|
assert Transmogrifier.take_emoji_tags(user) == [
|
||||||
|
%{
|
||||||
|
"icon" => %{"type" => "Image", "url" => "https://example.org/firefox.png"},
|
||||||
|
"id" => "https://example.org/firefox.png",
|
||||||
|
"name" => ":firefox:",
|
||||||
|
"type" => "Emoji",
|
||||||
|
"updated" => "1970-01-01T00:00:00Z"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -38,7 +38,7 @@ test "Renders profile fields" do
|
||||||
end
|
end
|
||||||
|
|
||||||
test "Renders with emoji tags" do
|
test "Renders with emoji tags" do
|
||||||
user = insert(:user, emoji: [%{"bib" => "/test"}])
|
user = insert(:user, emoji: %{"bib" => "/test"})
|
||||||
|
|
||||||
assert %{
|
assert %{
|
||||||
"tag" => [
|
"tag" => [
|
||||||
|
|
|
@ -97,18 +97,6 @@ test "it adds emoji in the object" do
|
||||||
assert Object.normalize(activity).data["emoji"]["firefox"]
|
assert Object.normalize(activity).data["emoji"]["firefox"]
|
||||||
end
|
end
|
||||||
|
|
||||||
test "it adds emoji when updating profiles" do
|
|
||||||
user = insert(:user, %{name: ":firefox:"})
|
|
||||||
|
|
||||||
{:ok, activity} = CommonAPI.update(user)
|
|
||||||
user = User.get_cached_by_ap_id(user.ap_id)
|
|
||||||
[firefox] = user.source_data["tag"]
|
|
||||||
|
|
||||||
assert firefox["name"] == ":firefox:"
|
|
||||||
|
|
||||||
assert Pleroma.Constants.as_public() in activity.recipients
|
|
||||||
end
|
|
||||||
|
|
||||||
describe "posting" do
|
describe "posting" do
|
||||||
test "it supports explicit addressing" do
|
test "it supports explicit addressing" do
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
|
|
|
@ -7,7 +7,6 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
|
||||||
alias Pleroma.Object
|
alias Pleroma.Object
|
||||||
alias Pleroma.Web.CommonAPI
|
alias Pleroma.Web.CommonAPI
|
||||||
alias Pleroma.Web.CommonAPI.Utils
|
alias Pleroma.Web.CommonAPI.Utils
|
||||||
alias Pleroma.Web.Endpoint
|
|
||||||
use Pleroma.DataCase
|
use Pleroma.DataCase
|
||||||
|
|
||||||
import ExUnit.CaptureLog
|
import ExUnit.CaptureLog
|
||||||
|
@ -42,28 +41,6 @@ test "correct password given" do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
test "parses emoji from name and bio" do
|
|
||||||
{:ok, user} = UserBuilder.insert(%{name: ":blank:", bio: ":firefox:"})
|
|
||||||
|
|
||||||
expected = [
|
|
||||||
%{
|
|
||||||
"type" => "Emoji",
|
|
||||||
"icon" => %{"type" => "Image", "url" => "#{Endpoint.url()}/emoji/Firefox.gif"},
|
|
||||||
"name" => ":firefox:"
|
|
||||||
},
|
|
||||||
%{
|
|
||||||
"type" => "Emoji",
|
|
||||||
"icon" => %{
|
|
||||||
"type" => "Image",
|
|
||||||
"url" => "#{Endpoint.url()}/emoji/blank.png"
|
|
||||||
},
|
|
||||||
"name" => ":blank:"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
|
|
||||||
assert expected == Utils.emoji_from_profile(user)
|
|
||||||
end
|
|
||||||
|
|
||||||
describe "format_input/3" do
|
describe "format_input/3" do
|
||||||
test "works for bare text/plain" do
|
test "works for bare text/plain" do
|
||||||
text = "hello world!"
|
text = "hello world!"
|
||||||
|
|
|
@ -19,16 +19,6 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
||||||
end
|
end
|
||||||
|
|
||||||
test "Represent a user account" do
|
test "Represent a user account" do
|
||||||
source_data = %{
|
|
||||||
"tag" => [
|
|
||||||
%{
|
|
||||||
"type" => "Emoji",
|
|
||||||
"icon" => %{"url" => "/file.png"},
|
|
||||||
"name" => ":karjalanpiirakka:"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
background_image = %{
|
background_image = %{
|
||||||
"url" => [%{"href" => "https://example.com/images/asuka_hospital.png"}]
|
"url" => [%{"href" => "https://example.com/images/asuka_hospital.png"}]
|
||||||
}
|
}
|
||||||
|
@ -37,13 +27,13 @@ test "Represent a user account" do
|
||||||
insert(:user, %{
|
insert(:user, %{
|
||||||
follower_count: 3,
|
follower_count: 3,
|
||||||
note_count: 5,
|
note_count: 5,
|
||||||
source_data: source_data,
|
|
||||||
background: background_image,
|
background: background_image,
|
||||||
nickname: "shp@shitposter.club",
|
nickname: "shp@shitposter.club",
|
||||||
name: ":karjalanpiirakka: shp",
|
name: ":karjalanpiirakka: shp",
|
||||||
bio:
|
bio:
|
||||||
"<script src=\"invalid-html\"></script><span>valid html</span>. a<br>b<br/>c<br >d<br />f",
|
"<script src=\"invalid-html\"></script><span>valid html</span>. a<br>b<br/>c<br >d<br />f",
|
||||||
inserted_at: ~N[2017-08-15 15:47:06.597036]
|
inserted_at: ~N[2017-08-15 15:47:06.597036],
|
||||||
|
emoji: %{"karjalanpiirakka" => "/file.png"}
|
||||||
})
|
})
|
||||||
|
|
||||||
expected = %{
|
expected = %{
|
||||||
|
@ -117,7 +107,6 @@ test "Represent a Service(bot) account" do
|
||||||
insert(:user, %{
|
insert(:user, %{
|
||||||
follower_count: 3,
|
follower_count: 3,
|
||||||
note_count: 5,
|
note_count: 5,
|
||||||
source_data: %{},
|
|
||||||
actor_type: "Service",
|
actor_type: "Service",
|
||||||
nickname: "shp@shitposter.club",
|
nickname: "shp@shitposter.club",
|
||||||
inserted_at: ~N[2017-08-15 15:47:06.597036]
|
inserted_at: ~N[2017-08-15 15:47:06.597036]
|
||||||
|
@ -311,7 +300,6 @@ test "represent an embedded relationship" do
|
||||||
insert(:user, %{
|
insert(:user, %{
|
||||||
follower_count: 0,
|
follower_count: 0,
|
||||||
note_count: 5,
|
note_count: 5,
|
||||||
source_data: %{},
|
|
||||||
actor_type: "Service",
|
actor_type: "Service",
|
||||||
nickname: "shp@shitposter.club",
|
nickname: "shp@shitposter.club",
|
||||||
inserted_at: ~N[2017-08-15 15:47:06.597036]
|
inserted_at: ~N[2017-08-15 15:47:06.597036]
|
||||||
|
|
Loading…
Reference in a new issue