2020-01-22 21:40:40 +00:00
|
|
|
defmodule Mobilizon.Federation.ActivityStream.Converter.Tombstone do
|
2019-12-03 10:29:51 +00:00
|
|
|
@moduledoc """
|
|
|
|
Comment converter.
|
|
|
|
|
|
|
|
This module allows to convert Tombstone models to ActivityStreams data
|
|
|
|
"""
|
|
|
|
|
|
|
|
alias Mobilizon.Tombstone, as: TombstoneModel
|
2020-01-22 01:14:42 +00:00
|
|
|
|
2020-01-22 21:40:40 +00:00
|
|
|
alias Mobilizon.Federation.ActivityStream.{Converter, Convertible}
|
2019-12-03 10:29:51 +00:00
|
|
|
|
|
|
|
require Logger
|
|
|
|
|
|
|
|
@behaviour Converter
|
|
|
|
|
|
|
|
defimpl Convertible, for: TombstoneModel do
|
2020-01-22 21:40:40 +00:00
|
|
|
alias Mobilizon.Federation.ActivityStream.Converter.Tombstone, as: TombstoneConverter
|
2019-12-03 10:29:51 +00:00
|
|
|
|
|
|
|
defdelegate model_to_as(comment), to: TombstoneConverter
|
|
|
|
end
|
|
|
|
|
|
|
|
@doc """
|
|
|
|
Make an AS tombstone object from an existing `Tombstone` structure.
|
|
|
|
"""
|
|
|
|
@impl Converter
|
|
|
|
@spec model_to_as(TombstoneModel.t()) :: map
|
|
|
|
def model_to_as(%TombstoneModel{} = tombstone) do
|
|
|
|
%{
|
|
|
|
"type" => "Tombstone",
|
|
|
|
"id" => tombstone.uri,
|
2020-08-27 09:53:24 +00:00
|
|
|
"actor" => if(tombstone.actor, do: tombstone.actor.url, else: nil),
|
2019-12-03 10:29:51 +00:00
|
|
|
"deleted" => tombstone.inserted_at
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
@doc """
|
|
|
|
Converting an Tombstone to an object makes no sense, nevertheless…
|
|
|
|
"""
|
|
|
|
@impl Converter
|
|
|
|
@spec as_to_model_data(map) :: map
|
|
|
|
def as_to_model_data(object), do: object
|
|
|
|
end
|