From: Maksim Pechnikov Date: Thu, 26 Sep 2019 13:13:07 +0000 (+0300) Subject: Merge branch 'develop' into tests/mastodon_api_controller.ex X-Git-Url: https://git.squeep.com/?a=commitdiff_plain;h=3d722dc2008ab7e5dde4b474bb038a1857a28d85;p=akkoma Merge branch 'develop' into tests/mastodon_api_controller.ex --- 3d722dc2008ab7e5dde4b474bb038a1857a28d85 diff --cc lib/pleroma/activity.ex index b6e8e9e1d,2c04a26f9..c1065611b --- a/lib/pleroma/activity.ex +++ b/lib/pleroma/activity.ex @@@ -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 diff --cc lib/pleroma/user.ex index e601b8ac0,f3dcf7ad4..4c1cdd042 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@@ -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 diff --cc lib/pleroma/web/mastodon_api/controllers/mastodon_api_controller.ex index fa768fa93,1e88ff7fe..5e1977b8e --- a/lib/pleroma/web/mastodon_api/controllers/mastodon_api_controller.ex +++ b/lib/pleroma/web/mastodon_api/controllers/mastodon_api_controller.ex @@@ -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)