Remove credo and use mix format, and lint everything
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
@@ -44,28 +44,28 @@ defmodule Eventos.Service.ActivityPub.Utils do
|
||||
generate_id("contexts")
|
||||
end
|
||||
|
||||
# def generate_object_id do
|
||||
# Helpers.o_status_url(Endpoint, :object, UUID.generate())
|
||||
# end
|
||||
# def generate_object_id do
|
||||
# Helpers.o_status_url(Endpoint, :object, UUID.generate())
|
||||
# end
|
||||
|
||||
def generate_id(type) do
|
||||
"#{EventosWeb.Endpoint.url()}/#{type}/#{UUID.generate()}"
|
||||
end
|
||||
|
||||
# def create_context(context) do
|
||||
# context = context || generate_id("contexts")
|
||||
# changeset = Object.context_mapping(context)
|
||||
#
|
||||
# case Repo.insert(changeset) do
|
||||
# {:ok, object} ->
|
||||
# object
|
||||
#
|
||||
# # This should be solved by an upsert, but it seems ecto
|
||||
# # has problems accessing the constraint inside the jsonb.
|
||||
# {:error, _} ->
|
||||
# Events.get_cached_by_url(context)
|
||||
# end
|
||||
# end
|
||||
# def create_context(context) do
|
||||
# context = context || generate_id("contexts")
|
||||
# changeset = Object.context_mapping(context)
|
||||
#
|
||||
# case Repo.insert(changeset) do
|
||||
# {:ok, object} ->
|
||||
# object
|
||||
#
|
||||
# # This should be solved by an upsert, but it seems ecto
|
||||
# # has problems accessing the constraint inside the jsonb.
|
||||
# {:error, _} ->
|
||||
# Events.get_cached_by_url(context)
|
||||
# end
|
||||
# end
|
||||
|
||||
@doc """
|
||||
Enqueues an activity for federation if it's local
|
||||
@@ -89,14 +89,14 @@ defmodule Eventos.Service.ActivityPub.Utils do
|
||||
also adds it to an included object
|
||||
"""
|
||||
def lazy_put_activity_defaults(map) do
|
||||
# %{data: %{"id" => context}, id: context_id} = create_context(map["context"])
|
||||
#
|
||||
# map =
|
||||
# map
|
||||
# |> Map.put_new_lazy("id", &generate_activity_id/0)
|
||||
# |> Map.put_new_lazy("published", &make_date/0)
|
||||
# |> Map.put_new("context", context)
|
||||
# |> Map.put_new("context_id", context_id)
|
||||
# %{data: %{"id" => context}, id: context_id} = create_context(map["context"])
|
||||
#
|
||||
# map =
|
||||
# map
|
||||
# |> Map.put_new_lazy("id", &generate_activity_id/0)
|
||||
# |> Map.put_new_lazy("published", &make_date/0)
|
||||
# |> Map.put_new("context", context)
|
||||
# |> Map.put_new("context_id", context_id)
|
||||
|
||||
if is_map(map["object"]) do
|
||||
object = lazy_put_object_defaults(map["object"], map)
|
||||
@@ -111,7 +111,7 @@ defmodule Eventos.Service.ActivityPub.Utils do
|
||||
"""
|
||||
def lazy_put_object_defaults(map, activity \\ %{}) do
|
||||
map
|
||||
#|> Map.put_new_lazy("id", &generate_object_id/0)
|
||||
# |> Map.put_new_lazy("id", &generate_object_id/0)
|
||||
|> Map.put_new_lazy("published", &make_date/0)
|
||||
|> Map.put_new("context", activity["context"])
|
||||
|> Map.put_new("context_id", activity["context_id"])
|
||||
@@ -134,9 +134,16 @@ defmodule Eventos.Service.ActivityPub.Utils do
|
||||
when is_map(object_data) and type == "Note" do
|
||||
import Logger
|
||||
Logger.debug("insert full object")
|
||||
Logger.debug(inspect object_data)
|
||||
Logger.debug(inspect(object_data))
|
||||
actor = Actors.get_actor_by_url(object_data["actor"])
|
||||
data = %{"text" => object_data["content"], "url" => object_data["id"], "actor_id" => actor.id, "in_reply_to_comment_id" => object_data["inReplyTo"]}
|
||||
|
||||
data = %{
|
||||
"text" => object_data["content"],
|
||||
"url" => object_data["id"],
|
||||
"actor_id" => actor.id,
|
||||
"in_reply_to_comment_id" => object_data["inReplyTo"]
|
||||
}
|
||||
|
||||
with {:ok, _} <- Events.create_comment(data) do
|
||||
:ok
|
||||
end
|
||||
@@ -144,43 +151,43 @@ defmodule Eventos.Service.ActivityPub.Utils do
|
||||
|
||||
def insert_full_object(_), do: :ok
|
||||
|
||||
# def update_object_in_activities(%{data: %{"id" => id}} = object) do
|
||||
# # TODO
|
||||
# # Update activities that already had this. Could be done in a seperate process.
|
||||
# # Alternatively, just don't do this and fetch the current object each time. Most
|
||||
# # could probably be taken from cache.
|
||||
# relevant_activities = Activity.all_by_object_url(id)
|
||||
#
|
||||
# Enum.map(relevant_activities, fn activity ->
|
||||
# new_activity_data = activity.data |> Map.put("object", object.data)
|
||||
# changeset = Changeset.change(activity, data: new_activity_data)
|
||||
# Repo.update(changeset)
|
||||
# end)
|
||||
# end
|
||||
# def update_object_in_activities(%{data: %{"id" => id}} = object) do
|
||||
# # TODO
|
||||
# # Update activities that already had this. Could be done in a seperate process.
|
||||
# # Alternatively, just don't do this and fetch the current object each time. Most
|
||||
# # could probably be taken from cache.
|
||||
# relevant_activities = Activity.all_by_object_url(id)
|
||||
#
|
||||
# Enum.map(relevant_activities, fn activity ->
|
||||
# new_activity_data = activity.data |> Map.put("object", object.data)
|
||||
# changeset = Changeset.change(activity, data: new_activity_data)
|
||||
# Repo.update(changeset)
|
||||
# end)
|
||||
# end
|
||||
|
||||
#### Like-related helpers
|
||||
|
||||
# @doc """
|
||||
# Returns an existing like if a user already liked an object
|
||||
# """
|
||||
# def get_existing_like(actor, %{data: %{"id" => id}}) do
|
||||
# query =
|
||||
# from(
|
||||
# activity in Activity,
|
||||
# where: fragment("(?)->>'actor' = ?", activity.data, ^actor),
|
||||
# # this is to use the index
|
||||
# where:
|
||||
# fragment(
|
||||
# "coalesce((?)->'object'->>'id', (?)->>'object') = ?",
|
||||
# activity.data,
|
||||
# activity.data,
|
||||
# ^id
|
||||
# ),
|
||||
# where: fragment("(?)->>'type' = 'Like'", activity.data)
|
||||
# )
|
||||
#
|
||||
# Repo.one(query)
|
||||
# end
|
||||
# @doc """
|
||||
# Returns an existing like if a user already liked an object
|
||||
# """
|
||||
# def get_existing_like(actor, %{data: %{"id" => id}}) do
|
||||
# query =
|
||||
# from(
|
||||
# activity in Activity,
|
||||
# where: fragment("(?)->>'actor' = ?", activity.data, ^actor),
|
||||
# # this is to use the index
|
||||
# where:
|
||||
# fragment(
|
||||
# "coalesce((?)->'object'->>'id', (?)->>'object') = ?",
|
||||
# activity.data,
|
||||
# activity.data,
|
||||
# ^id
|
||||
# ),
|
||||
# where: fragment("(?)->>'type' = 'Like'", activity.data)
|
||||
# )
|
||||
#
|
||||
# Repo.one(query)
|
||||
# end
|
||||
|
||||
def make_like_data(%Actor{url: url} = actor, %{data: %{"id" => id}} = object, activity_id) do
|
||||
data = %{
|
||||
@@ -206,21 +213,21 @@ defmodule Eventos.Service.ActivityPub.Utils do
|
||||
end
|
||||
end
|
||||
|
||||
# def update_likes_in_object(likes, object) do
|
||||
# update_element_in_object("like", likes, object)
|
||||
# end
|
||||
#
|
||||
# def add_like_to_object(%Activity{data: %{"actor" => actor}}, object) do
|
||||
# with likes <- [actor | object.data["likes"] || []] |> Enum.uniq() do
|
||||
# update_likes_in_object(likes, object)
|
||||
# end
|
||||
# end
|
||||
#
|
||||
# def remove_like_from_object(%Activity{data: %{"actor" => actor}}, object) do
|
||||
# with likes <- (object.data["likes"] || []) |> List.delete(actor) do
|
||||
# update_likes_in_object(likes, object)
|
||||
# end
|
||||
# end
|
||||
# def update_likes_in_object(likes, object) do
|
||||
# update_element_in_object("like", likes, object)
|
||||
# end
|
||||
#
|
||||
# def add_like_to_object(%Activity{data: %{"actor" => actor}}, object) do
|
||||
# with likes <- [actor | object.data["likes"] || []] |> Enum.uniq() do
|
||||
# update_likes_in_object(likes, object)
|
||||
# end
|
||||
# end
|
||||
#
|
||||
# def remove_like_from_object(%Activity{data: %{"actor" => actor}}, object) do
|
||||
# with likes <- (object.data["likes"] || []) |> List.delete(actor) do
|
||||
# update_likes_in_object(likes, object)
|
||||
# end
|
||||
# end
|
||||
|
||||
#### Follow-related helpers
|
||||
|
||||
@@ -239,22 +246,22 @@ defmodule Eventos.Service.ActivityPub.Utils do
|
||||
if activity_id, do: Map.put(data, "id", activity_id), else: data
|
||||
end
|
||||
|
||||
# def fetch_latest_follow(%Actor{url: follower_id}, %Actor{url: followed_id}) do
|
||||
# query =
|
||||
# from(
|
||||
# activity in Activity,
|
||||
# where:
|
||||
# fragment(
|
||||
# "? @> ?",
|
||||
# activity.data,
|
||||
# ^%{type: "Follow", actor: follower_id, object: followed_id}
|
||||
# ),
|
||||
# order_by: [desc: :id],
|
||||
# limit: 1
|
||||
# )
|
||||
#
|
||||
# Repo.one(query)
|
||||
# end
|
||||
# def fetch_latest_follow(%Actor{url: follower_id}, %Actor{url: followed_id}) do
|
||||
# query =
|
||||
# from(
|
||||
# activity in Activity,
|
||||
# where:
|
||||
# fragment(
|
||||
# "? @> ?",
|
||||
# activity.data,
|
||||
# ^%{type: "Follow", actor: follower_id, object: followed_id}
|
||||
# ),
|
||||
# order_by: [desc: :id],
|
||||
# limit: 1
|
||||
# )
|
||||
#
|
||||
# Repo.one(query)
|
||||
# end
|
||||
|
||||
#### Announce-related helpers
|
||||
|
||||
|
||||
Reference in New Issue
Block a user