@@ -56,7 +56,6 @@ defmodule Mobilizon.Actors do
|
||||
:rejected
|
||||
])
|
||||
|
||||
@public_visibility [:public, :unlisted]
|
||||
@administrator_roles [:creator, :administrator]
|
||||
@moderator_roles [:moderator] ++ @administrator_roles
|
||||
@member_roles [:member] ++ @moderator_roles
|
||||
@@ -537,6 +536,15 @@ defmodule Mobilizon.Actors do
|
||||
|> Page.build_page(page, limit)
|
||||
end
|
||||
|
||||
@doc """
|
||||
Lists the groups.
|
||||
"""
|
||||
@spec list_groups_for_stream :: Enum.t()
|
||||
def list_groups_for_stream do
|
||||
groups_query()
|
||||
|> Repo.stream()
|
||||
end
|
||||
|
||||
@doc """
|
||||
Returns the list of groups an actor is member of.
|
||||
"""
|
||||
@@ -1212,7 +1220,7 @@ defmodule Mobilizon.Actors do
|
||||
from(
|
||||
a in Actor,
|
||||
where: a.type == ^:Group,
|
||||
where: a.visibility in ^@public_visibility
|
||||
where: a.visibility == ^:public
|
||||
)
|
||||
end
|
||||
|
||||
|
||||
@@ -366,6 +366,15 @@ defmodule Mobilizon.Events do
|
||||
|> Repo.all()
|
||||
end
|
||||
|
||||
@spec stream_events_for_sitemap :: Enum.t()
|
||||
def stream_events_for_sitemap do
|
||||
Event
|
||||
|> filter_public_visibility()
|
||||
|> filter_draft()
|
||||
|> filter_local()
|
||||
|> Repo.stream()
|
||||
end
|
||||
|
||||
@doc """
|
||||
Returns the list of events with the same tags.
|
||||
"""
|
||||
@@ -1583,6 +1592,11 @@ defmodule Mobilizon.Events do
|
||||
|
||||
defp filter_future_events(query, false), do: query
|
||||
|
||||
@spec filter_local(Ecto.Query.t()) :: Ecto.Query.t()
|
||||
defp filter_local(query) do
|
||||
where(query, [q], q.local == true)
|
||||
end
|
||||
|
||||
@spec filter_local_or_from_followed_instances_events(Ecto.Query.t()) :: Ecto.Query.t()
|
||||
defp filter_local_or_from_followed_instances_events(query) do
|
||||
from(q in query,
|
||||
|
||||
@@ -21,6 +21,13 @@ defmodule Mobilizon.Posts do
|
||||
:private
|
||||
])
|
||||
|
||||
@spec list_posts_for_stream :: Enum.t()
|
||||
def list_posts_for_stream do
|
||||
Post
|
||||
|> filter_public()
|
||||
|> Repo.stream()
|
||||
end
|
||||
|
||||
@doc """
|
||||
Returns the list of recent posts for a group
|
||||
"""
|
||||
@@ -35,7 +42,7 @@ defmodule Mobilizon.Posts do
|
||||
def get_public_posts_for_group(%Actor{id: group_id}, page \\ nil, limit \\ nil) do
|
||||
group_id
|
||||
|> do_get_posts_for_group()
|
||||
|> where([p], p.visibility == ^:public and not p.draft)
|
||||
|> filter_public()
|
||||
|> Page.build_page(page, limit)
|
||||
end
|
||||
|
||||
@@ -132,4 +139,9 @@ defmodule Mobilizon.Posts do
|
||||
where: p.post_id == ^post_id
|
||||
)
|
||||
end
|
||||
|
||||
@spec filter_public(Ecto.Query.t()) :: Ecto.Query.t()
|
||||
defp filter_public(query) do
|
||||
where(query, [p], p.visibility == ^:public and not p.draft)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -43,7 +43,7 @@ defmodule Mobilizon.Storage.Ecto do
|
||||
|> put_change(:id, uuid)
|
||||
|> put_change(
|
||||
:url,
|
||||
apply(Routes, String.to_existing_atom("#{to_string(route)}_url"), [Endpoint, route, uuid])
|
||||
apply(Routes, String.to_existing_atom("page_url"), [Endpoint, route, uuid])
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user