Merge branch 'develop' into tests/mastodon_api_controller.ex
authorMaksim Pechnikov <parallel588@gmail.com>
Thu, 26 Sep 2019 13:13:07 +0000 (16:13 +0300)
committerMaksim Pechnikov <parallel588@gmail.com>
Thu, 26 Sep 2019 13:16:30 +0000 (16:16 +0300)
1  2 
lib/pleroma/activity.ex
lib/pleroma/user.ex
lib/pleroma/web/mastodon_api/controllers/mastodon_api_controller.ex
test/web/mastodon_api/mastodon_api_controller_test.exs

index b6e8e9e1dce4ffab3c5ea2779d9a3a30094a9e3d,2c04a26f95f11627cc966b4776793d76908f0659..c1065611bf31d9eccc5e8eba005ac8cc210c55e4
@@@ -137,18 -137,11 +137,18 @@@ defmodule Pleroma.Activity d
      |> Repo.one()
    end
  
 +  @spec get_by_id(String.t()) :: Activity.t() | nil
    def get_by_id(id) do
-     case Pleroma.FlakeId.is_flake_id?(id) do
 -    Activity
 -    |> where([a], a.id == ^id)
 -    |> restrict_deactivated_users()
 -    |> Repo.one()
++    case FlakeId.flake_id?(id) do
 +      true ->
 +        Activity
 +        |> where([a], a.id == ^id)
 +        |> restrict_deactivated_users()
 +        |> Repo.one()
 +
 +      _ ->
 +        nil
 +    end
    end
  
    def get_by_id_with_object(id) do
index e601b8ac071e44759345fba097e00144a1b49d7e,f3dcf7ad41175b2c8f7fabe8b14eb1ffddcaf4d6..4c1cdd042fecf864bca27d0c72857305e6dd8971
@@@ -798,30 -760,11 +765,24 @@@ defmodule Pleroma.User d
          where: fragment("?->>'actor' = ? and ?->>'type' = 'Note'", a.data, ^user.ap_id, a.data),
          select: count(a.id)
        )
+       |> Repo.one()
  
-     note_count = Repo.one(note_count_query)
-     info_cng = User.Info.set_note_count(user.info, note_count)
-     user
-     |> change()
-     |> put_embed(:info, info_cng)
-     |> update_and_set_cache()
+     update_info(user, &User.Info.set_note_count(&1, note_count))
    end
  
 +  def update_mascot(user, url) do
 +    info_changeset =
 +      User.Info.mascot_update(
 +        user.info,
 +        url
 +      )
 +
 +    user
 +    |> change()
 +    |> put_embed(:info, info_changeset)
 +    |> update_and_set_cache()
 +  end
 +
    @spec maybe_fetch_follow_information(User.t()) :: User.t()
    def maybe_fetch_follow_information(user) do
      with {:ok, user} <- fetch_follow_information(user) do
index fa768fa9335858c8a694e185204259f077278dd7,1e88ff7feec2c1dba5a2772911f0d8881e17a2c6..5e1977b8e640d47cb59813904b152dc3e70cea4c
@@@ -721,51 -713,10 +712,8 @@@ defmodule Pleroma.Web.MastodonAPI.Masto
      end
    end
  
-   def notifications(%{assigns: %{user: user}} = conn, params) do
-     notifications = MastodonAPI.get_notifications(user, params)
-     conn
-     |> add_link_headers(notifications)
-     |> put_view(NotificationView)
-     |> render("index.json", %{notifications: notifications, for: user})
-   end
-   def get_notification(%{assigns: %{user: user}} = conn, %{"id" => id} = _params) do
-     with {:ok, notification} <- Notification.get(user, id) do
-       conn
-       |> put_view(NotificationView)
-       |> render("show.json", %{notification: notification, for: user})
-     else
-       {:error, reason} ->
-         conn
-         |> put_status(:forbidden)
-         |> json(%{"error" => reason})
-     end
-   end
-   def clear_notifications(%{assigns: %{user: user}} = conn, _params) do
-     Notification.clear(user)
-     json(conn, %{})
-   end
-   def dismiss_notification(%{assigns: %{user: user}} = conn, %{"id" => id} = _params) do
-     with {:ok, _notif} <- Notification.dismiss(user, id) do
-       json(conn, %{})
-     else
-       {:error, reason} ->
-         conn
-         |> put_status(:forbidden)
-         |> json(%{"error" => reason})
-     end
-   end
-   def destroy_multiple(%{assigns: %{user: user}} = conn, %{"ids" => ids} = _params) do
-     Notification.destroy_multiple(user, ids)
-     json(conn, %{})
-   end
    def relationships(%{assigns: %{user: user}} = conn, %{"id" => id}) do
 -    id = List.wrap(id)
 -    q = from(u in User, where: u.id in ^id)
 -    targets = Repo.all(q)
 +    targets = User.get_all_by_ids(List.wrap(id))
  
      conn
      |> put_view(AccountView)