Fix handling incoming Likes

This commit is contained in:
Shadowfacts 2021-08-26 09:59:55 -04:00
parent dcadde5e37
commit 9dfb4b22e1
Signed by: shadowfacts
GPG Key ID: 94A5AB95422746E5
4 changed files with 7 additions and 6 deletions

View File

@ -60,11 +60,12 @@ defmodule Clacks.Activity do
Repo.one(from a in __MODULE__, where: fragment("?->>'id'", a.data) == ^ap_id) Repo.one(from a in __MODULE__, where: fragment("?->>'id'", a.data) == ^ap_id)
end end
@spec get_by_object_ap_id(object_id :: String.t()) :: t() | nil @spec get_by_object_ap_id(object_id :: String.t(), type :: String.t()) :: t() | nil
def get_by_object_ap_id(object_id) do def get_by_object_ap_id(object_id, type) do
__MODULE__ __MODULE__
|> where( |> where(
[a], [a],
fragment("?->>'type'", a.data) == ^type and
fragment("COALESCE(?->'object'->>'id', ?->>'object')", a.data, a.data) == ^object_id fragment("COALESCE(?->'object'->>'id', ?->>'object')", a.data, a.data) == ^object_id
) )
|> preload_object() |> preload_object()

View File

@ -75,7 +75,7 @@ defmodule Clacks.Notification do
) )
when type in ["Announce", "Like"] do when type in ["Announce", "Like"] do
with %Activity{local: true, actor: local_actor_id} <- with %Activity{local: true, actor: local_actor_id} <-
Activity.get_by_object_ap_id(original_object_ap_id), Activity.get_by_object_ap_id(original_object_ap_id, "Create"),
%Actor{local: true} = original_activity_actor <- %Actor{local: true} = original_activity_actor <-
Actor.get_cached_by_ap_id(local_actor_id) do Actor.get_cached_by_ap_id(local_actor_id) do
create(String.downcase(type), activity, original_activity_actor) create(String.downcase(type), activity, original_activity_actor)

View File

@ -74,7 +74,7 @@ defmodule Clacks.Object do
_ = Clacks.Actor.get_by_ap_id(actor) _ = Clacks.Actor.get_by_ap_id(actor)
activity = activity =
case Clacks.Activity.get_by_object_ap_id(ap_id) do case Clacks.Activity.get_by_object_ap_id(ap_id, "Create") do
nil -> nil ->
if synthesize_create do if synthesize_create do
create = Clacks.ActivityPub.synthesized_create(data) create = Clacks.ActivityPub.synthesized_create(data)

View File

@ -32,7 +32,7 @@ defmodule ClacksWeb.ObjectsController do
defp redirect_to_status(conn, _params) do defp redirect_to_status(conn, _params) do
object_id = current_url(conn) object_id = current_url(conn)
case Activity.get_by_object_ap_id(object_id) do case Activity.get_by_object_ap_id(object_id, "Create") do
nil -> nil ->
conn conn
|> resp(404, "Not Found") |> resp(404, "Not Found")