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)
end
@spec get_by_object_ap_id(object_id :: String.t()) :: t() | nil
def get_by_object_ap_id(object_id) do
@spec get_by_object_ap_id(object_id :: String.t(), type :: String.t()) :: t() | nil
def get_by_object_ap_id(object_id, type) do
__MODULE__
|> where(
[a],
fragment("?->>'type'", a.data) == ^type and
fragment("COALESCE(?->'object'->>'id', ?->>'object')", a.data, a.data) == ^object_id
)
|> preload_object()

View File

@ -75,7 +75,7 @@ defmodule Clacks.Notification do
)
when type in ["Announce", "Like"] do
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.get_cached_by_ap_id(local_actor_id) do
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)
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 ->
if synthesize_create do
create = Clacks.ActivityPub.synthesized_create(data)

View File

@ -32,7 +32,7 @@ defmodule ClacksWeb.ObjectsController do
defp redirect_to_status(conn, _params) do
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 ->
conn
|> resp(404, "Not Found")