2020-01-22 22:40:40 +01:00
|
|
|
defmodule Mobilizon.Federation.ActivityStream.Converter.Participant do
|
2019-09-22 18:29:13 +02:00
|
|
|
@moduledoc """
|
|
|
|
Participant converter.
|
|
|
|
|
|
|
|
This module allows to convert reports from ActivityStream format to our own
|
|
|
|
internal one, and back.
|
|
|
|
"""
|
|
|
|
|
|
|
|
alias Mobilizon.Events.Participant, as: ParticipantModel
|
|
|
|
|
2020-01-22 22:40:40 +01:00
|
|
|
alias Mobilizon.Federation.ActivityStream.Convertible
|
2019-09-22 18:29:13 +02:00
|
|
|
|
|
|
|
defimpl Convertible, for: ParticipantModel do
|
2020-01-22 22:40:40 +01:00
|
|
|
alias Mobilizon.Federation.ActivityStream.Converter.Participant, as: ParticipantConverter
|
2019-09-22 18:29:13 +02:00
|
|
|
|
|
|
|
defdelegate model_to_as(participant), to: ParticipantConverter
|
|
|
|
end
|
|
|
|
|
|
|
|
@doc """
|
|
|
|
Convert an event struct to an ActivityStream representation.
|
|
|
|
"""
|
|
|
|
@spec model_to_as(ParticipantModel.t()) :: map
|
|
|
|
def model_to_as(%ParticipantModel{} = participant) do
|
|
|
|
%{
|
|
|
|
"type" => "Join",
|
|
|
|
"id" => participant.url,
|
|
|
|
"actor" => participant.actor.url,
|
2020-03-05 19:32:34 +01:00
|
|
|
"object" => participant.event.url,
|
|
|
|
"participationMessage" => Map.get(participant.metadata, :message)
|
2019-09-22 18:29:13 +02:00
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|