Merge branch 'feature/create-tombstone-instead-of-delete' into 'develop'
[akkoma] / lib / pleroma / web / twitter_api / twitter_api_controller.ex
index e047ed0add186ca87a813c7d21222e3a7006d91d..7ae850d71471544f3f48392bdd6fe6a55d1bafe4 100644 (file)
@@ -1,3 +1,7 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
 defmodule Pleroma.Web.TwitterAPI.Controller do
   use Pleroma.Web, :controller
 
@@ -13,7 +17,6 @@ defmodule Pleroma.Web.TwitterAPI.Controller do
   require Logger
 
   plug(:only_if_public_instance when action in [:public_timeline, :public_and_external_timeline])
-  plug(:fetch_flash when action in [:confirm_email, :resend_confirmation_email])
   action_fallback(:errors)
 
   def verify_credentials(%{assigns: %{user: user}} = conn, _params) do
@@ -100,7 +103,9 @@ defmodule Pleroma.Web.TwitterAPI.Controller do
     for_user = conn.assigns.user
 
     with {:ok, shown} <- TwitterAPI.get_user(params),
-         true <- User.auth_active?(shown) || for_user && (for_user.id == shown.id || User.superuser?(for_user)) do
+         true <-
+           User.auth_active?(shown) ||
+             (for_user && (for_user.id == shown.id || User.superuser?(for_user))) do
       params =
         if for_user do
           %{user: shown, for: for_user}
@@ -125,6 +130,15 @@ defmodule Pleroma.Web.TwitterAPI.Controller do
   def user_timeline(%{assigns: %{user: user}} = conn, params) do
     case TwitterAPI.get_user(user, params) do
       {:ok, target_user} ->
+        # Twitter and ActivityPub use a different name and sense for this parameter.
+        {include_rts, params} = Map.pop(params, "include_rts")
+
+        params =
+          case include_rts do
+            x when x == "false" or x == "0" -> Map.put(params, "exclude_reblogs", "true")
+            _ -> params
+          end
+
         activities = ActivityPub.fetch_user_activities(target_user, user, params)
 
         conn
@@ -381,14 +395,15 @@ defmodule Pleroma.Web.TwitterAPI.Controller do
     end
   end
 
-  def confirm_email(conn, %{"token" => token}) do
-    with %User{} = user <- User.get_by_confirmation_token(token),
+  def confirm_email(conn, %{"user_id" => uid, "token" => token}) do
+    with %User{} = user <- Repo.get(User, uid),
          true <- user.local,
+         true <- user.info.confirmation_pending,
+         true <- user.info.confirmation_token == token,
          info_change <- User.Info.confirmation_changeset(user.info, :confirmed),
          changeset <- Changeset.change(user) |> Changeset.put_embed(:info, info_change),
          {:ok, _} <- User.update_and_set_cache(changeset) do
       conn
-      |> put_flash(:info, "Email confirmed. Please sign in.")
       |> redirect(to: "/")
     end
   end
@@ -399,7 +414,6 @@ defmodule Pleroma.Web.TwitterAPI.Controller do
     with %User{} = user <- User.get_by_nickname_or_email(nickname_or_email),
          {:ok, _} <- User.try_send_confirmation_email(user) do
       conn
-      |> put_flash(:info, "Email confirmation has been sent.")
       |> json_response(:no_content, "")
     end
   end