Remove duplicate @doc blocs
Elixir 11 notifies this a lot Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
parent
d0718ee397
commit
dc617d2239
@ -405,7 +405,7 @@ defmodule Mobilizon.Federation.ActivityPub do
|
||||
def leave(object, actor, local \\ true, additional \\ %{})
|
||||
|
||||
@doc """
|
||||
Leave an event
|
||||
Leave an event or a group
|
||||
"""
|
||||
def leave(
|
||||
%Event{id: event_id, url: event_url} = _event,
|
||||
@ -438,9 +438,6 @@ defmodule Mobilizon.Federation.ActivityPub do
|
||||
end
|
||||
end
|
||||
|
||||
@doc """
|
||||
Leave a group
|
||||
"""
|
||||
def leave(
|
||||
%Actor{type: :Group, id: group_id, url: group_url, members_url: group_members_url},
|
||||
%Actor{id: actor_id, url: actor_url},
|
||||
|
@ -15,11 +15,23 @@ defmodule Mobilizon.Federation.ActivityPub.Audience do
|
||||
@ap_public "https://www.w3.org/ns/activitystreams#Public"
|
||||
|
||||
@doc """
|
||||
Determines the full audience based on mentions for a public audience
|
||||
Determines the full audience based on mentions for an audience
|
||||
|
||||
Audience is:
|
||||
For a public audience:
|
||||
* `to` : the mentioned actors, the eventual actor we're replying to and the public
|
||||
* `cc` : the actor's followers
|
||||
|
||||
For an unlisted audience:
|
||||
* `to` : the mentioned actors, actor's followers and the eventual actor we're replying to
|
||||
* `cc` : public
|
||||
|
||||
For a private audience:
|
||||
* `to` : the mentioned actors, actor's followers and the eventual actor we're replying to
|
||||
* `cc` : none
|
||||
|
||||
For a direct audience:
|
||||
* `to` : the mentioned actors and the eventual actor we're replying to
|
||||
* `cc` : none
|
||||
"""
|
||||
@spec get_to_and_cc(Actor.t(), list(), String.t()) :: {list(), list()}
|
||||
def get_to_and_cc(%Actor{} = actor, mentions, :public) do
|
||||
@ -29,13 +41,6 @@ defmodule Mobilizon.Federation.ActivityPub.Audience do
|
||||
{to, cc}
|
||||
end
|
||||
|
||||
@doc """
|
||||
Determines the full audience based on mentions based on a unlisted audience
|
||||
|
||||
Audience is:
|
||||
* `to` : the mentioned actors, actor's followers and the eventual actor we're replying to
|
||||
* `cc` : public
|
||||
"""
|
||||
@spec get_to_and_cc(Actor.t(), list(), String.t()) :: {list(), list()}
|
||||
def get_to_and_cc(%Actor{} = actor, mentions, :unlisted) do
|
||||
to = [actor.followers_url | mentions]
|
||||
@ -44,26 +49,12 @@ defmodule Mobilizon.Federation.ActivityPub.Audience do
|
||||
{to, cc}
|
||||
end
|
||||
|
||||
@doc """
|
||||
Determines the full audience based on mentions based on a private audience
|
||||
|
||||
Audience is:
|
||||
* `to` : the mentioned actors, actor's followers and the eventual actor we're replying to
|
||||
* `cc` : none
|
||||
"""
|
||||
@spec get_to_and_cc(Actor.t(), list(), String.t()) :: {list(), list()}
|
||||
def get_to_and_cc(%Actor{} = actor, mentions, :private) do
|
||||
{to, cc} = get_to_and_cc(actor, mentions, :direct)
|
||||
{[actor.followers_url | to], cc}
|
||||
end
|
||||
|
||||
@doc """
|
||||
Determines the full audience based on mentions based on a direct audience
|
||||
|
||||
Audience is:
|
||||
* `to` : the mentioned actors and the eventual actor we're replying to
|
||||
* `cc` : none
|
||||
"""
|
||||
@spec get_to_and_cc(Actor.t(), list(), String.t()) :: {list(), list()}
|
||||
def get_to_and_cc(_actor, mentions, :direct) do
|
||||
{mentions, []}
|
||||
|
@ -26,6 +26,9 @@ defmodule Mobilizon.Federation.ActivityPub.Transmogrifier do
|
||||
|
||||
require Logger
|
||||
|
||||
@doc """
|
||||
Handle incoming activities
|
||||
"""
|
||||
def handle_incoming(%{"id" => nil}), do: :error
|
||||
def handle_incoming(%{"id" => ""}), do: :error
|
||||
|
||||
@ -47,18 +50,16 @@ defmodule Mobilizon.Federation.ActivityPub.Transmogrifier do
|
||||
end
|
||||
end
|
||||
|
||||
@doc """
|
||||
Handles a `Create` activity for `Note` (comments) objects
|
||||
|
||||
The following actions are performed
|
||||
* Fetch the author of the activity
|
||||
* Convert the ActivityStream data to the comment model format (it also finds and inserts tags)
|
||||
* Get (by it's URL) or create the comment with this data
|
||||
* Insert eventual mentions in the database
|
||||
* Convert the comment back in ActivityStreams data
|
||||
* Wrap this data back into a `Create` activity
|
||||
* Return the activity and the comment object
|
||||
"""
|
||||
# Handles a `Create` activity for `Note` (comments) objects
|
||||
#
|
||||
# The following actions are performed
|
||||
# * Fetch the author of the activity
|
||||
# * Convert the ActivityStream data to the comment model format (it also finds and inserts tags)
|
||||
# * Get (by it's URL) or create the comment with this data
|
||||
# * Insert eventual mentions in the database
|
||||
# * Convert the comment back in ActivityStreams data
|
||||
# * Wrap this data back into a `Create` activity
|
||||
# * Return the activity and the comment object
|
||||
def handle_incoming(%{"type" => "Create", "object" => %{"type" => "Note"} = object}) do
|
||||
Logger.info("Handle incoming to create notes")
|
||||
|
||||
@ -88,18 +89,16 @@ defmodule Mobilizon.Federation.ActivityPub.Transmogrifier do
|
||||
end
|
||||
end
|
||||
|
||||
@doc """
|
||||
Handles a `Create` activity for `Event` objects
|
||||
|
||||
The following actions are performed
|
||||
* Fetch the author of the activity
|
||||
* Convert the ActivityStream data to the event model format (it also finds and inserts tags)
|
||||
* Get (by it's URL) or create the event with this data
|
||||
* Insert eventual mentions in the database
|
||||
* Convert the event back in ActivityStreams data
|
||||
* Wrap this data back into a `Create` activity
|
||||
* Return the activity and the event object
|
||||
"""
|
||||
# Handles a `Create` activity for `Event` objects
|
||||
#
|
||||
# The following actions are performed
|
||||
# * Fetch the author of the activity
|
||||
# * Convert the ActivityStream data to the event model format (it also finds and inserts tags)
|
||||
# * Get (by it's URL) or create the event with this data
|
||||
# * Insert eventual mentions in the database
|
||||
# * Convert the event back in ActivityStreams data
|
||||
# * Wrap this data back into a `Create` activity
|
||||
# * Return the activity and the event object
|
||||
def handle_incoming(%{"type" => "Create", "object" => %{"type" => "Event"} = object}) do
|
||||
Logger.info("Handle incoming to create event")
|
||||
|
||||
@ -743,10 +742,8 @@ defmodule Mobilizon.Federation.ActivityPub.Transmogrifier do
|
||||
{:error, :not_supported}
|
||||
end
|
||||
|
||||
@doc """
|
||||
Handle incoming `Accept` activities wrapping a `Follow` activity
|
||||
"""
|
||||
def do_handle_incoming_accept_following(follow_object, %Actor{} = actor) do
|
||||
# Handle incoming `Accept` activities wrapping a `Follow` activity
|
||||
defp do_handle_incoming_accept_following(follow_object, %Actor{} = actor) do
|
||||
with {:follow,
|
||||
{:ok, %Follower{approved: false, target_actor: followed, actor: follower} = follow}} <-
|
||||
{:follow, get_follow(follow_object)},
|
||||
@ -781,10 +778,8 @@ defmodule Mobilizon.Federation.ActivityPub.Transmogrifier do
|
||||
end
|
||||
end
|
||||
|
||||
@doc """
|
||||
Handle incoming `Reject` activities wrapping a `Follow` activity
|
||||
"""
|
||||
def do_handle_incoming_reject_following(follow_object, %Actor{} = actor) do
|
||||
# Handle incoming `Reject` activities wrapping a `Follow` activity
|
||||
defp do_handle_incoming_reject_following(follow_object, %Actor{} = actor) do
|
||||
with {:follow, {:ok, %Follower{target_actor: followed} = follow}} <-
|
||||
{:follow, get_follow(follow_object)},
|
||||
{:same_actor, true} <- {:same_actor, actor.id == followed.id},
|
||||
|
@ -330,6 +330,12 @@ defmodule Mobilizon.Federation.ActivityPub.Utils do
|
||||
end
|
||||
|
||||
@doc """
|
||||
Return AS Link data from
|
||||
|
||||
* a `Plug.Upload` struct, stored an returned
|
||||
* a `Picture`, directly returned
|
||||
* a map containing picture information, stored, saved and returned
|
||||
|
||||
Save picture data from %Plug.Upload{} and return AS Link data.
|
||||
"""
|
||||
def make_picture_data(%Plug.Upload{} = picture, opts) do
|
||||
@ -342,16 +348,10 @@ defmodule Mobilizon.Federation.ActivityPub.Utils do
|
||||
end
|
||||
end
|
||||
|
||||
@doc """
|
||||
Convert a picture model into an AS Link representation.
|
||||
"""
|
||||
def make_picture_data(%Picture{} = picture) do
|
||||
Converter.Picture.model_to_as(picture)
|
||||
end
|
||||
|
||||
@doc """
|
||||
Save picture data from raw data and return AS Link data.
|
||||
"""
|
||||
def make_picture_data(picture) when is_map(picture) do
|
||||
with {:ok, %{"url" => [%{"href" => url, "mediaType" => content_type}], "size" => size}} <-
|
||||
Mobilizon.Web.Upload.store(picture.file),
|
||||
|
@ -88,6 +88,8 @@ defmodule Mobilizon.Federation.ActivityStream.Converter.Comment do
|
||||
|
||||
@doc """
|
||||
Make an AS comment object from an existing `Comment` structure.
|
||||
|
||||
A "soft-deleted" comment is a tombstone
|
||||
"""
|
||||
@impl Converter
|
||||
@spec model_to_as(CommentModel.t()) :: map
|
||||
@ -127,9 +129,6 @@ defmodule Mobilizon.Federation.ActivityStream.Converter.Comment do
|
||||
end
|
||||
end
|
||||
|
||||
@doc """
|
||||
A "soft-deleted" comment is a tombstone
|
||||
"""
|
||||
@impl Converter
|
||||
@spec model_to_as(CommentModel.t()) :: map
|
||||
def model_to_as(%CommentModel{} = comment) do
|
||||
|
@ -12,7 +12,7 @@ defmodule Mobilizon.GraphQL.Resolvers.FeedToken do
|
||||
require Logger
|
||||
|
||||
@doc """
|
||||
Create an feed token for an user and a defined actor
|
||||
Create an feed token for an user and optionally a defined actor
|
||||
"""
|
||||
@spec create_feed_token(any, map, map) :: {:ok, FeedToken.t()} | {:error, String.t()}
|
||||
def create_feed_token(
|
||||
@ -29,9 +29,6 @@ defmodule Mobilizon.GraphQL.Resolvers.FeedToken do
|
||||
end
|
||||
end
|
||||
|
||||
@doc """
|
||||
Create an feed token for an user
|
||||
"""
|
||||
@spec create_feed_token(any, map, map) :: {:ok, FeedToken.t()}
|
||||
def create_feed_token(_parent, %{}, %{context: %{current_user: %User{id: id}}}) do
|
||||
with {:ok, feed_token} <- Events.create_feed_token(%{user_id: id}) do
|
||||
|
@ -42,9 +42,6 @@ defmodule Mobilizon.GraphQL.Resolvers.Group do
|
||||
end
|
||||
end
|
||||
|
||||
@doc """
|
||||
Find a group
|
||||
"""
|
||||
def find_group(_parent, %{preferred_username: name}, _resolution) do
|
||||
with {:ok, actor} <- ActivityPub.find_or_make_group_from_nickname(name),
|
||||
%Actor{} = actor <- Person.proxify_pictures(actor),
|
||||
|
@ -14,7 +14,7 @@ defmodule Mobilizon.GraphQL.Resolvers.Participant do
|
||||
import Mobilizon.Web.Gettext
|
||||
|
||||
@doc """
|
||||
Join an event for an regular actor
|
||||
Join an event for an regular or anonymous actor
|
||||
"""
|
||||
def actor_join_event(
|
||||
_parent,
|
||||
@ -30,9 +30,6 @@ defmodule Mobilizon.GraphQL.Resolvers.Participant do
|
||||
end
|
||||
end
|
||||
|
||||
@doc """
|
||||
Join an event for an anonymous actor
|
||||
"""
|
||||
def actor_join_event(
|
||||
_parent,
|
||||
%{actor_id: actor_id, event_id: event_id} = args,
|
||||
|
@ -126,9 +126,6 @@ defmodule Mobilizon.GraphQL.Resolvers.Person do
|
||||
end
|
||||
end
|
||||
|
||||
@doc """
|
||||
This function is used to create more identities from an existing user
|
||||
"""
|
||||
def create_person(_parent, _args, _resolution) do
|
||||
{:error, :unauthenticated}
|
||||
end
|
||||
@ -240,7 +237,7 @@ defmodule Mobilizon.GraphQL.Resolvers.Person do
|
||||
end
|
||||
|
||||
@doc """
|
||||
Returns the participation for a specific event
|
||||
Returns the participations, optionally restricted to an event
|
||||
"""
|
||||
def person_participations(
|
||||
%Actor{id: actor_id},
|
||||
@ -260,9 +257,6 @@ defmodule Mobilizon.GraphQL.Resolvers.Person do
|
||||
end
|
||||
end
|
||||
|
||||
@doc """
|
||||
Returns the list of events this person is going to
|
||||
"""
|
||||
def person_participations(%Actor{id: actor_id} = actor, %{page: page, limit: limit}, %{
|
||||
context: %{current_user: %User{role: role} = user}
|
||||
}) do
|
||||
|
@ -10,17 +10,14 @@ defmodule Mobilizon.GraphQL.Resolvers.Picture do
|
||||
import Mobilizon.Web.Gettext
|
||||
|
||||
@doc """
|
||||
Get picture for an event's pic
|
||||
Get picture for an event
|
||||
|
||||
See Mobilizon.Web.Resolvers.Event.create_event/3
|
||||
"""
|
||||
def picture(%{picture_id: picture_id} = _parent, _args, _resolution) do
|
||||
with {:ok, picture} <- do_fetch_picture(picture_id), do: {:ok, picture}
|
||||
end
|
||||
|
||||
@doc """
|
||||
Get picture for an event that has an attached
|
||||
|
||||
See Mobilizon.Web.Resolvers.Event.create_event/3
|
||||
"""
|
||||
def picture(%{picture: picture} = _parent, _args, _resolution), do: {:ok, picture}
|
||||
def picture(_parent, %{id: picture_id}, _resolution), do: do_fetch_picture(picture_id)
|
||||
def picture(_parent, _args, _resolution), do: {:ok, nil}
|
||||
|
@ -44,7 +44,7 @@ defmodule Mobilizon.GraphQL.Resolvers.Report do
|
||||
end
|
||||
|
||||
@doc """
|
||||
Create a report
|
||||
Create a report, either logged-in or anonymously
|
||||
"""
|
||||
def create_report(
|
||||
_parent,
|
||||
@ -63,9 +63,6 @@ defmodule Mobilizon.GraphQL.Resolvers.Report do
|
||||
end
|
||||
end
|
||||
|
||||
@doc """
|
||||
Create a report anonymously if allowed
|
||||
"""
|
||||
def create_report(
|
||||
_parent,
|
||||
%{reporter_id: reporter_id} = args,
|
||||
|
@ -15,14 +15,14 @@ defmodule Mobilizon.GraphQL.Resolvers.Tag do
|
||||
|
||||
@doc """
|
||||
Retrieve the list of tags for an event
|
||||
|
||||
From an event or a struct with an url
|
||||
"""
|
||||
def list_tags_for_event(%Event{id: id}, _args, _resolution) do
|
||||
{:ok, Events.list_tags_for_event(id)}
|
||||
end
|
||||
|
||||
@doc """
|
||||
Retrieve the list of tags for an event
|
||||
"""
|
||||
# TODO: Check that I'm actually used
|
||||
def list_tags_for_event(%{url: url}, _args, _resolution) do
|
||||
with %Event{id: event_id} <- Events.get_event_by_url(url) do
|
||||
{:ok, Events.list_tags_for_event(event_id)}
|
||||
|
@ -558,6 +558,8 @@ defmodule Mobilizon.Events do
|
||||
|
||||
@doc """
|
||||
Gets an existing tag or creates the new one.
|
||||
|
||||
From a map containing a %{"name" => "#mytag"} or a direct binary
|
||||
"""
|
||||
@spec get_or_create_tag(map) :: {:ok, Tag.t()} | {:error, Changeset.t()}
|
||||
def get_or_create_tag(%{"name" => "#" <> title}) do
|
||||
@ -570,9 +572,6 @@ defmodule Mobilizon.Events do
|
||||
end
|
||||
end
|
||||
|
||||
@doc """
|
||||
Gets an existing tag or creates the new one.
|
||||
"""
|
||||
@spec get_or_create_tag(String.t()) :: {:ok, Tag.t()} | {:error, Changeset.t()}
|
||||
def get_or_create_tag(title) do
|
||||
case Repo.get_by(Tag, title: title) do
|
||||
|
@ -64,7 +64,7 @@ defmodule Mobilizon.Service.Export.ICalendar do
|
||||
end
|
||||
|
||||
@doc """
|
||||
Create cache for an actor
|
||||
Create cache for an actor, an event or an user token
|
||||
"""
|
||||
def create_cache("actor_" <> name) do
|
||||
with %Actor{} = actor <- Actors.get_local_actor_by_name(name),
|
||||
@ -76,9 +76,6 @@ defmodule Mobilizon.Service.Export.ICalendar do
|
||||
end
|
||||
end
|
||||
|
||||
@doc """
|
||||
Create cache for an actor
|
||||
"""
|
||||
def create_cache("event_" <> uuid) do
|
||||
with %Event{} = event <- Events.get_public_event_by_uuid_with_preload(uuid),
|
||||
{:ok, res} <- export_public_event(event) do
|
||||
@ -89,9 +86,6 @@ defmodule Mobilizon.Service.Export.ICalendar do
|
||||
end
|
||||
end
|
||||
|
||||
@doc """
|
||||
Create cache for an actor
|
||||
"""
|
||||
def create_cache("token_" <> token) do
|
||||
case fetch_events_from_token(token) do
|
||||
{:ok, res} ->
|
||||
|
@ -15,7 +15,9 @@ defmodule Mobilizon.Web.Email.Participation do
|
||||
alias Mobilizon.Web.{Email, Gettext}
|
||||
|
||||
@doc """
|
||||
Send emails to local user
|
||||
Send participation emails to local user
|
||||
|
||||
If the actor is anonymous, use information in metadata
|
||||
"""
|
||||
def send_emails_to_local_user(
|
||||
%Participant{actor: %Actor{user_id: nil, id: actor_id} = _actor} = participation
|
||||
@ -32,9 +34,6 @@ defmodule Mobilizon.Web.Email.Participation do
|
||||
:ok
|
||||
end
|
||||
|
||||
@doc """
|
||||
Send emails to local user
|
||||
"""
|
||||
def send_emails_to_local_user(
|
||||
%Participant{actor: %Actor{user_id: user_id} = _actor} = participation
|
||||
) do
|
||||
|
Loading…
Reference in New Issue
Block a user