Insert string-hashtags in Pipeline
Cannot be done in Ecto schemas because only one type is allowed in arrays, and needs to be done before the MRFs.
This commit is contained in:
parent
5ae27c8451
commit
37a7f521fd
|
@ -42,23 +42,33 @@ def common_pipeline(object, meta) do
|
||||||
|
|
||||||
def do_common_pipeline(%{__struct__: _}, _meta), do: {:error, :is_struct}
|
def do_common_pipeline(%{__struct__: _}, _meta), do: {:error, :is_struct}
|
||||||
|
|
||||||
def do_common_pipeline(object, meta) do
|
def do_common_pipeline(message, meta) do
|
||||||
with {_, {:ok, validated_object, meta}} <-
|
with {_, {:ok, message, meta}} <- {:validate, @object_validator.validate(message, meta)},
|
||||||
{:validate_object, @object_validator.validate(object, meta)},
|
{_, {:ok, message, meta}} <- {:fixup, validation_fixups(message, meta)},
|
||||||
{_, {:ok, mrfd_object, meta}} <-
|
{_, {:ok, message, meta}} <- {:mrf, @mrf.pipeline_filter(message, meta)},
|
||||||
{:mrf_object, @mrf.pipeline_filter(validated_object, meta)},
|
{_, {:ok, message, meta}} <- {:persist, @activity_pub.persist(message, meta)},
|
||||||
{_, {:ok, activity, meta}} <-
|
{_, {:ok, message, meta}} <- {:side_effects, @side_effects.handle(message, meta)},
|
||||||
{:persist_object, @activity_pub.persist(mrfd_object, meta)},
|
{_, {:ok, _}} <- {:federation, maybe_federate(message, meta)} do
|
||||||
{_, {:ok, activity, meta}} <-
|
{:ok, message, meta}
|
||||||
{:execute_side_effects, @side_effects.handle(activity, meta)},
|
|
||||||
{_, {:ok, _}} <- {:federation, maybe_federate(activity, meta)} do
|
|
||||||
{:ok, activity, meta}
|
|
||||||
else
|
else
|
||||||
{:mrf_object, {:reject, message, _}} -> {:reject, message}
|
{:mrf, {:reject, message, _}} -> {:reject, message}
|
||||||
e -> {:error, e}
|
e -> {:error, e}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defp validation_fixups(message, meta) do
|
||||||
|
# Insert copy of hashtags as strings for the non-hashtag table indexing
|
||||||
|
message =
|
||||||
|
if message["tag"] do
|
||||||
|
tag = Object.hashtags(%Object{data: message}) ++ (message["tag"] || [])
|
||||||
|
Map.put(message, "tag", tag)
|
||||||
|
else
|
||||||
|
message
|
||||||
|
end
|
||||||
|
|
||||||
|
{:ok, message, meta}
|
||||||
|
end
|
||||||
|
|
||||||
defp maybe_federate(%Object{}, _), do: {:ok, :not_federated}
|
defp maybe_federate(%Object{}, _), do: {:ok, :not_federated}
|
||||||
|
|
||||||
defp maybe_federate(%Activity{} = activity, meta) do
|
defp maybe_federate(%Activity{} = activity, meta) do
|
||||||
|
|
|
@ -564,7 +564,7 @@ def handle_incoming(
|
||||||
Pipeline.common_pipeline(data, local: false) do
|
Pipeline.common_pipeline(data, local: false) do
|
||||||
{:ok, activity}
|
{:ok, activity}
|
||||||
else
|
else
|
||||||
{:error, {:validate_object, _}} = e ->
|
{:error, {:validate, _}} = e ->
|
||||||
# Check if we have a create activity for this
|
# Check if we have a create activity for this
|
||||||
with {:ok, object_id} <- ObjectValidators.ObjectID.cast(data["object"]),
|
with {:ok, object_id} <- ObjectValidators.ObjectID.cast(data["object"]),
|
||||||
%Activity{data: %{"actor" => actor}} <-
|
%Activity{data: %{"actor" => actor}} <-
|
||||||
|
|
|
@ -228,17 +228,7 @@ def favorite_helper(user, id) do
|
||||||
{:find_object, _} ->
|
{:find_object, _} ->
|
||||||
{:error, :not_found}
|
{:error, :not_found}
|
||||||
|
|
||||||
{:common_pipeline,
|
{:common_pipeline, {:error, {:validate, {:error, changeset}}}} = e ->
|
||||||
{
|
|
||||||
:error,
|
|
||||||
{
|
|
||||||
:validate_object,
|
|
||||||
{
|
|
||||||
:error,
|
|
||||||
changeset
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}} = e ->
|
|
||||||
if {:object, {"already liked by this actor", []}} in changeset.errors do
|
if {:object, {"already liked by this actor", []}} in changeset.errors do
|
||||||
{:ok, :already_liked}
|
{:ok, :already_liked}
|
||||||
else
|
else
|
||||||
|
|
Loading…
Reference in New Issue