Revert "Merge branch 'revert-a26d5e6b' into 'develop'"
[akkoma] / lib / pleroma / web / twitter_api / twitter_api_controller.ex
index 65e67396b2284ebf54b572ae8c9f2856e48044e0..c6637e38db9f37d8b3773db077612214dcc1789b 100644 (file)
@@ -1,7 +1,9 @@
 defmodule Pleroma.Web.TwitterAPI.Controller do
   use Pleroma.Web, :controller
+  alias Pleroma.Formatter
   alias Pleroma.Web.TwitterAPI.{TwitterAPI, UserView, ActivityView, NotificationView}
   alias Pleroma.Web.CommonAPI
+  alias Pleroma.Web.CommonAPI.Utils, as: CommonUtils
   alias Pleroma.{Repo, Activity, User, Notification}
   alias Pleroma.Web.ActivityPub.ActivityPub
   alias Pleroma.Web.ActivityPub.Utils
@@ -411,8 +413,18 @@ defmodule Pleroma.Web.TwitterAPI.Controller do
   def update_profile(%{assigns: %{user: user}} = conn, params) do
     params =
       if bio = params["description"] do
-        bio_brs = Regex.replace(~r/\r?\n/, bio, "<br>")
-        Map.put(params, "bio", bio_brs)
+        mentions = Formatter.parse_mentions(bio)
+        tags = Formatter.parse_tags(bio)
+
+        emoji =
+          (user.info["source_data"]["tag"] || [])
+          |> Enum.filter(fn %{"type" => t} -> t == "Emoji" end)
+          |> Enum.map(fn %{"icon" => %{"url" => url}, "name" => name} ->
+            {String.trim(name, ":"), url}
+          end)
+
+        bio_html = CommonUtils.format_input(bio, mentions, tags, "text/plain")
+        Map.put(params, "bio", bio_html |> Formatter.emojify(emoji))
       else
         params
       end
@@ -431,6 +443,20 @@ defmodule Pleroma.Web.TwitterAPI.Controller do
         user
       end
 
+    user =
+      if no_rich_text = params["no_rich_text"] do
+        with no_rich_text <- no_rich_text == "true",
+             new_info <- Map.put(user.info, "no_rich_text", no_rich_text),
+             change <- User.info_changeset(user, %{info: new_info}),
+             {:ok, user} <- User.update_and_set_cache(change) do
+          user
+        else
+          _e -> user
+        end
+      else
+        user
+      end
+
     user =
       if default_scope = params["default_scope"] do
         with new_info <- Map.put(user.info, "default_scope", default_scope),