Merge branch 'test-transmogrifier' into 'master'
Test transmogrifier See merge request framasoft/mobilizon!28
This commit is contained in:
commit
2eaec5f497
|
@ -4,28 +4,12 @@ defmodule Mix.Tasks.Toot do
|
|||
"""
|
||||
|
||||
use Mix.Task
|
||||
alias Mobilizon.Actors
|
||||
alias Mobilizon.Actors.Actor
|
||||
alias Mobilizon.Service.ActivityPub
|
||||
alias Mobilizon.Service.ActivityPub.Utils
|
||||
require Logger
|
||||
|
||||
@shortdoc "Toot to an user"
|
||||
def run([from, to, content]) do
|
||||
def run([from, content]) do
|
||||
Mix.Task.run("app.start")
|
||||
|
||||
with %Actor{} = from <- Actors.get_actor_by_name(from),
|
||||
{:ok, %Actor{} = to} <- ActivityPub.find_or_make_actor_from_nickname(to) do
|
||||
comment = Utils.make_comment_data(from.url, [to.url], content)
|
||||
|
||||
ActivityPub.create(%{
|
||||
to: [to.url],
|
||||
actor: from,
|
||||
object: comment,
|
||||
local: true
|
||||
})
|
||||
else
|
||||
e -> Logger.error(inspect(e))
|
||||
end
|
||||
MobilizonWeb.API.Comments.create_comment(from, content)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -167,6 +167,7 @@ defmodule Mobilizon.Actors.Actor do
|
|||
])
|
||||
|> build_urls(:Group)
|
||||
|> put_change(:domain, nil)
|
||||
|> put_change(:keys, Actors.create_keys())
|
||||
|> put_change(:type, :Group)
|
||||
|> validate_required([:url, :outbox_url, :inbox_url, :type, :preferred_username])
|
||||
|> unique_constraint(:preferred_username, name: :actors_preferred_username_domain_type_index)
|
||||
|
@ -292,7 +293,7 @@ defmodule Mobilizon.Actors.Actor do
|
|||
{:already_following, false} <- {:already_following, following?(follower, followed)} do
|
||||
do_follow(follower, followed, approved)
|
||||
else
|
||||
{:already_following, _} ->
|
||||
{:already_following, %Follower{}} ->
|
||||
{:error,
|
||||
"Could not follow actor: you are already following #{followed.preferred_username}"}
|
||||
|
||||
|
@ -301,6 +302,17 @@ defmodule Mobilizon.Actors.Actor do
|
|||
end
|
||||
end
|
||||
|
||||
@spec unfollow(struct(), struct()) :: {:ok, Follower.t()} | {:error, Ecto.Changeset.t()}
|
||||
def unfollow(%Actor{} = followed, %Actor{} = follower) do
|
||||
with {:already_following, %Follower{} = follow} <-
|
||||
{:already_following, following?(follower, followed)} do
|
||||
Actors.delete_follower(follow)
|
||||
else
|
||||
{:already_following, false} ->
|
||||
{:error, "Could not unfollow actor: you are not following #{followed.preferred_username}"}
|
||||
end
|
||||
end
|
||||
|
||||
defp do_follow(%Actor{} = follower, %Actor{} = followed, approved) do
|
||||
Actors.create_follower(%{
|
||||
"actor_id" => follower.id,
|
||||
|
@ -311,12 +323,13 @@ defmodule Mobilizon.Actors.Actor do
|
|||
|
||||
@spec following?(struct(), struct()) :: boolean()
|
||||
def following?(
|
||||
%Actor{id: follower_actor_id} = _follower_actor,
|
||||
%Actor{followers: followers} = _followed
|
||||
%Actor{} = follower_actor,
|
||||
%Actor{} = followed_actor
|
||||
) do
|
||||
followers
|
||||
|> Enum.map(& &1.actor_id)
|
||||
|> Enum.member?(follower_actor_id)
|
||||
case Actors.get_follower(followed_actor, follower_actor) do
|
||||
nil -> false
|
||||
%Follower{} = follow -> follow
|
||||
end
|
||||
end
|
||||
|
||||
@spec actor_acct_from_actor(struct()) :: String.t()
|
||||
|
|
|
@ -162,16 +162,41 @@ defmodule Mobilizon.Actors do
|
|||
)
|
||||
end
|
||||
|
||||
def get_group_by_name(name) do
|
||||
case String.split(name, "@") do
|
||||
[name] ->
|
||||
Repo.get_by(Actor, preferred_username: name, type: :Group)
|
||||
@doc """
|
||||
Get a group by it's title
|
||||
"""
|
||||
@spec get_group_by_title(String.t()) :: Actor.t() | nil
|
||||
def get_group_by_title(title) do
|
||||
case String.split(title, "@") do
|
||||
[title] ->
|
||||
get_local_group_by_title(title)
|
||||
|
||||
[name, domain] ->
|
||||
Repo.get_by(Actor, preferred_username: name, domain: domain, type: :Group)
|
||||
[title, domain] ->
|
||||
Repo.one(
|
||||
from(a in Actor,
|
||||
where: a.preferred_username == ^title and a.type == "Group" and a.domain == ^domain
|
||||
)
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
@doc """
|
||||
Get a local group by it's title
|
||||
"""
|
||||
@spec get_local_group_by_title(String.t()) :: Actor.t() | nil
|
||||
def get_local_group_by_title(title) do
|
||||
title
|
||||
|> do_get_local_group_by_title
|
||||
|> Repo.one()
|
||||
end
|
||||
|
||||
@spec do_get_local_group_by_title(String.t()) :: Ecto.Query.t()
|
||||
defp do_get_local_group_by_title(title) do
|
||||
from(a in Actor,
|
||||
where: a.preferred_username == ^title and a.type == "Group" and is_nil(a.domain)
|
||||
)
|
||||
end
|
||||
|
||||
@doc """
|
||||
Creates a group.
|
||||
|
||||
|
@ -185,8 +210,6 @@ defmodule Mobilizon.Actors do
|
|||
|
||||
"""
|
||||
def create_group(attrs \\ %{}) do
|
||||
attrs = Map.put(attrs, :keys, create_keys())
|
||||
|
||||
%Actor{}
|
||||
|> Actor.group_creation(attrs)
|
||||
|> Repo.insert()
|
||||
|
@ -218,10 +241,11 @@ defmodule Mobilizon.Actors do
|
|||
keys: data.keys,
|
||||
avatar_url: data.avatar_url,
|
||||
banner_url: data.banner_url,
|
||||
name: data.name
|
||||
name: data.name,
|
||||
summary: data.summary
|
||||
]
|
||||
],
|
||||
conflict_target: [:preferred_username, :domain, :type]
|
||||
conflict_target: [:url]
|
||||
)
|
||||
|
||||
if preload, do: {:ok, Repo.preload(actor, [:followers])}, else: {:ok, actor}
|
||||
|
@ -516,9 +540,11 @@ defmodule Mobilizon.Actors do
|
|||
end
|
||||
end
|
||||
|
||||
# Create a new RSA key
|
||||
@doc """
|
||||
Create a new RSA key
|
||||
"""
|
||||
@spec create_keys() :: String.t()
|
||||
defp create_keys() do
|
||||
def create_keys() do
|
||||
key = :public_key.generate_key({:rsa, 2048, 65_537})
|
||||
entry = :public_key.pem_entry_encode(:RSAPrivateKey, key)
|
||||
[entry] |> :public_key.pem_encode() |> String.trim_trailing()
|
||||
|
@ -958,6 +984,13 @@ defmodule Mobilizon.Actors do
|
|||
|> Repo.preload([:actor, :target_actor])
|
||||
end
|
||||
|
||||
@spec get_follower(Actor.t(), Actor.t()) :: Follower.t()
|
||||
def get_follower(%Actor{id: followed_id}, %Actor{id: follower_id}) do
|
||||
Repo.one(
|
||||
from(f in Follower, where: f.target_actor_id == ^followed_id and f.actor_id == ^follower_id)
|
||||
)
|
||||
end
|
||||
|
||||
@doc """
|
||||
Creates a follower.
|
||||
|
||||
|
@ -1013,6 +1046,24 @@ defmodule Mobilizon.Actors do
|
|||
Repo.delete(follower)
|
||||
end
|
||||
|
||||
@doc """
|
||||
Delete a follower by followed and follower actors
|
||||
|
||||
## Examples
|
||||
|
||||
iex> delete_follower(%Actor{}, %Actor{})
|
||||
{:ok, %Mobilizon.Actors.Follower{}}
|
||||
|
||||
iex> delete_follower(%Actor{}, %Actor{})
|
||||
{:error, %Ecto.Changeset{}}
|
||||
|
||||
"""
|
||||
@spec delete_follower(Actor.t(), Actor.t()) ::
|
||||
{:ok, Follower.t()} | {:error, Ecto.Changeset.t()}
|
||||
def delete_follower(%Actor{} = followed, %Actor{} = follower) do
|
||||
get_follower(followed, follower) |> Repo.delete()
|
||||
end
|
||||
|
||||
@doc """
|
||||
Returns an `%Ecto.Changeset{}` for tracking follower changes.
|
||||
|
||||
|
|
|
@ -21,4 +21,8 @@ defmodule Mobilizon.Actors.Follower do
|
|||
|> validate_required([:score, :approved, :target_actor_id, :actor_id])
|
||||
|> unique_constraint(:target_actor_id, name: :followers_actor_target_actor_unique_index)
|
||||
end
|
||||
|
||||
def url(%Follower{id: id}) do
|
||||
"#{MobilizonWeb.Endpoint.url()}/follow/#{id}/activity"
|
||||
end
|
||||
end
|
||||
|
|
|
@ -116,7 +116,7 @@ defmodule Mobilizon.Addresses do
|
|||
rescue
|
||||
e in ArgumentError ->
|
||||
Logger.error("#{type_input} is not an existing atom : #{inspect(e)}")
|
||||
nil
|
||||
:invalid_type
|
||||
end
|
||||
else
|
||||
type_input
|
||||
|
@ -128,7 +128,7 @@ defmodule Mobilizon.Addresses do
|
|||
process_point(data["latitude"], data["longitude"])
|
||||
end
|
||||
else
|
||||
{:error, nil}
|
||||
{:error, :invalid_type}
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -117,11 +117,30 @@ defmodule Mobilizon.Events do
|
|||
Repo.get_by!(Event, url: url)
|
||||
end
|
||||
|
||||
# @doc """
|
||||
# Gets an event by it's UUID
|
||||
# """
|
||||
# @depreciated "Use get_event_full_by_uuid/3 instead"
|
||||
# def get_event_by_uuid(uuid) do
|
||||
# Repo.get_by(Event, uuid: uuid)
|
||||
# end
|
||||
|
||||
@doc """
|
||||
Gets an event by it's UUID
|
||||
Gets a full event by it's UUID
|
||||
"""
|
||||
def get_event_by_uuid(uuid) do
|
||||
Repo.get_by(Event, uuid: uuid)
|
||||
@spec get_event_full_by_uuid(String.t()) :: Event.t()
|
||||
def get_event_full_by_uuid(uuid) do
|
||||
event = Repo.get_by(Event, uuid: uuid)
|
||||
|
||||
Repo.preload(event, [
|
||||
:organizer_actor,
|
||||
:category,
|
||||
:sessions,
|
||||
:tracks,
|
||||
:tags,
|
||||
:participants,
|
||||
:physical_address
|
||||
])
|
||||
end
|
||||
|
||||
@doc """
|
||||
|
@ -144,10 +163,11 @@ defmodule Mobilizon.Events do
|
|||
@doc """
|
||||
Gets an event by it's URL
|
||||
"""
|
||||
def get_event_full_by_url!(url) do
|
||||
event = Repo.get_by!(Event, url: url)
|
||||
|
||||
Repo.preload(event, [
|
||||
def get_event_full_by_url(url) do
|
||||
case Repo.one(
|
||||
from(e in Event,
|
||||
where: e.url == ^url,
|
||||
preload: [
|
||||
:organizer_actor,
|
||||
:category,
|
||||
:sessions,
|
||||
|
@ -155,14 +175,19 @@ defmodule Mobilizon.Events do
|
|||
:tags,
|
||||
:participants,
|
||||
:physical_address
|
||||
])
|
||||
]
|
||||
)
|
||||
) do
|
||||
nil -> {:error, :event_not_found}
|
||||
event -> {:ok, event}
|
||||
end
|
||||
end
|
||||
|
||||
@doc """
|
||||
Gets a full event by it's UUID
|
||||
Gets an event by it's URL
|
||||
"""
|
||||
def get_event_full_by_uuid(uuid) do
|
||||
event = Repo.get_by(Event, uuid: uuid)
|
||||
def get_event_full_by_url!(url) do
|
||||
event = Repo.get_by!(Event, url: url)
|
||||
|
||||
Repo.preload(event, [
|
||||
:organizer_actor,
|
||||
|
@ -233,7 +258,7 @@ defmodule Mobilizon.Events do
|
|||
{:ok, %Participant{} = _participant} <-
|
||||
%Participant{}
|
||||
|> Participant.changeset(%{
|
||||
actor_id: attrs.organizer_actor_id,
|
||||
actor_id: event.organizer_actor_id,
|
||||
role: 4,
|
||||
event_id: event.id
|
||||
})
|
||||
|
@ -609,8 +634,12 @@ defmodule Mobilizon.Events do
|
|||
Participant.changeset(participant, %{})
|
||||
end
|
||||
|
||||
def list_requests_for_actor(%Actor{} = actor) do
|
||||
Repo.all(from(p in Participant, where: p.actor_id == ^actor.id and p.approved == false))
|
||||
@doc """
|
||||
List event participation requests for an actor
|
||||
"""
|
||||
@spec list_requests_for_actor(Actor.t()) :: list(Participant.t())
|
||||
def list_requests_for_actor(%Actor{id: actor_id}) do
|
||||
Repo.all(from(p in Participant, where: p.actor_id == ^actor_id and p.approved == false))
|
||||
end
|
||||
|
||||
alias Mobilizon.Events.Session
|
||||
|
@ -631,24 +660,18 @@ defmodule Mobilizon.Events do
|
|||
@doc """
|
||||
Returns the list of sessions for an event
|
||||
"""
|
||||
def list_sessions_for_event(event_uuid) do
|
||||
@spec list_sessions_for_event(Event.t()) :: list(Session.t())
|
||||
def list_sessions_for_event(%Event{id: event_id}) do
|
||||
Repo.all(
|
||||
from(
|
||||
s in Session,
|
||||
join: e in Event,
|
||||
on: s.event_id == e.id,
|
||||
where: e.uuid == ^event_uuid
|
||||
where: e.id == ^event_id
|
||||
)
|
||||
)
|
||||
end
|
||||
|
||||
@doc """
|
||||
Returns the list of sessions for a track
|
||||
"""
|
||||
def list_sessions_for_track(track_id) do
|
||||
Repo.all(from(s in Session, where: s.track_id == ^track_id))
|
||||
end
|
||||
|
||||
@doc """
|
||||
Gets a single session.
|
||||
|
||||
|
@ -745,6 +768,14 @@ defmodule Mobilizon.Events do
|
|||
Repo.all(Track)
|
||||
end
|
||||
|
||||
@doc """
|
||||
Returns the list of sessions for a track
|
||||
"""
|
||||
@spec list_sessions_for_track(Track.t()) :: list(Session.t())
|
||||
def list_sessions_for_track(%Track{id: track_id}) do
|
||||
Repo.all(from(s in Session, where: s.track_id == ^track_id))
|
||||
end
|
||||
|
||||
@doc """
|
||||
Gets a single track.
|
||||
|
||||
|
@ -880,9 +911,29 @@ defmodule Mobilizon.Events do
|
|||
"""
|
||||
def get_comment!(id), do: Repo.get!(Comment, id)
|
||||
|
||||
def get_comment_from_uuid(uuid), do: Repo.get_by(Comment, uuid: uuid)
|
||||
# @doc """
|
||||
# Gets a single comment from it's UUID
|
||||
|
||||
def get_comment_from_uuid!(uuid), do: Repo.get_by!(Comment, uuid: uuid)
|
||||
# """
|
||||
# @spec get_comment_from_uuid(String.t) :: {:ok, Comment.t} | {:error, nil}
|
||||
# def get_comment_from_uuid(uuid), do: Repo.get_by(Comment, uuid: uuid)
|
||||
|
||||
# @doc """
|
||||
# Gets a single comment by it's UUID.
|
||||
|
||||
# Raises `Ecto.NoResultsError` if the Comment does not exist.
|
||||
|
||||
# ## Examples
|
||||
|
||||
# iex> get_comment_from_uuid!("123AFV13")
|
||||
# %Comment{}
|
||||
|
||||
# iex> get_comment_from_uuid!("20R9HKDJHF")
|
||||
# ** (Ecto.NoResultsError)
|
||||
|
||||
# """
|
||||
# @spec get_comment_from_uuid(String.t) :: Comment.t
|
||||
# def get_comment_from_uuid!(uuid), do: Repo.get_by!(Comment, uuid: uuid)
|
||||
|
||||
def get_comment_full_from_uuid(uuid) do
|
||||
with %Comment{} = comment <- Repo.get_by!(Comment, uuid: uuid) do
|
||||
|
@ -894,9 +945,18 @@ defmodule Mobilizon.Events do
|
|||
|
||||
def get_comment_from_url!(url), do: Repo.get_by!(Comment, url: url)
|
||||
|
||||
def get_comment_full_from_url(url) do
|
||||
case Repo.one(
|
||||
from(c in Comment, where: c.url == ^url, preload: [:actor, :in_reply_to_comment])
|
||||
) do
|
||||
nil -> {:error, :comment_not_found}
|
||||
comment -> {:ok, comment}
|
||||
end
|
||||
end
|
||||
|
||||
def get_comment_full_from_url!(url) do
|
||||
with %Comment{} = comment <- Repo.get_by!(Comment, url: url) do
|
||||
Repo.preload(comment, :actor)
|
||||
Repo.preload(comment, [:actor, :in_reply_to_comment])
|
||||
end
|
||||
end
|
||||
|
||||
|
|
58
lib/mobilizon_web/api/comments.ex
Normal file
58
lib/mobilizon_web/api/comments.ex
Normal file
|
@ -0,0 +1,58 @@
|
|||
defmodule MobilizonWeb.API.Comments do
|
||||
@moduledoc """
|
||||
API for Comments
|
||||
"""
|
||||
|
||||
alias Mobilizon.Actors
|
||||
alias Mobilizon.Actors.Actor
|
||||
alias Mobilizon.Events.Comment
|
||||
alias Mobilizon.Service.Formatter
|
||||
alias Mobilizon.Service.ActivityPub
|
||||
alias Mobilizon.Service.ActivityPub.Utils, as: ActivityPubUtils
|
||||
import MobilizonWeb.API.Utils
|
||||
|
||||
@doc """
|
||||
Create a comment
|
||||
|
||||
Creates a comment from an actor and a status
|
||||
"""
|
||||
@spec create_comment(String.t(), String.t(), String.t()) :: {:ok, Activity.t()} | any()
|
||||
def create_comment(from_username, status, visibility \\ "public", inReplyToCommentURL \\ nil) do
|
||||
with %Actor{url: url} = actor <- Actors.get_local_actor_by_name(from_username),
|
||||
status <- String.trim(status),
|
||||
mentions <- Formatter.parse_mentions(status),
|
||||
inReplyToComment <- get_in_reply_to_comment(inReplyToCommentURL),
|
||||
{to, cc} <- to_for_actor_and_mentions(actor, mentions, inReplyToComment, visibility),
|
||||
tags <- Formatter.parse_tags(status),
|
||||
content_html <-
|
||||
make_content_html(
|
||||
status,
|
||||
mentions,
|
||||
tags,
|
||||
"text/plain"
|
||||
),
|
||||
comment <-
|
||||
ActivityPubUtils.make_comment_data(
|
||||
url,
|
||||
to,
|
||||
content_html,
|
||||
inReplyToComment,
|
||||
tags,
|
||||
cc
|
||||
) do
|
||||
ActivityPub.create(%{
|
||||
to: ["https://www.w3.org/ns/activitystreams#Public"],
|
||||
actor: actor,
|
||||
object: comment,
|
||||
local: true
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
@spec get_in_reply_to_comment(nil) :: nil
|
||||
defp get_in_reply_to_comment(nil), do: nil
|
||||
@spec get_in_reply_to_comment(String.t()) :: Comment.t()
|
||||
defp get_in_reply_to_comment(inReplyToCommentURL) do
|
||||
ActivityPub.fetch_object_from_url(inReplyToCommentURL)
|
||||
end
|
||||
end
|
54
lib/mobilizon_web/api/events.ex
Normal file
54
lib/mobilizon_web/api/events.ex
Normal file
|
@ -0,0 +1,54 @@
|
|||
defmodule MobilizonWeb.API.Events do
|
||||
@moduledoc """
|
||||
API for Events
|
||||
"""
|
||||
alias Mobilizon.Actors
|
||||
alias Mobilizon.Actors.Actor
|
||||
alias Mobilizon.Service.Formatter
|
||||
alias Mobilizon.Service.ActivityPub
|
||||
alias Mobilizon.Service.ActivityPub.Utils, as: ActivityPubUtils
|
||||
import MobilizonWeb.API.Utils
|
||||
|
||||
@spec create_event(map()) :: {:ok, Activity.t()} | any()
|
||||
def create_event(
|
||||
%{
|
||||
title: title,
|
||||
description: description,
|
||||
organizer_actor_username: organizer_actor_username,
|
||||
begins_on: begins_on,
|
||||
category: category
|
||||
} = args
|
||||
) do
|
||||
with %Actor{url: url} = actor <- Actors.get_local_actor_by_name(organizer_actor_username),
|
||||
title <- String.trim(title),
|
||||
mentions <- Formatter.parse_mentions(description),
|
||||
visibility <- Map.get(args, :visibility, "public"),
|
||||
{to, cc} <- to_for_actor_and_mentions(actor, mentions, nil, visibility),
|
||||
tags <- Formatter.parse_tags(description),
|
||||
content_html <-
|
||||
make_content_html(
|
||||
description,
|
||||
mentions,
|
||||
tags,
|
||||
"text/plain"
|
||||
),
|
||||
event <-
|
||||
ActivityPubUtils.make_event_data(
|
||||
url,
|
||||
to,
|
||||
title,
|
||||
content_html,
|
||||
tags,
|
||||
cc,
|
||||
%{begins_on: begins_on},
|
||||
category
|
||||
) do
|
||||
ActivityPub.create(%{
|
||||
to: ["https://www.w3.org/ns/activitystreams#Public"],
|
||||
actor: actor,
|
||||
object: event,
|
||||
local: true
|
||||
})
|
||||
end
|
||||
end
|
||||
end
|
58
lib/mobilizon_web/api/groups.ex
Normal file
58
lib/mobilizon_web/api/groups.ex
Normal file
|
@ -0,0 +1,58 @@
|
|||
defmodule MobilizonWeb.API.Groups do
|
||||
@moduledoc """
|
||||
API for Events
|
||||
"""
|
||||
alias Mobilizon.Actors
|
||||
alias Mobilizon.Actors.Actor
|
||||
alias Mobilizon.Service.Formatter
|
||||
alias Mobilizon.Service.ActivityPub
|
||||
alias Mobilizon.Service.ActivityPub.Utils, as: ActivityPubUtils
|
||||
import MobilizonWeb.API.Utils
|
||||
|
||||
@spec create_group(map()) :: {:ok, Activity.t()} | any()
|
||||
def create_group(
|
||||
%{
|
||||
preferred_username: title,
|
||||
description: description,
|
||||
admin_actor_username: admin_actor_username
|
||||
} = args
|
||||
) do
|
||||
with {:bad_actor, %Actor{url: url} = actor} <-
|
||||
{:bad_actor, Actors.get_local_actor_by_name(admin_actor_username)},
|
||||
{:existing_group, nil} <- {:existing_group, Actors.get_group_by_title(title)},
|
||||
title <- String.trim(title),
|
||||
mentions <- Formatter.parse_mentions(description),
|
||||
visibility <- Map.get(args, :visibility, "public"),
|
||||
{to, cc} <- to_for_actor_and_mentions(actor, mentions, nil, visibility),
|
||||
tags <- Formatter.parse_tags(description),
|
||||
content_html <-
|
||||
make_content_html(
|
||||
description,
|
||||
mentions,
|
||||
tags,
|
||||
"text/plain"
|
||||
),
|
||||
group <-
|
||||
ActivityPubUtils.make_group_data(
|
||||
url,
|
||||
to,
|
||||
title,
|
||||
content_html,
|
||||
tags,
|
||||
cc
|
||||
) do
|
||||
ActivityPub.create(%{
|
||||
to: ["https://www.w3.org/ns/activitystreams#Public"],
|
||||
actor: actor,
|
||||
object: group,
|
||||
local: true
|
||||
})
|
||||
else
|
||||
{:existing_group, _} ->
|
||||
{:error, :existing_group_name}
|
||||
|
||||
{:bad_actor} ->
|
||||
{:error, :bad_admin_actor}
|
||||
end
|
||||
end
|
||||
end
|
123
lib/mobilizon_web/api/utils.ex
Normal file
123
lib/mobilizon_web/api/utils.ex
Normal file
|
@ -0,0 +1,123 @@
|
|||
defmodule MobilizonWeb.API.Utils do
|
||||
@moduledoc """
|
||||
Utils for API
|
||||
"""
|
||||
alias Mobilizon.Actors.Actor
|
||||
alias Mobilizon.Service.Formatter
|
||||
|
||||
@doc """
|
||||
Determines the full audience based on mentions for a public audience
|
||||
|
||||
Audience is:
|
||||
* `to` : the mentionned actors, the eventual actor we're replying to and the public
|
||||
* `cc` : the actor's followers
|
||||
"""
|
||||
@spec to_for_actor_and_mentions(Actor.t(), list(), map(), String.t()) :: {list(), list()}
|
||||
def to_for_actor_and_mentions(%Actor{} = actor, mentions, inReplyTo, "public") do
|
||||
mentioned_actors = Enum.map(mentions, fn {_, %{url: url}} -> url end)
|
||||
|
||||
to = ["https://www.w3.org/ns/activitystreams#Public" | mentioned_actors]
|
||||
cc = [actor.followers_url]
|
||||
|
||||
if inReplyTo do
|
||||
{Enum.uniq([inReplyTo.actor | to]), cc}
|
||||
else
|
||||
{to, cc}
|
||||
end
|
||||
end
|
||||
|
||||
@doc """
|
||||
Determines the full audience based on mentions based on a unlisted audience
|
||||
|
||||
Audience is:
|
||||
* `to` : the mentionned actors, actor's followers and the eventual actor we're replying to
|
||||
* `cc` : public
|
||||
"""
|
||||
@spec to_for_actor_and_mentions(Actor.t(), list(), map(), String.t()) :: {list(), list()}
|
||||
def to_for_actor_and_mentions(%Actor{} = actor, mentions, inReplyTo, "unlisted") do
|
||||
mentioned_actors = Enum.map(mentions, fn {_, %{url: url}} -> url end)
|
||||
|
||||
to = [actor.followers_url | mentioned_actors]
|
||||
cc = ["https://www.w3.org/ns/activitystreams#Public"]
|
||||
|
||||
if inReplyTo do
|
||||
{Enum.uniq([inReplyTo.actor | to]), cc}
|
||||
else
|
||||
{to, cc}
|
||||
end
|
||||
end
|
||||
|
||||
@doc """
|
||||
Determines the full audience based on mentions based on a private audience
|
||||
|
||||
Audience is:
|
||||
* `to` : the mentionned actors, actor's followers and the eventual actor we're replying to
|
||||
* `cc` : none
|
||||
"""
|
||||
@spec to_for_actor_and_mentions(Actor.t(), list(), map(), String.t()) :: {list(), list()}
|
||||
def to_for_actor_and_mentions(%Actor{} = actor, mentions, inReplyTo, "private") do
|
||||
{to, cc} = to_for_actor_and_mentions(actor, mentions, inReplyTo, "direct")
|
||||
{[actor.followers_url | to], cc}
|
||||
end
|
||||
|
||||
@doc """
|
||||
Determines the full audience based on mentions based on a direct audience
|
||||
|
||||
Audience is:
|
||||
* `to` : the mentionned actors and the eventual actor we're replying to
|
||||
* `cc` : none
|
||||
"""
|
||||
@spec to_for_actor_and_mentions(Actor.t(), list(), map(), String.t()) :: {list(), list()}
|
||||
def to_for_actor_and_mentions(_actor, mentions, inReplyTo, "direct") do
|
||||
mentioned_actors = Enum.map(mentions, fn {_, %{url: url}} -> url end)
|
||||
|
||||
if inReplyTo do
|
||||
{Enum.uniq([inReplyTo.actor | mentioned_actors]), []}
|
||||
else
|
||||
{mentioned_actors, []}
|
||||
end
|
||||
end
|
||||
|
||||
@doc """
|
||||
Creates HTML content from text and mentions
|
||||
"""
|
||||
@spec make_content_html(String.t(), list(), list(), String.t()) :: String.t()
|
||||
def make_content_html(
|
||||
status,
|
||||
mentions,
|
||||
tags,
|
||||
content_type
|
||||
),
|
||||
do: format_input(status, mentions, tags, content_type)
|
||||
|
||||
def format_input(text, mentions, tags, "text/plain") do
|
||||
text
|
||||
|> Formatter.html_escape("text/plain")
|
||||
|> String.replace(~r/\r?\n/, "<br>")
|
||||
|> (&{[], &1}).()
|
||||
|> Formatter.add_links()
|
||||
|> Formatter.add_actor_links(mentions)
|
||||
|> Formatter.add_hashtag_links(tags)
|
||||
|> Formatter.finalize()
|
||||
end
|
||||
|
||||
def format_input(text, mentions, _tags, "text/html") do
|
||||
text
|
||||
|> Formatter.html_escape("text/html")
|
||||
|> String.replace(~r/\r?\n/, "<br>")
|
||||
|> (&{[], &1}).()
|
||||
|> Formatter.add_actor_links(mentions)
|
||||
|> Formatter.finalize()
|
||||
end
|
||||
|
||||
def format_input(text, mentions, tags, "text/markdown") do
|
||||
text
|
||||
|> Earmark.as_html!()
|
||||
|> Formatter.html_escape("text/html")
|
||||
|> String.replace(~r/\r?\n/, "")
|
||||
|> (&{[], &1}).()
|
||||
|> Formatter.add_actor_links(mentions)
|
||||
|> Formatter.add_hashtag_links(tags)
|
||||
|> Formatter.finalize()
|
||||
end
|
||||
end
|
|
@ -2,6 +2,9 @@ defmodule MobilizonWeb.Resolvers.Category do
|
|||
require Logger
|
||||
alias Mobilizon.Actors.User
|
||||
|
||||
###
|
||||
# TODO : Refactor this into MobilizonWeb.API.Categories when a standard AS category is defined
|
||||
###
|
||||
def list_categories(_parent, %{page: page, limit: limit}, _resolution) do
|
||||
categories =
|
||||
Mobilizon.Events.list_categories(page, limit)
|
||||
|
|
25
lib/mobilizon_web/resolvers/comment.ex
Normal file
25
lib/mobilizon_web/resolvers/comment.ex
Normal file
|
@ -0,0 +1,25 @@
|
|||
defmodule MobilizonWeb.Resolvers.Comment do
|
||||
require Logger
|
||||
alias Mobilizon.Events.Comment
|
||||
alias Mobilizon.Activity
|
||||
alias Mobilizon.Actors.User
|
||||
alias MobilizonWeb.API.Comments
|
||||
|
||||
def create_comment(_parent, %{text: comment, actor_username: username}, %{
|
||||
context: %{current_user: %User{} = _user}
|
||||
}) do
|
||||
with {:ok, %Activity{data: %{"object" => %{"type" => "Note"} = object}}} <-
|
||||
Comments.create_comment(username, comment) do
|
||||
{:ok,
|
||||
%Comment{
|
||||
text: object["content"],
|
||||
url: object["id"],
|
||||
uuid: object["uuid"]
|
||||
}}
|
||||
end
|
||||
end
|
||||
|
||||
def create_comment(_parent, _args, %{}) do
|
||||
{:error, "You are not allowed to create a comment if not connected"}
|
||||
end
|
||||
end
|
|
@ -1,6 +1,8 @@
|
|||
defmodule MobilizonWeb.Resolvers.Event do
|
||||
alias Mobilizon.Service.ActivityPub
|
||||
alias Mobilizon.Activity
|
||||
alias Mobilizon.Actors
|
||||
alias Mobilizon.Events.Event
|
||||
|
||||
def list_events(_parent, %{page: page, limit: limit}, _resolution) do
|
||||
{:ok, Mobilizon.Events.list_events(page, limit)}
|
||||
|
@ -63,10 +65,27 @@ defmodule MobilizonWeb.Resolvers.Event do
|
|||
{:ok, found}
|
||||
end
|
||||
|
||||
@doc """
|
||||
Create an event
|
||||
"""
|
||||
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)
|
||||
with {:ok, %Activity{data: %{"object" => %{"type" => "Event"} = object}}} <-
|
||||
args
|
||||
# Set default organizer_actor_id if none set
|
||||
|> Map.update(
|
||||
:organizer_actor_username,
|
||||
Actors.get_actor_for_user(user).preferred_username,
|
||||
& &1
|
||||
)
|
||||
|> MobilizonWeb.API.Events.create_event() do
|
||||
{:ok,
|
||||
%Event{
|
||||
title: object["name"],
|
||||
description: object["content"],
|
||||
uuid: object["uuid"],
|
||||
url: object["id"]
|
||||
}}
|
||||
end
|
||||
end
|
||||
|
||||
def create_event(_parent, _args, _resolution) do
|
||||
|
|
|
@ -2,6 +2,7 @@ defmodule MobilizonWeb.Resolvers.Group do
|
|||
alias Mobilizon.Actors
|
||||
alias Mobilizon.Actors.{Actor}
|
||||
alias Mobilizon.Service.ActivityPub
|
||||
alias Mobilizon.Activity
|
||||
require Logger
|
||||
|
||||
@doc """
|
||||
|
@ -29,24 +30,36 @@ defmodule MobilizonWeb.Resolvers.Group do
|
|||
"""
|
||||
def create_group(
|
||||
_parent,
|
||||
%{preferred_username: preferred_username, creator_username: actor_username},
|
||||
args,
|
||||
%{
|
||||
context: %{current_user: user}
|
||||
context: %{current_user: _user}
|
||||
}
|
||||
) do
|
||||
with %Actor{id: actor_id} <- Actors.get_local_actor_by_name(actor_username),
|
||||
{:user_actor, true} <-
|
||||
{:user_actor, actor_id in Enum.map(Actors.get_actors_for_user(user), & &1.id)},
|
||||
{:ok, %Actor{} = group} <- Actors.create_group(%{preferred_username: preferred_username}) do
|
||||
{:ok, group}
|
||||
else
|
||||
{:error, %Ecto.Changeset{errors: [url: {"has already been taken", []}]}} ->
|
||||
{:error, :group_name_not_available}
|
||||
|
||||
err ->
|
||||
Logger.error(inspect(err))
|
||||
err
|
||||
with {:ok, %Activity{data: %{"object" => %{"type" => "Group"} = object}}} <-
|
||||
MobilizonWeb.API.Groups.create_group(args) do
|
||||
{:ok,
|
||||
%Actor{
|
||||
preferred_username: object["preferredUsername"],
|
||||
summary: object["summary"],
|
||||
type: :Group,
|
||||
# uuid: object["uuid"],
|
||||
url: object["id"]
|
||||
}}
|
||||
end
|
||||
|
||||
# with %Actor{id: actor_id} <- Actors.get_local_actor_by_name(actor_username),
|
||||
# {:user_actor, true} <-
|
||||
# {:user_actor, actor_id in Enum.map(Actors.get_actors_for_user(user), & &1.id)},
|
||||
# {:ok, %Actor{} = group} <- Actors.create_group(%{preferred_username: preferred_username}) do
|
||||
# {:ok, group}
|
||||
# else
|
||||
# {:error, %Ecto.Changeset{errors: [url: {"has already been taken", []}]}} ->
|
||||
# {:error, :group_name_not_available}
|
||||
|
||||
# err ->
|
||||
# Logger.error(inspect(err))
|
||||
# err
|
||||
# end
|
||||
end
|
||||
|
||||
def create_group(_parent, _args, _resolution) do
|
||||
|
|
|
@ -253,7 +253,7 @@ defmodule MobilizonWeb.Schema do
|
|||
field(:uuid, :uuid)
|
||||
field(:url, :string)
|
||||
field(:local, :boolean)
|
||||
field(:content, :string)
|
||||
field(:text, :string)
|
||||
field(:primaryLanguage, :string)
|
||||
field(:replies, list_of(:comment))
|
||||
field(:threadLanguages, non_null(list_of(:string)))
|
||||
|
@ -484,12 +484,20 @@ defmodule MobilizonWeb.Schema do
|
|||
arg(:address_type, non_null(:address_type))
|
||||
arg(:online_address, :string)
|
||||
arg(:phone, :string)
|
||||
arg(:organizer_actor_id, non_null(:integer))
|
||||
arg(:category_id, non_null(:integer))
|
||||
arg(:organizer_actor_username, non_null(:string))
|
||||
arg(:category, non_null(:string))
|
||||
|
||||
resolve(&Resolvers.Event.create_event/3)
|
||||
end
|
||||
|
||||
@desc "Create a comment"
|
||||
field :create_comment, type: :comment do
|
||||
arg(:text, non_null(:string))
|
||||
arg(:actor_username, non_null(:string))
|
||||
|
||||
resolve(&Resolvers.Comment.create_comment/3)
|
||||
end
|
||||
|
||||
@desc "Create a category with a title, description and picture"
|
||||
field :create_category, type: :category do
|
||||
arg(:title, non_null(:string))
|
||||
|
@ -552,8 +560,9 @@ defmodule MobilizonWeb.Schema do
|
|||
field :create_group, :group do
|
||||
arg(:preferred_username, non_null(:string), description: "The name for the group")
|
||||
arg(:name, :string, description: "The displayed name for the group")
|
||||
arg(:description, :string, description: "The summary for the group", default_value: "")
|
||||
|
||||
arg(:creator_username, :string,
|
||||
arg(:admin_actor_username, :string,
|
||||
description: "The actor's username which will be the admin (otherwise user's default one)"
|
||||
)
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@ defmodule Mobilizon.Service.ActivityPub do
|
|||
|
||||
alias Mobilizon.Actors
|
||||
alias Mobilizon.Actors.Actor
|
||||
alias Mobilizon.Actors.Follower
|
||||
|
||||
alias Mobilizon.Service.Federator
|
||||
alias Mobilizon.Service.HTTPSignatures
|
||||
|
@ -36,7 +37,7 @@ defmodule Mobilizon.Service.ActivityPub do
|
|||
@spec insert(map(), boolean()) :: {:ok, %Activity{}} | {:error, any()}
|
||||
def insert(map, local \\ true) when is_map(map) do
|
||||
with map <- lazy_put_activity_defaults(map),
|
||||
:ok <- insert_full_object(map, local) do
|
||||
:ok <- insert_full_object(map) do
|
||||
object_id =
|
||||
cond do
|
||||
is_map(map["object"]) ->
|
||||
|
@ -46,7 +47,7 @@ defmodule Mobilizon.Service.ActivityPub do
|
|||
map["id"]
|
||||
end
|
||||
|
||||
map = Map.put(map, "id", "#{object_id}/activity")
|
||||
map = if local, do: Map.put(map, "id", "#{object_id}/activity"), else: map
|
||||
|
||||
activity = %Activity{
|
||||
data: map,
|
||||
|
@ -69,6 +70,8 @@ defmodule Mobilizon.Service.ActivityPub do
|
|||
"""
|
||||
@spec fetch_object_from_url(String.t()) :: {:ok, %Event{}} | {:ok, %Comment{}} | {:error, any()}
|
||||
def fetch_object_from_url(url) do
|
||||
Logger.info("Fetching object from url #{url}")
|
||||
|
||||
with true <- String.starts_with?(url, "http"),
|
||||
nil <- Events.get_event_by_url(url),
|
||||
nil <- Events.get_comment_from_url(url),
|
||||
|
@ -94,17 +97,22 @@ defmodule Mobilizon.Service.ActivityPub do
|
|||
{:ok, Events.get_event_by_url!(activity.data["object"]["id"])}
|
||||
|
||||
"Note" ->
|
||||
{:ok, Events.get_comment_from_url!(activity.data["object"]["id"])}
|
||||
{:ok, Events.get_comment_full_from_url!(activity.data["object"]["id"])}
|
||||
|
||||
other ->
|
||||
{:error, other}
|
||||
end
|
||||
else
|
||||
object = %Event{} -> {:ok, object}
|
||||
object = %Comment{} -> {:ok, object}
|
||||
%Event{url: event_url} -> {:ok, Events.get_event_by_url!(event_url)}
|
||||
%Comment{url: comment_url} -> {:ok, Events.get_comment_full_from_url!(comment_url)}
|
||||
e -> {:error, e}
|
||||
end
|
||||
end
|
||||
|
||||
def create(%{to: to, actor: actor, object: object} = params) do
|
||||
Logger.debug("creating an activity")
|
||||
Logger.debug(inspect(params))
|
||||
Logger.debug(inspect(object))
|
||||
additional = params[:additional] || %{}
|
||||
# only accept false as false value
|
||||
local = !(params[:local] == false)
|
||||
|
@ -115,6 +123,7 @@ defmodule Mobilizon.Service.ActivityPub do
|
|||
%{to: to, actor: actor, published: published, object: object},
|
||||
additional
|
||||
),
|
||||
:ok <- Logger.debug(inspect(create_data)),
|
||||
{:ok, activity} <- insert(create_data, local),
|
||||
:ok <- maybe_federate(activity) do
|
||||
# {:ok, actor} <- Actors.increase_event_count(actor) do
|
||||
|
@ -123,6 +132,7 @@ defmodule Mobilizon.Service.ActivityPub do
|
|||
err ->
|
||||
Logger.error("Something went wrong")
|
||||
Logger.error(inspect(err))
|
||||
err
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -154,9 +164,82 @@ defmodule Mobilizon.Service.ActivityPub do
|
|||
end
|
||||
end
|
||||
|
||||
def follow(%Actor{} = follower, %Actor{} = followed, _activity_id \\ nil, local \\ true) do
|
||||
with {:ok, follow} <- Actor.follow(followed, follower, true),
|
||||
data <- make_follow_data(follower, followed, follow.id),
|
||||
# TODO: This is weird, maybe we shouldn't check here if we can make the activity.
|
||||
# def like(
|
||||
# %Actor{url: url} = actor,
|
||||
# object,
|
||||
# activity_id \\ nil,
|
||||
# local \\ true
|
||||
# ) do
|
||||
# with nil <- get_existing_like(url, object),
|
||||
# like_data <- make_like_data(user, object, activity_id),
|
||||
# {:ok, activity} <- insert(like_data, local),
|
||||
# {:ok, object} <- add_like_to_object(activity, object),
|
||||
# :ok <- maybe_federate(activity) do
|
||||
# {:ok, activity, object}
|
||||
# else
|
||||
# %Activity{} = activity -> {:ok, activity, object}
|
||||
# error -> {:error, error}
|
||||
# end
|
||||
# end
|
||||
|
||||
# def unlike(
|
||||
# %User{} = actor,
|
||||
# %Object{} = object,
|
||||
# activity_id \\ nil,
|
||||
# local \\ true
|
||||
# ) do
|
||||
# with %Activity{} = like_activity <- get_existing_like(actor.ap_id, object),
|
||||
# unlike_data <- make_unlike_data(actor, like_activity, activity_id),
|
||||
# {:ok, unlike_activity} <- insert(unlike_data, local),
|
||||
# {:ok, _activity} <- Repo.delete(like_activity),
|
||||
# {:ok, object} <- remove_like_from_object(like_activity, object),
|
||||
# :ok <- maybe_federate(unlike_activity) do
|
||||
# {:ok, unlike_activity, like_activity, object}
|
||||
# else
|
||||
# _e -> {:ok, object}
|
||||
# end
|
||||
# end
|
||||
|
||||
# def announce(
|
||||
# %Actor{} = actor,
|
||||
# object,
|
||||
# activity_id \\ nil,
|
||||
# local \\ true
|
||||
# ) do
|
||||
# #with true <- is_public?(object),
|
||||
# with announce_data <- make_announce_data(actor, object, activity_id),
|
||||
# {:ok, activity} <- insert(announce_data, local),
|
||||
# # {:ok, object} <- add_announce_to_object(activity, object),
|
||||
# :ok <- maybe_federate(activity) do
|
||||
# {:ok, activity, object}
|
||||
# else
|
||||
# error -> {:error, error}
|
||||
# end
|
||||
# end
|
||||
|
||||
# def unannounce(
|
||||
# %Actor{} = actor,
|
||||
# object,
|
||||
# activity_id \\ nil,
|
||||
# local \\ true
|
||||
# ) do
|
||||
# with %Activity{} = announce_activity <- get_existing_announce(actor.ap_id, object),
|
||||
# unannounce_data <- make_unannounce_data(actor, announce_activity, activity_id),
|
||||
# {:ok, unannounce_activity} <- insert(unannounce_data, local),
|
||||
# :ok <- maybe_federate(unannounce_activity),
|
||||
# {:ok, _activity} <- Repo.delete(announce_activity),
|
||||
# {:ok, object} <- remove_announce_from_object(announce_activity, object) do
|
||||
# {:ok, unannounce_activity, object}
|
||||
# else
|
||||
# _e -> {:ok, object}
|
||||
# end
|
||||
# end
|
||||
|
||||
def follow(%Actor{} = follower, %Actor{} = followed, activity_id \\ nil, local \\ true) do
|
||||
with {:ok, %Follower{} = follow} <- Actor.follow(followed, follower, true),
|
||||
activity_follow_id <- activity_id || Follower.url(follow),
|
||||
data <- make_follow_data(followed, follower, activity_follow_id),
|
||||
{:ok, activity} <- insert(data, local),
|
||||
:ok <- maybe_federate(activity) do
|
||||
{:ok, activity}
|
||||
|
@ -166,6 +249,23 @@ defmodule Mobilizon.Service.ActivityPub do
|
|||
end
|
||||
end
|
||||
|
||||
@spec unfollow(Actor.t(), Actor.t(), String.t(), boolean()) :: {:ok, map()} | any()
|
||||
def unfollow(%Actor{} = followed, %Actor{} = follower, activity_id \\ nil, local \\ true) do
|
||||
with {:ok, %Follower{id: follow_id}} <- Actor.unfollow(followed, follower),
|
||||
# We recreate the follow activity
|
||||
data <- make_follow_data(followed, follower, follow_id),
|
||||
{:ok, follow_activity} <- insert(data, local),
|
||||
unfollow_data <- make_unfollow_data(follower, followed, follow_activity, activity_id),
|
||||
{:ok, activity} <- insert(unfollow_data, local),
|
||||
:ok <- maybe_federate(activity) do
|
||||
{:ok, activity}
|
||||
else
|
||||
err ->
|
||||
Logger.error(inspect(err))
|
||||
err
|
||||
end
|
||||
end
|
||||
|
||||
def delete(object, local \\ true)
|
||||
|
||||
def delete(%Event{url: url, organizer_actor: actor} = event, local) do
|
||||
|
@ -198,6 +298,21 @@ defmodule Mobilizon.Service.ActivityPub do
|
|||
end
|
||||
end
|
||||
|
||||
def delete(%Actor{url: url} = actor, local) do
|
||||
data = %{
|
||||
"type" => "Delete",
|
||||
"actor" => url,
|
||||
"object" => url,
|
||||
"to" => [url <> "/followers", "https://www.w3.org/ns/activitystreams#Public"]
|
||||
}
|
||||
|
||||
with Actors.delete_actor(actor),
|
||||
{:ok, activity} <- insert(data, local),
|
||||
:ok <- maybe_federate(activity) do
|
||||
{:ok, activity}
|
||||
end
|
||||
end
|
||||
|
||||
@doc """
|
||||
Create an actor locally by it's URL (AP ID)
|
||||
"""
|
||||
|
@ -278,7 +393,7 @@ defmodule Mobilizon.Service.ActivityPub do
|
|||
|
||||
def publish_one(%{inbox: inbox, json: json, actor: actor, id: id}) do
|
||||
Logger.info("Federating #{id} to #{inbox}")
|
||||
{host, path} = URI.parse(inbox)
|
||||
%URI{host: host, path: path} = URI.parse(inbox)
|
||||
|
||||
digest = HTTPSignatures.build_digest(json)
|
||||
date = HTTPSignatures.generate_date_header()
|
||||
|
@ -333,15 +448,10 @@ defmodule Mobilizon.Service.ActivityPub do
|
|||
def actor_data_from_actor_object(data) when is_map(data) do
|
||||
actor_data = %{
|
||||
url: data["id"],
|
||||
info: %{
|
||||
"ap_enabled" => true,
|
||||
"source_data" => data
|
||||
},
|
||||
avatar_url: data["icon"]["url"],
|
||||
banner_url: data["image"]["url"],
|
||||
name: data["name"],
|
||||
preferred_username: data["preferredUsername"],
|
||||
follower_address: data["followers"],
|
||||
summary: data["summary"],
|
||||
keys: data["publicKey"]["publicKeyPem"],
|
||||
inbox_url: data["inbox"],
|
||||
|
@ -416,7 +526,7 @@ defmodule Mobilizon.Service.ActivityPub do
|
|||
|
||||
# Create an activity from a comment
|
||||
@spec comment_to_activity(%Comment{}, boolean()) :: Activity.t()
|
||||
defp comment_to_activity(%Comment{} = comment, local \\ true) do
|
||||
def comment_to_activity(%Comment{} = comment, local \\ true) do
|
||||
%Activity{
|
||||
recipients: ["https://www.w3.org/ns/activitystreams#Public"],
|
||||
actor: comment.actor.url,
|
||||
|
@ -471,4 +581,9 @@ defmodule Mobilizon.Service.ActivityPub do
|
|||
defp sanitize_ical_event_strings(nil) do
|
||||
nil
|
||||
end
|
||||
|
||||
def is_public?(activity) do
|
||||
"https://www.w3.org/ns/activitystreams#Public" in (activity.data["to"] ++
|
||||
(activity.data["cc"] || []))
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,14 +2,36 @@ defmodule Mobilizon.Service.ActivityPub.Transmogrifier do
|
|||
@moduledoc """
|
||||
A module to handle coding from internal to wire ActivityPub and back.
|
||||
"""
|
||||
alias Mobilizon.Actors.Actor
|
||||
alias Mobilizon.Actors
|
||||
alias Mobilizon.Actors.Actor
|
||||
alias Mobilizon.Events
|
||||
alias Mobilizon.Events.{Event, Comment}
|
||||
alias Mobilizon.Service.ActivityPub
|
||||
alias Mobilizon.Service.ActivityPub.Utils
|
||||
|
||||
require Logger
|
||||
|
||||
def get_actor(%{"actor" => actor}) when is_binary(actor) do
|
||||
actor
|
||||
end
|
||||
|
||||
def get_actor(%{"actor" => actor}) when is_list(actor) do
|
||||
if is_binary(Enum.at(actor, 0)) do
|
||||
Enum.at(actor, 0)
|
||||
else
|
||||
Enum.find(actor, fn %{"type" => type} -> type in ["Person", "Service", "Application"] end)
|
||||
|> Map.get("id")
|
||||
end
|
||||
end
|
||||
|
||||
def get_actor(%{"actor" => %{"id" => id}}) when is_bitstring(id) do
|
||||
id
|
||||
end
|
||||
|
||||
def get_actor(%{"actor" => nil, "attributedTo" => actor}) when not is_nil(actor) do
|
||||
get_actor(%{"actor" => actor})
|
||||
end
|
||||
|
||||
@doc """
|
||||
Modifies an incoming AP object (mastodon format) to our internal format.
|
||||
"""
|
||||
|
@ -48,6 +70,10 @@ defmodule Mobilizon.Service.ActivityPub.Transmogrifier do
|
|||
object
|
||||
|> Map.put("inReplyTo", replied_object.url)
|
||||
|
||||
{:error, {:error, :not_supported}} ->
|
||||
Logger.info("Object reply origin has not a supported type")
|
||||
object
|
||||
|
||||
e ->
|
||||
Logger.error("Couldn't fetch #{in_reply_to_id} #{inspect(e)}")
|
||||
object
|
||||
|
@ -88,6 +114,7 @@ defmodule Mobilizon.Service.ActivityPub.Transmogrifier do
|
|||
|
||||
with {:ok, %Actor{} = actor} <- Actors.get_or_fetch_by_url(data["actor"]) do
|
||||
Logger.debug("found actor")
|
||||
Logger.debug(inspect(actor))
|
||||
|
||||
params = %{
|
||||
to: data["to"],
|
||||
|
@ -136,78 +163,134 @@ defmodule Mobilizon.Service.ActivityPub.Transmogrifier do
|
|||
# _e -> :error
|
||||
# end
|
||||
# end
|
||||
#
|
||||
# #
|
||||
# def handle_incoming(
|
||||
# %{"type" => "Announce", "object" => object_id, "actor" => actor, "id" => id} = data
|
||||
# ) do
|
||||
# with {:ok, %Actor{} = actor} <- Actors.get_or_fetch_by_url(actor),
|
||||
# {:ok, object} <-
|
||||
# fetch_obj_helper(object_id) || ActivityPub.fetch_object_from_url(object_id),
|
||||
# {:ok, activity, object} <- ActivityPub.announce(actor, object, id, false) do
|
||||
# with actor <- get_actor(data),
|
||||
# {:ok, %Actor{} = actor} <- Actors.get_or_fetch_by_url(actor),
|
||||
# {:ok, object} <- get_obj_helper(object_id) || fetch_obj_helper(object_id),
|
||||
# {:ok, activity, _object} <- ActivityPub.announce(actor, object, id, false) do
|
||||
# {:ok, activity}
|
||||
# else
|
||||
# e -> Logger.error(inspect e)
|
||||
# :error
|
||||
# end
|
||||
# end
|
||||
|
||||
def handle_incoming(
|
||||
%{"type" => "Update", "object" => %{"type" => object_type} = object, "actor" => _actor_id} =
|
||||
data
|
||||
)
|
||||
when object_type in ["Person", "Application", "Service", "Organization"] do
|
||||
with {:ok, %Actor{url: url}} <- Actors.get_actor_by_url(object["id"]) do
|
||||
{:ok, new_actor_data} = ActivityPub.actor_data_from_actor_object(object)
|
||||
|
||||
Actors.insert_or_update_actor(new_actor_data)
|
||||
|
||||
ActivityPub.update(%{
|
||||
local: false,
|
||||
to: data["to"] || [],
|
||||
cc: data["cc"] || [],
|
||||
object: object,
|
||||
actor: url
|
||||
})
|
||||
else
|
||||
e ->
|
||||
Logger.error(inspect(e))
|
||||
:error
|
||||
end
|
||||
end
|
||||
|
||||
# def handle_incoming(
|
||||
# %{
|
||||
# "type" => "Undo",
|
||||
# "object" => %{"type" => "Announce", "object" => object_id},
|
||||
# "actor" => actor,
|
||||
# "id" => id
|
||||
# } = data
|
||||
# ) do
|
||||
# with actor <- get_actor(data),
|
||||
# {:ok, %Actor{} = actor} <- Actors.get_or_fetch_by_url(actor),
|
||||
# {:ok, object} <- get_obj_helper(object_id) || fetch_obj_helper(object_id),
|
||||
# {:ok, activity, _} <- ActivityPub.unannounce(actor, object, id, false) do
|
||||
# {:ok, activity}
|
||||
# else
|
||||
# _e -> :error
|
||||
# end
|
||||
# end
|
||||
|
||||
#
|
||||
# def handle_incoming(
|
||||
# %{"type" => "Update", "object" => %{"type" => "Person"} = object, "actor" => actor_id} =
|
||||
# data
|
||||
# ) do
|
||||
# with %User{ap_id: ^actor_id} = actor <- User.get_by_ap_id(object["id"]) do
|
||||
# {:ok, new_user_data} = ActivityPub.actor_data_from_actor_object(object)
|
||||
#
|
||||
# banner = new_user_data[:info]["banner"]
|
||||
#
|
||||
# update_data =
|
||||
# new_user_data
|
||||
# |> Map.take([:name, :bio, :avatar])
|
||||
# |> Map.put(:info, Map.merge(actor.info, %{"banner" => banner}))
|
||||
#
|
||||
# actor
|
||||
# |> User.upgrade_changeset(update_data)
|
||||
# |> User.update_and_set_cache()
|
||||
#
|
||||
# ActivityPub.update(%{
|
||||
# local: false,
|
||||
# to: data["to"] || [],
|
||||
# cc: data["cc"] || [],
|
||||
# object: object,
|
||||
# actor: actor_id
|
||||
# })
|
||||
# else
|
||||
# e ->
|
||||
# Logger.error(e)
|
||||
# :error
|
||||
# end
|
||||
# end
|
||||
#
|
||||
# # TODO: Make secure.
|
||||
# def handle_incoming(
|
||||
# %{"type" => "Delete", "object" => object_id, "actor" => actor, "id" => id} = data
|
||||
# ) do
|
||||
# object_id =
|
||||
# case object_id do
|
||||
# %{"id" => id} -> id
|
||||
# id -> id
|
||||
# end
|
||||
#
|
||||
# with %User{} = actor <- User.get_or_fetch_by_ap_id(actor),
|
||||
# {:ok, object} <-
|
||||
# fetch_obj_helper(object_id) || ActivityPub.fetch_object_from_id(object_id),
|
||||
# {:ok, activity} <- ActivityPub.delete(object, false) do
|
||||
# {:ok, activity}
|
||||
# else
|
||||
# e -> :error
|
||||
# end
|
||||
# end
|
||||
def handle_incoming(
|
||||
%{
|
||||
"type" => "Undo",
|
||||
"object" => %{"type" => "Follow", "object" => followed},
|
||||
"actor" => follower,
|
||||
"id" => id
|
||||
} = _data
|
||||
) do
|
||||
with {:ok, %Actor{domain: nil} = followed} <- Actors.get_actor_by_url(followed),
|
||||
{:ok, %Actor{} = follower} <- Actors.get_actor_by_url(follower),
|
||||
{:ok, activity} <- ActivityPub.unfollow(followed, follower, id, false) do
|
||||
Actor.unfollow(follower, followed)
|
||||
{:ok, activity}
|
||||
else
|
||||
e ->
|
||||
Logger.error(inspect(e))
|
||||
:error
|
||||
end
|
||||
end
|
||||
|
||||
# TODO: We presently assume that any actor on the same origin domain as the object being
|
||||
# deleted has the rights to delete that object. A better way to validate whether or not
|
||||
# the object should be deleted is to refetch the object URI, which should return either
|
||||
# an error or a tombstone. This would allow us to verify that a deletion actually took
|
||||
# place.
|
||||
def handle_incoming(
|
||||
%{"type" => "Delete", "object" => object, "actor" => _actor, "id" => _id} = data
|
||||
) do
|
||||
object_id = Utils.get_url(object)
|
||||
|
||||
with actor <- get_actor(data),
|
||||
{:ok, %Actor{url: _actor_url}} <- Actors.get_actor_by_url(actor),
|
||||
{:ok, object} <- get_obj_helper(object_id) || fetch_obj_helper(object_id),
|
||||
# TODO : Validate that DELETE comes indeed form right domain (see above)
|
||||
# :ok <- contain_origin(actor_url, object.data),
|
||||
{:ok, activity} <- ActivityPub.delete(object, false) do
|
||||
{:ok, activity}
|
||||
else
|
||||
e ->
|
||||
Logger.debug(inspect(e))
|
||||
:error
|
||||
end
|
||||
end
|
||||
|
||||
#
|
||||
# # TODO
|
||||
# # Accept
|
||||
# # Undo
|
||||
#
|
||||
def handle_incoming(_), do: :error
|
||||
# def handle_incoming(
|
||||
# %{
|
||||
# "type" => "Undo",
|
||||
# "object" => %{"type" => "Like", "object" => object_id},
|
||||
# "actor" => _actor,
|
||||
# "id" => id
|
||||
# } = data
|
||||
# ) do
|
||||
# with actor <- get_actor(data),
|
||||
# %Actor{} = actor <- Actors.get_or_fetch_by_url(actor),
|
||||
# {:ok, object} <- get_obj_helper(object_id) || fetch_obj_helper(object_id),
|
||||
# {:ok, activity, _, _} <- ActivityPub.unlike(actor, object, id, false) do
|
||||
# {:ok, activity}
|
||||
# else
|
||||
# _e -> :error
|
||||
# end
|
||||
# end
|
||||
|
||||
def handle_incoming(_) do
|
||||
Logger.info("Handing something not supported")
|
||||
{:error, :not_supported}
|
||||
end
|
||||
|
||||
def set_reply_to_uri(%{"inReplyTo" => in_reply_to} = object) do
|
||||
with false <- String.starts_with?(in_reply_to, "http"),
|
||||
|
@ -224,7 +307,7 @@ defmodule Mobilizon.Service.ActivityPub.Transmogrifier do
|
|||
def prepare_object(object) do
|
||||
object
|
||||
# |> set_sensitive
|
||||
# |> add_hashtags
|
||||
|> add_hashtags
|
||||
|> add_mention_tags
|
||||
# |> add_emoji_tags
|
||||
|> add_attributed_to
|
||||
|
@ -326,7 +409,13 @@ defmodule Mobilizon.Service.ActivityPub.Transmogrifier do
|
|||
|
||||
mentions =
|
||||
recipients
|
||||
|> Enum.map(fn url -> Actors.get_actor_by_url!(url) end)
|
||||
|> Enum.filter(& &1)
|
||||
|> Enum.map(fn url ->
|
||||
case Actors.get_actor_by_url(url) do
|
||||
{:ok, actor} -> actor
|
||||
_ -> nil
|
||||
end
|
||||
end)
|
||||
|> Enum.filter(& &1)
|
||||
|> Enum.map(fn actor ->
|
||||
%{"type" => "Mention", "href" => actor.url, "name" => "@#{actor.preferred_username}"}
|
||||
|
@ -391,4 +480,43 @@ defmodule Mobilizon.Service.ActivityPub.Transmogrifier do
|
|||
|
||||
@spec fetch_obj_helper(map()) :: {:ok, %Event{}} | {:ok, %Comment{}} | {:error, any()}
|
||||
def fetch_obj_helper(obj) when is_map(obj), do: ActivityPub.fetch_object_from_url(obj["id"])
|
||||
|
||||
@spec get_obj_helper(String.t()) :: {:ok, struct()} | nil
|
||||
def get_obj_helper(id) do
|
||||
if object = normalize(id), do: {:ok, object}, else: nil
|
||||
end
|
||||
|
||||
@spec normalize(map()) :: struct() | nil
|
||||
def normalize(obj) when is_map(obj), do: get_anything_by_url(obj["id"])
|
||||
@spec normalize(String.t()) :: struct() | nil
|
||||
def normalize(url) when is_binary(url), do: get_anything_by_url(url)
|
||||
@spec normalize(any()) :: nil
|
||||
def normalize(_), do: nil
|
||||
|
||||
@spec normalize(String.t()) :: struct() | nil
|
||||
def get_anything_by_url(url) do
|
||||
Logger.debug("Getting anything from url #{url}")
|
||||
get_actor_url(url) || get_event_url(url) || get_comment_url(url)
|
||||
end
|
||||
|
||||
defp get_actor_url(url) do
|
||||
case Actors.get_actor_by_url(url) do
|
||||
{:ok, %Actor{} = actor} -> actor
|
||||
_ -> nil
|
||||
end
|
||||
end
|
||||
|
||||
defp get_event_url(url) do
|
||||
case Events.get_event_by_url(url) do
|
||||
{:ok, %Event{} = event} -> event
|
||||
_ -> nil
|
||||
end
|
||||
end
|
||||
|
||||
defp get_comment_url(url) do
|
||||
case Events.get_comment_full_from_url(url) do
|
||||
{:ok, %Comment{} = comment} -> comment
|
||||
_ -> nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -13,11 +13,17 @@ defmodule Mobilizon.Service.ActivityPub.Utils do
|
|||
alias Mobilizon.Events
|
||||
alias Mobilizon.Activity
|
||||
alias Mobilizon.Service.ActivityPub
|
||||
alias Ecto.{Changeset, UUID}
|
||||
alias Ecto.Changeset
|
||||
require Logger
|
||||
|
||||
def make_context(%Activity{data: %{"context" => context}}), do: context
|
||||
def make_context(_), do: generate_context_id()
|
||||
# Some implementations send the actor URI as the actor field, others send the entire actor object,
|
||||
# so figure out what the actor's URI is based on what we have.
|
||||
def get_url(object) do
|
||||
case object do
|
||||
%{"id" => id} -> id
|
||||
id -> id
|
||||
end
|
||||
end
|
||||
|
||||
def make_json_ld_header do
|
||||
%{
|
||||
|
@ -38,18 +44,6 @@ defmodule Mobilizon.Service.ActivityPub.Utils do
|
|||
DateTime.utc_now() |> DateTime.to_iso8601()
|
||||
end
|
||||
|
||||
def generate_activity_id do
|
||||
generate_id("activities")
|
||||
end
|
||||
|
||||
def generate_context_id do
|
||||
generate_id("contexts")
|
||||
end
|
||||
|
||||
def generate_id(type) do
|
||||
"#{MobilizonWeb.Endpoint.url()}/#{type}/#{UUID.generate()}"
|
||||
end
|
||||
|
||||
@doc """
|
||||
Enqueues an activity for federation if it's local
|
||||
"""
|
||||
|
@ -108,16 +102,42 @@ defmodule Mobilizon.Service.ActivityPub.Utils do
|
|||
end
|
||||
|
||||
@doc """
|
||||
Inserts a full object if it is contained in an activity.
|
||||
Converts an AP object data to our internal data structure
|
||||
"""
|
||||
def insert_full_object(object_data, local \\ false)
|
||||
def object_to_event_data(object) do
|
||||
{:ok, %Actor{id: actor_id}} = Actors.get_actor_by_url(object["actor"])
|
||||
|
||||
%{
|
||||
"title" => object["name"],
|
||||
"description" => object["content"],
|
||||
"organizer_actor_id" => actor_id,
|
||||
"begins_on" => object["begins_on"],
|
||||
"category_id" => Events.get_category_by_title(object["category"]).id,
|
||||
"url" => object["id"]
|
||||
}
|
||||
end
|
||||
|
||||
@doc """
|
||||
Inserts a full object if it is contained in an activity.
|
||||
"""
|
||||
def insert_full_object(%{"object" => %{"type" => type} = object_data}, local)
|
||||
when is_map(object_data) and type == "Event" and not local do
|
||||
with {:ok, _} <- Events.create_event(object_data) do
|
||||
def insert_full_object(object_data)
|
||||
|
||||
@doc """
|
||||
Inserts a full object if it is contained in an activity.
|
||||
"""
|
||||
def insert_full_object(%{"object" => %{"type" => "Event"} = object_data})
|
||||
when is_map(object_data) do
|
||||
with object_data <- object_to_event_data(object_data),
|
||||
{:ok, _} <- Events.create_event(object_data) do
|
||||
:ok
|
||||
end
|
||||
end
|
||||
|
||||
def insert_full_object(%{"object" => %{"type" => "Group"} = object_data})
|
||||
when is_map(object_data) do
|
||||
with object_data <-
|
||||
Map.put(object_data, "preferred_username", object_data["preferredUsername"]),
|
||||
{:ok, _} <- Actors.create_group(object_data) do
|
||||
:ok
|
||||
end
|
||||
end
|
||||
|
@ -125,8 +145,11 @@ defmodule Mobilizon.Service.ActivityPub.Utils do
|
|||
@doc """
|
||||
Inserts a full object if it is contained in an activity.
|
||||
"""
|
||||
def insert_full_object(%{"object" => %{"type" => type} = object_data}, local)
|
||||
when is_map(object_data) and type == "Note" and not local do
|
||||
def insert_full_object(%{"object" => %{"type" => "Note"} = object_data})
|
||||
when is_map(object_data) do
|
||||
Logger.debug("Inserting full comment")
|
||||
Logger.debug(inspect(object_data))
|
||||
|
||||
with {:ok, %Actor{id: actor_id}} <- Actors.get_or_fetch_by_url(object_data["actor"]) do
|
||||
data = %{
|
||||
"text" => object_data["content"],
|
||||
|
@ -134,11 +157,12 @@ defmodule Mobilizon.Service.ActivityPub.Utils do
|
|||
"actor_id" => actor_id,
|
||||
"in_reply_to_comment_id" => nil,
|
||||
"event_id" => nil,
|
||||
"uuid" => object_data["uuid"],
|
||||
"local" => local
|
||||
"uuid" => object_data["uuid"]
|
||||
}
|
||||
|
||||
# We fetch the parent object
|
||||
Logger.debug("We're fetching the parent object")
|
||||
|
||||
data =
|
||||
if Map.has_key?(object_data, "inReplyTo") && object_data["inReplyTo"] != nil &&
|
||||
object_data["inReplyTo"] != "" do
|
||||
|
@ -159,7 +183,7 @@ defmodule Mobilizon.Service.ActivityPub.Utils do
|
|||
|> Map.put("origin_comment_id", comment |> Comment.get_thread_id())
|
||||
|
||||
# Anthing else is kind of a MP
|
||||
object ->
|
||||
{:error, object} ->
|
||||
Logger.debug("Parent object is something we don't handle")
|
||||
Logger.debug(inspect(object))
|
||||
data
|
||||
|
@ -180,7 +204,7 @@ defmodule Mobilizon.Service.ActivityPub.Utils do
|
|||
end
|
||||
end
|
||||
|
||||
def insert_full_object(_, _), do: :ok
|
||||
def insert_full_object(_), do: :ok
|
||||
|
||||
#### Like-related helpers
|
||||
|
||||
|
@ -206,6 +230,41 @@ defmodule Mobilizon.Service.ActivityPub.Utils do
|
|||
# Repo.one(query)
|
||||
# end
|
||||
|
||||
@doc """
|
||||
Make an AP event object from an set of values
|
||||
"""
|
||||
def make_event_data(
|
||||
actor,
|
||||
to,
|
||||
title,
|
||||
content_html,
|
||||
# attachments,
|
||||
tags \\ [],
|
||||
# _cw \\ nil,
|
||||
cc \\ [],
|
||||
metadata \\ %{},
|
||||
category \\ ""
|
||||
) do
|
||||
Logger.debug("Making event data")
|
||||
uuid = Ecto.UUID.generate()
|
||||
|
||||
%{
|
||||
"type" => "Event",
|
||||
"to" => to,
|
||||
"cc" => cc,
|
||||
"content" => content_html,
|
||||
"name" => title,
|
||||
# "summary" => cw,
|
||||
# "attachment" => attachments,
|
||||
"begins_on" => metadata.begins_on,
|
||||
"category" => category,
|
||||
"actor" => actor,
|
||||
"id" => "#{MobilizonWeb.Endpoint.url()}/events/#{uuid}",
|
||||
"uuid" => uuid,
|
||||
"tag" => tags |> Enum.map(fn {_, tag} -> tag end) |> Enum.uniq()
|
||||
}
|
||||
end
|
||||
|
||||
def make_event_data(
|
||||
%Event{title: title, organizer_actor: actor, uuid: uuid},
|
||||
to \\ ["https://www.w3.org/ns/activitystreams#Public"]
|
||||
|
@ -238,6 +297,7 @@ defmodule Mobilizon.Service.ActivityPub.Utils do
|
|||
"to" => to,
|
||||
"content" => text,
|
||||
"actor" => actor.url,
|
||||
"attributedTo" => actor.url,
|
||||
"uuid" => uuid,
|
||||
"id" => "#{MobilizonWeb.Endpoint.url()}/comments/#{uuid}"
|
||||
}
|
||||
|
@ -249,14 +309,17 @@ defmodule Mobilizon.Service.ActivityPub.Utils do
|
|||
end
|
||||
end
|
||||
|
||||
@doc """
|
||||
Make an AP comment object from an set of values
|
||||
"""
|
||||
def make_comment_data(
|
||||
actor,
|
||||
to,
|
||||
content_html,
|
||||
# attachments,
|
||||
inReplyTo \\ nil,
|
||||
# tags,
|
||||
_cw \\ nil,
|
||||
tags \\ [],
|
||||
# _cw \\ nil,
|
||||
cc \\ []
|
||||
) do
|
||||
Logger.debug("Making comment data")
|
||||
|
@ -271,8 +334,8 @@ defmodule Mobilizon.Service.ActivityPub.Utils do
|
|||
# "attachment" => attachments,
|
||||
"actor" => actor,
|
||||
"id" => "#{MobilizonWeb.Endpoint.url()}/comments/#{uuid}",
|
||||
"uuid" => uuid
|
||||
# "tag" => tags |> Enum.map(fn {_, tag} -> tag end) |> Enum.uniq()
|
||||
"uuid" => uuid,
|
||||
"tag" => tags |> Enum.map(fn {_, tag} -> tag end) |> Enum.uniq()
|
||||
}
|
||||
|
||||
if inReplyTo do
|
||||
|
@ -283,19 +346,54 @@ defmodule Mobilizon.Service.ActivityPub.Utils do
|
|||
end
|
||||
end
|
||||
|
||||
def make_like_data(%Actor{url: url} = actor, %{data: %{"id" => id}} = object, activity_id) do
|
||||
data = %{
|
||||
"type" => "Like",
|
||||
"actor" => url,
|
||||
"object" => id,
|
||||
"to" => [actor.follower_address, object.data["actor"]],
|
||||
"cc" => ["https://www.w3.org/ns/activitystreams#Public"],
|
||||
"context" => object.data["context"]
|
||||
}
|
||||
def make_group_data(
|
||||
actor,
|
||||
to,
|
||||
preferred_username,
|
||||
content_html,
|
||||
# attachments,
|
||||
tags \\ [],
|
||||
# _cw \\ nil,
|
||||
cc \\ []
|
||||
) do
|
||||
uuid = Ecto.UUID.generate()
|
||||
|
||||
if activity_id, do: Map.put(data, "id", activity_id), else: data
|
||||
%{
|
||||
"type" => "Group",
|
||||
"to" => to,
|
||||
"cc" => cc,
|
||||
"summary" => content_html,
|
||||
"attributedTo" => actor,
|
||||
"preferredUsername" => preferred_username,
|
||||
"id" => "#{MobilizonWeb.Endpoint.url()}/~#{preferred_username}",
|
||||
"uuid" => uuid,
|
||||
"tag" => tags |> Enum.map(fn {_, tag} -> tag end) |> Enum.uniq()
|
||||
}
|
||||
end
|
||||
|
||||
#### Like-related helpers
|
||||
|
||||
@doc """
|
||||
Returns an existing like if a user already liked an object
|
||||
"""
|
||||
# @spec get_existing_like(Actor.t, map()) :: nil
|
||||
# def get_existing_like(%Actor{url: url} = actor, %{data: %{"id" => id}}) do
|
||||
# nil
|
||||
# end
|
||||
|
||||
# def make_like_data(%Actor{url: url} = actor, %{data: %{"id" => id}} = object, activity_id) do
|
||||
# data = %{
|
||||
# "type" => "Like",
|
||||
# "actor" => url,
|
||||
# "object" => id,
|
||||
# "to" => [actor.followers_url, object.data["actor"]],
|
||||
# "cc" => ["https://www.w3.org/ns/activitystreams#Public"],
|
||||
# "context" => object.data["context"]
|
||||
# }
|
||||
|
||||
# if activity_id, do: Map.put(data, "id", activity_id), else: data
|
||||
# end
|
||||
|
||||
def update_element_in_object(property, element, object) do
|
||||
with new_data <-
|
||||
object.data
|
||||
|
@ -326,9 +424,9 @@ defmodule Mobilizon.Service.ActivityPub.Utils do
|
|||
#### Follow-related helpers
|
||||
|
||||
@doc """
|
||||
Makes a follow activity data for the given follower and followed
|
||||
Makes a follow activity data for the given followed and follower
|
||||
"""
|
||||
def make_follow_data(%Actor{url: follower_id}, %Actor{url: followed_id}, activity_id) do
|
||||
def make_follow_data(%Actor{url: followed_id}, %Actor{url: follower_id}, activity_id) do
|
||||
Logger.debug("Make follow data")
|
||||
|
||||
data = %{
|
||||
|
@ -342,7 +440,7 @@ defmodule Mobilizon.Service.ActivityPub.Utils do
|
|||
Logger.debug(inspect(data))
|
||||
|
||||
if activity_id,
|
||||
do: Map.put(data, "id", "#{MobilizonWeb.Endpoint.url()}/follow/#{activity_id}/activity"),
|
||||
do: Map.put(data, "id", activity_id),
|
||||
else: data
|
||||
end
|
||||
|
||||
|
@ -352,17 +450,37 @@ defmodule Mobilizon.Service.ActivityPub.Utils do
|
|||
Make announce activity data for the given actor and object
|
||||
"""
|
||||
def make_announce_data(
|
||||
%Actor{url: url} = user,
|
||||
%Event{id: id} = object,
|
||||
%Actor{url: actor_url} = actor,
|
||||
%Event{url: event_url} = object,
|
||||
activity_id
|
||||
) do
|
||||
data = %{
|
||||
"type" => "Announce",
|
||||
"actor" => url,
|
||||
"object" => id,
|
||||
"to" => [user.follower_address, object.data["actor"]],
|
||||
"cc" => ["https://www.w3.org/ns/activitystreams#Public"],
|
||||
"context" => object.data["context"]
|
||||
"actor" => actor_url,
|
||||
"object" => event_url,
|
||||
"to" => [actor.followers_url, object.actor.url],
|
||||
"cc" => ["https://www.w3.org/ns/activitystreams#Public"]
|
||||
# "context" => object.data["context"]
|
||||
}
|
||||
|
||||
if activity_id, do: Map.put(data, "id", activity_id), else: data
|
||||
end
|
||||
|
||||
@doc """
|
||||
Make announce activity data for the given actor and object
|
||||
"""
|
||||
def make_announce_data(
|
||||
%Actor{url: actor_url} = actor,
|
||||
%Comment{url: comment_url} = object,
|
||||
activity_id
|
||||
) do
|
||||
data = %{
|
||||
"type" => "Announce",
|
||||
"actor" => actor_url,
|
||||
"object" => comment_url,
|
||||
"to" => [actor.followers_url, object.actor.url],
|
||||
"cc" => ["https://www.w3.org/ns/activitystreams#Public"]
|
||||
# "context" => object.data["context"]
|
||||
}
|
||||
|
||||
if activity_id, do: Map.put(data, "id", activity_id), else: data
|
||||
|
@ -376,18 +494,32 @@ defmodule Mobilizon.Service.ActivityPub.Utils do
|
|||
|
||||
#### Unfollow-related helpers
|
||||
|
||||
def make_unfollow_data(follower, followed, follow_activity) do
|
||||
%{
|
||||
@spec make_unfollow_data(Actor.t(), Actor.t(), map(), String.t()) :: map()
|
||||
def make_unfollow_data(
|
||||
%Actor{url: follower_url},
|
||||
%Actor{url: followed_url},
|
||||
follow_activity,
|
||||
activity_id
|
||||
) do
|
||||
data = %{
|
||||
"type" => "Undo",
|
||||
"actor" => follower.url,
|
||||
"to" => [followed.url],
|
||||
"object" => follow_activity.data["id"]
|
||||
"actor" => follower_url,
|
||||
"to" => [followed_url],
|
||||
"object" => follow_activity.data
|
||||
}
|
||||
|
||||
if activity_id, do: Map.put(data, "id", activity_id), else: data
|
||||
end
|
||||
|
||||
#### Create-related helpers
|
||||
|
||||
@doc """
|
||||
Make create activity data
|
||||
"""
|
||||
@spec make_create_data(map(), map()) :: map()
|
||||
def make_create_data(params, additional \\ %{}) do
|
||||
Logger.debug("Making create data")
|
||||
Logger.debug(inspect(params))
|
||||
published = params.published || make_date()
|
||||
|
||||
%{
|
||||
|
|
157
lib/service/formatter/formatter.ex
Normal file
157
lib/service/formatter/formatter.ex
Normal file
|
@ -0,0 +1,157 @@
|
|||
defmodule Mobilizon.Service.Formatter do
|
||||
alias Mobilizon.Actors.Actor
|
||||
alias Mobilizon.Actors
|
||||
|
||||
@tag_regex ~r/\#\w+/u
|
||||
def parse_tags(text, data \\ %{}) do
|
||||
Regex.scan(@tag_regex, text)
|
||||
|> Enum.map(fn ["#" <> tag = full_tag] -> {full_tag, String.downcase(tag)} end)
|
||||
|> (fn map ->
|
||||
if data["sensitive"] in [true, "True", "true", "1"],
|
||||
do: [{"#nsfw", "nsfw"}] ++ map,
|
||||
else: map
|
||||
end).()
|
||||
end
|
||||
|
||||
def parse_mentions(text) do
|
||||
# Modified from https://www.w3.org/TR/html5/forms.html#valid-e-mail-address
|
||||
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])?)*/u
|
||||
|
||||
Regex.scan(regex, text)
|
||||
|> List.flatten()
|
||||
|> Enum.uniq()
|
||||
|> Enum.map(fn "@" <> match = full_match ->
|
||||
{full_match, Actors.get_actor_by_name(match)}
|
||||
end)
|
||||
|> Enum.filter(fn {_match, user} -> user end)
|
||||
end
|
||||
|
||||
# def emojify(text) do
|
||||
# emojify(text, Emoji.get_all())
|
||||
# end
|
||||
|
||||
# def emojify(text, nil), do: text
|
||||
|
||||
# def emojify(text, emoji) do
|
||||
# Enum.reduce(emoji, text, fn {emoji, file}, text ->
|
||||
# emoji = HTML.strip_tags(emoji)
|
||||
# file = HTML.strip_tags(file)
|
||||
|
||||
# String.replace(
|
||||
# text,
|
||||
# ":#{emoji}:",
|
||||
# "<img height='32px' width='32px' alt='#{emoji}' title='#{emoji}' src='#{
|
||||
# MediaProxy.url(file)
|
||||
# }' />"
|
||||
# )
|
||||
# |> HTML.filter_tags()
|
||||
# end)
|
||||
# end
|
||||
|
||||
# def get_emoji(text) when is_binary(text) do
|
||||
# Enum.filter(Emoji.get_all(), fn {emoji, _} -> String.contains?(text, ":#{emoji}:") end)
|
||||
# end
|
||||
|
||||
# def get_emoji(_), do: []
|
||||
|
||||
@link_regex ~r/[0-9a-z+\-\.]+:[0-9a-z$-_.+!*'(),]+/ui
|
||||
|
||||
@uri_schemes Application.get_env(:pleroma, :uri_schemes, [])
|
||||
@valid_schemes Keyword.get(@uri_schemes, :valid_schemes, [])
|
||||
|
||||
# # TODO: make it use something other than @link_regex
|
||||
# def html_escape(text, "text/html") do
|
||||
# HTML.filter_tags(text)
|
||||
# end
|
||||
|
||||
def html_escape(text, "text/plain") do
|
||||
Regex.split(@link_regex, text, include_captures: true)
|
||||
|> Enum.map_every(2, fn chunk ->
|
||||
{:safe, part} = Phoenix.HTML.html_escape(chunk)
|
||||
part
|
||||
end)
|
||||
|> Enum.join("")
|
||||
end
|
||||
|
||||
@doc "changes scheme:... urls to html links"
|
||||
def add_links({subs, text}) do
|
||||
links =
|
||||
text
|
||||
|> String.split([" ", "\t", "<br>"])
|
||||
|> Enum.filter(fn word -> String.starts_with?(word, @valid_schemes) end)
|
||||
|> Enum.filter(fn word -> Regex.match?(@link_regex, word) end)
|
||||
|> Enum.map(fn url -> {Ecto.UUID.generate(), url} end)
|
||||
|> Enum.sort_by(fn {_, url} -> -String.length(url) end)
|
||||
|
||||
uuid_text =
|
||||
links
|
||||
|> Enum.reduce(text, fn {uuid, url}, acc -> String.replace(acc, url, uuid) end)
|
||||
|
||||
subs =
|
||||
subs ++
|
||||
Enum.map(links, fn {uuid, url} ->
|
||||
{uuid, "<a href=\"#{url}\">#{url}</a>"}
|
||||
end)
|
||||
|
||||
{subs, uuid_text}
|
||||
end
|
||||
|
||||
@doc "Adds the links to mentioned actors"
|
||||
def add_actor_links({subs, text}, mentions) do
|
||||
mentions =
|
||||
mentions
|
||||
|> Enum.sort_by(fn {name, _} -> -String.length(name) end)
|
||||
|> Enum.map(fn {name, actor} -> {name, actor, Ecto.UUID.generate()} end)
|
||||
|
||||
uuid_text =
|
||||
mentions
|
||||
|> Enum.reduce(text, fn {match, _actor, uuid}, text ->
|
||||
String.replace(text, match, uuid)
|
||||
end)
|
||||
|
||||
subs =
|
||||
subs ++
|
||||
Enum.map(mentions, fn {match, %Actor{id: id, url: url}, uuid} ->
|
||||
short_match = String.split(match, "@") |> tl() |> hd()
|
||||
|
||||
{uuid,
|
||||
"<span><a data-user='#{id}' class='mention' href='#{url}'>@<span>#{short_match}</span></a></span>"}
|
||||
end)
|
||||
|
||||
{subs, uuid_text}
|
||||
end
|
||||
|
||||
@doc "Adds the hashtag links"
|
||||
def add_hashtag_links({subs, text}, tags) do
|
||||
tags =
|
||||
tags
|
||||
|> Enum.sort_by(fn {name, _} -> -String.length(name) end)
|
||||
|> Enum.map(fn {name, short} -> {name, short, Ecto.UUID.generate()} end)
|
||||
|
||||
uuid_text =
|
||||
tags
|
||||
|> Enum.reduce(text, fn {match, _short, uuid}, text ->
|
||||
String.replace(text, match, uuid)
|
||||
end)
|
||||
|
||||
subs =
|
||||
subs ++
|
||||
Enum.map(tags, fn {tag_text, tag, uuid} ->
|
||||
url =
|
||||
"<a data-tag='#{tag}' href='#{MobilizonWeb.Endpoint.url()}/tag/#{tag}' rel='tag'>#{
|
||||
tag_text
|
||||
}</a>"
|
||||
|
||||
{uuid, url}
|
||||
end)
|
||||
|
||||
{subs, uuid_text}
|
||||
end
|
||||
|
||||
def finalize({subs, text}) do
|
||||
Enum.reduce(subs, text, fn {uuid, replacement}, result_text ->
|
||||
String.replace(result_text, uuid, replacement)
|
||||
end)
|
||||
end
|
||||
end
|
37
test/fixtures/mastodon-announce.json
vendored
Normal file
37
test/fixtures/mastodon-announce.json
vendored
Normal file
|
@ -0,0 +1,37 @@
|
|||
{
|
||||
"type": "Announce",
|
||||
"to": [
|
||||
"https://www.w3.org/ns/activitystreams#Public"
|
||||
],
|
||||
"signature": {
|
||||
"type": "RsaSignature2017",
|
||||
"signatureValue": "T95DRE0eAligvMuRMkQA01lsoz2PKi4XXF+cyZ0BqbrO12p751TEWTyyRn5a+HH0e4kc77EUhQVXwMq80WAYDzHKVUTf2XBJPBa68vl0j6RXw3+HK4ef5hR4KWFNBU34yePS7S1fEmc1mTG4Yx926wtmZwDpEMTp1CXOeVEjCYzmdyHpepPPH2ZZettiacmPRSqBLPGWZoot7kH/SioIdnrMGY0I7b+rqkIdnnEcdhu9N1BKPEO9Sr+KmxgAUiidmNZlbBXX6gCxp8BiIdH4ABsIcwoDcGNkM5EmWunGW31LVjsEQXhH5c1Wly0ugYYPCg/0eHLNBOhKkY/teSM8Lg==",
|
||||
"creator": "https://social.tcit.fr/users/tcit#main-key",
|
||||
"created": "2018-02-17T19:39:15Z"
|
||||
},
|
||||
"published": "2018-02-17T19:39:15Z",
|
||||
"object": "https://social.tcit.fr/@tcit/101188891162897047",
|
||||
"id": "https://social.tcit.fr/users/tcit/statuses/101188891162897047/activity",
|
||||
"cc": [
|
||||
"https://social.tcit.fr/users/tcit",
|
||||
"https://social.tcit.fr/users/tcit/followers"
|
||||
],
|
||||
"atomUri": "https://social.tcit.fr/users/tcit/statuses/101188891162897047/activity",
|
||||
"actor": "https://social.tcit.fr/users/tcit",
|
||||
"@context": [
|
||||
"https://www.w3.org/ns/activitystreams",
|
||||
"https://w3id.org/security/v1",
|
||||
{
|
||||
"toot": "http://joinmastodon.org/ns#",
|
||||
"sensitive": "as:sensitive",
|
||||
"ostatus": "http://ostatus.org#",
|
||||
"movedTo": "as:movedTo",
|
||||
"manuallyApprovesFollowers": "as:manuallyApprovesFollowers",
|
||||
"inReplyToAtomUri": "ostatus:inReplyToAtomUri",
|
||||
"conversation": "ostatus:conversation",
|
||||
"atomUri": "ostatus:atomUri",
|
||||
"Hashtag": "as:Hashtag",
|
||||
"Emoji": "toot:Emoji"
|
||||
}
|
||||
]
|
||||
}
|
33
test/fixtures/mastodon-delete.json
vendored
Normal file
33
test/fixtures/mastodon-delete.json
vendored
Normal file
|
@ -0,0 +1,33 @@
|
|||
{
|
||||
"type": "Delete",
|
||||
"signature": {
|
||||
"type": "RsaSignature2017",
|
||||
"signatureValue": "cw0RlfNREf+5VdsOYcCBDrv521eiLsDTAYNHKffjF0bozhCnOh+wHkFik7WamUk$
|
||||
uEiN4L2H6vPlGRprAZGRhEwgy+A7rIFQNmLrpW5qV5UNVI/2F7kngEHqZQgbQYj9hW+5GMYmPkHdv3D72ZefGw$
|
||||
4Xa2NBLGFpAjQllfzt7kzZLKKY2DM99FdUa64I2Wj3iD04Hs23SbrUdAeuGk/c1Cg6bwGNG4vxoiwn1jikgJLA$
|
||||
NAlSGjsRGdR7LfbC7GqWWsW3cSNsLFPoU6FyALjgTrrYoHiXe0QHggw+L3yMLfzB2S/L46/VRbyb+WDKMBIXUL$
|
||||
5owmzHSi6e/ZtCI3w==",
|
||||
"creator": "http://mastodon.example.org/users/gargron#main-key", "created": "2018-03-03T16:24:11Z"
|
||||
},
|
||||
"object": {
|
||||
"type": "Tombstone",
|
||||
"id": "http://mastodon.example.org/users/gargron/statuses/99620895606148759",
|
||||
"atomUri": "http://mastodon.example.org/users/gargron/statuses/99620895606148759"
|
||||
},
|
||||
"id": "http://mastodon.example.org/users/gargron/statuses/99620895606148759#delete",
|
||||
"actor": "http://mastodon.example.org/users/gargron",
|
||||
"@context": [
|
||||
{
|
||||
"toot": "http://joinmastodon.org/ns#",
|
||||
"sensitive": "as:sensitive",
|
||||
"ostatus": "http://ostatus.org#",
|
||||
"movedTo": "as:movedTo",
|
||||
"manuallyApprovesFollowers": "as:manuallyApprovesFollowers",
|
||||
"inReplyToAtomUri": "ostatus:inReplyToAtomUri",
|
||||
"conversation": "ostatus:conversation",
|
||||
"atomUri": "ostatus:atomUri",
|
||||
"Hashtag": "as:Hashtag",
|
||||
"Emoji": "toot:Emoji"
|
||||
}
|
||||
]
|
||||
}
|
29
test/fixtures/mastodon-follow-activity.json
vendored
Normal file
29
test/fixtures/mastodon-follow-activity.json
vendored
Normal file
|
@ -0,0 +1,29 @@
|
|||
{
|
||||
"type": "Follow",
|
||||
"signature": {
|
||||
"type": "RsaSignature2017",
|
||||
"signatureValue": "Kn1/UkAQGJVaXBfWLAHcnwHg8YMAUqlEaBuYLazAG+pz5hqivsyrBmPV186Xzr+B4ZLExA9+SnOoNx/GOz4hBm0kAmukNSILAsUd84tcJ2yT9zc1RKtembK4WiwOw7li0+maeDN0HaB6t+6eTqsCWmtiZpprhXD8V1GGT8yG7X24fQ9oFGn+ng7lasbcCC0988Y1eGqNe7KryxcPuQz57YkDapvtONzk8gyLTkZMV4De93MyRHq6GVjQVIgtiYabQAxrX6Q8C+4P/jQoqdWJHEe+MY5JKyNaT/hMPt2Md1ok9fZQBGHlErk22/zy8bSN19GdG09HmIysBUHRYpBLig==",
|
||||
"creator": "https://social.tcit.fr/users/tcit#main-key",
|
||||
"created": "2018-02-17T13:29:31Z"
|
||||
},
|
||||
"object": "http://localtesting.pleroma.lol/users/lain",
|
||||
"nickname": "lain",
|
||||
"id": "https://social.tcit.fr/users/tcit#follows/2",
|
||||
"actor": "https://social.tcit.fr/users/tcit",
|
||||
"@context": [
|
||||
"https://www.w3.org/ns/activitystreams",
|
||||
"https://w3id.org/security/v1",
|
||||
{
|
||||
"toot": "http://joinmastodon.org/ns#",
|
||||
"sensitive": "as:sensitive",
|
||||
"ostatus": "http://ostatus.org#",
|
||||
"movedTo": "as:movedTo",
|
||||
"manuallyApprovesFollowers": "as:manuallyApprovesFollowers",
|
||||
"inReplyToAtomUri": "ostatus:inReplyToAtomUri",
|
||||
"conversation": "ostatus:conversation",
|
||||
"atomUri": "ostatus:atomUri",
|
||||
"Hashtag": "as:Hashtag",
|
||||
"Emoji": "toot:Emoji"
|
||||
}
|
||||
]
|
||||
}
|
29
test/fixtures/mastodon-like.json
vendored
Normal file
29
test/fixtures/mastodon-like.json
vendored
Normal file
|
@ -0,0 +1,29 @@
|
|||
{
|
||||
"type": "Like",
|
||||
"signature": {
|
||||
"type": "RsaSignature2017",
|
||||
"signatureValue": "fdxMfQSMwbC6wP6sh6neS/vM5879K67yQkHTbiT5Npr5wAac0y6+o3Ij+41tN3rL6wfuGTosSBTHOtta6R4GCOOhCaCSLMZKypnp1VltCzLDoyrZELnYQIC8gpUXVmIycZbREk22qWUe/w7DAFaKK4UscBlHDzeDVcA0K3Se5Sluqi9/Zh+ldAnEzj/rSEPDjrtvf5wGNf3fHxbKSRKFt90JvKK6hS+vxKUhlRFDf6/SMETw+EhwJSNW4d10yMUakqUWsFv4Acq5LW7l+HpYMvlYY1FZhNde1+uonnCyuQDyvzkff8zwtEJmAXC4RivO/VVLa17SmqheJZfI8oluVg==",
|
||||
"creator": "http://mastodon.example.org/users/admin#main-key",
|
||||
"created": "2018-02-17T18:57:49Z"
|
||||
},
|
||||
"object": "http://localtesting.pleroma.lol/objects/eb92579d-3417-42a8-8652-2492c2d4f454",
|
||||
"nickname": "lain",
|
||||
"id": "http://mastodon.example.org/users/admin#likes/2",
|
||||
"actor": "http://mastodon.example.org/users/admin",
|
||||
"@context": [
|
||||
"https://www.w3.org/ns/activitystreams",
|
||||
"https://w3id.org/security/v1",
|
||||
{
|
||||
"toot": "http://joinmastodon.org/ns#",
|
||||
"sensitive": "as:sensitive",
|
||||
"ostatus": "http://ostatus.org#",
|
||||
"movedTo": "as:movedTo",
|
||||
"manuallyApprovesFollowers": "as:manuallyApprovesFollowers",
|
||||
"inReplyToAtomUri": "ostatus:inReplyToAtomUri",
|
||||
"conversation": "ostatus:conversation",
|
||||
"atomUri": "ostatus:atomUri",
|
||||
"Hashtag": "as:Hashtag",
|
||||
"Emoji": "toot:Emoji"
|
||||
}
|
||||
]
|
||||
}
|
70
test/fixtures/mastodon-post-activity-hashtag.json
vendored
Normal file
70
test/fixtures/mastodon-post-activity-hashtag.json
vendored
Normal file
|
@ -0,0 +1,70 @@
|
|||
{
|
||||
"@context": [
|
||||
"https://www.w3.org/ns/activitystreams",
|
||||
"https://w3id.org/security/v1",
|
||||
{
|
||||
"Emoji": "toot:Emoji",
|
||||
"Hashtag": "as:Hashtag",
|
||||
"atomUri": "ostatus:atomUri",
|
||||
"conversation": "ostatus:conversation",
|
||||
"inReplyToAtomUri": "ostatus:inReplyToAtomUri",
|
||||
"manuallyApprovesFollowers": "as:manuallyApprovesFollowers",
|
||||
"movedTo": "as:movedTo",
|
||||
"ostatus": "http://ostatus.org#",
|
||||
"sensitive": "as:sensitive",
|
||||
"toot": "http://joinmastodon.org/ns#"
|
||||
}
|
||||
],
|
||||
"actor": "https://framapiaf.org/users/admin",
|
||||
"cc": [
|
||||
"https://framapiaf.org/users/admin/followers",
|
||||
"http://mobilizon.com/@tcit"
|
||||
],
|
||||
"id": "https://framapiaf.org/users/admin/statuses/99512778738411822/activity",
|
||||
"nickname": "lain",
|
||||
"object": {
|
||||
"atomUri": "https://framapiaf.org/users/admin/statuses/99512778738411822",
|
||||
"attachment": [],
|
||||
"attributedTo": "https://framapiaf.org/users/admin",
|
||||
"cc": [
|
||||
"https://framapiaf.org/users/admin/followers",
|
||||
"http://localtesting.pleroma.lol/users/lain"
|
||||
],
|
||||
"content": "<p><span class=\"h-card\"><a href=\"http://localtesting.pleroma.lol/users/lain\" class=\"u-url mention\">@<span>lain</span></a></span> #moo</p>",
|
||||
"conversation": "tag:mastodon.example.org,2018-02-12:objectId=20:objectType=Conversation",
|
||||
"id": "https://framapiaf.org/users/admin/statuses/99512778738411822",
|
||||
"inReplyTo": null,
|
||||
"inReplyToAtomUri": null,
|
||||
"published": "2018-02-12T14:08:20Z",
|
||||
"sensitive": true,
|
||||
"summary": "cw",
|
||||
"tag": [
|
||||
{
|
||||
"href": "http://localtesting.pleroma.lol/users/lain",
|
||||
"name": "@lain@localtesting.pleroma.lol",
|
||||
"type": "Mention"
|
||||
},
|
||||
{
|
||||
"href": "http://mastodon.example.org/tags/moo",
|
||||
"name": "#moo",
|
||||
"type": "Hashtag"
|
||||
}
|
||||
],
|
||||
"to": [
|
||||
"https://www.w3.org/ns/activitystreams#Public"
|
||||
],
|
||||
"type": "Note",
|
||||
"url": "https://framapiaf.org/@admin/99512778738411822"
|
||||
},
|
||||
"published": "2018-02-12T14:08:20Z",
|
||||
"signature": {
|
||||
"created": "2018-02-12T14:08:20Z",
|
||||
"creator": "https://framapiaf.org/users/admin#main-key",
|
||||
"signatureValue": "rnNfcopkc6+Ju73P806popcfwrK9wGYHaJVG1/ZvrlEbWVDzaHjkXqj9Q3/xju5l8CSn9tvSgCCtPFqZsFQwn/pFIFUcw7ZWB2xi4bDm3NZ3S4XQ8JRaaX7og5hFxAhWkGhJhAkfxVnOg2hG+w2d/7d7vRVSC1vo5ip4erUaA/PkWusZvPIpxnRWoXaxJsFmVx0gJgjpJkYDyjaXUlp+jmaoseeZ4EPQUWqHLKJ59PRG0mg8j2xAjYH9nQaN14qMRmTGPxY8gfv/CUFcatA+8VJU9KEsJkDAwLVvglydNTLGrxpAJU78a2eaht0foV43XUIZGe3DKiJPgE+UOKGCJw==",
|
||||
"type": "RsaSignature2017"
|
||||
},
|
||||
"to": [
|
||||
"https://www.w3.org/ns/activitystreams#Public"
|
||||
],
|
||||
"type": "Create"
|
||||
}
|
18
test/fixtures/mastodon-post-activity.json
vendored
18
test/fixtures/mastodon-post-activity.json
vendored
|
@ -15,24 +15,24 @@
|
|||
"toot": "http://joinmastodon.org/ns#"
|
||||
}
|
||||
],
|
||||
"actor": "http://framapiaf.org/users/admin",
|
||||
"actor": "https://framapiaf.org/users/admin",
|
||||
"cc": [
|
||||
"http://framapiaf.org/users/admin/followers",
|
||||
"https://framapiaf.org/users/admin/followers",
|
||||
"http://mobilizon.com/@tcit"
|
||||
],
|
||||
"id": "http://framapiaf.org/users/admin/statuses/99512778738411822/activity",
|
||||
"id": "https://framapiaf.org/users/admin/statuses/99512778738411822/activity",
|
||||
"nickname": "lain",
|
||||
"object": {
|
||||
"atomUri": "http://framapiaf.org/users/admin/statuses/99512778738411822",
|
||||
"atomUri": "https://framapiaf.org/users/admin/statuses/99512778738411822",
|
||||
"attachment": [],
|
||||
"attributedTo": "http://framapiaf.org/users/admin",
|
||||
"attributedTo": "https://framapiaf.org/users/admin",
|
||||
"cc": [
|
||||
"http://framapiaf.org/users/admin/followers",
|
||||
"https://framapiaf.org/users/admin/followers",
|
||||
"http://localtesting.pleroma.lol/users/lain"
|
||||
],
|
||||
"content": "<p><span class=\"h-card\"><a href=\"http://localtesting.pleroma.lol/users/lain\" class=\"u-url mention\">@<span>lain</span></a></span></p>",
|
||||
"conversation": "tag:mastodon.example.org,2018-02-12:objectId=20:objectType=Conversation",
|
||||
"id": "http://framapiaf.org/users/admin/statuses/99512778738411822",
|
||||
"id": "https://framapiaf.org/users/admin/statuses/99512778738411822",
|
||||
"inReplyTo": null,
|
||||
"inReplyToAtomUri": null,
|
||||
"published": "2018-02-12T14:08:20Z",
|
||||
|
@ -49,12 +49,12 @@
|
|||
"https://www.w3.org/ns/activitystreams#Public"
|
||||
],
|
||||
"type": "Note",
|
||||
"url": "http://framapiaf.org/@admin/99512778738411822"
|
||||
"url": "https://framapiaf.org/@admin/99512778738411822"
|
||||
},
|
||||
"published": "2018-02-12T14:08:20Z",
|
||||
"signature": {
|
||||
"created": "2018-02-12T14:08:20Z",
|
||||
"creator": "http://framapiaf.org/users/admin#main-key",
|
||||
"creator": "https://framapiaf.org/users/admin#main-key",
|
||||
"signatureValue": "rnNfcopkc6+Ju73P806popcfwrK9wGYHaJVG1/ZvrlEbWVDzaHjkXqj9Q3/xju5l8CSn9tvSgCCtPFqZsFQwn/pFIFUcw7ZWB2xi4bDm3NZ3S4XQ8JRaaX7og5hFxAhWkGhJhAkfxVnOg2hG+w2d/7d7vRVSC1vo5ip4erUaA/PkWusZvPIpxnRWoXaxJsFmVx0gJgjpJkYDyjaXUlp+jmaoseeZ4EPQUWqHLKJ59PRG0mg8j2xAjYH9nQaN14qMRmTGPxY8gfv/CUFcatA+8VJU9KEsJkDAwLVvglydNTLGrxpAJU78a2eaht0foV43XUIZGe3DKiJPgE+UOKGCJw==",
|
||||
"type": "RsaSignature2017"
|
||||
},
|
||||
|
|
47
test/fixtures/mastodon-undo-announce.json
vendored
Normal file
47
test/fixtures/mastodon-undo-announce.json
vendored
Normal file
|
@ -0,0 +1,47 @@
|
|||
{
|
||||
"type": "Undo",
|
||||
"signature": {
|
||||
"type": "RsaSignature2017",
|
||||
"signatureValue": "VU9AmHf3Pus9cWtMG/TOdxr+MRQfPHdTVKBBgFJBXhAlMhxEtcbxsu7zmqBgfIz6u0HpTCi5jRXEMftc228OJf/aBUkr4hyWADgcdmhPQgpibouDLgQf9BmnrPqb2rMbzZyt49GJkQZma8taLh077TTq6OKcnsAAJ1evEKOcRYS4OxBSwh4nI726bOXzZWoNzpTcrnm+llcUEN980sDSAS0uyZdb8AxZdfdG6DJQX4AkUD5qTpfqP/vC1ISirrNphvVhlxjUV9Amr4SYTsLx80vdZe5NjeL5Ir4jTIIQLedpxaDu1M9Q+Jpc0fYByQ2hOwUq8JxEmvHvarKjrq0Oww==",
|
||||
"creator": "http://mastodon.example.org/users/admin#main-key",
|
||||
"created": "2018-05-11T16:23:45Z"
|
||||
},
|
||||
"object": {
|
||||
"type": "Announce",
|
||||
"to": [
|
||||
"http://www.w3.org/ns/activitystreams#Public"
|
||||
],
|
||||
"published": "2018-05-11T16:23:37Z",
|
||||
"object": "http://mastodon.example.org/@admin/99541947525187367",
|
||||
"id": "http://mastodon.example.org/users/admin/statuses/99542391527669785/activity",
|
||||
"cc": [
|
||||
"http://mastodon.example.org/users/admin",
|
||||
"http://mastodon.example.org/users/admin/followers"
|
||||
],
|
||||
"atomUri": "http://mastodon.example.org/users/admin/statuses/99542391527669785/activity",
|
||||
"actor": "http://mastodon.example.org/users/admin"
|
||||
},
|
||||
"id": "http://mastodon.example.org/users/admin#announces/100011594053806179/undo",
|
||||
"actor": "http://mastodon.example.org/users/admin",
|
||||
"@context": [
|
||||
"http://www.w3.org/ns/activitystreams",
|
||||
"http://w3id.org/security/v1",
|
||||
{
|
||||
"toot": "http://joinmastodon.org/ns#",
|
||||
"sensitive": "as:sensitive",
|
||||
"ostatus": "http://ostatus.org#",
|
||||
"movedTo": "as:movedTo",
|
||||
"manuallyApprovesFollowers": "as:manuallyApprovesFollowers",
|
||||
"inReplyToAtomUri": "ostatus:inReplyToAtomUri",
|
||||
"focalPoint": {
|
||||
"@id": "toot:focalPoint",
|
||||
"@container": "@list"
|
||||
},
|
||||
"featured": "toot:featured",
|
||||
"conversation": "ostatus:conversation",
|
||||
"atomUri": "ostatus:atomUri",
|
||||
"Hashtag": "as:Hashtag",
|
||||
"Emoji": "toot:Emoji"
|
||||
}
|
||||
]
|
||||
}
|
34
test/fixtures/mastodon-undo-like.json
vendored
Normal file
34
test/fixtures/mastodon-undo-like.json
vendored
Normal file
|
@ -0,0 +1,34 @@
|
|||
{
|
||||
"type": "Undo",
|
||||
"signature": {
|
||||
"type": "RsaSignature2017",
|
||||
"signatureValue": "fdxMfQSMwbC6wP6sh6neS/vM5879K67yQkHTbiT5Npr5wAac0y6+o3Ij+41tN3rL6wfuGTosSBTHOtta6R4GCOOhCaCSLMZKypnp1VltCzLDoyrZELnYQIC8gpUXVmIycZbREk22qWUe/w7DAFaKK4UscBlHDzeDVcA0K3Se5Sluqi9/Zh+ldAnEzj/rSEPDjrtvf5wGNf3fHxbKSRKFt90JvKK6hS+vxKUhlRFDf6/SMETw+EhwJSNW4d10yMUakqUWsFv4Acq5LW7l+HpYMvlYY1FZhNde1+uonnCyuQDyvzkff8zwtEJmAXC4RivO/VVLa17SmqheJZfI8oluVg==",
|
||||
"creator": "http://mastodon.example.org/users/admin#main-key",
|
||||
"created": "2018-05-19T16:36:58Z"
|
||||
},
|
||||
"object": {
|
||||
"type": "Like",
|
||||
"object": "http://localtesting.pleroma.lol/objects/eb92579d-3417-42a8-8652-2492c2d4f454",
|
||||
"id": "http://mastodon.example.org/users/admin#likes/2",
|
||||
"actor": "http://mastodon.example.org/users/admin"
|
||||
},
|
||||
"nickname": "lain",
|
||||
"id": "http://mastodon.example.org/users/admin#likes/2/undo",
|
||||
"actor": "http://mastodon.example.org/users/admin",
|
||||
"@context": [
|
||||
"https://www.w3.org/ns/activitystreams",
|
||||
"https://w3id.org/security/v1",
|
||||
{
|
||||
"toot": "http://joinmastodon.org/ns#",
|
||||
"sensitive": "as:sensitive",
|
||||
"ostatus": "http://ostatus.org#",
|
||||
"movedTo": "as:movedTo",
|
||||
"manuallyApprovesFollowers": "as:manuallyApprovesFollowers",
|
||||
"inReplyToAtomUri": "ostatus:inReplyToAtomUri",
|
||||
"conversation": "ostatus:conversation",
|
||||
"atomUri": "ostatus:atomUri",
|
||||
"Hashtag": "as:Hashtag",
|
||||
"Emoji": "toot:Emoji"
|
||||
}
|
||||
]
|
||||
}
|
34
test/fixtures/mastodon-unfollow-activity.json
vendored
Normal file
34
test/fixtures/mastodon-unfollow-activity.json
vendored
Normal file
|
@ -0,0 +1,34 @@
|
|||
{
|
||||
"@context":[
|
||||
"https://www.w3.org/ns/activitystreams",
|
||||
"https://w3id.org/security/v1",
|
||||
{
|
||||
"toot":"http://joinmastodon.org/ns#",
|
||||
"sensitive":"as:sensitive",
|
||||
"ostatus":"http://ostatus.org#",
|
||||
"movedTo":"as:movedTo",
|
||||
"manuallyApprovesFollowers":"as:manuallyApprovesFollowers",
|
||||
"inReplyToAtomUri":"ostatus:inReplyToAtomUri",
|
||||
"conversation":"ostatus:conversation",
|
||||
"atomUri":"ostatus:atomUri",
|
||||
"Hashtag":"as:Hashtag",
|
||||
"Emoji":"toot:Emoji"
|
||||
}
|
||||
],
|
||||
"signature":{
|
||||
"type":"RsaSignature2017",
|
||||
"signatureValue":"Kn1/UkAQGJVaXBfWLAHcnwHg8YMAUqlEaBuYLazAG+pz5hqivsyrBmPV186Xzr+B4ZLExA9+SnOoNx/GOz4hBm0kAmukNSILAsUd84tcJ2yT9zc1RKtembK4WiwOw7li0+maeDN0HaB6t+6eTqsCWmtiZpprhXD8V1GGT8yG7X24fQ9oFGn+ng7lasbcCC0988Y1eGqNe7KryxcPuQz57YkDapvtONzk8gyLTkZMV4De93MyRHq6GVjQVIgtiYabQAxrX6Q8C+4P/jQoqdWJHEe+MY5JKyNaT/hMPt2Md1ok9fZQBGHlErk22/zy8bSN19GdG09HmIysBUHRYpBLig==",
|
||||
"creator":"https://social.tcit.fr/users/tcit#main-key",
|
||||
"created":"2018-02-17T13:29:31Z"
|
||||
},
|
||||
"type":"Undo",
|
||||
"object":{
|
||||
"type":"Follow",
|
||||
"object":"http://localtesting.pleroma.lol/users/lain",
|
||||
"nickname":"lain",
|
||||
"id":"https://social.tcit.fr/users/tcit#follows/2",
|
||||
"actor":"https://social.tcit.fr/users/tcit"
|
||||
},
|
||||
"actor":"https://social.tcit.fr/users/tcit",
|
||||
"id": "https://social.tcit.fr/users/tcit#follow/2/undo"
|
||||
}
|
43
test/fixtures/mastodon-update.json
vendored
Normal file
43
test/fixtures/mastodon-update.json
vendored
Normal file
|
@ -0,0 +1,43 @@
|
|||
{
|
||||
"type": "Update",
|
||||
"object": {
|
||||
"url": "http://mastodon.example.org/@gargron",
|
||||
"type": "Person",
|
||||
"summary": "<p>Some bio</p>",
|
||||
"publicKey": {
|
||||
"publicKeyPem": "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA0gs3VnQf6am3R+CeBV4H\nlfI1HZTNRIBHgvFszRZkCERbRgEWMu+P+I6/7GJC5H5jhVQ60z4MmXcyHOGmYMK/\n5XyuHQz7V2Ssu1AxLfRN5Biq1ayb0+DT/E7QxNXDJPqSTnstZ6C7zKH/uAETqg3l\nBonjCQWyds+IYbQYxf5Sp3yhvQ80lMwHML3DaNCMlXWLoOnrOX5/yK5+dedesg2\n/HIvGk+HEt36vm6hoH7bwPuEkgA++ACqwjXRe5Mta7i3eilHxFaF8XIrJFARV0t\nqOu4GID/jG6oA+swIWndGrtR2QRJIt9QIBFfK3HG5M0koZbY1eTqwNFRHFL3xaD\nUQIDAQAB\n-----END PUBLIC KEY-----\n",
|
||||
"owner": "http://mastodon.example.org/users/gargron",
|
||||
"id": "http://mastodon.example.org/users/gargron#main-key"
|
||||
},
|
||||
"preferredUsername": "gargron",
|
||||
"outbox": "http://mastodon.example.org/users/gargron/outbox",
|
||||
"name": "gargle",
|
||||
"manuallyApprovesFollowers": false,
|
||||
"inbox": "http://mastodon.example.org/users/gargron/inbox",
|
||||
"id": "http://mastodon.example.org/users/gargron",
|
||||
"following": "http://mastodon.example.org/users/gargron/following",
|
||||
"followers": "http://mastodon.example.org/users/gargron/followers",
|
||||
"endpoints": {
|
||||
"sharedInbox": "http://mastodon.example.org/inbox"
|
||||
},
|
||||
"icon":{"type":"Image","mediaType":"image/jpeg","url":"https://cd.niu.moe/accounts/avatars/000/033/323/original/fd7f8ae0b3ffedc9.jpeg"},"image":{"type":"Image","mediaType":"image/png","url":"https://cd.niu.moe/accounts/headers/000/033/323/original/850b3448fa5fd477.png"}
|
||||
},
|
||||
"id": "http://mastodon.example.org/users/gargron#updates/1519563538",
|
||||
"actor": "http://mastodon.example.org/users/gargron",
|
||||
"@context": [
|
||||
"https://www.w3.org/ns/activitystreams",
|
||||
"https://w3id.org/security/v1",
|
||||
{
|
||||
"toot": "http://joinmastodon.org/ns#",
|
||||
"sensitive": "as:sensitive",
|
||||
"ostatus": "http://ostatus.org#",
|
||||
"movedTo": "as:movedTo",
|
||||
"manuallyApprovesFollowers": "as:manuallyApprovesFollowers",
|
||||
"inReplyToAtomUri": "ostatus:inReplyToAtomUri",
|
||||
"conversation": "ostatus:conversation",
|
||||
"atomUri": "ostatus:atomUri",
|
||||
"Hashtag": "as:Hashtag",
|
||||
"Emoji": "toot:Emoji"
|
||||
}
|
||||
]
|
||||
}
|
65
test/fixtures/prismo-url-map.json
vendored
Normal file
65
test/fixtures/prismo-url-map.json
vendored
Normal file
|
@ -0,0 +1,65 @@
|
|||
{
|
||||
"id": "https://prismo.news/posts/83#Create",
|
||||
"type": "Create",
|
||||
"actor": [
|
||||
{
|
||||
"type": "Person",
|
||||
"id": "https://prismo.news/@mxb"
|
||||
}
|
||||
],
|
||||
"to": [
|
||||
"https://www.w3.org/ns/activitystreams#Public"
|
||||
],
|
||||
"object": {
|
||||
"id": "https://prismo.news/posts/83",
|
||||
"type": "Article",
|
||||
"name": "Introducing: Federated follows!",
|
||||
"published": "2018-11-01T07:10:05Z",
|
||||
"content": "We are more than thrilled to announce that Prismo now supports federated follows! It means you ca...",
|
||||
"url": {
|
||||
"type": "Link",
|
||||
"mimeType": "text/html",
|
||||
"href": "https://prismo.news/posts/83"
|
||||
},
|
||||
"votes": 12,
|
||||
"attributedTo": [
|
||||
{
|
||||
"type": "Person",
|
||||
"id": "https://prismo.news/@mxb"
|
||||
}
|
||||
],
|
||||
"to": [
|
||||
"https://www.w3.org/ns/activitystreams#Public"
|
||||
],
|
||||
"tags": [
|
||||
{
|
||||
"type": "Hashtag",
|
||||
"href": "https://prismo.news/tags/prismo",
|
||||
"name": "#prismo"
|
||||
},
|
||||
{
|
||||
"type": "Hashtag",
|
||||
"href": "https://prismo.news/tags/prismodev",
|
||||
"name": "#prismodev"
|
||||
},
|
||||
{
|
||||
"type": "Hashtag",
|
||||
"href": "https://prismo.news/tags/meta",
|
||||
"name": "#meta"
|
||||
}
|
||||
],
|
||||
"@context": [
|
||||
"https://www.w3.org/ns/activitystreams",
|
||||
"https://w3id.org/security/v1",
|
||||
{
|
||||
"Hashtag": "as:Hashtag"
|
||||
},
|
||||
{
|
||||
"votes": {
|
||||
"@id": "as:votes",
|
||||
"@type": "@id"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
118
test/fixtures/vcr_cassettes/activity_pub/fetch_reply_to_framatube.json
vendored
Normal file
118
test/fixtures/vcr_cassettes/activity_pub/fetch_reply_to_framatube.json
vendored
Normal file
File diff suppressed because one or more lines are too long
156
test/fixtures/vcr_cassettes/activity_pub/fetch_social_tcit_fr_reply.json
vendored
Normal file
156
test/fixtures/vcr_cassettes/activity_pub/fetch_social_tcit_fr_reply.json
vendored
Normal file
|
@ -0,0 +1,156 @@
|
|||
[
|
||||
{
|
||||
"request": {
|
||||
"body": "",
|
||||
"headers": {
|
||||
"Accept": "application/activity+json"
|
||||
},
|
||||
"method": "get",
|
||||
"options": {
|
||||
"follow_redirect": "true",
|
||||
"recv_timeout": 20000,
|
||||
"connect_timeout": 10000
|
||||
},
|
||||
"request_body": "",
|
||||
"url": "https://social.tcit.fr/users/tcit/statuses/101160654038714030"
|
||||
},
|
||||
"response": {
|
||||
"binary": false,
|
||||
"body": "{\"@context\":[\"https://www.w3.org/ns/activitystreams\",\"https://w3id.org/security/v1\",{\"manuallyApprovesFollowers\":\"as:manuallyApprovesFollowers\",\"sensitive\":\"as:sensitive\",\"movedTo\":{\"@id\":\"as:movedTo\",\"@type\":\"@id\"},\"Hashtag\":\"as:Hashtag\",\"ostatus\":\"http://ostatus.org#\",\"atomUri\":\"ostatus:atomUri\",\"inReplyToAtomUri\":\"ostatus:inReplyToAtomUri\",\"conversation\":\"ostatus:conversation\",\"toot\":\"http://joinmastodon.org/ns#\",\"Emoji\":\"toot:Emoji\",\"focalPoint\":{\"@container\":\"@list\",\"@id\":\"toot:focalPoint\"},\"featured\":{\"@id\":\"toot:featured\",\"@type\":\"@id\"},\"schema\":\"http://schema.org#\",\"PropertyValue\":\"schema:PropertyValue\",\"value\":\"schema:value\"}],\"id\":\"https://social.tcit.fr/users/tcit/statuses/101160654038714030\",\"type\":\"Note\",\"summary\":null,\"inReplyTo\":\"https://social.tcit.fr/users/tcit/statuses/101160195754333819\",\"published\":\"2018-11-30T14:44:41Z\",\"url\":\"https://social.tcit.fr/@tcit/101160654038714030\",\"attributedTo\":\"https://social.tcit.fr/users/tcit\",\"to\":[\"https://www.w3.org/ns/activitystreams#Public\"],\"cc\":[\"https://social.tcit.fr/users/tcit/followers\"],\"sensitive\":false,\"atomUri\":\"https://social.tcit.fr/users/tcit/statuses/101160654038714030\",\"inReplyToAtomUri\":\"https://social.tcit.fr/users/tcit/statuses/101160195754333819\",\"conversation\":\"tag:social.tcit.fr,2018-11-30:objectId=3642669:objectType=Conversation\",\"content\":\"\\u003cp\\u003eOkay so that\\u0026apos;s it.\\u003cbr /\\u003e\\u003ca href=\\\"https://tcit.frama.io/group-uri-scheme/draft-tcit-group-uri-01.txt\\\" rel=\\\"nofollow noopener\\\" target=\\\"_blank\\\"\\u003e\\u003cspan class=\\\"invisible\\\"\\u003ehttps://\\u003c/span\\u003e\\u003cspan class=\\\"ellipsis\\\"\\u003etcit.frama.io/group-uri-scheme\\u003c/span\\u003e\\u003cspan class=\\\"invisible\\\"\\u003e/draft-tcit-group-uri-01.txt\\u003c/span\\u003e\\u003c/a\\u003e\\u003c/p\\u003e\",\"contentMap\":{\"fr\":\"\\u003cp\\u003eOkay so that\\u0026apos;s it.\\u003cbr /\\u003e\\u003ca href=\\\"https://tcit.frama.io/group-uri-scheme/draft-tcit-group-uri-01.txt\\\" rel=\\\"nofollow noopener\\\" target=\\\"_blank\\\"\\u003e\\u003cspan class=\\\"invisible\\\"\\u003ehttps://\\u003c/span\\u003e\\u003cspan class=\\\"ellipsis\\\"\\u003etcit.frama.io/group-uri-scheme\\u003c/span\\u003e\\u003cspan class=\\\"invisible\\\"\\u003e/draft-tcit-group-uri-01.txt\\u003c/span\\u003e\\u003c/a\\u003e\\u003c/p\\u003e\"},\"attachment\":[],\"tag\":[]}",
|
||||
"headers": {
|
||||
"Date": "Tue, 04 Dec 2018 13:59:58 GMT",
|
||||
"Content-Type": "application/activity+json; charset=utf-8",
|
||||
"Transfer-Encoding": "chunked",
|
||||
"Connection": "keep-alive",
|
||||
"Server": "Mastodon",
|
||||
"X-Frame-Options": "DENY",
|
||||
"X-Content-Type-Options": "nosniff",
|
||||
"X-XSS-Protection": "1; mode=block",
|
||||
"Link": "<https://social.tcit.fr/users/tcit/updates/15979.atom>; rel=\"alternate\"; type=\"application/atom+xml\", <https://social.tcit.fr/users/tcit/statuses/101160654038714030>; rel=\"alternate\"; type=\"application/activity+json\"",
|
||||
"Vary": "Accept,Accept-Encoding",
|
||||
"Cache-Control": "max-age=180, public",
|
||||
"ETag": "W/\"619af54f65bbb41538e430b8247c36d7\"",
|
||||
"X-Request-Id": "84a750de-2dfa-4a36-976e-bae0b0ac4821",
|
||||
"X-Runtime": "0.056423",
|
||||
"X-Cached": "MISS"
|
||||
},
|
||||
"status_code": 200,
|
||||
"type": "ok"
|
||||
}
|
||||
},
|
||||
{
|
||||
"request": {
|
||||
"body": "",
|
||||
"headers": {
|
||||
"Accept": "application/activity+json"
|
||||
},
|
||||
"method": "get",
|
||||
"options": {
|
||||
"follow_redirect": "true"
|
||||
},
|
||||
"request_body": "",
|
||||
"url": "https://social.tcit.fr/users/tcit"
|
||||
},
|
||||
"response": {
|
||||
"binary": false,
|
||||
"body": "{\"@context\":[\"https://www.w3.org/ns/activitystreams\",\"https://w3id.org/security/v1\",{\"manuallyApprovesFollowers\":\"as:manuallyApprovesFollowers\",\"sensitive\":\"as:sensitive\",\"movedTo\":{\"@id\":\"as:movedTo\",\"@type\":\"@id\"},\"Hashtag\":\"as:Hashtag\",\"ostatus\":\"http://ostatus.org#\",\"atomUri\":\"ostatus:atomUri\",\"inReplyToAtomUri\":\"ostatus:inReplyToAtomUri\",\"conversation\":\"ostatus:conversation\",\"toot\":\"http://joinmastodon.org/ns#\",\"Emoji\":\"toot:Emoji\",\"focalPoint\":{\"@container\":\"@list\",\"@id\":\"toot:focalPoint\"},\"featured\":{\"@id\":\"toot:featured\",\"@type\":\"@id\"},\"schema\":\"http://schema.org#\",\"PropertyValue\":\"schema:PropertyValue\",\"value\":\"schema:value\"}],\"id\":\"https://social.tcit.fr/users/tcit\",\"type\":\"Person\",\"following\":\"https://social.tcit.fr/users/tcit/following\",\"followers\":\"https://social.tcit.fr/users/tcit/followers\",\"inbox\":\"https://social.tcit.fr/users/tcit/inbox\",\"outbox\":\"https://social.tcit.fr/users/tcit/outbox\",\"featured\":\"https://social.tcit.fr/users/tcit/collections/featured\",\"preferredUsername\":\"tcit\",\"name\":\"🦄 Thomas Citharel\",\"summary\":\"\\u003cp\\u003eHoping to make people\\u0026apos;s life better with free software at \\u003cspan class=\\\"h-card\\\"\\u003e\\u003ca href=\\\"https://framapiaf.org/@Framasoft\\\" class=\\\"u-url mention\\\"\\u003e@\\u003cspan\\u003eFramasoft\\u003c/span\\u003e\\u003c/a\\u003e\\u003c/span\\u003e.\\u003c/p\\u003e\",\"url\":\"https://social.tcit.fr/@tcit\",\"manuallyApprovesFollowers\":false,\"publicKey\":{\"id\":\"https://social.tcit.fr/users/tcit#main-key\",\"owner\":\"https://social.tcit.fr/users/tcit\",\"publicKeyPem\":\"-----BEGIN PUBLIC KEY-----\\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEApXwYMUdFg3XUd+bGsh8C\\nyiMRGpRGAWuCdM5pDWx5uM4pW2pM3xbHbcI21j9h8BmlAiPg6hbZD73KGly2N8Rt\\n5iIS0I+l6i8kA1JCCdlAaDTRd41RKMggZDoQvjVZQtsyE1VzMeU2kbqqTFN6ew7H\\nvbd6O0NhixoKoZ5f3jwuBDZoT0p1TAcaMdmG8oqHD97isizkDnRn8cOBA6wtI+xb\\n5xP2zxZMsLpTDZLiKU8XcPKZCw4OfQfmDmKkHtrFb77jCAQj/s/FxjVnvxRwmfhN\\nnWy0D+LUV/g63nHh/b5zXIeV92QZLvDYbgbezmzUzv9UeA1s70GGbaDqCIy85gw9\\n+wIDAQAB\\n-----END PUBLIC KEY-----\\n\"},\"tag\":[],\"attachment\":[{\"type\":\"PropertyValue\",\"name\":\"Works at\",\"value\":\"\\u003cspan class=\\\"h-card\\\"\\u003e\\u003ca href=\\\"https://framapiaf.org/@Framasoft\\\" class=\\\"u-url mention\\\"\\u003e@\\u003cspan\\u003eFramasoft\\u003c/span\\u003e\\u003c/a\\u003e\\u003c/span\\u003e\"},{\"type\":\"PropertyValue\",\"name\":\"Pronouns\",\"value\":\"He/Him\"},{\"type\":\"PropertyValue\",\"name\":\"Work Account\",\"value\":\"\\u003ca href=\\\"https://framapiaf.org/@tcit\\\" rel=\\\"me nofollow noopener\\\" target=\\\"_blank\\\"\\u003e\\u003cspan class=\\\"invisible\\\"\\u003ehttps://\\u003c/span\\u003e\\u003cspan class=\\\"\\\"\\u003eframapiaf.org/@tcit\\u003c/span\\u003e\\u003cspan class=\\\"invisible\\\"\\u003e\\u003c/span\\u003e\\u003c/a\\u003e\"},{\"type\":\"PropertyValue\",\"name\":\"Site\",\"value\":\"\\u003ca href=\\\"https://tcit.fr\\\" rel=\\\"me nofollow noopener\\\" target=\\\"_blank\\\"\\u003e\\u003cspan class=\\\"invisible\\\"\\u003ehttps://\\u003c/span\\u003e\\u003cspan class=\\\"\\\"\\u003etcit.fr\\u003c/span\\u003e\\u003cspan class=\\\"invisible\\\"\\u003e\\u003c/span\\u003e\\u003c/a\\u003e\"}],\"endpoints\":{\"sharedInbox\":\"https://social.tcit.fr/inbox\"},\"icon\":{\"type\":\"Image\",\"mediaType\":\"image/jpeg\",\"url\":\"https://media.social.tcit.fr/mastodontcit/accounts/avatars/000/000/001/original/a28c50ce5f2b13fd.jpg\"},\"image\":{\"type\":\"Image\",\"mediaType\":\"image/jpeg\",\"url\":\"https://media.social.tcit.fr/mastodontcit/accounts/headers/000/000/001/original/4d1ab77c20265ee9.jpg\"}}",
|
||||
"headers": {
|
||||
"Date": "Tue, 04 Dec 2018 13:59:58 GMT",
|
||||
"Content-Type": "application/activity+json; charset=utf-8",
|
||||
"Transfer-Encoding": "chunked",
|
||||
"Connection": "keep-alive",
|
||||
"Server": "Mastodon",
|
||||
"X-Frame-Options": "DENY",
|
||||
"X-Content-Type-Options": "nosniff",
|
||||
"X-XSS-Protection": "1; mode=block",
|
||||
"Link": "<https://social.tcit.fr/.well-known/webfinger?resource=acct%3Atcit%40social.tcit.fr>; rel=\"lrdd\"; type=\"application/xrd+xml\", <https://social.tcit.fr/users/tcit.atom>; rel=\"alternate\"; type=\"application/atom+xml\", <https://social.tcit.fr/users/tcit>; rel=\"alternate\"; type=\"application/activity+json\"",
|
||||
"Vary": "Accept,Accept-Encoding",
|
||||
"Cache-Control": "max-age=180, public",
|
||||
"ETag": "W/\"039b9e136f81a55656fb1f38a23640d2\"",
|
||||
"X-Request-Id": "91a50164-aa87-45c9-8100-786b9c74fbe0",
|
||||
"X-Runtime": "0.039489",
|
||||
"X-Cached": "MISS"
|
||||
},
|
||||
"status_code": 200,
|
||||
"type": "ok"
|
||||
}
|
||||
},
|
||||
{
|
||||
"request": {
|
||||
"body": "",
|
||||
"headers": {
|
||||
"Accept": "application/activity+json"
|
||||
},
|
||||
"method": "get",
|
||||
"options": {
|
||||
"follow_redirect": "true",
|
||||
"recv_timeout": 20000,
|
||||
"connect_timeout": 10000
|
||||
},
|
||||
"request_body": "",
|
||||
"url": "https://social.tcit.fr/users/tcit/statuses/101160195754333819"
|
||||
},
|
||||
"response": {
|
||||
"binary": false,
|
||||
"body": "{\"@context\":[\"https://www.w3.org/ns/activitystreams\",\"https://w3id.org/security/v1\",{\"manuallyApprovesFollowers\":\"as:manuallyApprovesFollowers\",\"sensitive\":\"as:sensitive\",\"movedTo\":{\"@id\":\"as:movedTo\",\"@type\":\"@id\"},\"Hashtag\":\"as:Hashtag\",\"ostatus\":\"http://ostatus.org#\",\"atomUri\":\"ostatus:atomUri\",\"inReplyToAtomUri\":\"ostatus:inReplyToAtomUri\",\"conversation\":\"ostatus:conversation\",\"toot\":\"http://joinmastodon.org/ns#\",\"Emoji\":\"toot:Emoji\",\"focalPoint\":{\"@container\":\"@list\",\"@id\":\"toot:focalPoint\"},\"featured\":{\"@id\":\"toot:featured\",\"@type\":\"@id\"},\"schema\":\"http://schema.org#\",\"PropertyValue\":\"schema:PropertyValue\",\"value\":\"schema:value\"}],\"id\":\"https://social.tcit.fr/users/tcit/statuses/101160195754333819\",\"type\":\"Note\",\"summary\":null,\"inReplyTo\":\"https://social.tcit.fr/users/tcit/statuses/101159468934977010\",\"published\":\"2018-11-30T12:48:08Z\",\"url\":\"https://social.tcit.fr/@tcit/101160195754333819\",\"attributedTo\":\"https://social.tcit.fr/users/tcit\",\"to\":[\"https://www.w3.org/ns/activitystreams#Public\"],\"cc\":[\"https://social.tcit.fr/users/tcit/followers\"],\"sensitive\":false,\"atomUri\":\"https://social.tcit.fr/users/tcit/statuses/101160195754333819\",\"inReplyToAtomUri\":\"https://social.tcit.fr/users/tcit/statuses/101159468934977010\",\"conversation\":\"tag:social.tcit.fr,2018-11-30:objectId=3642669:objectType=Conversation\",\"content\":\"\\u003cp\\u003eOkay so YOLO.\\u003c/p\\u003e\",\"contentMap\":{\"fr\":\"\\u003cp\\u003eOkay so YOLO.\\u003c/p\\u003e\"},\"attachment\":[{\"type\":\"Document\",\"mediaType\":\"image/png\",\"url\":\"https://media.social.tcit.fr/mastodontcit/media_attachments/files/000/718/393/original/b56706a78fd355b8.png\",\"name\":\"Start of a 'group' URI RFC\"}],\"tag\":[]}",
|
||||
"headers": {
|
||||
"Date": "Tue, 04 Dec 2018 13:59:58 GMT",
|
||||
"Content-Type": "application/activity+json; charset=utf-8",
|
||||
"Transfer-Encoding": "chunked",
|
||||
"Connection": "keep-alive",
|
||||
"Server": "Mastodon",
|
||||
"X-Frame-Options": "DENY",
|
||||
"X-Content-Type-Options": "nosniff",
|
||||
"X-XSS-Protection": "1; mode=block",
|
||||
"Link": "<https://social.tcit.fr/users/tcit/updates/15967.atom>; rel=\"alternate\"; type=\"application/atom+xml\", <https://social.tcit.fr/users/tcit/statuses/101160195754333819>; rel=\"alternate\"; type=\"application/activity+json\"",
|
||||
"Vary": "Accept,Accept-Encoding",
|
||||
"Cache-Control": "max-age=180, public",
|
||||
"ETag": "W/\"e878d9ab8dfa31073b27b4661046b911\"",
|
||||
"X-Request-Id": "b598d538-88b5-4d7a-867c-d78b85ee5677",
|
||||
"X-Runtime": "0.078823",
|
||||
"X-Cached": "MISS"
|
||||
},
|
||||
"status_code": 200,
|
||||
"type": "ok"
|
||||
}
|
||||
},
|
||||
{
|
||||
"request": {
|
||||
"body": "",
|
||||
"headers": {
|
||||
"Accept": "application/activity+json"
|
||||
},
|
||||
"method": "get",
|
||||
"options": {
|
||||
"follow_redirect": "true",
|
||||
"recv_timeout": 20000,
|
||||
"connect_timeout": 10000
|
||||
},
|
||||
"request_body": "",
|
||||
"url": "https://social.tcit.fr/users/tcit/statuses/101159468934977010"
|
||||
},
|
||||
"response": {
|
||||
"binary": false,
|
||||
"body": "{\"@context\":[\"https://www.w3.org/ns/activitystreams\",\"https://w3id.org/security/v1\",{\"manuallyApprovesFollowers\":\"as:manuallyApprovesFollowers\",\"sensitive\":\"as:sensitive\",\"movedTo\":{\"@id\":\"as:movedTo\",\"@type\":\"@id\"},\"Hashtag\":\"as:Hashtag\",\"ostatus\":\"http://ostatus.org#\",\"atomUri\":\"ostatus:atomUri\",\"inReplyToAtomUri\":\"ostatus:inReplyToAtomUri\",\"conversation\":\"ostatus:conversation\",\"toot\":\"http://joinmastodon.org/ns#\",\"Emoji\":\"toot:Emoji\",\"focalPoint\":{\"@container\":\"@list\",\"@id\":\"toot:focalPoint\"},\"featured\":{\"@id\":\"toot:featured\",\"@type\":\"@id\"},\"schema\":\"http://schema.org#\",\"PropertyValue\":\"schema:PropertyValue\",\"value\":\"schema:value\"}],\"id\":\"https://social.tcit.fr/users/tcit/statuses/101159468934977010\",\"type\":\"Note\",\"summary\":null,\"inReplyTo\":null,\"published\":\"2018-11-30T09:43:18Z\",\"url\":\"https://social.tcit.fr/@tcit/101159468934977010\",\"attributedTo\":\"https://social.tcit.fr/users/tcit\",\"to\":[\"https://www.w3.org/ns/activitystreams#Public\"],\"cc\":[\"https://social.tcit.fr/users/tcit/followers\"],\"sensitive\":false,\"atomUri\":\"https://social.tcit.fr/users/tcit/statuses/101159468934977010\",\"inReplyToAtomUri\":null,\"conversation\":\"tag:social.tcit.fr,2018-11-30:objectId=3642669:objectType=Conversation\",\"content\":\"\\u003cp\\u003eApart from PeerTube, which software that implements ActivityPub does have a group functionnality?\\u003cbr /\\u003eIt\\u0026apos;s to discuss about a Webfinger group: query prefix, similar to the acct: query prefix.\\u003c/p\\u003e\",\"contentMap\":{\"en\":\"\\u003cp\\u003eApart from PeerTube, which software that implements ActivityPub does have a group functionnality?\\u003cbr /\\u003eIt\\u0026apos;s to discuss about a Webfinger group: query prefix, similar to the acct: query prefix.\\u003c/p\\u003e\"},\"attachment\":[],\"tag\":[]}",
|
||||
"headers": {
|
||||
"Date": "Tue, 04 Dec 2018 13:59:58 GMT",
|
||||
"Content-Type": "application/activity+json; charset=utf-8",
|
||||
"Transfer-Encoding": "chunked",
|
||||
"Connection": "keep-alive",
|
||||
"Server": "Mastodon",
|
||||
"X-Frame-Options": "DENY",
|
||||
"X-Content-Type-Options": "nosniff",
|
||||
"X-XSS-Protection": "1; mode=block",
|
||||
"Link": "<https://social.tcit.fr/users/tcit/updates/15941.atom>; rel=\"alternate\"; type=\"application/atom+xml\", <https://social.tcit.fr/users/tcit/statuses/101159468934977010>; rel=\"alternate\"; type=\"application/activity+json\"",
|
||||
"Vary": "Accept,Accept-Encoding",
|
||||
"Cache-Control": "max-age=180, public",
|
||||
"ETag": "W/\"a29cc605a433ed904736da57572038d3\"",
|
||||
"X-Request-Id": "18488387-c5a3-40db-8c9e-5a3a067401a9",
|
||||
"X-Runtime": "0.054993",
|
||||
"X-Cached": "MISS"
|
||||
},
|
||||
"status_code": 200,
|
||||
"type": "ok"
|
||||
}
|
||||
}
|
||||
]
|
|
@ -10,13 +10,13 @@
|
|||
"follow_redirect": "true"
|
||||
},
|
||||
"request_body": "",
|
||||
"url": "http://framapiaf.org/users/admin"
|
||||
"url": "https://framapiaf.org/users/admin"
|
||||
},
|
||||
"response": {
|
||||
"binary": false,
|
||||
"body": "{\"@context\":[\"https://www.w3.org/ns/activitystreams\",\"https://w3id.org/security/v1\",{\"manuallyApprovesFollowers\":\"as:manuallyApprovesFollowers\",\"sensitive\":\"as:sensitive\",\"movedTo\":{\"@id\":\"as:movedTo\",\"@type\":\"@id\"},\"Hashtag\":\"as:Hashtag\",\"ostatus\":\"http://ostatus.org#\",\"atomUri\":\"ostatus:atomUri\",\"inReplyToAtomUri\":\"ostatus:inReplyToAtomUri\",\"conversation\":\"ostatus:conversation\",\"toot\":\"http://joinmastodon.org/ns#\",\"Emoji\":\"toot:Emoji\",\"focalPoint\":{\"@container\":\"@list\",\"@id\":\"toot:focalPoint\"},\"featured\":{\"@id\":\"toot:featured\",\"@type\":\"@id\"},\"schema\":\"http://schema.org#\",\"PropertyValue\":\"schema:PropertyValue\",\"value\":\"schema:value\"}],\"id\":\"https://framapiaf.org/users/admin\",\"type\":\"Person\",\"following\":\"https://framapiaf.org/users/admin/following\",\"followers\":\"https://framapiaf.org/users/admin/followers\",\"inbox\":\"https://framapiaf.org/users/admin/inbox\",\"outbox\":\"https://framapiaf.org/users/admin/outbox\",\"featured\":\"https://framapiaf.org/users/admin/collections/featured\",\"preferredUsername\":\"admin\",\"name\":\"\",\"summary\":\"\\u003cp\\u003e\\u003c/p\\u003e\",\"url\":\"https://framapiaf.org/@admin\",\"manuallyApprovesFollowers\":false,\"publicKey\":{\"id\":\"https://framapiaf.org/users/admin#main-key\",\"owner\":\"https://framapiaf.org/users/admin\",\"publicKeyPem\":\"-----BEGIN PUBLIC KEY-----\\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAyHaU/AZ5dWtSxZXkPa89\\nDUQ4z+JQHGGUG/xkGuq0v8P6qJfQqtHPBO5vH0IQJqluXWQS96gqTwjZnYevcpNA\\nveYv0K25DWszx5Ehz6JX2/sSvu2rNUcQ3YZvSjdo/Yy1u5Fuc5lLmvw8uFzXYekD\\nWovTMOnp4mIKpVEm/G/v4w8jvFEKw88h743vwaEIim88GEQItMxzGAV6zSqV1DWO\\nLxtoRsinslJYfAG46ex4YUATFveWvOUeWk5W1sEa5f3c0moaTmBM/PAAo8vLxhlw\\nJhsHihsCH+BcXKVMjW8OCqYYqISMxEifUBX63HcJt78ELHpOuc1c2eG59PomtTjQ\\nywIDAQAB\\n-----END PUBLIC KEY-----\\n\"},\"tag\":[],\"attachment\":[],\"endpoints\":{\"sharedInbox\":\"https://framapiaf.org/inbox\"}}",
|
||||
"body": "{\"@context\":[\"https://www.w3.org/ns/activitystreams\",\"https://w3id.org/security/v1\",{\"manuallyApprovesFollowers\":\"as:manuallyApprovesFollowers\",\"sensitive\":\"as:sensitive\",\"movedTo\":{\"@id\":\"as:movedTo\",\"@type\":\"@id\"},\"Hashtag\":\"as:Hashtag\",\"ostatus\":\"http://ostatus.org#\",\"atomUri\":\"ostatus:atomUri\",\"inReplyToAtomUri\":\"ostatus:inReplyToAtomUri\",\"conversation\":\"ostatus:conversation\",\"toot\":\"http://joinmastodon.org/ns#\",\"Emoji\":\"toot:Emoji\",\"focalPoint\":{\"@container\":\"@list\",\"@id\":\"toot:focalPoint\"},\"featured\":{\"@id\":\"toot:featured\",\"@type\":\"@id\"},\"schema\":\"http://schema.org#\",\"PropertyValue\":\"schema:PropertyValue\",\"value\":\"schema:value\"}],\"id\":\"https://framapiaf.org/users/admin\",\"type\":\"Service\",\"following\":\"https://framapiaf.org/users/admin/following\",\"followers\":\"https://framapiaf.org/users/admin/followers\",\"inbox\":\"https://framapiaf.org/users/admin/inbox\",\"outbox\":\"https://framapiaf.org/users/admin/outbox\",\"featured\":\"https://framapiaf.org/users/admin/collections/featured\",\"preferredUsername\":\"admin\",\"name\":\"Administrateur\",\"summary\":\"\\u003cp\\u003eJe ne suis qu\\u0026apos;un compte inutile. Merci nous de contacter via \\u003ca href=\\\"https://contact.framasoft.org/\\\" rel=\\\"nofollow noopener\\\" target=\\\"_blank\\\"\\u003e\\u003cspan class=\\\"invisible\\\"\\u003ehttps://\\u003c/span\\u003e\\u003cspan class=\\\"\\\"\\u003econtact.framasoft.org/\\u003c/span\\u003e\\u003cspan class=\\\"invisible\\\"\\u003e\\u003c/span\\u003e\\u003c/a\\u003e\\u003c/p\\u003e\",\"url\":\"https://framapiaf.org/@admin\",\"manuallyApprovesFollowers\":false,\"publicKey\":{\"id\":\"https://framapiaf.org/users/admin#main-key\",\"owner\":\"https://framapiaf.org/users/admin\",\"publicKeyPem\":\"-----BEGIN PUBLIC KEY-----\\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAyHaU/AZ5dWtSxZXkPa89\\nDUQ4z+JQHGGUG/xkGuq0v8P6qJfQqtHPBO5vH0IQJqluXWQS96gqTwjZnYevcpNA\\nveYv0K25DWszx5Ehz6JX2/sSvu2rNUcQ3YZvSjdo/Yy1u5Fuc5lLmvw8uFzXYekD\\nWovTMOnp4mIKpVEm/G/v4w8jvFEKw88h743vwaEIim88GEQItMxzGAV6zSqV1DWO\\nLxtoRsinslJYfAG46ex4YUATFveWvOUeWk5W1sEa5f3c0moaTmBM/PAAo8vLxhlw\\nJhsHihsCH+BcXKVMjW8OCqYYqISMxEifUBX63HcJt78ELHpOuc1c2eG59PomtTjQ\\nywIDAQAB\\n-----END PUBLIC KEY-----\\n\"},\"tag\":[],\"attachment\":[{\"type\":\"PropertyValue\",\"name\":\"News\",\"value\":\"\\u003cspan class=\\\"h-card\\\"\\u003e\\u003ca href=\\\"https://framapiaf.org/@Framasoft\\\" class=\\\"u-url mention\\\"\\u003e@\\u003cspan\\u003eFramasoft\\u003c/span\\u003e\\u003c/a\\u003e\\u003c/span\\u003e\"},{\"type\":\"PropertyValue\",\"name\":\"Support\",\"value\":\"\\u003ca href=\\\"https://contact.framasoft.org/\\\" rel=\\\"me nofollow noopener\\\" target=\\\"_blank\\\"\\u003e\\u003cspan class=\\\"invisible\\\"\\u003ehttps://\\u003c/span\\u003e\\u003cspan class=\\\"\\\"\\u003econtact.framasoft.org/\\u003c/span\\u003e\\u003cspan class=\\\"invisible\\\"\\u003e\\u003c/span\\u003e\\u003c/a\\u003e\"},{\"type\":\"PropertyValue\",\"name\":\"Soutenir\",\"value\":\"\\u003ca href=\\\"https://soutenir.framasoft.org/\\\" rel=\\\"me nofollow noopener\\\" target=\\\"_blank\\\"\\u003e\\u003cspan class=\\\"invisible\\\"\\u003ehttps://\\u003c/span\\u003e\\u003cspan class=\\\"\\\"\\u003esoutenir.framasoft.org/\\u003c/span\\u003e\\u003cspan class=\\\"invisible\\\"\\u003e\\u003c/span\\u003e\\u003c/a\\u003e\"},{\"type\":\"PropertyValue\",\"name\":\"Site\",\"value\":\"\\u003ca href=\\\"https://framasoft.org/\\\" rel=\\\"me nofollow noopener\\\" target=\\\"_blank\\\"\\u003e\\u003cspan class=\\\"invisible\\\"\\u003ehttps://\\u003c/span\\u003e\\u003cspan class=\\\"\\\"\\u003eframasoft.org/\\u003c/span\\u003e\\u003cspan class=\\\"invisible\\\"\\u003e\\u003c/span\\u003e\\u003c/a\\u003e\"}],\"endpoints\":{\"sharedInbox\":\"https://framapiaf.org/inbox\"},\"icon\":{\"type\":\"Image\",\"mediaType\":\"image/jpeg\",\"url\":\"https://framapiaf.org/system/accounts/avatars/000/000/002/original/85fbb27ad5e3cf71.jpg?1544008249\"},\"image\":{\"type\":\"Image\",\"mediaType\":\"image/jpeg\",\"url\":\"https://framapiaf.org/system/accounts/headers/000/000/002/original/6aba75f1ab1ab6de.jpg?1544008352\"}}",
|
||||
"headers": {
|
||||
"Date": "Tue, 13 Nov 2018 11:22:02 GMT",
|
||||
"Date": "Wed, 05 Dec 2018 11:59:22 GMT",
|
||||
"Content-Type": "application/activity+json; charset=utf-8",
|
||||
"Transfer-Encoding": "chunked",
|
||||
"Connection": "keep-alive",
|
||||
|
@ -27,9 +27,9 @@
|
|||
"Link": "<https://framapiaf.org/.well-known/webfinger?resource=acct%3Aadmin%40framapiaf.org>; rel=\"lrdd\"; type=\"application/xrd+xml\", <https://framapiaf.org/users/admin.atom>; rel=\"alternate\"; type=\"application/atom+xml\", <https://framapiaf.org/users/admin>; rel=\"alternate\"; type=\"application/activity+json\"",
|
||||
"Vary": "Accept,Accept-Encoding",
|
||||
"Cache-Control": "max-age=180, public",
|
||||
"ETag": "W/\"82f88eaea909e6c3f20f908ad16e4b54\"",
|
||||
"X-Request-Id": "cef423e2-d143-422f-94b0-03450f70a32d",
|
||||
"X-Runtime": "0.005097",
|
||||
"ETag": "W/\"dff68e9e1738cc89f28a977f39715b36\"",
|
||||
"X-Request-Id": "1f2f4f2b-567f-48b0-a3f9-fef153cfa793",
|
||||
"X-Runtime": "0.013117",
|
||||
"Strict-Transport-Security": "max-age=31536000; includeSubDomains; preload",
|
||||
"Referrer-Policy": "same-origin"
|
||||
},
|
||||
|
|
|
@ -98,6 +98,9 @@ defmodule Mobilizon.AddressesTest do
|
|||
test "process_geom/2 with invalid data returns nil" do
|
||||
attrs = %{"type" => :point, "data" => %{"latitude" => nil, "longitude" => nil}}
|
||||
assert {:error, "Latitude and longitude must be numbers"} = Addresses.process_geom(attrs)
|
||||
|
||||
attrs = %{"type" => :not_valid, "data" => %{"latitude" => nil, "longitude" => nil}}
|
||||
assert {:error, :invalid_type} == Addresses.process_geom(attrs)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -415,6 +415,12 @@ defmodule Mobilizon.EventsTest do
|
|||
assert [session.id] == Events.list_sessions() |> Enum.map(& &1.id)
|
||||
end
|
||||
|
||||
test "list_sessions_for_event/1 returns sessions for an event" do
|
||||
event = insert(:event)
|
||||
session = insert(:session, event: event)
|
||||
assert Events.list_sessions_for_event(event) |> Enum.map(& &1.id) == [session.id]
|
||||
end
|
||||
|
||||
test "get_session!/1 returns the session with given id" do
|
||||
session = insert(:session)
|
||||
assert Events.get_session!(session.id).id == session.id
|
||||
|
@ -485,6 +491,13 @@ defmodule Mobilizon.EventsTest do
|
|||
assert [track.id] == Events.list_tracks() |> Enum.map(& &1.id)
|
||||
end
|
||||
|
||||
test "list_sessions_for_track/1 returns sessions for an event" do
|
||||
event = insert(:event)
|
||||
track = insert(:track, event: event)
|
||||
session = insert(:session, track: track, event: event)
|
||||
assert Events.list_sessions_for_track(track) |> Enum.map(& &1.id) == [session.id]
|
||||
end
|
||||
|
||||
test "get_track!/1 returns the track with given id" do
|
||||
track = insert(:track)
|
||||
assert Events.get_track!(track.id).id == track.id
|
||||
|
|
|
@ -78,7 +78,30 @@ defmodule Mobilizon.Service.Activitypub.ActivitypubTest do
|
|||
"https://social.tcit.fr/users/tcit/statuses/99908779444618462"
|
||||
)
|
||||
|
||||
assert object == object_again
|
||||
assert object.id == object_again.id
|
||||
end
|
||||
end
|
||||
|
||||
test "object reply by url" do
|
||||
use_cassette "activity_pub/fetch_social_tcit_fr_reply" do
|
||||
{:ok, object} =
|
||||
ActivityPub.fetch_object_from_url(
|
||||
"https://social.tcit.fr/users/tcit/statuses/101160654038714030"
|
||||
)
|
||||
|
||||
assert object.in_reply_to_comment.url ==
|
||||
"https://social.tcit.fr/users/tcit/statuses/101160195754333819"
|
||||
end
|
||||
end
|
||||
|
||||
test "object reply to a video by url" do
|
||||
use_cassette "activity_pub/fetch_reply_to_framatube" do
|
||||
{:ok, object} =
|
||||
ActivityPub.fetch_object_from_url(
|
||||
"https://framapiaf.org/@troisiemelobe/101156292125317651"
|
||||
)
|
||||
|
||||
assert object.in_reply_to_comment == nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
894
test/mobilizon/service/activitypub/transmogrifier_test.exs
Normal file
894
test/mobilizon/service/activitypub/transmogrifier_test.exs
Normal file
|
@ -0,0 +1,894 @@
|
|||
defmodule Mobilizon.Service.Activitypub.TransmogrifierTest do
|
||||
use Mobilizon.DataCase
|
||||
|
||||
import Mobilizon.Factory
|
||||
|
||||
alias Mobilizon.Activity
|
||||
alias Mobilizon.Actors
|
||||
alias Mobilizon.Actors.Actor
|
||||
alias Mobilizon.Events
|
||||
alias Mobilizon.Events.Comment
|
||||
alias Mobilizon.Service.ActivityPub.Utils
|
||||
alias Mobilizon.Service.ActivityPub.Transmogrifier
|
||||
use ExVCR.Mock, adapter: ExVCR.Adapter.Hackney
|
||||
|
||||
setup_all do
|
||||
HTTPoison.start()
|
||||
end
|
||||
|
||||
describe "handle_incoming" do
|
||||
# test "it ignores an incoming comment if we already have it" do
|
||||
# comment = insert(:comment)
|
||||
|
||||
# activity = %{
|
||||
# "type" => "Create",
|
||||
# "to" => ["https://www.w3.org/ns/activitystreams#Public"],
|
||||
# "actor" => comment.actor.url,
|
||||
# "object" => Utils.make_comment_data(comment)
|
||||
# }
|
||||
|
||||
# data =
|
||||
# File.read!("test/fixtures/mastodon-post-activity.json")
|
||||
# |> Poison.decode!()
|
||||
# |> Map.put("object", activity["object"])
|
||||
|
||||
# {:ok, returned_activity} = Transmogrifier.handle_incoming(data)
|
||||
|
||||
# assert activity == returned_activity.data
|
||||
# end
|
||||
|
||||
# test "it fetches replied-to activities if we don't have them" do
|
||||
# data =
|
||||
# File.read!("test/fixtures/mastodon-post-activity.json")
|
||||
# |> Poison.decode!()
|
||||
|
||||
# object =
|
||||
# data["object"]
|
||||
# |> Map.put("inReplyTo", "https://shitposter.club/notice/2827873")
|
||||
|
||||
# data =
|
||||
# data
|
||||
# |> Map.put("object", object)
|
||||
|
||||
# {:ok, returned_activity} = Transmogrifier.handle_incoming(data)
|
||||
|
||||
# assert activity =
|
||||
# Activity.get_create_activity_by_object_ap_id(
|
||||
# "tag:shitposter.club,2017-05-05:noticeId=2827873:objectType=comment"
|
||||
# )
|
||||
|
||||
# assert returned_activity.data["object"]["inReplyToAtomUri"] ==
|
||||
# "https://shitposter.club/notice/2827873"
|
||||
|
||||
# assert returned_activity.data["object"]["inReplyToStatusId"] == activity.id
|
||||
# end
|
||||
|
||||
test "it works for incoming notices" do
|
||||
data = File.read!("test/fixtures/mastodon-post-activity.json") |> Poison.decode!()
|
||||
|
||||
{:ok, %Mobilizon.Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
|
||||
|
||||
assert data["id"] == "https://framapiaf.org/users/admin/statuses/99512778738411822/activity"
|
||||
|
||||
assert data["to"] == ["https://www.w3.org/ns/activitystreams#Public"]
|
||||
|
||||
assert data["cc"] == [
|
||||
"https://framapiaf.org/users/admin/followers",
|
||||
"http://mobilizon.com/@tcit"
|
||||
]
|
||||
|
||||
assert data["actor"] == "https://framapiaf.org/users/admin"
|
||||
|
||||
object = data["object"]
|
||||
assert object["id"] == "https://framapiaf.org/users/admin/statuses/99512778738411822"
|
||||
|
||||
assert object["to"] == ["https://www.w3.org/ns/activitystreams#Public"]
|
||||
|
||||
assert object["cc"] == [
|
||||
"https://framapiaf.org/users/admin/followers",
|
||||
"http://localtesting.pleroma.lol/users/lain"
|
||||
]
|
||||
|
||||
assert object["actor"] == "https://framapiaf.org/users/admin"
|
||||
assert object["attributedTo"] == "https://framapiaf.org/users/admin"
|
||||
|
||||
assert object["sensitive"] == true
|
||||
|
||||
{:ok, %Actor{}} = Actors.get_actor_by_url(object["actor"])
|
||||
end
|
||||
|
||||
test "it works for incoming notices with hashtags" do
|
||||
data = File.read!("test/fixtures/mastodon-post-activity-hashtag.json") |> Poison.decode!()
|
||||
|
||||
{:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
|
||||
assert Enum.at(data["object"]["tag"], 2) == "moo"
|
||||
end
|
||||
|
||||
# test "it works for incoming notices with contentMap" do
|
||||
# data =
|
||||
# File.read!("test/fixtures/mastodon-post-activity-contentmap.json") |> Poison.decode!()
|
||||
|
||||
# {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
|
||||
|
||||
# assert data["object"]["content"] ==
|
||||
# "<p><span class=\"h-card\"><a href=\"http://localtesting.pleroma.lol/users/lain\" class=\"u-url mention\">@<span>lain</span></a></span></p>"
|
||||
# end
|
||||
|
||||
# test "it works for incoming notices with to/cc not being an array (kroeg)" do
|
||||
# data = File.read!("test/fixtures/kroeg-post-activity.json") |> Poison.decode!()
|
||||
|
||||
# {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
|
||||
|
||||
# assert data["object"]["content"] ==
|
||||
# "<p>henlo from my Psion netBook</p><p>message sent from my Psion netBook</p>"
|
||||
# end
|
||||
|
||||
# test "it works for incoming announces with actor being inlined (kroeg)" do
|
||||
# data = File.read!("test/fixtures/kroeg-announce-with-inline-actor.json") |> Poison.decode!()
|
||||
|
||||
# {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
|
||||
|
||||
# assert data["actor"] == "https://puckipedia.com/"
|
||||
# end
|
||||
|
||||
# test "it works for incoming notices with tag not being an array (kroeg)" do
|
||||
# data = File.read!("test/fixtures/kroeg-array-less-emoji.json") |> Poison.decode!()
|
||||
|
||||
# {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
|
||||
|
||||
# assert data["object"]["emoji"] == %{
|
||||
# "icon_e_smile" => "https://puckipedia.com/forum/images/smilies/icon_e_smile.png"
|
||||
# }
|
||||
|
||||
# data = File.read!("test/fixtures/kroeg-array-less-hashtag.json") |> Poison.decode!()
|
||||
|
||||
# {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
|
||||
|
||||
# assert "test" in data["object"]["tag"]
|
||||
# end
|
||||
|
||||
test "it works for incoming notices with url not being a string (prismo)" do
|
||||
data = File.read!("test/fixtures/prismo-url-map.json") |> Poison.decode!()
|
||||
|
||||
assert {:error, :not_supported} == Transmogrifier.handle_incoming(data)
|
||||
# Pages are not supported
|
||||
# {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
|
||||
|
||||
# assert data["object"]["url"] == "https://prismo.news/posts/83"
|
||||
end
|
||||
|
||||
test "it works for incoming follow requests" do
|
||||
actor = insert(:actor)
|
||||
|
||||
data =
|
||||
File.read!("test/fixtures/mastodon-follow-activity.json")
|
||||
|> Poison.decode!()
|
||||
|> Map.put("object", actor.url)
|
||||
|
||||
{:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
|
||||
|
||||
assert data["actor"] == "https://social.tcit.fr/users/tcit"
|
||||
assert data["type"] == "Follow"
|
||||
assert data["id"] == "https://social.tcit.fr/users/tcit#follows/2"
|
||||
|
||||
actor = Actors.get_actor_with_everything!(actor.id)
|
||||
assert Actor.following?(Actors.get_actor_by_url!(data["actor"], true), actor)
|
||||
end
|
||||
|
||||
# test "it works for incoming follow requests from hubzilla" do
|
||||
# user = insert(:user)
|
||||
|
||||
# data =
|
||||
# File.read!("test/fixtures/hubzilla-follow-activity.json")
|
||||
# |> Poison.decode!()
|
||||
# |> Map.put("object", user.ap_id)
|
||||
# |> Utils.normalize_params()
|
||||
|
||||
# {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
|
||||
|
||||
# assert data["actor"] == "https://hubzilla.example.org/channel/kaniini"
|
||||
# assert data["type"] == "Follow"
|
||||
# assert data["id"] == "https://hubzilla.example.org/channel/kaniini#follows/2"
|
||||
# assert User.following?(User.get_by_ap_id(data["actor"]), user)
|
||||
# end
|
||||
|
||||
# test "it works for incoming likes" do
|
||||
# %Comment{url: url} = insert(:comment)
|
||||
|
||||
# data =
|
||||
# File.read!("test/fixtures/mastodon-like.json")
|
||||
# |> Poison.decode!()
|
||||
# |> Map.put("object", url)
|
||||
|
||||
# {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
|
||||
|
||||
# assert data["actor"] == "http://mastodon.example.org/users/admin"
|
||||
# assert data["type"] == "Like"
|
||||
# assert data["id"] == "http://mastodon.example.org/users/admin#likes/2"
|
||||
# assert data["object"] == url
|
||||
# end
|
||||
|
||||
# test "it returns an error for incoming unlikes wihout a like activity" do
|
||||
# %Comment{url: url} = insert(:comment)
|
||||
|
||||
# data =
|
||||
# File.read!("test/fixtures/mastodon-undo-like.json")
|
||||
# |> Poison.decode!()
|
||||
# |> Map.put("object", url)
|
||||
|
||||
# assert Transmogrifier.handle_incoming(data) == {:error, :not_supported}
|
||||
# end
|
||||
|
||||
# test "it works for incoming unlikes with an existing like activity" do
|
||||
# comment = insert(:comment)
|
||||
|
||||
# like_data =
|
||||
# File.read!("test/fixtures/mastodon-like.json")
|
||||
# |> Poison.decode!()
|
||||
# |> Map.put("object", comment.url)
|
||||
|
||||
# {:ok, %Activity{data: like_data, local: false}} = Transmogrifier.handle_incoming(like_data)
|
||||
|
||||
# data =
|
||||
# File.read!("test/fixtures/mastodon-undo-like.json")
|
||||
# |> Poison.decode!()
|
||||
# |> Map.put("object", like_data)
|
||||
# |> Map.put("actor", like_data["actor"])
|
||||
|
||||
# {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
|
||||
|
||||
# assert data["actor"] == "http://mastodon.example.org/users/admin"
|
||||
# assert data["type"] == "Undo"
|
||||
# assert data["id"] == "http://mastodon.example.org/users/admin#likes/2/undo"
|
||||
# assert data["object"]["id"] == "http://mastodon.example.org/users/admin#likes/2"
|
||||
# end
|
||||
|
||||
# test "it works for incoming announces" do
|
||||
# data = File.read!("test/fixtures/mastodon-announce.json") |> Poison.decode!()
|
||||
|
||||
# {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
|
||||
|
||||
# assert data["actor"] == "https://social.tcit.fr/users/tcit"
|
||||
# assert data["type"] == "Announce"
|
||||
|
||||
# assert data["id"] ==
|
||||
# "https://social.tcit.fr/users/tcit/statuses/101188891162897047/activity"
|
||||
|
||||
# assert data["object"] ==
|
||||
# "https://social.tcit.fr/users/tcit/statuses/101188891162897047"
|
||||
|
||||
# assert %Comment{} = Events.get_comment_from_url(data["object"])
|
||||
# end
|
||||
|
||||
# test "it works for incoming announces with an existing activity" do
|
||||
# comment = insert(:comment)
|
||||
|
||||
# data =
|
||||
# File.read!("test/fixtures/mastodon-announce.json")
|
||||
# |> Poison.decode!()
|
||||
# |> Map.put("object", comment.url)
|
||||
|
||||
# {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
|
||||
|
||||
# assert data["actor"] == "https://social.tcit.fr/users/tcit"
|
||||
# assert data["type"] == "Announce"
|
||||
|
||||
# assert data["id"] ==
|
||||
# "https://social.tcit.fr/users/tcit/statuses/101188891162897047/activity"
|
||||
|
||||
# assert data["object"] == comment.url
|
||||
|
||||
# # assert Activity.get_create_activity_by_object_ap_id(data["object"]).id == activity.id
|
||||
# end
|
||||
|
||||
test "it works for incoming update activities" do
|
||||
data = File.read!("test/fixtures/mastodon-post-activity.json") |> Poison.decode!()
|
||||
|
||||
{:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
|
||||
update_data = File.read!("test/fixtures/mastodon-update.json") |> Poison.decode!()
|
||||
|
||||
object =
|
||||
update_data["object"]
|
||||
|> Map.put("actor", data["actor"])
|
||||
|> Map.put("id", data["actor"])
|
||||
|
||||
update_data =
|
||||
update_data
|
||||
|> Map.put("actor", data["actor"])
|
||||
|> Map.put("object", object)
|
||||
|
||||
{:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(update_data)
|
||||
|
||||
{:ok, %Actor{} = actor} = Actors.get_actor_by_url(data["actor"])
|
||||
assert actor.name == "gargle"
|
||||
|
||||
assert actor.avatar_url ==
|
||||
"https://cd.niu.moe/accounts/avatars/000/033/323/original/fd7f8ae0b3ffedc9.jpeg"
|
||||
|
||||
assert actor.banner_url ==
|
||||
"https://cd.niu.moe/accounts/headers/000/033/323/original/850b3448fa5fd477.png"
|
||||
|
||||
assert actor.summary == "<p>Some bio</p>"
|
||||
end
|
||||
|
||||
# test "it works for incoming update activities which lock the account" do
|
||||
# data = File.read!("test/fixtures/mastodon-post-activity.json") |> Poison.decode!()
|
||||
|
||||
# {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
|
||||
# update_data = File.read!("test/fixtures/mastodon-update.json") |> Poison.decode!()
|
||||
|
||||
# object =
|
||||
# update_data["object"]
|
||||
# |> Map.put("actor", data["actor"])
|
||||
# |> Map.put("id", data["actor"])
|
||||
# |> Map.put("manuallyApprovesFollowers", true)
|
||||
|
||||
# update_data =
|
||||
# update_data
|
||||
# |> Map.put("actor", data["actor"])
|
||||
# |> Map.put("object", object)
|
||||
|
||||
# {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(update_data)
|
||||
|
||||
# user = User.get_cached_by_ap_id(data["actor"])
|
||||
# assert user.info["locked"] == true
|
||||
# end
|
||||
|
||||
test "it works for incoming deletes" do
|
||||
%Actor{url: actor_url} = actor = insert(:actor)
|
||||
%Comment{url: comment_url} = insert(:comment, actor: actor)
|
||||
|
||||
data =
|
||||
File.read!("test/fixtures/mastodon-delete.json")
|
||||
|> Poison.decode!()
|
||||
|
||||
object =
|
||||
data["object"]
|
||||
|> Map.put("id", comment_url)
|
||||
|
||||
data =
|
||||
data
|
||||
|> Map.put("object", object)
|
||||
|> Map.put("actor", actor_url)
|
||||
|
||||
assert Events.get_comment_from_url(comment_url)
|
||||
|
||||
{:ok, %Activity{local: false}} = Transmogrifier.handle_incoming(data)
|
||||
|
||||
refute Events.get_comment_from_url(comment_url)
|
||||
end
|
||||
|
||||
# TODO : make me ASAP
|
||||
# test "it fails for incoming deletes with spoofed origin" do
|
||||
# activity = insert(:note_activity)
|
||||
|
||||
# data =
|
||||
# File.read!("test/fixtures/mastodon-delete.json")
|
||||
# |> Poison.decode!()
|
||||
|
||||
# object =
|
||||
# data["object"]
|
||||
# |> Map.put("id", activity.data["object"]["id"])
|
||||
|
||||
# data =
|
||||
# data
|
||||
# |> Map.put("object", object)
|
||||
|
||||
# :error = Transmogrifier.handle_incoming(data)
|
||||
|
||||
# assert Repo.get(Activity, activity.id)
|
||||
# end
|
||||
|
||||
# test "it works for incoming unannounces with an existing notice" do
|
||||
# comment = insert(:comment)
|
||||
|
||||
# announce_data =
|
||||
# File.read!("test/fixtures/mastodon-announce.json")
|
||||
# |> Poison.decode!()
|
||||
# |> Map.put("object", comment.url)
|
||||
|
||||
# {:ok, %Activity{data: announce_data, local: false}} =
|
||||
# Transmogrifier.handle_incoming(announce_data)
|
||||
|
||||
# data =
|
||||
# File.read!("test/fixtures/mastodon-undo-announce.json")
|
||||
# |> Poison.decode!()
|
||||
# |> Map.put("object", announce_data)
|
||||
# |> Map.put("actor", announce_data["actor"])
|
||||
|
||||
# {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
|
||||
|
||||
# assert data["type"] == "Undo"
|
||||
# assert data["object"]["type"] == "Announce"
|
||||
# assert data["object"]["object"] == comment.url
|
||||
|
||||
# assert data["object"]["id"] ==
|
||||
# "http://mastodon.example.org/users/admin/statuses/99542391527669785/activity"
|
||||
# end
|
||||
|
||||
test "it works for incomming unfollows with an existing follow" do
|
||||
actor = insert(:actor)
|
||||
|
||||
follow_data =
|
||||
File.read!("test/fixtures/mastodon-follow-activity.json")
|
||||
|> Poison.decode!()
|
||||
|> Map.put("object", actor.url)
|
||||
|
||||
{:ok, %Activity{data: _, local: false}} = Transmogrifier.handle_incoming(follow_data)
|
||||
|
||||
data =
|
||||
File.read!("test/fixtures/mastodon-unfollow-activity.json")
|
||||
|> Poison.decode!()
|
||||
|> Map.put("object", follow_data)
|
||||
|
||||
{:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
|
||||
|
||||
assert data["type"] == "Undo"
|
||||
assert data["object"]["type"] == "Follow"
|
||||
assert data["object"]["object"] == actor.url
|
||||
assert data["actor"] == "https://social.tcit.fr/users/tcit"
|
||||
|
||||
{:ok, followed} = Actors.get_actor_by_url(data["actor"])
|
||||
refute Actor.following?(followed, actor)
|
||||
end
|
||||
|
||||
# test "it works for incoming blocks" do
|
||||
# user = insert(:user)
|
||||
|
||||
# data =
|
||||
# File.read!("test/fixtures/mastodon-block-activity.json")
|
||||
# |> Poison.decode!()
|
||||
# |> Map.put("object", user.ap_id)
|
||||
|
||||
# {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
|
||||
|
||||
# assert data["type"] == "Block"
|
||||
# assert data["object"] == user.ap_id
|
||||
# assert data["actor"] == "http://mastodon.example.org/users/admin"
|
||||
|
||||
# blocker = User.get_by_ap_id(data["actor"])
|
||||
|
||||
# assert User.blocks?(blocker, user)
|
||||
# end
|
||||
|
||||
# test "incoming blocks successfully tear down any follow relationship" do
|
||||
# blocker = insert(:user)
|
||||
# blocked = insert(:user)
|
||||
|
||||
# data =
|
||||
# File.read!("test/fixtures/mastodon-block-activity.json")
|
||||
# |> Poison.decode!()
|
||||
# |> Map.put("object", blocked.ap_id)
|
||||
# |> Map.put("actor", blocker.ap_id)
|
||||
|
||||
# {:ok, blocker} = User.follow(blocker, blocked)
|
||||
# {:ok, blocked} = User.follow(blocked, blocker)
|
||||
|
||||
# assert User.following?(blocker, blocked)
|
||||
# assert User.following?(blocked, blocker)
|
||||
|
||||
# {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
|
||||
|
||||
# assert data["type"] == "Block"
|
||||
# assert data["object"] == blocked.ap_id
|
||||
# assert data["actor"] == blocker.ap_id
|
||||
|
||||
# blocker = User.get_by_ap_id(data["actor"])
|
||||
# blocked = User.get_by_ap_id(data["object"])
|
||||
|
||||
# assert User.blocks?(blocker, blocked)
|
||||
|
||||
# refute User.following?(blocker, blocked)
|
||||
# refute User.following?(blocked, blocker)
|
||||
# end
|
||||
|
||||
# test "it works for incoming unblocks with an existing block" do
|
||||
# user = insert(:user)
|
||||
|
||||
# block_data =
|
||||
# File.read!("test/fixtures/mastodon-block-activity.json")
|
||||
# |> Poison.decode!()
|
||||
# |> Map.put("object", user.ap_id)
|
||||
|
||||
# {:ok, %Activity{data: _, local: false}} = Transmogrifier.handle_incoming(block_data)
|
||||
|
||||
# data =
|
||||
# File.read!("test/fixtures/mastodon-unblock-activity.json")
|
||||
# |> Poison.decode!()
|
||||
# |> Map.put("object", block_data)
|
||||
|
||||
# {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
|
||||
# assert data["type"] == "Undo"
|
||||
# assert data["object"]["type"] == "Block"
|
||||
# assert data["object"]["object"] == user.ap_id
|
||||
# assert data["actor"] == "http://mastodon.example.org/users/admin"
|
||||
|
||||
# blocker = User.get_by_ap_id(data["actor"])
|
||||
|
||||
# refute User.blocks?(blocker, user)
|
||||
# end
|
||||
|
||||
# test "it works for incoming accepts which were pre-accepted" do
|
||||
# follower = insert(:user)
|
||||
# followed = insert(:user)
|
||||
|
||||
# {:ok, follower} = User.follow(follower, followed)
|
||||
# assert User.following?(follower, followed) == true
|
||||
|
||||
# {:ok, follow_activity} = ActivityPub.follow(follower, followed)
|
||||
|
||||
# accept_data =
|
||||
# File.read!("test/fixtures/mastodon-accept-activity.json")
|
||||
# |> Poison.decode!()
|
||||
# |> Map.put("actor", followed.ap_id)
|
||||
|
||||
# object =
|
||||
# accept_data["object"]
|
||||
# |> Map.put("actor", follower.ap_id)
|
||||
# |> Map.put("id", follow_activity.data["id"])
|
||||
|
||||
# accept_data = Map.put(accept_data, "object", object)
|
||||
|
||||
# {:ok, activity} = Transmogrifier.handle_incoming(accept_data)
|
||||
# refute activity.local
|
||||
|
||||
# assert activity.data["object"] == follow_activity.data["id"]
|
||||
|
||||
# follower = Repo.get(User, follower.id)
|
||||
|
||||
# assert User.following?(follower, followed) == true
|
||||
# end
|
||||
|
||||
# test "it works for incoming accepts which were orphaned" do
|
||||
# follower = insert(:user)
|
||||
# followed = insert(:user, %{info: %{"locked" => true}})
|
||||
|
||||
# {:ok, follow_activity} = ActivityPub.follow(follower, followed)
|
||||
|
||||
# accept_data =
|
||||
# File.read!("test/fixtures/mastodon-accept-activity.json")
|
||||
# |> Poison.decode!()
|
||||
# |> Map.put("actor", followed.ap_id)
|
||||
|
||||
# accept_data =
|
||||
# Map.put(accept_data, "object", Map.put(accept_data["object"], "actor", follower.ap_id))
|
||||
|
||||
# {:ok, activity} = Transmogrifier.handle_incoming(accept_data)
|
||||
# assert activity.data["object"] == follow_activity.data["id"]
|
||||
|
||||
# follower = Repo.get(User, follower.id)
|
||||
|
||||
# assert User.following?(follower, followed) == true
|
||||
# end
|
||||
|
||||
# test "it works for incoming accepts which are referenced by IRI only" do
|
||||
# follower = insert(:user)
|
||||
# followed = insert(:user, %{info: %{"locked" => true}})
|
||||
|
||||
# {:ok, follow_activity} = ActivityPub.follow(follower, followed)
|
||||
|
||||
# accept_data =
|
||||
# File.read!("test/fixtures/mastodon-accept-activity.json")
|
||||
# |> Poison.decode!()
|
||||
# |> Map.put("actor", followed.ap_id)
|
||||
# |> Map.put("object", follow_activity.data["id"])
|
||||
|
||||
# {:ok, activity} = Transmogrifier.handle_incoming(accept_data)
|
||||
# assert activity.data["object"] == follow_activity.data["id"]
|
||||
|
||||
# follower = Repo.get(User, follower.id)
|
||||
|
||||
# assert User.following?(follower, followed) == true
|
||||
# end
|
||||
|
||||
# test "it fails for incoming accepts which cannot be correlated" do
|
||||
# follower = insert(:user)
|
||||
# followed = insert(:user, %{info: %{"locked" => true}})
|
||||
|
||||
# accept_data =
|
||||
# File.read!("test/fixtures/mastodon-accept-activity.json")
|
||||
# |> Poison.decode!()
|
||||
# |> Map.put("actor", followed.ap_id)
|
||||
|
||||
# accept_data =
|
||||
# Map.put(accept_data, "object", Map.put(accept_data["object"], "actor", follower.ap_id))
|
||||
|
||||
# :error = Transmogrifier.handle_incoming(accept_data)
|
||||
|
||||
# follower = Repo.get(User, follower.id)
|
||||
|
||||
# refute User.following?(follower, followed) == true
|
||||
# end
|
||||
|
||||
# test "it fails for incoming rejects which cannot be correlated" do
|
||||
# follower = insert(:user)
|
||||
# followed = insert(:user, %{info: %{"locked" => true}})
|
||||
|
||||
# accept_data =
|
||||
# File.read!("test/fixtures/mastodon-reject-activity.json")
|
||||
# |> Poison.decode!()
|
||||
# |> Map.put("actor", followed.ap_id)
|
||||
|
||||
# accept_data =
|
||||
# Map.put(accept_data, "object", Map.put(accept_data["object"], "actor", follower.ap_id))
|
||||
|
||||
# :error = Transmogrifier.handle_incoming(accept_data)
|
||||
|
||||
# follower = Repo.get(User, follower.id)
|
||||
|
||||
# refute User.following?(follower, followed) == true
|
||||
# end
|
||||
|
||||
# test "it works for incoming rejects which are orphaned" do
|
||||
# follower = insert(:user)
|
||||
# followed = insert(:user, %{info: %{"locked" => true}})
|
||||
|
||||
# {:ok, follower} = User.follow(follower, followed)
|
||||
# {:ok, _follow_activity} = ActivityPub.follow(follower, followed)
|
||||
|
||||
# assert User.following?(follower, followed) == true
|
||||
|
||||
# reject_data =
|
||||
# File.read!("test/fixtures/mastodon-reject-activity.json")
|
||||
# |> Poison.decode!()
|
||||
# |> Map.put("actor", followed.ap_id)
|
||||
|
||||
# reject_data =
|
||||
# Map.put(reject_data, "object", Map.put(reject_data["object"], "actor", follower.ap_id))
|
||||
|
||||
# {:ok, activity} = Transmogrifier.handle_incoming(reject_data)
|
||||
# refute activity.local
|
||||
|
||||
# follower = Repo.get(User, follower.id)
|
||||
|
||||
# assert User.following?(follower, followed) == false
|
||||
# end
|
||||
|
||||
# test "it works for incoming rejects which are referenced by IRI only" do
|
||||
# follower = insert(:user)
|
||||
# followed = insert(:user, %{info: %{"locked" => true}})
|
||||
|
||||
# {:ok, follower} = User.follow(follower, followed)
|
||||
# {:ok, follow_activity} = ActivityPub.follow(follower, followed)
|
||||
|
||||
# assert User.following?(follower, followed) == true
|
||||
|
||||
# reject_data =
|
||||
# File.read!("test/fixtures/mastodon-reject-activity.json")
|
||||
# |> Poison.decode!()
|
||||
# |> Map.put("actor", followed.ap_id)
|
||||
# |> Map.put("object", follow_activity.data["id"])
|
||||
|
||||
# {:ok, %Activity{data: _}} = Transmogrifier.handle_incoming(reject_data)
|
||||
|
||||
# follower = Repo.get(User, follower.id)
|
||||
|
||||
# assert User.following?(follower, followed) == false
|
||||
# end
|
||||
|
||||
# test "it rejects activities without a valid ID" do
|
||||
# user = insert(:user)
|
||||
|
||||
# data =
|
||||
# File.read!("test/fixtures/mastodon-follow-activity.json")
|
||||
# |> Poison.decode!()
|
||||
# |> Map.put("object", user.ap_id)
|
||||
# |> Map.put("id", "")
|
||||
|
||||
# :error = Transmogrifier.handle_incoming(data)
|
||||
# end
|
||||
end
|
||||
|
||||
describe "prepare outgoing" do
|
||||
test "it turns mentions into tags" do
|
||||
actor = insert(:actor)
|
||||
other_actor = insert(:actor)
|
||||
|
||||
{:ok, activity} =
|
||||
MobilizonWeb.API.Comments.create_comment(
|
||||
actor.preferred_username,
|
||||
"hey, @#{other_actor.preferred_username}, how are ya? #2hu"
|
||||
)
|
||||
|
||||
{:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
|
||||
object = modified["object"]
|
||||
|
||||
expected_mention = %{
|
||||
"href" => other_actor.url,
|
||||
"name" => "@#{other_actor.preferred_username}",
|
||||
"type" => "Mention"
|
||||
}
|
||||
|
||||
expected_tag = %{
|
||||
"href" => MobilizonWeb.Endpoint.url() <> "/tags/2hu",
|
||||
"type" => "Hashtag",
|
||||
"name" => "#2hu"
|
||||
}
|
||||
|
||||
assert Enum.member?(object["tag"], expected_tag)
|
||||
assert Enum.member?(object["tag"], expected_mention)
|
||||
end
|
||||
|
||||
# test "it adds the sensitive property" do
|
||||
# user = insert(:user)
|
||||
|
||||
# {:ok, activity} = CommonAPI.post(user, %{"status" => "#nsfw hey"})
|
||||
# {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
|
||||
|
||||
# assert modified["object"]["sensitive"]
|
||||
# end
|
||||
|
||||
test "it adds the json-ld context and the conversation property" do
|
||||
actor = insert(:actor)
|
||||
|
||||
{:ok, activity} = MobilizonWeb.API.Comments.create_comment(actor.preferred_username, "hey")
|
||||
{:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
|
||||
|
||||
assert modified["@context"] ==
|
||||
Mobilizon.Service.ActivityPub.Utils.make_json_ld_header()["@context"]
|
||||
end
|
||||
|
||||
test "it sets the 'attributedTo' property to the actor of the object if it doesn't have one" do
|
||||
actor = insert(:actor)
|
||||
|
||||
{:ok, activity} = MobilizonWeb.API.Comments.create_comment(actor.preferred_username, "hey")
|
||||
{:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
|
||||
|
||||
assert modified["object"]["actor"] == modified["object"]["attributedTo"]
|
||||
end
|
||||
|
||||
test "it strips internal hashtag data" do
|
||||
actor = insert(:actor)
|
||||
|
||||
{:ok, activity} = MobilizonWeb.API.Comments.create_comment(actor.preferred_username, "#2hu")
|
||||
|
||||
expected_tag = %{
|
||||
"href" => MobilizonWeb.Endpoint.url() <> "/tags/2hu",
|
||||
"type" => "Hashtag",
|
||||
"name" => "#2hu"
|
||||
}
|
||||
|
||||
{:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
|
||||
|
||||
assert modified["object"]["tag"] == [expected_tag]
|
||||
end
|
||||
|
||||
test "it strips internal fields" do
|
||||
actor = insert(:actor)
|
||||
|
||||
{:ok, activity} = MobilizonWeb.API.Comments.create_comment(actor.preferred_username, "#2hu")
|
||||
|
||||
{:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
|
||||
|
||||
# TODO : When and if custom emoji are implemented, this should be 2
|
||||
assert length(modified["object"]["tag"]) == 1
|
||||
|
||||
assert is_nil(modified["object"]["emoji"])
|
||||
assert is_nil(modified["object"]["likes"])
|
||||
assert is_nil(modified["object"]["like_count"])
|
||||
assert is_nil(modified["object"]["announcements"])
|
||||
assert is_nil(modified["object"]["announcement_count"])
|
||||
assert is_nil(modified["object"]["context_id"])
|
||||
end
|
||||
|
||||
# describe "actor rewriting" do
|
||||
# test "it fixes the actor URL property to be a proper URI" do
|
||||
# data = %{
|
||||
# "url" => %{"href" => "http://example.com"}
|
||||
# }
|
||||
|
||||
# rewritten = Transmogrifier.maybe_fix_user_object(data)
|
||||
# assert rewritten["url"] == "http://example.com"
|
||||
# end
|
||||
# end
|
||||
|
||||
# describe "actor origin containment" do
|
||||
# test "it rejects objects with a bogus origin" do
|
||||
# {:error, _} = ActivityPub.fetch_object_from_id("https://info.pleroma.site/activity.json")
|
||||
# end
|
||||
|
||||
# test "it rejects activities which reference objects with bogus origins" do
|
||||
# data = %{
|
||||
# "@context" => "https://www.w3.org/ns/activitystreams",
|
||||
# "id" => "http://mastodon.example.org/users/admin/activities/1234",
|
||||
# "actor" => "http://mastodon.example.org/users/admin",
|
||||
# "to" => ["https://www.w3.org/ns/activitystreams#Public"],
|
||||
# "object" => "https://info.pleroma.site/activity.json",
|
||||
# "type" => "Announce"
|
||||
# }
|
||||
|
||||
# :error = Transmogrifier.handle_incoming(data)
|
||||
# end
|
||||
|
||||
# test "it rejects objects when attributedTo is wrong (variant 1)" do
|
||||
# {:error, _} = ActivityPub.fetch_object_from_id("https://info.pleroma.site/activity2.json")
|
||||
# end
|
||||
|
||||
# test "it rejects activities which reference objects that have an incorrect attribution (variant 1)" do
|
||||
# data = %{
|
||||
# "@context" => "https://www.w3.org/ns/activitystreams",
|
||||
# "id" => "http://mastodon.example.org/users/admin/activities/1234",
|
||||
# "actor" => "http://mastodon.example.org/users/admin",
|
||||
# "to" => ["https://www.w3.org/ns/activitystreams#Public"],
|
||||
# "object" => "https://info.pleroma.site/activity2.json",
|
||||
# "type" => "Announce"
|
||||
# }
|
||||
|
||||
# :error = Transmogrifier.handle_incoming(data)
|
||||
# end
|
||||
|
||||
# test "it rejects objects when attributedTo is wrong (variant 2)" do
|
||||
# {:error, _} = ActivityPub.fetch_object_from_id("https://info.pleroma.site/activity3.json")
|
||||
# end
|
||||
|
||||
# test "it rejects activities which reference objects that have an incorrect attribution (variant 2)" do
|
||||
# data = %{
|
||||
# "@context" => "https://www.w3.org/ns/activitystreams",
|
||||
# "id" => "http://mastodon.example.org/users/admin/activities/1234",
|
||||
# "actor" => "http://mastodon.example.org/users/admin",
|
||||
# "to" => ["https://www.w3.org/ns/activitystreams#Public"],
|
||||
# "object" => "https://info.pleroma.site/activity3.json",
|
||||
# "type" => "Announce"
|
||||
# }
|
||||
|
||||
# :error = Transmogrifier.handle_incoming(data)
|
||||
# end
|
||||
# end
|
||||
|
||||
# describe "general origin containment" do
|
||||
# test "contain_origin_from_id() catches obvious spoofing attempts" do
|
||||
# data = %{
|
||||
# "id" => "http://example.com/~alyssa/activities/1234.json"
|
||||
# }
|
||||
|
||||
# :error =
|
||||
# Transmogrifier.contain_origin_from_id(
|
||||
# "http://example.org/~alyssa/activities/1234.json",
|
||||
# data
|
||||
# )
|
||||
# end
|
||||
|
||||
# test "contain_origin_from_id() allows alternate IDs within the same origin domain" do
|
||||
# data = %{
|
||||
# "id" => "http://example.com/~alyssa/activities/1234.json"
|
||||
# }
|
||||
|
||||
# :ok =
|
||||
# Transmogrifier.contain_origin_from_id(
|
||||
# "http://example.com/~alyssa/activities/1234",
|
||||
# data
|
||||
# )
|
||||
# end
|
||||
|
||||
# test "contain_origin_from_id() allows matching IDs" do
|
||||
# data = %{
|
||||
# "id" => "http://example.com/~alyssa/activities/1234.json"
|
||||
# }
|
||||
|
||||
# :ok =
|
||||
# Transmogrifier.contain_origin_from_id(
|
||||
# "http://example.com/~alyssa/activities/1234.json",
|
||||
# data
|
||||
# )
|
||||
# end
|
||||
|
||||
# test "users cannot be collided through fake direction spoofing attempts" do
|
||||
# user =
|
||||
# insert(:user, %{
|
||||
# nickname: "rye@niu.moe",
|
||||
# local: false,
|
||||
# ap_id: "https://niu.moe/users/rye",
|
||||
# follower_address: User.ap_followers(%User{nickname: "rye@niu.moe"})
|
||||
# })
|
||||
|
||||
# {:error, _} = User.get_or_fetch_by_ap_id("https://n1u.moe/users/rye")
|
||||
# end
|
||||
|
||||
# test "all objects with fake directions are rejected by the object fetcher" do
|
||||
# {:error, _} =
|
||||
# ActivityPub.fetch_and_contain_remote_object_from_id(
|
||||
# "https://info.pleroma.site/activity4.json"
|
||||
# )
|
||||
# end
|
||||
end
|
||||
end
|
40
test/mobilizon/service/activitypub/utils_test.exs
Normal file
40
test/mobilizon/service/activitypub/utils_test.exs
Normal file
|
@ -0,0 +1,40 @@
|
|||
defmodule Mobilizon.Service.Activitypub.UtilsTest do
|
||||
use Mobilizon.DataCase
|
||||
import Mobilizon.Factory
|
||||
alias Mobilizon.Service.ActivityPub.Utils
|
||||
use ExVCR.Mock, adapter: ExVCR.Adapter.Hackney
|
||||
|
||||
setup_all do
|
||||
HTTPoison.start()
|
||||
end
|
||||
|
||||
describe "make" do
|
||||
test "comment data from struct" do
|
||||
comment = insert(:comment)
|
||||
reply = insert(:comment, in_reply_to_comment: comment)
|
||||
|
||||
assert %{
|
||||
"type" => "Note",
|
||||
"to" => ["https://www.w3.org/ns/activitystreams#Public"],
|
||||
"content" => reply.text,
|
||||
"actor" => reply.actor.url,
|
||||
"uuid" => reply.uuid,
|
||||
"id" => "#{MobilizonWeb.Endpoint.url()}/comments/#{reply.uuid}",
|
||||
"inReplyTo" => comment.url,
|
||||
"attributedTo" => reply.actor.url
|
||||
} == Utils.make_comment_data(reply)
|
||||
end
|
||||
|
||||
test "comment data from map" do
|
||||
comment = insert(:comment)
|
||||
reply = insert(:comment, in_reply_to_comment: comment)
|
||||
to = ["https://www.w3.org/ns/activitystreams#Public"]
|
||||
comment_data = Utils.make_comment_data(reply.actor.url, to, reply.text, comment.url)
|
||||
assert comment_data["type"] == "Note"
|
||||
assert comment_data["to"] == to
|
||||
assert comment_data["content"] == reply.text
|
||||
assert comment_data["actor"] == reply.actor.url
|
||||
assert comment_data["inReplyTo"] == comment.url
|
||||
end
|
||||
end
|
||||
end
|
41
test/mobilizon_web/resolvers/comment_resolver_test.exs
Normal file
41
test/mobilizon_web/resolvers/comment_resolver_test.exs
Normal file
|
@ -0,0 +1,41 @@
|
|||
defmodule MobilizonWeb.Resolvers.CommentResolverTest do
|
||||
use MobilizonWeb.ConnCase
|
||||
alias Mobilizon.{Events, Actors}
|
||||
alias Mobilizon.Actors.{Actor, User}
|
||||
alias MobilizonWeb.AbsintheHelpers
|
||||
import Mobilizon.Factory
|
||||
|
||||
@comment %{text: "some body"}
|
||||
|
||||
setup %{conn: conn} do
|
||||
{:ok, %User{default_actor: %Actor{} = actor} = user} =
|
||||
Actors.register(%{email: "test@test.tld", password: "testest", username: "test"})
|
||||
|
||||
{:ok, conn: conn, actor: actor, user: user}
|
||||
end
|
||||
|
||||
describe "Comment Resolver" do
|
||||
test "create_comment/3 creates a comment", %{conn: conn, actor: actor, user: user} do
|
||||
category = insert(:category)
|
||||
|
||||
mutation = """
|
||||
mutation {
|
||||
createComment(
|
||||
text: "I love this event",
|
||||
actor_username: "#{actor.preferred_username}"
|
||||
) {
|
||||
text,
|
||||
uuid
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
res =
|
||||
conn
|
||||
|> auth_conn(user)
|
||||
|> post("/api", AbsintheHelpers.mutation_skeleton(mutation))
|
||||
|
||||
assert json_response(res, 200)["data"]["createComment"]["text"] == "I love this event"
|
||||
end
|
||||
end
|
||||
end
|
|
@ -116,10 +116,10 @@ defmodule MobilizonWeb.Resolvers.EventResolverTest do
|
|||
createEvent(
|
||||
title: "come to my event",
|
||||
description: "it will be fine",
|
||||
beginsOn: "#{DateTime.utc_now() |> DateTime.to_iso8601()}",
|
||||
organizer_actor_id: #{actor.id},
|
||||
category_id: #{category.id},
|
||||
addressType: #{"OTHER"}
|
||||
begins_on: "#{DateTime.utc_now() |> DateTime.to_iso8601()}",
|
||||
organizer_actor_username: "#{actor.preferred_username}",
|
||||
category: "#{category.title}",
|
||||
address_type: #{"OTHER"}
|
||||
) {
|
||||
title,
|
||||
uuid
|
||||
|
|
|
@ -22,7 +22,7 @@ defmodule MobilizonWeb.Resolvers.GroupResolverTest do
|
|||
mutation {
|
||||
createGroup(
|
||||
preferred_username: "#{@new_group_params.groupname}",
|
||||
creator_username: "#{actor.preferred_username}"
|
||||
admin_actor_username: "#{actor.preferred_username}"
|
||||
) {
|
||||
preferred_username,
|
||||
type
|
||||
|
@ -44,7 +44,7 @@ defmodule MobilizonWeb.Resolvers.GroupResolverTest do
|
|||
mutation {
|
||||
createGroup(
|
||||
preferred_username: "#{@new_group_params.groupname}",
|
||||
creator_username: "#{actor.preferred_username}",
|
||||
admin_actor_username: "#{actor.preferred_username}",
|
||||
) {
|
||||
preferred_username,
|
||||
type
|
||||
|
@ -57,7 +57,7 @@ defmodule MobilizonWeb.Resolvers.GroupResolverTest do
|
|||
|> auth_conn(user)
|
||||
|> post("/api", AbsintheHelpers.mutation_skeleton(mutation))
|
||||
|
||||
assert hd(json_response(res, 200)["errors"])["message"] == "group_name_not_available"
|
||||
assert hd(json_response(res, 200)["errors"])["message"] == "existing_group_name"
|
||||
end
|
||||
|
||||
test "list_groups/3 returns all groups", context do
|
||||
|
|
Loading…
Reference in a new issue