2020-01-22 02:14:42 +01:00
|
|
|
defmodule Mobilizon.Federation.ActivityPub.ActivityStream.Converter.Follower do
|
2019-10-25 17:43:37 +02:00
|
|
|
@moduledoc """
|
|
|
|
Participant converter.
|
|
|
|
|
|
|
|
This module allows to convert followers from ActivityStream format to our own
|
|
|
|
internal one, and back.
|
|
|
|
"""
|
|
|
|
|
2020-01-22 02:14:42 +01:00
|
|
|
alias Mobilizon.Actors.Actor
|
2019-10-25 17:43:37 +02:00
|
|
|
alias Mobilizon.Actors.Follower, as: FollowerModel
|
|
|
|
|
2020-01-22 02:14:42 +01:00
|
|
|
alias Mobilizon.Federation.ActivityPub.ActivityStream.Convertible
|
2019-10-25 17:43:37 +02:00
|
|
|
|
|
|
|
defimpl Convertible, for: FollowerModel do
|
2020-01-22 02:14:42 +01:00
|
|
|
alias Mobilizon.Federation.ActivityPub.ActivityStream.Converter.Follower,
|
|
|
|
as: FollowerConverter
|
2019-10-25 17:43:37 +02:00
|
|
|
|
|
|
|
defdelegate model_to_as(follower), to: FollowerConverter
|
|
|
|
end
|
|
|
|
|
|
|
|
@doc """
|
|
|
|
Convert an follow struct to an ActivityStream representation.
|
|
|
|
"""
|
|
|
|
@spec model_to_as(FollowerModel.t()) :: map
|
|
|
|
def model_to_as(
|
|
|
|
%FollowerModel{actor: %Actor{} = actor, target_actor: %Actor{} = target_actor} = follower
|
|
|
|
) do
|
|
|
|
%{
|
|
|
|
"type" => "Follow",
|
|
|
|
"actor" => actor.url,
|
|
|
|
"to" => [target_actor.url],
|
|
|
|
"cc" => ["https://www.w3.org/ns/activitystreams#Public"],
|
|
|
|
"object" => target_actor.url,
|
|
|
|
"id" => follower.url
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|