end
def restrict_recipients(query, user, %{"recipients" => user_ids}) do
- user_ids =
+ user_binary_ids =
[user.id | user_ids]
|> Enum.uniq()
- |> Enum.reduce([], fn user_id, acc ->
- {:ok, user_id} = FlakeId.Ecto.CompatType.dump(user_id)
- [user_id | acc]
- end)
+ |> User.binary_id()
conversation_subquery =
__MODULE__
|> group_by([p], p.conversation_id)
|> having(
[p],
- count(p.user_id) == ^length(user_ids) and
- fragment("array_agg(?) @> ?", p.user_id, ^user_ids)
+ count(p.user_id) == ^length(user_binary_ids) and
+ fragment("array_agg(?) @> ?", p.user_id, ^user_binary_ids)
)
|> select([p], %{id: p.conversation_id})
target_users
)
when is_list(source_users) and is_list(target_users) do
- get_bin_ids = fn user ->
- with {:ok, bin_id} <- CompatType.dump(user.id), do: bin_id
- end
-
- source_user_ids = Enum.map(source_users, &get_bin_ids.(&1))
- target_user_ids = Enum.map(target_users, &get_bin_ids.(&1))
+ source_user_ids = User.binary_id(source_users)
+ target_user_ids = User.binary_id(target_users)
__MODULE__
|> where(
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_id)
+ |> Ecto.Query.where(user_id: ^user_binary_id)
|> Ecto.Query.where(context: ^context)
end
end
end
+ @doc "Dumps id to SQL-compatible format"
+ def binary_id(source_id) when is_binary(source_id) do
+ with {:ok, dumped_id} <- FlakeId.Ecto.CompatType.dump(source_id) do
+ dumped_id
+ else
+ _ -> source_id
+ end
+ end
+
+ def binary_id(source_ids) when is_list(source_ids) do
+ Enum.map(source_ids, &binary_id/1)
+ end
+
+ def binary_id(%User{} = user), do: binary_id(user.id)
+
@doc "Returns status account"
@spec account_status(User.t()) :: account_status()
def account_status(%User{deactivated: true}), do: :deactivated
import Ecto.Changeset
import Ecto.Query
- alias FlakeId.Ecto.CompatType
alias Pleroma.Repo
alias Pleroma.User
alias Pleroma.UserRelationship
target_to_source_rel_types \\ nil
)
when is_list(source_users) and is_list(target_users) do
- get_bin_ids = fn user ->
- with {:ok, bin_id} <- CompatType.dump(user.id), do: bin_id
- end
-
- source_user_ids = Enum.map(source_users, &get_bin_ids.(&1))
- target_user_ids = Enum.map(target_users, &get_bin_ids.(&1))
+ source_user_ids = User.binary_id(source_users)
+ target_user_ids = User.binary_id(target_users)
get_rel_type_codes = fn rel_type -> user_relationship_mappings()[rel_type] end
alias Pleroma.UserRelationship
alias Pleroma.Web.CommonAPI.Utils
alias Pleroma.Web.MastodonAPI.AccountView
+ alias Pleroma.Web.MastodonAPI.StatusView
alias Pleroma.Web.MediaProxy
defp find_following_rel(following_relationships, follower, following) do
end
def render("relationships.json", %{user: user, targets: targets}) do
- render_many(targets, AccountView, "relationship.json", user: user, as: :target)
+ relationships_opts = StatusView.relationships_opts(user, targets)
+ opts = %{as: :target, user: user, relationships: relationships_opts}
+
+ render_many(targets, AccountView, "relationship.json", opts)
end
defp do_render("show.json", %{user: user} = opts) do