Fix code readability issues

This commit is contained in:
miffigriffi 2019-09-22 16:26:23 +02:00 committed by Thomas Citharel
parent 20dfce5c83
commit aed824f1aa
No known key found for this signature in database
GPG Key ID: A061B9DDE0CA0773
81 changed files with 379 additions and 309 deletions

View File

@ -4,7 +4,9 @@
# Upstream: https://git.pleroma.social/pleroma/pleroma/blob/develop/lib/mix/tasks/pleroma/common.ex
defmodule Mix.Tasks.Mobilizon.Common do
@moduledoc "Common functions to be reused in mix tasks"
@moduledoc """
Common functions to be reused in mix tasks
"""
def get_option(options, opt, prompt, defval \\ nil, defname \\ nil) do
display = if defname || defval, do: "#{prompt} [#{defname || defval}]", else: "#{prompt}"
@ -13,17 +15,21 @@ defmodule Mix.Tasks.Mobilizon.Common do
case Mix.shell().prompt(display) do
"\n" ->
case defval do
nil -> get_option(options, opt, prompt, defval)
defval -> defval
nil ->
get_option(options, opt, prompt, defval)
defval ->
defval
end
opt ->
opt |> String.trim()
String.trim(opt)
end
end
def start_mobilizon do
Application.put_env(:phoenix, :serve_endpoints, false, persistent: true)
{:ok, _} = Application.ensure_all_started(:mobilizon)
end

View File

@ -1,13 +1,14 @@
defmodule Mix.Tasks.Mobilizon.CreateBot do
@moduledoc """
Creates a bot from a source
Creates a bot from a source.
"""
use Mix.Task
alias Mobilizon.Actors
alias Mobilizon.Users
alias Mobilizon.{Actors, Users}
alias Mobilizon.Actors.Bot
alias Mobilizon.Users.User
require Logger
@shortdoc "Register user"
@ -25,7 +26,8 @@ defmodule Mix.Tasks.Mobilizon.CreateBot do
}) do
bot
else
e -> Logger.error(inspect(e))
error ->
Logger.error(inspect(error))
end
end
end

View File

@ -4,11 +4,6 @@
# Upstream: https://git.pleroma.social/pleroma/pleroma/blob/develop/lib/mix/tasks/pleroma/instance.ex
defmodule Mix.Tasks.Mobilizon.Instance do
use Mix.Task
alias Mix.Tasks.Mobilizon.Common
@shortdoc "Generates a new config"
@preferred_cli_env "prod"
@moduledoc """
Generates a new config
@ -31,6 +26,13 @@ defmodule Mix.Tasks.Mobilizon.Instance do
- `--dbpass DBPASS` - the password to use for the database connection
"""
use Mix.Task
alias Mix.Tasks.Mobilizon.Common
@preferred_cli_env "prod"
@shortdoc "Generates a new config"
def run(["gen" | options]) do
{options, [], []} =
OptionParser.parse(

View File

@ -4,11 +4,6 @@
# Upstream: https://git.pleroma.social/pleroma/pleroma/blob/develop/lib/mix/tasks/pleroma/relay.ex
defmodule Mix.Tasks.Mobilizon.Relay do
use Mix.Task
alias Mobilizon.Service.ActivityPub.Relay
alias Mix.Tasks.Mobilizon.Common
@shortdoc "Manages remote relays"
@moduledoc """
Manages remote relays
@ -24,6 +19,13 @@ defmodule Mix.Tasks.Mobilizon.Relay do
Example: ``mix mobilizon.relay unfollow https://example.org/relay``
"""
use Mix.Task
alias Mix.Tasks.Mobilizon.Common
alias Mobilizon.Service.ActivityPub.Relay
@shortdoc "Manages remote relays"
def run(["follow", target]) do
Common.start_mobilizon()

View File

@ -1,9 +1,10 @@
defmodule Mix.Tasks.Mobilizon.Toot do
@moduledoc """
Creates a bot from a source
Creates a bot from a source.
"""
use Mix.Task
require Logger
@shortdoc "Toot to an user"

View File

@ -11,11 +11,11 @@ defmodule Mobilizon.Actors.Actor do
alias Mobilizon.Actors.{ActorOpenness, ActorType, ActorVisibility, Follower, Member}
alias Mobilizon.Events.{Event, FeedToken}
alias Mobilizon.Media.File
alias Mobilizon.Reports.{Report, Note}
alias Mobilizon.Reports.{Note, Report}
alias Mobilizon.Users.User
alias MobilizonWeb.Router.Helpers, as: Routes
alias MobilizonWeb.Endpoint
alias MobilizonWeb.Router.Helpers, as: Routes
require Logger

View File

@ -10,8 +10,8 @@ defmodule Mobilizon.Events.Comment do
alias Mobilizon.Actors.Actor
alias Mobilizon.Events.{Comment, CommentVisibility, Event}
alias MobilizonWeb.Router.Helpers, as: Routes
alias MobilizonWeb.Endpoint
alias MobilizonWeb.Router.Helpers, as: Routes
@type t :: %__MODULE__{
text: String.t(),

View File

@ -16,8 +16,8 @@ defmodule Mobilizon.Events.Event do
EventVisibility,
JoinOptions,
Participant,
Tag,
Session,
Tag,
Track
}

View File

@ -8,9 +8,9 @@ defmodule Mobilizon.Events.EventOptions do
import Ecto.Changeset
alias Mobilizon.Events.{
CommentModeration,
EventOffer,
EventParticipationCondition,
CommentModeration
EventParticipationCondition
}
@type t :: %__MODULE__{

View File

@ -7,8 +7,8 @@ defmodule Mobilizon.Events.Tag do
import Ecto.Changeset
alias Mobilizon.Events.TagRelation
alias Mobilizon.Events.Tag.TitleSlug
alias Mobilizon.Events.TagRelation
@type t :: %__MODULE__{
title: String.t(),

View File

@ -1,6 +1,6 @@
defmodule MobilizonWeb.API.Comments do
@moduledoc """
API for Comments
API for Comments.
"""
alias Mobilizon.Actors
@ -8,6 +8,7 @@ defmodule MobilizonWeb.API.Comments do
alias Mobilizon.Events.Comment
alias Mobilizon.Service.ActivityPub
alias Mobilizon.Service.ActivityPub.Utils, as: ActivityPubUtils
alias MobilizonWeb.API.Utils
@doc """

View File

@ -1,12 +1,14 @@
defmodule MobilizonWeb.API.Events do
@moduledoc """
API for Events
API for Events.
"""
alias Mobilizon.Events.Event
alias Mobilizon.Actors.Actor
alias Mobilizon.Service.ActivityPub
alias Mobilizon.Service.ActivityPub.Utils, as: ActivityPubUtils
alias Mobilizon.Service.ActivityPub.Activity
alias Mobilizon.Service.ActivityPub.Utils, as: ActivityPubUtils
alias MobilizonWeb.API.Utils
@doc """

View File

@ -6,6 +6,7 @@ defmodule MobilizonWeb.API.Follows do
alias Mobilizon.Actors
alias Mobilizon.Actors.{Actor, Follower}
alias Mobilizon.Service.ActivityPub
require Logger
def follow(%Actor{} = follower, %Actor{} = followed) do

View File

@ -1,12 +1,14 @@
defmodule MobilizonWeb.API.Groups do
@moduledoc """
API for Events
API for Groups.
"""
alias Mobilizon.Actors
alias Mobilizon.Actors.Actor
alias Mobilizon.Users.User
alias Mobilizon.Service.ActivityPub
alias Mobilizon.Service.ActivityPub.Utils, as: ActivityPubUtils
alias Mobilizon.Users.User
alias MobilizonWeb.API.Utils
@doc """

View File

@ -1,6 +1,6 @@
defmodule MobilizonWeb.API.Participations do
@moduledoc """
Common API to join events and groups
Common API to join events and groups.
"""
alias Mobilizon.Actors.Actor

View File

@ -1,18 +1,19 @@
defmodule MobilizonWeb.API.Reports do
@moduledoc """
API for Reports
API for Reports.
"""
import MobilizonWeb.API.Utils
import Mobilizon.Service.Admin.ActionLogService
import MobilizonWeb.API.Utils
alias Mobilizon.Actors
alias Mobilizon.Actors.Actor
alias Mobilizon.Events
alias Mobilizon.Service.ActivityPub.Activity
alias Mobilizon.Reports, as: ReportsAction
alias Mobilizon.Reports.{Report, Note}
alias Mobilizon.Reports.{Note, Report}
alias Mobilizon.Service.ActivityPub
alias Mobilizon.Service.ActivityPub.Activity
alias Mobilizon.Users
alias Mobilizon.Users.User

View File

@ -1,6 +1,6 @@
defmodule MobilizonWeb.API.Utils do
@moduledoc """
Utils for API
Utils for API.
"""
alias Mobilizon.Actors.Actor

View File

@ -8,8 +8,8 @@ defmodule MobilizonWeb.MediaProxyController do
alias Mobilizon.Config
alias MobilizonWeb.ReverseProxy
alias MobilizonWeb.MediaProxy
alias MobilizonWeb.ReverseProxy
@default_proxy_opts [max_body_length: 25 * 1_048_576, http: [follow_redirect: true]]

View File

@ -1,14 +1,16 @@
defmodule MobilizonWeb.Resolvers.Admin do
@moduledoc """
Handles the report-related GraphQL calls
Handles the report-related GraphQL calls.
"""
alias Mobilizon.Events
alias Mobilizon.Users.User
import Mobilizon.Users.Guards
alias Mobilizon.Admin.ActionLog
alias Mobilizon.Reports.{Report, Note}
alias Mobilizon.Events
alias Mobilizon.Events.Event
alias Mobilizon.Reports.{Note, Report}
alias Mobilizon.Service.Statistics
alias Mobilizon.Users.User
def list_action_logs(
_parent,

View File

@ -1,11 +1,12 @@
defmodule MobilizonWeb.Resolvers.Comment do
@moduledoc """
Handles the comment-related GraphQL calls
Handles the comment-related GraphQL calls.
"""
alias Mobilizon.Events.Comment
alias Mobilizon.Users.User
alias Mobilizon.Service.ActivityPub.Activity
alias Mobilizon.Users.User
alias MobilizonWeb.API.Comments
require Logger

View File

@ -1,19 +1,21 @@
defmodule MobilizonWeb.Resolvers.Event do
@moduledoc """
Handles the event-related GraphQL calls
Handles the event-related GraphQL calls.
"""
import Mobilizon.Service.Admin.ActionLogService
alias Mobilizon.Actors
alias Mobilizon.Actors.Actor
alias Mobilizon.Addresses
alias Mobilizon.Addresses.Address
alias Mobilizon.Events
alias Mobilizon.Events.{Event, Participant}
alias Mobilizon.Media.Picture
alias Mobilizon.Users.User
alias Mobilizon.Actors
alias Mobilizon.Actors.Actor
alias MobilizonWeb.Resolvers.Person
alias Mobilizon.Service.ActivityPub.Activity
import Mobilizon.Service.Admin.ActionLogService
alias Mobilizon.Users.User
alias MobilizonWeb.Resolvers.Person
# We limit the max number of events that can be retrieved
@event_max_limit 100

View File

@ -1,11 +1,13 @@
defmodule MobilizonWeb.Resolvers.FeedToken do
@moduledoc """
Handles the feed tokens-related GraphQL calls
Handles the feed tokens-related GraphQL calls.
"""
alias Mobilizon.Actors.Actor
alias Mobilizon.Users.User
alias Mobilizon.Events
alias Mobilizon.Events.FeedToken
alias Mobilizon.Users.User
require Logger
@doc """

View File

@ -1,12 +1,13 @@
defmodule MobilizonWeb.Resolvers.Group do
@moduledoc """
Handles the group-related GraphQL calls
Handles the group-related GraphQL calls.
"""
alias Mobilizon.Actors
alias Mobilizon.Actors.{Actor, Member}
alias Mobilizon.Service.ActivityPub
alias Mobilizon.Service.ActivityPub.Activity
alias Mobilizon.Users.User
alias Mobilizon.Service.ActivityPub
alias MobilizonWeb.Resolvers.Person

View File

@ -1,15 +1,18 @@
defmodule MobilizonWeb.Resolvers.Report do
@moduledoc """
Handles the report-related GraphQL calls
Handles the report-related GraphQL calls.
"""
alias Mobilizon.Reports
alias Mobilizon.Reports.{Report, Note}
alias Mobilizon.Actors.Actor
alias Mobilizon.Actors
alias Mobilizon.Users.User
alias MobilizonWeb.API.Reports, as: ReportsAPI
import Mobilizon.Users.Guards
alias Mobilizon.Actors
alias Mobilizon.Actors.Actor
alias Mobilizon.Reports
alias Mobilizon.Reports.{Note, Report}
alias Mobilizon.Users.User
alias MobilizonWeb.API.Reports, as: ReportsAPI
def list_reports(
_parent,
%{page: page, limit: limit, status: status},

View File

@ -1,16 +1,16 @@
defmodule MobilizonWeb.Resolvers.User do
@moduledoc """
Handles the user-related GraphQL calls
Handles the user-related GraphQL calls.
"""
import Mobilizon.Users.Guards
alias Mobilizon.{Actors, Config, Users, Events}
alias Mobilizon.Actors.Actor
alias Mobilizon.Service.Users.{ResetPassword, Activation}
alias Mobilizon.Service.Users.{Activation, ResetPassword}
alias Mobilizon.Users.User
alias Mobilizon.Storage.Repo
import Mobilizon.Users.Guards
require Logger
@doc """

View File

@ -1,12 +1,13 @@
defmodule MobilizonWeb.Schema do
@moduledoc """
GraphQL schema representation
GraphQL schema representation.
"""
use Absinthe.Schema
alias Mobilizon.{Actors, Events, Users, Addresses, Media, Reports}
alias Mobilizon.{Actors, Addresses, Events, Media, Reports, Users}
alias Mobilizon.Actors.{Actor, Follower, Member}
alias Mobilizon.Events.{Event, Comment, Participant}
alias Mobilizon.Events.{Comment, Event, Participant}
alias Mobilizon.Storage.Repo
import_types(MobilizonWeb.Schema.Custom.UUID)

View File

@ -1,13 +1,18 @@
defmodule MobilizonWeb.Schema.Actors.GroupType do
@moduledoc """
Schema representation for Group
Schema representation for Group.
"""
use Absinthe.Schema.Notation
import Absinthe.Resolution.Helpers, only: [dataloader: 1]
import_types(MobilizonWeb.Schema.Actors.MemberType)
alias MobilizonWeb.Resolvers.{Member, Group}
alias Mobilizon.Events
alias MobilizonWeb.Resolvers.{Group, Member}
import_types(MobilizonWeb.Schema.Actors.MemberType)
@desc """
Represents a group of actors
"""

View File

@ -1,11 +1,14 @@
defmodule MobilizonWeb.Schema.AdminType do
@moduledoc """
Schema representation for ActionLog
Schema representation for ActionLog.
"""
use Absinthe.Schema.Notation
alias MobilizonWeb.Resolvers.Admin
alias Mobilizon.Reports.{Report, Note}
alias Mobilizon.Events.Event
alias Mobilizon.Reports.{Note, Report}
alias MobilizonWeb.Resolvers.Admin
@desc "An action log"
object :action_log do

View File

@ -1,14 +1,19 @@
defmodule MobilizonWeb.Schema.EventType do
@moduledoc """
Schema representation for Event
Schema representation for Event.
"""
use Absinthe.Schema.Notation
alias Mobilizon.{Actors, Addresses}
import Absinthe.Resolution.Helpers, only: [dataloader: 1]
alias Mobilizon.{Actors, Addresses}
alias MobilizonWeb.Resolvers.{Event, Picture, Tag}
import_types(MobilizonWeb.Schema.AddressType)
import_types(MobilizonWeb.Schema.Events.ParticipantType)
import_types(MobilizonWeb.Schema.TagType)
alias MobilizonWeb.Resolvers.{Picture, Event, Tag}
@desc "An event"
object :event do

View File

@ -1,12 +1,15 @@
defmodule MobilizonWeb.Schema.Events.FeedTokenType do
@moduledoc """
Schema representation for Participant
Schema representation for Participant.
"""
use Absinthe.Schema.Notation
import Absinthe.Resolution.Helpers, only: [dataloader: 1]
alias Mobilizon.{Actors, Users}
alias MobilizonWeb.Resolvers
alias Mobilizon.Users
alias Mobilizon.Actors
@desc "Represents a participant to an event"
object :feed_token do

View File

@ -1,12 +1,15 @@
defmodule MobilizonWeb.Schema.Events.ParticipantType do
@moduledoc """
Schema representation for Participant
Schema representation for Participant.
"""
use Absinthe.Schema.Notation
import Absinthe.Resolution.Helpers, only: [dataloader: 1]
alias Mobilizon.{Actors, Events}
alias MobilizonWeb.Resolvers
alias Mobilizon.Events
alias Mobilizon.Actors
@desc "Represents a participant to an event"
object :participant do

View File

@ -3,9 +3,8 @@ defmodule MobilizonWeb.ActivityPub.ActorView do
alias Mobilizon.Actors
alias Mobilizon.Actors.Actor
alias Mobilizon.Service.ActivityPub.Activity
alias Mobilizon.Service.ActivityPub
alias Mobilizon.Service.ActivityPub.Utils
alias Mobilizon.Service.ActivityPub.{Activity, Utils}
@private_visibility_empty_collection %{elements: [], total: 0}

View File

@ -1,9 +1,10 @@
defmodule MobilizonWeb.JsonLD.ObjectView do
use MobilizonWeb, :view
alias Mobilizon.Events.Event
alias Mobilizon.Actors.Actor
alias Mobilizon.Addresses.Address
alias Mobilizon.Events.Event
alias MobilizonWeb.JsonLD.ObjectView
alias MobilizonWeb.MediaProxy

View File

@ -84,7 +84,7 @@ defmodule MobilizonWeb.PageView do
end
end
defp index_file_path() do
defp index_file_path do
Path.join(Application.app_dir(:mobilizon, "priv/static"), "index.html")
end
end

View File

@ -5,28 +5,19 @@
defmodule Mobilizon.Service.ActivityPub do
@moduledoc """
# ActivityPub
Every ActivityPub method
# ActivityPub context.
"""
alias Mobilizon.Config
alias Mobilizon.Events
alias Mobilizon.Events.{Event, Comment, Participant}
alias Mobilizon.Service.ActivityPub.Transmogrifier
alias Mobilizon.Service.WebFinger
import Mobilizon.Service.ActivityPub.{Utils, Visibility}
alias Mobilizon.Actors
alias Mobilizon.{Actors, Config, Events}
alias Mobilizon.Actors.{Actor, Follower}
alias Mobilizon.Service.Federator
alias Mobilizon.Events.{Comment, Event, Participant}
alias Mobilizon.Service.ActivityPub.{Activity, Convertible, Transmogrifier}
alias Mobilizon.Service.{Federator, WebFinger}
alias Mobilizon.Service.HTTPSignatures.Signature
alias Mobilizon.Service.ActivityPub.{Activity, Convertible}
require Logger
import Mobilizon.Service.ActivityPub.Utils
import Mobilizon.Service.ActivityPub.Visibility
@doc """
Get recipients for an activity or object
@ -452,7 +443,8 @@ defmodule Mobilizon.Service.ActivityPub do
def leave(object, actor, local \\ true)
# TODO: If we want to use this for exclusion we need to have an extra field for the actor that excluded the participant
# TODO: If we want to use this for exclusion we need to have an extra field
# for the actor that excluded the participant
def leave(
%Event{id: event_id, url: event_url} = event,
%Actor{id: actor_id, url: actor_url} = _actor,

View File

@ -2,8 +2,10 @@ defmodule Mobilizon.Service.ActivityPub.Converters.Actor do
@moduledoc """
Actor converter
This module allows to convert events from ActivityStream format to our own internal one, and back
This module allows to convert events from ActivityStream format to our own
internal one, and back.
"""
alias Mobilizon.Actors.Actor, as: ActorModel
alias Mobilizon.Service.ActivityPub.Converter

View File

@ -1,11 +1,13 @@
defmodule Mobilizon.Service.ActivityPub.Converters.Address do
@moduledoc """
Flag converter
Address converter.
This module allows to convert reports from ActivityStream format to our own internal one, and back.
This module allows to convert reports from ActivityStream format to our own
internal one, and back.
Note: Reports are named Flag in AS.
"""
alias Mobilizon.Addresses.Address, as: AddressModel
alias Mobilizon.Service.ActivityPub.Converter

View File

@ -1,14 +1,17 @@
defmodule Mobilizon.Service.ActivityPub.Converters.Comment do
@moduledoc """
Comment converter
Comment converter.
This module allows to convert events from ActivityStream format to our own internal one, and back
This module allows to convert events from ActivityStream format to our own
internal one, and back.
"""
alias Mobilizon.Actors.Actor
alias Mobilizon.Events.Comment, as: CommentModel
alias Mobilizon.Events.Event
alias Mobilizon.Service.ActivityPub.Converter
alias Mobilizon.Service.ActivityPub
alias Mobilizon.Service.ActivityPub.Converter
require Logger
@behaviour Converter

View File

@ -1,26 +1,24 @@
defmodule Mobilizon.Service.ActivityPub.Converters.Event do
@moduledoc """
Event converter
Event converter.
This module allows to convert events from ActivityStream format to our own internal one, and back
This module allows to convert events from ActivityStream format to our own
internal one, and back.
"""
alias Mobilizon.Actors
alias Mobilizon.Media
alias Mobilizon.Media.Picture
alias Mobilizon.Actors.Actor
alias Mobilizon.Events.Event, as: EventModel
alias Mobilizon.Service.ActivityPub.Converter
alias Mobilizon.Service.ActivityPub.Converters.Address, as: AddressConverter
alias Mobilizon.Service.ActivityPub.Utils
alias Mobilizon.Events
alias Mobilizon.Events.Tag
alias Mobilizon.Addresses
alias Mobilizon.Addresses.Address
@behaviour Converter
alias Mobilizon.{Actors, Addresses, Events, Media}
alias Mobilizon.Actors.Actor
alias Mobilizon.Addresses.Address
alias Mobilizon.Events.Event, as: EventModel
alias Mobilizon.Events.Tag
alias Mobilizon.Media.Picture
alias Mobilizon.Service.ActivityPub.{Converter, Utils}
alias Mobilizon.Service.ActivityPub.Converters.Address, as: AddressConverter
require Logger
@behaviour Converter
@doc """
Converts an AP object data to our internal data structure
"""

View File

@ -1,11 +1,13 @@
defmodule Mobilizon.Service.ActivityPub.Converters.Flag do
@moduledoc """
Flag converter
Flag converter.
This module allows to convert reports from ActivityStream format to our own internal one, and back.
This module allows to convert reports from ActivityStream format to our own
internal one, and back.
Note: Reports are named Flag in AS.
"""
alias Mobilizon.Actors
alias Mobilizon.Actors.Actor
alias Mobilizon.Events

View File

@ -1,11 +1,13 @@
defmodule Mobilizon.Service.ActivityPub.Converters.Participant do
@moduledoc """
Flag converter
Participant converter.
This module allows to convert reports from ActivityStream format to our own internal one, and back.
This module allows to convert reports from ActivityStream format to our own
internal one, and back.
Note: Reports are named Flag in AS.
"""
alias Mobilizon.Events.Participant, as: ParticipantModel
@doc """

View File

@ -5,13 +5,13 @@
defmodule Mobilizon.Service.ActivityPub.Relay do
@moduledoc """
Handles following and unfollowing relays and instances
Handles following and unfollowing relays and instances.
"""
alias Mobilizon.Actors
alias Mobilizon.Actors.Actor
alias Mobilizon.Service.ActivityPub.Activity
alias Mobilizon.Service.ActivityPub
alias Mobilizon.Service.ActivityPub.Activity
alias MobilizonWeb.API.Follows

View File

@ -7,12 +7,13 @@ defmodule Mobilizon.Service.ActivityPub.Transmogrifier do
@moduledoc """
A module to handle coding from internal to wire ActivityPub and back.
"""
alias Mobilizon.Actors
alias Mobilizon.Actors.{Actor, Follower}
alias Mobilizon.Events
alias Mobilizon.Events.{Event, Comment, Participant}
alias Mobilizon.Events.{Comment, Event, Participant}
alias Mobilizon.Service.ActivityPub
alias Mobilizon.Service.ActivityPub.{Visibility, Utils}
alias Mobilizon.Service.ActivityPub.{Utils, Visibility}
require Logger

View File

@ -5,25 +5,19 @@
defmodule Mobilizon.Service.ActivityPub.Utils do
@moduledoc """
# Utils
Various utils
# Various ActivityPub related utils.
"""
alias Ecto.Changeset
alias Mobilizon.Addresses
alias Mobilizon.Addresses.Address
alias Mobilizon.Actors
alias Mobilizon.{Actors, Addresses, Events, Reports, Users}
alias Mobilizon.Actors.Actor
alias Mobilizon.Events
alias Mobilizon.Addresses.Address
alias Mobilizon.Events.{Comment, Event}
alias Mobilizon.Media.Picture
alias Mobilizon.Reports
alias Mobilizon.Reports.Report
alias Mobilizon.Service.ActivityPub.{Activity, Converters}
alias Mobilizon.Storage.Repo
alias Mobilizon.Users
alias MobilizonWeb.{Email, Endpoint}
alias MobilizonWeb.Router.Helpers, as: Routes

View File

@ -1,13 +1,13 @@
defmodule Mobilizon.Service.Admin.ActionLogService do
@moduledoc """
Module to handle action log creations
Module to handle action log creations.
"""
alias Mobilizon.Users
alias Mobilizon.Users.User
alias Mobilizon.Actors.Actor
alias Mobilizon.Admin
alias Mobilizon.Admin.ActionLog
alias Mobilizon.Users
alias Mobilizon.Users.User
@doc """
Log an admin action

View File

@ -1,15 +1,14 @@
defmodule Mobilizon.Service.EmailChecker do
@moduledoc """
Provides a function to test emails against a "not so bad" regex
Provides a function to test emails against a "not so bad" regex.
"""
# TODO: simplify me!
@email_regex ~r/^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
@doc """
Returns whether the email is valid
Returns whether the email is valid.
"""
@spec valid?(String.t()) :: boolean()
def valid?(email) do
email =~ @email_regex
end
@spec valid?(String.t()) :: boolean
def valid?(email), do: email =~ @email_regex
end

View File

@ -1,23 +1,24 @@
defmodule Mobilizon.Service.Export.Feed do
@moduledoc """
Serve Atom Syndication Feeds
Serve Atom Syndication Feeds.
"""
alias Mobilizon.Users.User
alias Mobilizon.Users
alias Mobilizon.Actors
alias Mobilizon.Actors.Actor
alias Mobilizon.Events
alias Mobilizon.Events.{Event, FeedToken}
alias Atomex.{Feed, Entry}
import MobilizonWeb.Gettext
alias Atomex.{Entry, Feed}
alias Mobilizon.{Actors, Events, Users}
alias Mobilizon.Actors.Actor
alias Mobilizon.Events.{Event, FeedToken}
alias Mobilizon.Users.User
alias MobilizonWeb.{Endpoint, MediaProxy}
alias MobilizonWeb.Router.Helpers, as: Routes
alias MobilizonWeb.Endpoint
alias MobilizonWeb.MediaProxy
require Logger
@version Mix.Project.config()[:version]
def version(), do: @version
def version, do: @version
@spec create_cache(String.t()) :: {:commit, String.t()} | {:ignore, any()}
def create_cache("actor_" <> name) do

View File

@ -1,14 +1,12 @@
defmodule Mobilizon.Service.Export.ICalendar do
@moduledoc """
Export an event to iCalendar format
Export an event to iCalendar format.
"""
alias Mobilizon.Events.{Event, FeedToken}
alias Mobilizon.Events
alias Mobilizon.{Actors, Events, Users}
alias Mobilizon.Actors.Actor
alias Mobilizon.Actors
alias Mobilizon.Events.{Event, FeedToken}
alias Mobilizon.Users.User
alias Mobilizon.Users
@doc """
Export a public event to iCalendar format.

View File

@ -5,10 +5,11 @@
defmodule Mobilizon.Service.Formatter do
@moduledoc """
Formats input text to structured data, extracts mentions and hashtags
Formats input text to structured data, extracts mentions and hashtags.
"""
alias Mobilizon.Actors.Actor
alias Mobilizon.Actors
alias Mobilizon.Actors.Actor
alias Mobilizon.Service.HTML
@link_regex ~r"((?:http(s)?:\/\/)?[\w.-]+(?:\.[\w\.-]+)+[\w\-\._~%:/?#[\]@!\$&'\(\)\*\+,;=.]+)|[0-9a-z+\-\.]+:[0-9a-z$-_.+!*'(),]+"ui

View File

@ -2,9 +2,11 @@ defmodule Mobilizon.Service.Geospatial.Addok do
@moduledoc """
[Addok](https://github.com/addok/addok) backend.
"""
alias Mobilizon.Service.Geospatial.Provider
require Logger
alias Mobilizon.Addresses.Address
alias Mobilizon.Service.Geospatial.Provider
require Logger
@behaviour Provider

View File

@ -1,15 +1,17 @@
defmodule Mobilizon.Service.Geospatial do
@moduledoc """
Module to load the service adapter defined inside the configuration
Module to load the service adapter defined inside the configuration.
See `Mobilizon.Service.Geospatial.Provider`
See `Mobilizon.Service.Geospatial.Provider`.
"""
@doc """
Returns the appropriate service adapter
Returns the appropriate service adapter.
According to the config behind `config :mobilizon, Mobilizon.Service.Geospatial, service: Mobilizon.Service.Geospatial.Module`
According to the config behind
`config :mobilizon, Mobilizon.Service.Geospatial,
service: Mobilizon.Service.Geospatial.Module`
"""
@spec service() :: module()
def service(), do: Application.get_env(:mobilizon, __MODULE__) |> get_in([:service])
@spec service :: module
def service, do: get_in(Application.get_env(:mobilizon, __MODULE__), [:service])
end

View File

@ -1,11 +1,13 @@
defmodule Mobilizon.Service.Geospatial.GoogleMaps do
@moduledoc """
Google Maps [Geocoding service](https://developers.google.com/maps/documentation/geocoding/intro)
Google Maps [Geocoding service](https://developers.google.com/maps/documentation/geocoding/intro).
Note: Endpoint is hardcoded to Google Maps API
Note: Endpoint is hardcoded to Google Maps API.
"""
alias Mobilizon.Service.Geospatial.Provider
alias Mobilizon.Addresses.Address
alias Mobilizon.Service.Geospatial.Provider
require Logger
@behaviour Provider

View File

@ -8,8 +8,10 @@ defmodule Mobilizon.Service.Geospatial.MapQuest do
* `:open_data` Whether to use [Open Data or Licenced Data](https://developer.mapquest.com/documentation/open/).
Defaults to `true`
"""
alias Mobilizon.Service.Geospatial.Provider
alias Mobilizon.Addresses.Address
alias Mobilizon.Service.Geospatial.Provider
require Logger
@behaviour Provider

View File

@ -2,8 +2,10 @@ defmodule Mobilizon.Service.Geospatial.Nominatim do
@moduledoc """
[Nominatim](https://wiki.openstreetmap.org/wiki/Nominatim) backend.
"""
alias Mobilizon.Service.Geospatial.Provider
alias Mobilizon.Addresses.Address
alias Mobilizon.Service.Geospatial.Provider
require Logger
@behaviour Provider
@ -66,23 +68,22 @@ defmodule Mobilizon.Service.Geospatial.Nominatim do
@spec process_data(map()) :: Address.t()
defp process_data(%{"address" => address} = body) do
try do
%Address{
country: Map.get(address, "country"),
locality: Map.get(address, "city"),
region: Map.get(address, "state"),
description: description(body),
floor: Map.get(address, "floor"),
geom: [Map.get(body, "lon"), Map.get(body, "lat")] |> Provider.coordinates(),
postal_code: Map.get(address, "postcode"),
street: street_address(address),
origin_id: "osm:" <> to_string(Map.get(body, "osm_id"))
}
rescue
e in ArgumentError ->
Logger.warn(inspect(e))
nil
end
%Address{
country: Map.get(address, "country"),
locality: Map.get(address, "city"),
region: Map.get(address, "state"),
description: description(body),
floor: Map.get(address, "floor"),
geom: [Map.get(body, "lon"), Map.get(body, "lat")] |> Provider.coordinates(),
postal_code: Map.get(address, "postcode"),
street: street_address(address),
origin_id: "osm:" <> to_string(Map.get(body, "osm_id"))
}
rescue
error in ArgumentError ->
Logger.warn(inspect(error))
nil
end
@spec street_address(map()) :: String.t()

View File

@ -2,9 +2,11 @@ defmodule Mobilizon.Service.Geospatial.Photon do
@moduledoc """
[Photon](https://photon.komoot.de) backend.
"""
alias Mobilizon.Service.Geospatial.Provider
require Logger
alias Mobilizon.Addresses.Address
alias Mobilizon.Service.Geospatial.Provider
require Logger
@behaviour Provider

View File

@ -14,11 +14,13 @@ defmodule Mobilizon.Service.Geospatial.Provider do
## Shared options
* `:user_agent` User-Agent string to send to the backend. Defaults to `"Mobilizon"`
* `:lang` Lang in which to prefer results. Used as a request parameter or through an `Accept-Language` HTTP header.
Defaults to `"en"`.
* `:limit` Maximum limit for the number of results returned by the backend. Defaults to `10`
* `:api_key` Allows to override the API key (if the backend requires one) set inside the configuration.
* `:endpoint` Allows to override the endpoint set inside the configuration
* `:lang` Lang in which to prefer results. Used as a request parameter or
through an `Accept-Language` HTTP header. Defaults to `"en"`.
* `:limit` Maximum limit for the number of results returned by the backend.
Defaults to `10`
* `:api_key` Allows to override the API key (if the backend requires one) set
inside the configuration.
* `:endpoint` Allows to override the endpoint set inside the configuration.
"""
alias Mobilizon.Addresses.Address
@ -35,38 +37,40 @@ defmodule Mobilizon.Service.Geospatial.Provider do
iex> geocode(48.11, -1.77)
%Address{}
"""
@callback geocode(longitude :: number(), latitude :: number(), options :: keyword()) ::
list(Address.t())
@callback geocode(longitude :: number, latitude :: number, options :: keyword) :: [Addres