From: Ivan Tashkinov Date: Thu, 26 Mar 2020 06:43:58 +0000 (+0300) Subject: Merge remote-tracking branch 'remotes/origin/develop' into relations-preloading-for... X-Git-Url: https://git.squeep.com/?a=commitdiff_plain;h=112101ca52a98b97749a56f2476a0f941a4aabdf;p=akkoma Merge remote-tracking branch 'remotes/origin/develop' into relations-preloading-for-statuses-rendering # Conflicts: # lib/pleroma/thread_mute.ex --- 112101ca52a98b97749a56f2476a0f941a4aabdf diff --cc lib/pleroma/thread_mute.ex index f657758aa,a7ea13891..5768e7711 --- a/lib/pleroma/thread_mute.ex +++ b/lib/pleroma/thread_mute.ex @@@ -24,13 -25,38 +25,38 @@@ defmodule Pleroma.ThreadMute d end def query(user_id, context) do - {:ok, user_id} = FlakeId.Ecto.CompatType.dump(user_id) + user_binary_id = User.binary_id(user_id) ThreadMute - |> Ecto.Query.where(user_id: ^user_binary_id) - |> Ecto.Query.where(context: ^context) - |> where(user_id: ^user_id) ++ |> where(user_id: ^user_binary_id) + |> where(context: ^context) end + def muters_query(context) do + ThreadMute + |> join(:inner, [tm], u in assoc(tm, :user)) + |> where([tm], tm.context == ^context) + |> select([tm, u], u.ap_id) + end + + def muter_ap_ids(context, ap_ids \\ nil) + + # Note: applies to fake activities (ActivityPub.Utils.get_notified_from_object/1 etc.) + def muter_ap_ids(context, _ap_ids) when is_nil(context), do: [] + + def muter_ap_ids(context, ap_ids) do + context + |> muters_query() + |> maybe_filter_on_ap_id(ap_ids) + |> Repo.all() + end + + defp maybe_filter_on_ap_id(query, ap_ids) when is_list(ap_ids) do + where(query, [tm, u], u.ap_id in ^ap_ids) + end + + defp maybe_filter_on_ap_id(query, _ap_ids), do: query + def add_mute(user_id, context) do %ThreadMute{} |> changeset(%{user_id: user_id, context: context})