Merge branch 'develop' into feature/tag_feed
This commit is contained in:
commit
5ea8596448
9 changed files with 88 additions and 23 deletions
|
|
@ -312,9 +312,7 @@ defmodule Pleroma.Activity do
|
|||
from(u in User.Query.build(deactivated: true), select: u.ap_id)
|
||||
|> Repo.all()
|
||||
|
||||
from(activity in query,
|
||||
where: activity.actor not in ^deactivated_users
|
||||
)
|
||||
Activity.Queries.exclude_authors(query, deactivated_users)
|
||||
end
|
||||
|
||||
defdelegate search(user, query, options \\ []), to: Pleroma.Activity.Search
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ defmodule Pleroma.Activity.Queries do
|
|||
@type query :: Ecto.Queryable.t() | Activity.t()
|
||||
|
||||
alias Pleroma.Activity
|
||||
alias Pleroma.User
|
||||
|
||||
@spec by_ap_id(query, String.t()) :: query
|
||||
def by_ap_id(query \\ Activity, ap_id) do
|
||||
|
|
@ -29,6 +30,11 @@ defmodule Pleroma.Activity.Queries do
|
|||
)
|
||||
end
|
||||
|
||||
@spec by_author(query, String.t()) :: query
|
||||
def by_author(query \\ Activity, %User{ap_id: ap_id}) do
|
||||
from(a in query, where: a.actor == ^ap_id)
|
||||
end
|
||||
|
||||
@spec by_object_id(query, String.t() | [String.t()]) :: query
|
||||
def by_object_id(query \\ Activity, object_id)
|
||||
|
||||
|
|
@ -72,4 +78,8 @@ defmodule Pleroma.Activity.Queries do
|
|||
where: fragment("(?)->>'type' != ?", activity.data, ^activity_type)
|
||||
)
|
||||
end
|
||||
|
||||
def exclude_authors(query \\ Activity, actors) do
|
||||
from(activity in query, where: activity.actor not in ^actors)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -26,18 +26,23 @@ defmodule Pleroma.Activity.Search do
|
|||
|> query_with(index_type, search_query)
|
||||
|> maybe_restrict_local(user)
|
||||
|> maybe_restrict_author(author)
|
||||
|> maybe_restrict_blocked(user)
|
||||
|> Pagination.fetch_paginated(%{"offset" => offset, "limit" => limit}, :offset)
|
||||
|> maybe_fetch(user, search_query)
|
||||
end
|
||||
|
||||
def maybe_restrict_author(query, %User{} = author) do
|
||||
from([a, o] in query,
|
||||
where: a.actor == ^author.ap_id
|
||||
)
|
||||
Activity.Queries.by_author(query, author)
|
||||
end
|
||||
|
||||
def maybe_restrict_author(query, _), do: query
|
||||
|
||||
def maybe_restrict_blocked(query, %User{} = user) do
|
||||
Activity.Queries.exclude_authors(query, User.blocked_users_ap_ids(user))
|
||||
end
|
||||
|
||||
def maybe_restrict_blocked(query, _), do: query
|
||||
|
||||
defp restrict_public(q) do
|
||||
from([a, o] in q,
|
||||
where: fragment("?->>'type' = 'Create'", a.data),
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ defmodule Pleroma.Web.MastodonAPI.SearchController do
|
|||
result =
|
||||
default_values
|
||||
|> Enum.map(fn {resource, default_value} ->
|
||||
if params["type"] == nil or params["type"] == resource do
|
||||
if params["type"] in [nil, resource] do
|
||||
{resource, fn -> resource_search(version, resource, query, options) end}
|
||||
else
|
||||
{resource, fn -> default_value end}
|
||||
|
|
|
|||
|
|
@ -253,6 +253,16 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
|
|||
nil
|
||||
end
|
||||
|
||||
emoji_reactions =
|
||||
with %{data: %{"reactions" => emoji_reactions}} <- object do
|
||||
Enum.map(emoji_reactions, fn {emoji, users} ->
|
||||
{emoji, length(users)}
|
||||
end)
|
||||
|> Enum.into(%{})
|
||||
else
|
||||
_ -> %{}
|
||||
end
|
||||
|
||||
%{
|
||||
id: to_string(activity.id),
|
||||
uri: object.data["id"],
|
||||
|
|
@ -293,7 +303,8 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
|
|||
spoiler_text: %{"text/plain" => summary_plaintext},
|
||||
expires_at: expires_at,
|
||||
direct_conversation_id: direct_conversation_id,
|
||||
thread_muted: thread_muted?
|
||||
thread_muted: thread_muted?,
|
||||
emoji_reactions: emoji_reactions
|
||||
}
|
||||
}
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue