Fix all warnings
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
parent
a04dfc5293
commit
2939485321
|
@ -6,9 +6,8 @@ defmodule Mix.Tasks.CreateBot do
|
||||||
use Mix.Task
|
use Mix.Task
|
||||||
alias Mobilizon.Actors
|
alias Mobilizon.Actors
|
||||||
alias Mobilizon.Actors.Bot
|
alias Mobilizon.Actors.Bot
|
||||||
alias Mobilizon.Repo
|
|
||||||
alias Mobilizon.Actors.User
|
alias Mobilizon.Actors.User
|
||||||
import Logger
|
require Logger
|
||||||
|
|
||||||
@shortdoc "Register user"
|
@shortdoc "Register user"
|
||||||
def run([email, name, summary, type, url]) do
|
def run([email, name, summary, type, url]) do
|
||||||
|
|
|
@ -6,9 +6,6 @@ defmodule Mix.Tasks.Toot do
|
||||||
use Mix.Task
|
use Mix.Task
|
||||||
alias Mobilizon.Actors
|
alias Mobilizon.Actors
|
||||||
alias Mobilizon.Actors.Actor
|
alias Mobilizon.Actors.Actor
|
||||||
alias Mobilizon.Repo
|
|
||||||
alias Mobilizon.Events
|
|
||||||
alias Mobilizon.Events.Comment
|
|
||||||
alias Mobilizon.Service.ActivityPub
|
alias Mobilizon.Service.ActivityPub
|
||||||
alias Mobilizon.Service.ActivityPub.Utils
|
alias Mobilizon.Service.ActivityPub.Utils
|
||||||
require Logger
|
require Logger
|
||||||
|
|
|
@ -17,7 +17,6 @@ defmodule Mobilizon.Actors.Actor do
|
||||||
alias Mobilizon.Actors
|
alias Mobilizon.Actors
|
||||||
alias Mobilizon.Actors.{Actor, User, Follower, Member}
|
alias Mobilizon.Actors.{Actor, User, Follower, Member}
|
||||||
alias Mobilizon.Events.Event
|
alias Mobilizon.Events.Event
|
||||||
alias Mobilizon.Service.ActivityPub
|
|
||||||
|
|
||||||
import Ecto.Query
|
import Ecto.Query
|
||||||
alias Mobilizon.Repo
|
alias Mobilizon.Repo
|
||||||
|
@ -105,7 +104,7 @@ defmodule Mobilizon.Actors.Actor do
|
||||||
end
|
end
|
||||||
|
|
||||||
# TODO : Use me !
|
# TODO : Use me !
|
||||||
@email_regex ~r/^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/
|
# @email_regex ~r/^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/
|
||||||
def remote_actor_creation(params) do
|
def remote_actor_creation(params) do
|
||||||
changes =
|
changes =
|
||||||
%Actor{}
|
%Actor{}
|
||||||
|
@ -279,7 +278,7 @@ defmodule Mobilizon.Actors.Actor do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
defp do_follow(%Actor{} = follower, %Actor{} = followed, approved \\ true) do
|
defp do_follow(%Actor{} = follower, %Actor{} = followed, approved) do
|
||||||
Actors.create_follower(%{
|
Actors.create_follower(%{
|
||||||
"actor_id" => follower.id,
|
"actor_id" => follower.id,
|
||||||
"target_actor_id" => followed.id,
|
"target_actor_id" => followed.id,
|
||||||
|
|
|
@ -7,7 +7,6 @@ defmodule Mobilizon.Actors do
|
||||||
alias Mobilizon.Repo
|
alias Mobilizon.Repo
|
||||||
|
|
||||||
alias Mobilizon.Actors.{Actor, Bot, Member, Follower, User}
|
alias Mobilizon.Actors.{Actor, Bot, Member, Follower, User}
|
||||||
alias Mobilizon.Actors
|
|
||||||
|
|
||||||
alias Mobilizon.Service.ActivityPub
|
alias Mobilizon.Service.ActivityPub
|
||||||
|
|
||||||
|
@ -63,13 +62,9 @@ defmodule Mobilizon.Actors do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@doc """
|
# Returns the first actor found for an user
|
||||||
Returns the first actor found for an user
|
# Useful when the user has not defined default actor
|
||||||
|
# Raises `Ecto.NoResultsError` if no Actor is found for this ID
|
||||||
Useful when the user has not defined default actor
|
|
||||||
|
|
||||||
Raises `Ecto.NoResultsError` if no Actor is found for this ID
|
|
||||||
"""
|
|
||||||
defp get_first_actor_for_user(%Mobilizon.Actors.User{id: id} = _user) do
|
defp get_first_actor_for_user(%Mobilizon.Actors.User{id: id} = _user) do
|
||||||
Repo.one!(from(a in Actor, where: a.user_id == ^id))
|
Repo.one!(from(a in Actor, where: a.user_id == ^id))
|
||||||
end
|
end
|
||||||
|
@ -195,9 +190,6 @@ defmodule Mobilizon.Actors do
|
||||||
Repo.all(User)
|
Repo.all(User)
|
||||||
end
|
end
|
||||||
|
|
||||||
defp blank?(""), do: nil
|
|
||||||
defp blank?(n), do: n
|
|
||||||
|
|
||||||
def insert_or_update_actor(data, preload \\ false) do
|
def insert_or_update_actor(data, preload \\ false) do
|
||||||
cs = Actor.remote_actor_creation(data)
|
cs = Actor.remote_actor_creation(data)
|
||||||
|
|
||||||
|
@ -321,7 +313,6 @@ defmodule Mobilizon.Actors do
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_actor_by_name(name) do
|
def get_actor_by_name(name) do
|
||||||
actor =
|
|
||||||
case String.split(name, "@") do
|
case String.split(name, "@") do
|
||||||
[name] ->
|
[name] ->
|
||||||
Repo.one(from(a in Actor, where: a.preferred_username == ^name and is_nil(a.domain)))
|
Repo.one(from(a in Actor, where: a.preferred_username == ^name and is_nil(a.domain)))
|
||||||
|
@ -404,7 +395,7 @@ defmodule Mobilizon.Actors do
|
||||||
Find actors by their name or displayed name
|
Find actors by their name or displayed name
|
||||||
"""
|
"""
|
||||||
def find_actors_by_username_or_name(username, page \\ 1, limit \\ 10)
|
def find_actors_by_username_or_name(username, page \\ 1, limit \\ 10)
|
||||||
def find_actors_by_username_or_name("", page, limit), do: []
|
def find_actors_by_username_or_name("", _page, _limit), do: []
|
||||||
|
|
||||||
def find_actors_by_username_or_name(username, page, limit) do
|
def find_actors_by_username_or_name(username, page, limit) do
|
||||||
start = (page - 1) * limit
|
start = (page - 1) * limit
|
||||||
|
@ -421,9 +412,7 @@ defmodule Mobilizon.Actors do
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
@doc """
|
# Sanitize the LIKE queries
|
||||||
Sanitize the LIKE queries
|
|
||||||
"""
|
|
||||||
defp like_sanitize(value) do
|
defp like_sanitize(value) do
|
||||||
"%" <> String.replace(value, ~r/([\\%_])/, "\\1") <> "%"
|
"%" <> String.replace(value, ~r/([\\%_])/, "\\1") <> "%"
|
||||||
end
|
end
|
||||||
|
@ -515,7 +504,7 @@ defmodule Mobilizon.Actors do
|
||||||
defp handle_actor_user_changeset(changeset) do
|
defp handle_actor_user_changeset(changeset) do
|
||||||
changeset =
|
changeset =
|
||||||
Ecto.Changeset.traverse_errors(changeset, fn
|
Ecto.Changeset.traverse_errors(changeset, fn
|
||||||
{msg, opts} -> msg
|
{msg, _opts} -> msg
|
||||||
msg -> msg
|
msg -> msg
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ defmodule Mobilizon.Actors.Bot do
|
||||||
"""
|
"""
|
||||||
use Ecto.Schema
|
use Ecto.Schema
|
||||||
import Ecto.Changeset
|
import Ecto.Changeset
|
||||||
alias Mobilizon.Actors.{Actor, User, Bot}
|
alias Mobilizon.Actors.{Actor, User}
|
||||||
|
|
||||||
schema "bots" do
|
schema "bots" do
|
||||||
field(:source, :string)
|
field(:source, :string)
|
||||||
|
|
|
@ -23,7 +23,7 @@ defmodule Mobilizon.Actors.Service.ResetPassword do
|
||||||
) do
|
) do
|
||||||
{:ok, user}
|
{:ok, user}
|
||||||
else
|
else
|
||||||
err ->
|
_err ->
|
||||||
{:error, :invalid_token}
|
{:error, :invalid_token}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -114,9 +114,7 @@ defmodule Mobilizon.Actors.User do
|
||||||
|> Base.url_encode64()
|
|> Base.url_encode64()
|
||||||
end
|
end
|
||||||
|
|
||||||
@doc """
|
# Hash password when it's changed
|
||||||
Hash password when it's changed
|
|
||||||
"""
|
|
||||||
defp hash_password(changeset) do
|
defp hash_password(changeset) do
|
||||||
case changeset do
|
case changeset do
|
||||||
%Ecto.Changeset{valid?: true, changes: %{password: password}} ->
|
%Ecto.Changeset{valid?: true, changes: %{password: password}} ->
|
||||||
|
|
|
@ -5,7 +5,7 @@ defmodule Mobilizon.Addresses.Address do
|
||||||
import Ecto.Changeset
|
import Ecto.Changeset
|
||||||
alias Mobilizon.Addresses.Address
|
alias Mobilizon.Addresses.Address
|
||||||
alias Mobilizon.Events.Event
|
alias Mobilizon.Events.Event
|
||||||
alias Mobilizon.Groups.Group
|
# alias Mobilizon.Actors.Actor
|
||||||
|
|
||||||
schema "addresses" do
|
schema "addresses" do
|
||||||
field(:addressCountry, :string)
|
field(:addressCountry, :string)
|
||||||
|
@ -16,8 +16,8 @@ defmodule Mobilizon.Addresses.Address do
|
||||||
field(:geom, Geo.PostGIS.Geometry)
|
field(:geom, Geo.PostGIS.Geometry)
|
||||||
field(:postalCode, :string)
|
field(:postalCode, :string)
|
||||||
field(:streetAddress, :string)
|
field(:streetAddress, :string)
|
||||||
has_one(:event, Event)
|
has_one(:event, Event, foreign_key: :physical_address_id)
|
||||||
has_one(:group, Group)
|
# has_one(:group, Actor)
|
||||||
|
|
||||||
timestamps()
|
timestamps()
|
||||||
end
|
end
|
||||||
|
|
|
@ -5,11 +5,10 @@ defmodule Mobilizon.Addresses do
|
||||||
|
|
||||||
import Ecto.Query, warn: false
|
import Ecto.Query, warn: false
|
||||||
alias Mobilizon.Repo
|
alias Mobilizon.Repo
|
||||||
|
require Logger
|
||||||
|
|
||||||
alias Mobilizon.Addresses.Address
|
alias Mobilizon.Addresses.Address
|
||||||
|
|
||||||
import Logger
|
|
||||||
|
|
||||||
@geom_types [:point]
|
@geom_types [:point]
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
|
|
|
@ -215,9 +215,7 @@ defmodule Mobilizon.Events do
|
||||||
Repo.all(query)
|
Repo.all(query)
|
||||||
end
|
end
|
||||||
|
|
||||||
@doc """
|
# Sanitize the LIKE queries
|
||||||
Sanitize the LIKE queries
|
|
||||||
"""
|
|
||||||
defp like_sanitize(value) do
|
defp like_sanitize(value) do
|
||||||
"%" <> String.replace(value, ~r/([\\%_])/, "\\1") <> "%"
|
"%" <> String.replace(value, ~r/([\\%_])/, "\\1") <> "%"
|
||||||
end
|
end
|
||||||
|
|
|
@ -21,10 +21,6 @@ defmodule MobilizonWeb.NodeInfoController do
|
||||||
|
|
||||||
# Schema definition: https://github.com/jhass/nodeinfo/blob/master/schemas/2.0/schema.json
|
# Schema definition: https://github.com/jhass/nodeinfo/blob/master/schemas/2.0/schema.json
|
||||||
def nodeinfo(conn, %{"version" => "2.0"}) do
|
def nodeinfo(conn, %{"version" => "2.0"}) do
|
||||||
import Logger
|
|
||||||
Logger.debug(inspect(@instance))
|
|
||||||
# stats = Stats.get_stats()
|
|
||||||
|
|
||||||
response = %{
|
response = %{
|
||||||
version: "2.0",
|
version: "2.0",
|
||||||
software: %{
|
software: %{
|
||||||
|
@ -39,12 +35,10 @@ defmodule MobilizonWeb.NodeInfoController do
|
||||||
openRegistrations: Keyword.get(@instance, :registrations_open),
|
openRegistrations: Keyword.get(@instance, :registrations_open),
|
||||||
usage: %{
|
usage: %{
|
||||||
users: %{
|
users: %{
|
||||||
# total: stats.user_count || 0
|
|
||||||
total: Actors.count_users()
|
total: Actors.count_users()
|
||||||
},
|
},
|
||||||
localPosts: Events.count_local_events(),
|
localPosts: Events.count_local_events(),
|
||||||
localComments: Events.count_local_comments()
|
localComments: Events.count_local_comments()
|
||||||
# localPosts: stats.status_count || 0
|
|
||||||
},
|
},
|
||||||
metadata: %{
|
metadata: %{
|
||||||
nodeName: Keyword.get(@instance, :name)
|
nodeName: Keyword.get(@instance, :name)
|
||||||
|
|
|
@ -1,6 +1,4 @@
|
||||||
defmodule MobilizonWeb.Resolvers.Actor do
|
defmodule MobilizonWeb.Resolvers.Actor do
|
||||||
alias Mobilizon.Actors.Actor, as: ActorSchema
|
|
||||||
alias Mobilizon.Actors.User
|
|
||||||
alias Mobilizon.Actors
|
alias Mobilizon.Actors
|
||||||
alias Mobilizon.Service.ActivityPub
|
alias Mobilizon.Service.ActivityPub
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
defmodule MobilizonWeb.Resolvers.Category do
|
defmodule MobilizonWeb.Resolvers.Category do
|
||||||
require Logger
|
require Logger
|
||||||
|
alias Mobilizon.Actors.User
|
||||||
|
|
||||||
def list_categories(_parent, _args, _resolution) do
|
def list_categories(_parent, _args, _resolution) do
|
||||||
categories =
|
categories =
|
||||||
|
@ -13,7 +14,7 @@ defmodule MobilizonWeb.Resolvers.Category do
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_category(_parent, %{title: title, picture: picture, description: description}, %{
|
def create_category(_parent, %{title: title, picture: picture, description: description}, %{
|
||||||
context: %{current_user: user}
|
context: %{current_user: %User{} = _user}
|
||||||
}) do
|
}) do
|
||||||
with {:ok, category} <-
|
with {:ok, category} <-
|
||||||
Mobilizon.Events.create_category(%{
|
Mobilizon.Events.create_category(%{
|
||||||
|
@ -35,7 +36,7 @@ defmodule MobilizonWeb.Resolvers.Category do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_category(_parent, %{title: title, picture: picture, description: description}, %{}) do
|
def create_category(_parent, _args, %{}) do
|
||||||
{:error, "You are not allowed to create a category if not connected"}
|
{:error, "You are not allowed to create a category if not connected"}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
defmodule MobilizonWeb.Resolvers.Event do
|
defmodule MobilizonWeb.Resolvers.Event do
|
||||||
alias Mobilizon.Service.ActivityPub
|
alias Mobilizon.Service.ActivityPub
|
||||||
|
alias Mobilizon.Actors
|
||||||
|
|
||||||
def list_events(_parent, _args, _resolution) do
|
def list_events(_parent, _args, _resolution) do
|
||||||
{:ok, Mobilizon.Events.list_events()}
|
{:ok, Mobilizon.Events.list_events()}
|
||||||
|
@ -15,10 +16,20 @@ defmodule MobilizonWeb.Resolvers.Event do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@doc """
|
||||||
|
List participant for event (separate request)
|
||||||
|
"""
|
||||||
def list_participants_for_event(_parent, %{uuid: uuid}, _resolution) do
|
def list_participants_for_event(_parent, %{uuid: uuid}, _resolution) do
|
||||||
{:ok, Mobilizon.Events.list_participants_for_event(uuid)}
|
{:ok, Mobilizon.Events.list_participants_for_event(uuid)}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@doc """
|
||||||
|
List participants for event (through an event request)
|
||||||
|
"""
|
||||||
|
def list_participants_for_event(%{uuid: uuid}, _args, _resolution) do
|
||||||
|
{:ok, Mobilizon.Events.list_participants_for_event(uuid)}
|
||||||
|
end
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
Search events by title
|
Search events by title
|
||||||
"""
|
"""
|
||||||
|
@ -30,7 +41,7 @@ defmodule MobilizonWeb.Resolvers.Event do
|
||||||
Search events and actors by title
|
Search events and actors by title
|
||||||
"""
|
"""
|
||||||
def search_events_and_actors(_parent, %{search: search, page: page, limit: limit}, _resolution) do
|
def search_events_and_actors(_parent, %{search: search, page: page, limit: limit}, _resolution) do
|
||||||
search = String.strip(search)
|
search = String.trim(search)
|
||||||
|
|
||||||
found =
|
found =
|
||||||
case String.contains?(search, "@") do
|
case String.contains?(search, "@") do
|
||||||
|
@ -52,14 +63,9 @@ defmodule MobilizonWeb.Resolvers.Event do
|
||||||
{:ok, found}
|
{:ok, found}
|
||||||
end
|
end
|
||||||
|
|
||||||
@doc """
|
|
||||||
List participants for event (through an event request)
|
|
||||||
"""
|
|
||||||
def list_participants_for_event(%{uuid: uuid}, _args, _resolution) do
|
|
||||||
{:ok, Mobilizon.Events.list_participants_for_event(uuid)}
|
|
||||||
end
|
|
||||||
|
|
||||||
def create_event(_parent, args, %{context: %{current_user: user}}) do
|
def create_event(_parent, args, %{context: %{current_user: user}}) do
|
||||||
|
organizer_actor_id = Map.get(args, "organizer_actor_id") || Actors.get_actor_for_user(user).id
|
||||||
|
args = args |> Map.put("organizer_actor_id", organizer_actor_id)
|
||||||
Mobilizon.Events.create_event(args)
|
Mobilizon.Events.create_event(args)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@ defmodule MobilizonWeb.Resolvers.User do
|
||||||
{:error, "You need to be logged-in to view current user"}
|
{:error, "You need to be logged-in to view current user"}
|
||||||
end
|
end
|
||||||
|
|
||||||
@desc """
|
@doc """
|
||||||
Login an user. Returns a token and the user
|
Login an user. Returns a token and the user
|
||||||
"""
|
"""
|
||||||
def login_user(_parent, %{email: email, password: password}, _resolution) do
|
def login_user(_parent, %{email: email, password: password}, _resolution) do
|
||||||
|
@ -37,7 +37,7 @@ defmodule MobilizonWeb.Resolvers.User do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@desc """
|
@doc """
|
||||||
Register an user :
|
Register an user :
|
||||||
- create the user
|
- create the user
|
||||||
- create the actor
|
- create the actor
|
||||||
|
@ -111,7 +111,7 @@ defmodule MobilizonWeb.Resolvers.User do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@desc "Change an user default actor"
|
@doc "Change an user default actor"
|
||||||
def change_default_actor(_parent, %{preferred_username: username}, %{
|
def change_default_actor(_parent, %{preferred_username: username}, %{
|
||||||
context: %{current_user: user}
|
context: %{current_user: user}
|
||||||
}) do
|
}) do
|
||||||
|
|
|
@ -10,9 +10,6 @@ defmodule MobilizonWeb.Schema do
|
||||||
import_types(Absinthe.Type.Custom)
|
import_types(Absinthe.Type.Custom)
|
||||||
import_types(Absinthe.Plug.Types)
|
import_types(Absinthe.Plug.Types)
|
||||||
|
|
||||||
# import_types(MobilizonWeb.Schema.EventTypes)
|
|
||||||
# import_types(MobilizonWeb.Schema.ActorTypes)
|
|
||||||
|
|
||||||
alias MobilizonWeb.Resolvers
|
alias MobilizonWeb.Resolvers
|
||||||
|
|
||||||
@desc "An ActivityPub actor"
|
@desc "An ActivityPub actor"
|
||||||
|
|
|
@ -23,7 +23,7 @@ defmodule MobilizonWeb.Uploaders.Category do
|
||||||
end
|
end
|
||||||
|
|
||||||
# Override the persisted filenames:
|
# Override the persisted filenames:
|
||||||
def filename(version, {file, %{title: title}}) do
|
def filename(version, {_file, %{title: title}}) do
|
||||||
"#{title}_#{version}"
|
"#{title}_#{version}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -3,14 +3,10 @@ defmodule MobilizonWeb.ActivityPub.ActorView do
|
||||||
|
|
||||||
alias MobilizonWeb.ActivityPub.ActorView
|
alias MobilizonWeb.ActivityPub.ActorView
|
||||||
alias MobilizonWeb.ActivityPub.ObjectView
|
alias MobilizonWeb.ActivityPub.ObjectView
|
||||||
alias MobilizonWeb.WebFinger
|
|
||||||
alias Mobilizon.Actors.Actor
|
alias Mobilizon.Actors.Actor
|
||||||
alias Mobilizon.Repo
|
|
||||||
alias Mobilizon.Service.ActivityPub
|
alias Mobilizon.Service.ActivityPub
|
||||||
alias Mobilizon.Service.ActivityPub.Transmogrifier
|
|
||||||
alias Mobilizon.Service.ActivityPub.Utils
|
alias Mobilizon.Service.ActivityPub.Utils
|
||||||
alias Mobilizon.Activity
|
alias Mobilizon.Activity
|
||||||
import Ecto.Query
|
|
||||||
|
|
||||||
def render("actor.json", %{actor: actor}) do
|
def render("actor.json", %{actor: actor}) do
|
||||||
public_key = Mobilizon.Service.ActivityPub.Utils.pem_to_public_key_pem(actor.keys)
|
public_key = Mobilizon.Service.ActivityPub.Utils.pem_to_public_key_pem(actor.keys)
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
defmodule MobilizonWeb.ActivityPub.ObjectView do
|
defmodule MobilizonWeb.ActivityPub.ObjectView do
|
||||||
use MobilizonWeb, :view
|
use MobilizonWeb, :view
|
||||||
alias MobilizonWeb.ActivityPub.ObjectView
|
alias MobilizonWeb.ActivityPub.ObjectView
|
||||||
alias Mobilizon.Service.ActivityPub.Transmogrifier
|
|
||||||
alias Mobilizon.Service.ActivityPub.Utils
|
alias Mobilizon.Service.ActivityPub.Utils
|
||||||
|
|
||||||
def render("event.json", %{event: event}) do
|
def render("event.json", %{event: event}) do
|
||||||
|
@ -37,14 +36,14 @@ defmodule MobilizonWeb.ActivityPub.ObjectView do
|
||||||
Map.merge(comment, Utils.make_json_ld_header())
|
Map.merge(comment, Utils.make_json_ld_header())
|
||||||
end
|
end
|
||||||
|
|
||||||
def render("category.json", %{category: category}) do
|
def render("category.json", %{category: category}) when not is_nil(category) do
|
||||||
%{
|
%{
|
||||||
"identifier" => category.id,
|
"identifier" => category.id,
|
||||||
"name" => category.title
|
"name" => category.title
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
def render("category.json", %{category: nil}) do
|
def render("category.json", %{category: _category}) do
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -153,7 +153,7 @@ defmodule Mobilizon.Service.ActivityPub do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def follow(%Actor{} = follower, %Actor{} = followed, activity_id \\ nil, local \\ true) do
|
def follow(%Actor{} = follower, %Actor{} = followed, _activity_id \\ nil, local \\ true) do
|
||||||
with {:ok, follow} <- Actor.follow(follower, followed, true),
|
with {:ok, follow} <- Actor.follow(follower, followed, true),
|
||||||
data <- make_follow_data(follower, followed, follow.id),
|
data <- make_follow_data(follower, followed, follow.id),
|
||||||
{:ok, activity} <- insert(data, local),
|
{:ok, activity} <- insert(data, local),
|
||||||
|
@ -197,9 +197,6 @@ defmodule Mobilizon.Service.ActivityPub do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_public_activities(%Actor{} = actor) do
|
|
||||||
end
|
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
Create an actor locally by it's URL (AP ID)
|
Create an actor locally by it's URL (AP ID)
|
||||||
"""
|
"""
|
||||||
|
@ -283,7 +280,6 @@ defmodule Mobilizon.Service.ActivityPub do
|
||||||
"content-length": byte_size(json)
|
"content-length": byte_size(json)
|
||||||
})
|
})
|
||||||
|
|
||||||
{:ok, response} =
|
|
||||||
HTTPoison.post(
|
HTTPoison.post(
|
||||||
inbox,
|
inbox,
|
||||||
json,
|
json,
|
||||||
|
@ -292,9 +288,7 @@ defmodule Mobilizon.Service.ActivityPub do
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
@doc """
|
# Fetching a remote actor's informations through it's AP ID
|
||||||
Fetching a remote actor's informations through it's AP ID
|
|
||||||
"""
|
|
||||||
@spec fetch_and_prepare_actor_from_url(String.t()) :: {:ok, struct()} | {:error, atom()} | any()
|
@spec fetch_and_prepare_actor_from_url(String.t()) :: {:ok, struct()} | {:error, atom()} | any()
|
||||||
defp fetch_and_prepare_actor_from_url(url) do
|
defp fetch_and_prepare_actor_from_url(url) do
|
||||||
Logger.debug("Fetching and preparing actor from url")
|
Logger.debug("Fetching and preparing actor from url")
|
||||||
|
@ -352,8 +346,8 @@ defmodule Mobilizon.Service.ActivityPub do
|
||||||
def fetch_public_activities_for_actor(%Actor{} = actor, page \\ 1, limit \\ 10) do
|
def fetch_public_activities_for_actor(%Actor{} = actor, page \\ 1, limit \\ 10) do
|
||||||
case actor.type do
|
case actor.type do
|
||||||
:Person ->
|
:Person ->
|
||||||
{:ok, events, total} = Events.get_events_for_actor(actor, page, limit)
|
{:ok, events, total_events} = Events.get_events_for_actor(actor, page, limit)
|
||||||
{:ok, comments, total} = Events.get_comments_for_actor(actor, page, limit)
|
{:ok, comments, total_comments} = Events.get_comments_for_actor(actor, page, limit)
|
||||||
|
|
||||||
event_activities = Enum.map(events, &event_to_activity/1)
|
event_activities = Enum.map(events, &event_to_activity/1)
|
||||||
|
|
||||||
|
@ -361,7 +355,7 @@ defmodule Mobilizon.Service.ActivityPub do
|
||||||
|
|
||||||
activities = event_activities ++ comment_activities
|
activities = event_activities ++ comment_activities
|
||||||
|
|
||||||
{activities, total}
|
{activities, total_events + total_comments}
|
||||||
|
|
||||||
:Service ->
|
:Service ->
|
||||||
bot = Actors.get_bot_by_actor(actor)
|
bot = Actors.get_bot_by_actor(actor)
|
||||||
|
@ -389,9 +383,7 @@ defmodule Mobilizon.Service.ActivityPub do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@doc """
|
# Create an activity from an event
|
||||||
Create an activity from an event
|
|
||||||
"""
|
|
||||||
@spec event_to_activity(%Event{}, boolean()) :: Activity.t()
|
@spec event_to_activity(%Event{}, boolean()) :: Activity.t()
|
||||||
defp event_to_activity(%Event{} = event, local \\ true) do
|
defp event_to_activity(%Event{} = event, local \\ true) do
|
||||||
%Activity{
|
%Activity{
|
||||||
|
@ -402,9 +394,7 @@ defmodule Mobilizon.Service.ActivityPub do
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
@doc """
|
# Create an activity from a comment
|
||||||
Create an activity from a comment
|
|
||||||
"""
|
|
||||||
@spec comment_to_activity(%Comment{}, boolean()) :: Activity.t()
|
@spec comment_to_activity(%Comment{}, boolean()) :: Activity.t()
|
||||||
defp comment_to_activity(%Comment{} = comment, local \\ true) do
|
defp comment_to_activity(%Comment{} = comment, local \\ true) do
|
||||||
%Activity{
|
%Activity{
|
||||||
|
@ -415,7 +405,7 @@ defmodule Mobilizon.Service.ActivityPub do
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
defp ical_event_to_activity(%ExIcal.Event{} = ical_event, %Actor{} = actor, source) do
|
defp ical_event_to_activity(%ExIcal.Event{} = ical_event, %Actor{} = actor, _source) do
|
||||||
# Logger.debug(inspect ical_event)
|
# Logger.debug(inspect ical_event)
|
||||||
# TODO : refactor me !
|
# TODO : refactor me !
|
||||||
# TODO : also, there should be a form of cache that allows this to be more efficient
|
# TODO : also, there should be a form of cache that allows this to be more efficient
|
||||||
|
|
|
@ -6,8 +6,7 @@ defmodule Mobilizon.Service.ActivityPub.Transmogrifier do
|
||||||
alias Mobilizon.Actors
|
alias Mobilizon.Actors
|
||||||
alias Mobilizon.Events.{Event, Comment}
|
alias Mobilizon.Events.{Event, Comment}
|
||||||
alias Mobilizon.Service.ActivityPub
|
alias Mobilizon.Service.ActivityPub
|
||||||
|
alias Mobilizon.Service.ActivityPub.Utils
|
||||||
import Ecto.Query
|
|
||||||
|
|
||||||
require Logger
|
require Logger
|
||||||
|
|
||||||
|
@ -89,11 +88,10 @@ defmodule Mobilizon.Service.ActivityPub.Transmogrifier do
|
||||||
|
|
||||||
with {:ok, %Actor{} = actor} <- Actors.get_or_fetch_by_url(data["actor"]) do
|
with {:ok, %Actor{} = actor} <- Actors.get_or_fetch_by_url(data["actor"]) do
|
||||||
Logger.debug("found actor")
|
Logger.debug("found actor")
|
||||||
object = fix_object(data["object"])
|
|
||||||
|
|
||||||
params = %{
|
params = %{
|
||||||
to: data["to"],
|
to: data["to"],
|
||||||
object: object,
|
object: object |> fix_object,
|
||||||
actor: actor,
|
actor: actor,
|
||||||
local: false,
|
local: false,
|
||||||
published: data["published"],
|
published: data["published"],
|
||||||
|
@ -234,11 +232,9 @@ defmodule Mobilizon.Service.ActivityPub.Transmogrifier do
|
||||||
|> set_reply_to_uri
|
|> set_reply_to_uri
|
||||||
end
|
end
|
||||||
|
|
||||||
@doc
|
@doc """
|
||||||
"""
|
|
||||||
internal -> Mastodon
|
internal -> Mastodon
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def prepare_outgoing(%{"type" => "Create", "object" => %{"type" => "Note"} = object} = data) do
|
def prepare_outgoing(%{"type" => "Create", "object" => %{"type" => "Note"} = object} = data) do
|
||||||
Logger.debug("Prepare outgoing for a note creation")
|
Logger.debug("Prepare outgoing for a note creation")
|
||||||
|
|
||||||
|
@ -249,43 +245,42 @@ defmodule Mobilizon.Service.ActivityPub.Transmogrifier do
|
||||||
data =
|
data =
|
||||||
data
|
data
|
||||||
|> Map.put("object", object)
|
|> Map.put("object", object)
|
||||||
|> Map.put("@context", "https://www.w3.org/ns/activitystreams")
|
|> Map.merge(Utils.make_json_ld_header())
|
||||||
|
|
||||||
Logger.debug("Finished prepare outgoing for a note creation")
|
Logger.debug("Finished prepare outgoing for a note creation")
|
||||||
|
|
||||||
{:ok, data}
|
{:ok, data}
|
||||||
end
|
end
|
||||||
|
|
||||||
def prepare_outgoing(%{"type" => type} = data) do
|
def prepare_outgoing(%{"type" => _type} = data) do
|
||||||
data =
|
data =
|
||||||
data
|
data
|
||||||
# |> maybe_fix_object_url
|
|> Map.merge(Utils.make_json_ld_header())
|
||||||
|> Map.put("@context", "https://www.w3.org/ns/activitystreams")
|
|
||||||
|
|
||||||
{:ok, data}
|
{:ok, data}
|
||||||
end
|
end
|
||||||
|
|
||||||
def prepare_outgoing(%Event{} = event) do
|
# def prepare_outgoing(%Event{} = event) do
|
||||||
event =
|
# event =
|
||||||
event
|
# event
|
||||||
|> Map.from_struct()
|
# |> Map.from_struct()
|
||||||
|> Map.drop([:__meta__])
|
# |> Map.drop([:__meta__])
|
||||||
|> Map.put(:"@context", "https://www.w3.org/ns/activitystreams")
|
# |> Map.put(:"@context", "https://www.w3.org/ns/activitystreams")
|
||||||
|> prepare_object
|
# |> prepare_object
|
||||||
|
|
||||||
{:ok, event}
|
# {:ok, event}
|
||||||
end
|
# end
|
||||||
|
|
||||||
def prepare_outgoing(%Comment{} = comment) do
|
# def prepare_outgoing(%Comment{} = comment) do
|
||||||
comment =
|
# comment =
|
||||||
comment
|
# comment
|
||||||
|> Map.from_struct()
|
# |> Map.from_struct()
|
||||||
|> Map.drop([:__meta__])
|
# |> Map.drop([:__meta__])
|
||||||
|> Map.put(:"@context", "https://www.w3.org/ns/activitystreams")
|
# |> Map.put(:"@context", "https://www.w3.org/ns/activitystreams")
|
||||||
|> prepare_object
|
# |> prepare_object
|
||||||
|
|
||||||
{:ok, comment}
|
# {:ok, comment}
|
||||||
end
|
# end
|
||||||
|
|
||||||
#
|
#
|
||||||
# def maybe_fix_object_url(data) do
|
# def maybe_fix_object_url(data) do
|
||||||
|
|
|
@ -13,11 +13,8 @@ defmodule Mobilizon.Service.ActivityPub.Utils do
|
||||||
alias Mobilizon.Events
|
alias Mobilizon.Events
|
||||||
alias Mobilizon.Activity
|
alias Mobilizon.Activity
|
||||||
alias MobilizonWeb
|
alias MobilizonWeb
|
||||||
alias MobilizonWeb.Router.Helpers
|
|
||||||
alias MobilizonWeb.Endpoint
|
|
||||||
alias Mobilizon.Service.ActivityPub
|
alias Mobilizon.Service.ActivityPub
|
||||||
alias Ecto.{Changeset, UUID}
|
alias Ecto.{Changeset, UUID}
|
||||||
import Ecto.Query
|
|
||||||
require Logger
|
require Logger
|
||||||
|
|
||||||
def make_context(%Activity{data: %{"context" => context}}), do: context
|
def make_context(%Activity{data: %{"context" => context}}), do: context
|
||||||
|
@ -97,7 +94,7 @@ defmodule Mobilizon.Service.ActivityPub.Utils do
|
||||||
"""
|
"""
|
||||||
def lazy_put_activity_defaults(map) do
|
def lazy_put_activity_defaults(map) do
|
||||||
if is_map(map["object"]) do
|
if is_map(map["object"]) do
|
||||||
object = lazy_put_object_defaults(map["object"], map)
|
object = lazy_put_object_defaults(map["object"])
|
||||||
%{map | "object" => object}
|
%{map | "object" => object}
|
||||||
else
|
else
|
||||||
map
|
map
|
||||||
|
@ -107,9 +104,8 @@ defmodule Mobilizon.Service.ActivityPub.Utils do
|
||||||
@doc """
|
@doc """
|
||||||
Adds an id and published date if they aren't there.
|
Adds an id and published date if they aren't there.
|
||||||
"""
|
"""
|
||||||
def lazy_put_object_defaults(map, activity \\ %{}) do
|
def lazy_put_object_defaults(map) do
|
||||||
map
|
Map.put_new_lazy(map, "published", &make_date/0)
|
||||||
|> Map.put_new_lazy("published", &make_date/0)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
|
@ -174,7 +170,7 @@ defmodule Mobilizon.Service.ActivityPub.Utils do
|
||||||
data
|
data
|
||||||
end
|
end
|
||||||
|
|
||||||
with {:ok, comm} <- Events.create_comment(data) do
|
with {:ok, _comment} <- Events.create_comment(data) do
|
||||||
:ok
|
:ok
|
||||||
else
|
else
|
||||||
err ->
|
err ->
|
||||||
|
@ -261,7 +257,7 @@ defmodule Mobilizon.Service.ActivityPub.Utils do
|
||||||
# attachments,
|
# attachments,
|
||||||
inReplyTo \\ nil,
|
inReplyTo \\ nil,
|
||||||
# tags,
|
# tags,
|
||||||
cw \\ nil,
|
_cw \\ nil,
|
||||||
cc \\ []
|
cc \\ []
|
||||||
) do
|
) do
|
||||||
Logger.debug("Making comment data")
|
Logger.debug("Making comment data")
|
||||||
|
@ -270,7 +266,7 @@ defmodule Mobilizon.Service.ActivityPub.Utils do
|
||||||
object = %{
|
object = %{
|
||||||
"type" => "Note",
|
"type" => "Note",
|
||||||
"to" => to,
|
"to" => to,
|
||||||
# "cc" => cc,
|
"cc" => cc,
|
||||||
"content" => content_html,
|
"content" => content_html,
|
||||||
# "summary" => cw,
|
# "summary" => cw,
|
||||||
# "attachment" => attachments,
|
# "attachment" => attachments,
|
||||||
|
|
|
@ -8,7 +8,7 @@ defmodule Mobilizon.Service.HTTPSignatures do
|
||||||
|
|
||||||
alias Mobilizon.Actors.Actor
|
alias Mobilizon.Actors.Actor
|
||||||
alias Mobilizon.Service.ActivityPub
|
alias Mobilizon.Service.ActivityPub
|
||||||
import Logger
|
require Logger
|
||||||
|
|
||||||
def split_signature(sig) do
|
def split_signature(sig) do
|
||||||
default = %{"headers" => "date"}
|
default = %{"headers" => "date"}
|
||||||
|
|
|
@ -7,7 +7,6 @@ defmodule Mobilizon.Service.Streamer do
|
||||||
|
|
||||||
use GenServer
|
use GenServer
|
||||||
require Logger
|
require Logger
|
||||||
alias Mobilizon.Accounts.Actor
|
|
||||||
|
|
||||||
def init(args) do
|
def init(args) do
|
||||||
{:ok, args}
|
{:ok, args}
|
||||||
|
|
|
@ -7,7 +7,6 @@ defmodule Mobilizon.Service.WebFinger do
|
||||||
|
|
||||||
alias Mobilizon.Actors
|
alias Mobilizon.Actors
|
||||||
alias Mobilizon.Service.XmlBuilder
|
alias Mobilizon.Service.XmlBuilder
|
||||||
alias Mobilizon.Repo
|
|
||||||
require Jason
|
require Jason
|
||||||
require Logger
|
require Logger
|
||||||
|
|
||||||
|
|
1
mix.exs
1
mix.exs
|
@ -84,6 +84,7 @@ defmodule Mobilizon.Mixfile do
|
||||||
{:arc, "~> 0.11.0"},
|
{:arc, "~> 0.11.0"},
|
||||||
{:arc_ecto, "~> 0.11.0"},
|
{:arc_ecto, "~> 0.11.0"},
|
||||||
{:email_checker, "~> 0.1.2"},
|
{:email_checker, "~> 0.1.2"},
|
||||||
|
{:plug_cowboy, "~> 1.0"},
|
||||||
# Dev and test dependencies
|
# Dev and test dependencies
|
||||||
{:phoenix_live_reload, "~> 1.0", only: :dev},
|
{:phoenix_live_reload, "~> 1.0", only: :dev},
|
||||||
{:ex_machina, "~> 2.2", only: [:dev, :test]},
|
{:ex_machina, "~> 2.2", only: [:dev, :test]},
|
||||||
|
|
1
mix.lock
1
mix.lock
|
@ -71,6 +71,7 @@
|
||||||
"phoenix_live_reload": {:hex, :phoenix_live_reload, "1.1.7", "425fff579085f7eacaf009e71940be07338c8d8b78d16e307c50c7d82a381497", [:mix], [{:file_system, "~> 0.2.1 or ~> 0.3", [hex: :file_system, repo: "hexpm", optional: false]}, {:phoenix, "~> 1.0 or ~> 1.2 or ~> 1.3 or ~> 1.4", [hex: :phoenix, repo: "hexpm", optional: false]}], "hexpm"},
|
"phoenix_live_reload": {:hex, :phoenix_live_reload, "1.1.7", "425fff579085f7eacaf009e71940be07338c8d8b78d16e307c50c7d82a381497", [:mix], [{:file_system, "~> 0.2.1 or ~> 0.3", [hex: :file_system, repo: "hexpm", optional: false]}, {:phoenix, "~> 1.0 or ~> 1.2 or ~> 1.3 or ~> 1.4", [hex: :phoenix, repo: "hexpm", optional: false]}], "hexpm"},
|
||||||
"phoenix_pubsub": {:hex, :phoenix_pubsub, "1.1.1", "6668d787e602981f24f17a5fbb69cc98f8ab085114ebfac6cc36e10a90c8e93c", [:mix], [], "hexpm"},
|
"phoenix_pubsub": {:hex, :phoenix_pubsub, "1.1.1", "6668d787e602981f24f17a5fbb69cc98f8ab085114ebfac6cc36e10a90c8e93c", [:mix], [], "hexpm"},
|
||||||
"plug": {:hex, :plug, "1.7.1", "8516d565fb84a6a8b2ca722e74e2cd25ca0fc9d64f364ec9dbec09d33eb78ccd", [:mix], [{:mime, "~> 1.0", [hex: :mime, repo: "hexpm", optional: false]}, {:plug_crypto, "~> 1.0", [hex: :plug_crypto, repo: "hexpm", optional: false]}], "hexpm"},
|
"plug": {:hex, :plug, "1.7.1", "8516d565fb84a6a8b2ca722e74e2cd25ca0fc9d64f364ec9dbec09d33eb78ccd", [:mix], [{:mime, "~> 1.0", [hex: :mime, repo: "hexpm", optional: false]}, {:plug_crypto, "~> 1.0", [hex: :plug_crypto, repo: "hexpm", optional: false]}], "hexpm"},
|
||||||
|
"plug_cowboy": {:hex, :plug_cowboy, "1.0.0", "2e2a7d3409746d335f451218b8bb0858301c3de6d668c3052716c909936eb57a", [:mix], [{:cowboy, "~> 1.0", [hex: :cowboy, repo: "hexpm", optional: false]}, {:plug, "~> 1.7", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm"},
|
||||||
"plug_crypto": {:hex, :plug_crypto, "1.0.0", "18e49317d3fa343f24620ed22795ec29d4a5e602d52d1513ccea0b07d8ea7d4d", [:mix], [], "hexpm"},
|
"plug_crypto": {:hex, :plug_crypto, "1.0.0", "18e49317d3fa343f24620ed22795ec29d4a5e602d52d1513ccea0b07d8ea7d4d", [:mix], [], "hexpm"},
|
||||||
"poison": {:hex, :poison, "3.1.0", "d9eb636610e096f86f25d9a46f35a9facac35609a7591b3be3326e99a0484665", [:mix], [], "hexpm"},
|
"poison": {:hex, :poison, "3.1.0", "d9eb636610e096f86f25d9a46f35a9facac35609a7591b3be3326e99a0484665", [:mix], [], "hexpm"},
|
||||||
"poolboy": {:hex, :poolboy, "1.5.1", "6b46163901cfd0a1b43d692657ed9d7e599853b3b21b95ae5ae0a777cf9b6ca8", [:rebar], [], "hexpm"},
|
"poolboy": {:hex, :poolboy, "1.5.1", "6b46163901cfd0a1b43d692657ed9d7e599853b3b21b95ae5ae0a777cf9b6ca8", [:rebar], [], "hexpm"},
|
||||||
|
|
Loading…
Reference in a new issue