projects
/
akkoma
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Streamer: Stream out Conversations/Participations.
[akkoma]
/
lib
/
pleroma
/
activity.ex
diff --git
a/lib/pleroma/activity.ex
b/lib/pleroma/activity.ex
index 26190df2fabac32305e5fba728eadc6e844bbf66..4a2ded51819f7dde23a89905609622735262fbb5 100644
(file)
--- a/
lib/pleroma/activity.ex
+++ b/
lib/pleroma/activity.ex
@@
-10,6
+10,7
@@
defmodule Pleroma.Activity do
alias Pleroma.Object
alias Pleroma.Repo
alias Pleroma.Object
alias Pleroma.Repo
+ import Ecto.Changeset
import Ecto.Query
@type t :: %__MODULE__{}
import Ecto.Query
@type t :: %__MODULE__{}
@@
-31,7
+32,7
@@
defmodule Pleroma.Activity do
field(:data, :map)
field(:local, :boolean, default: true)
field(:actor, :string)
field(:data, :map)
field(:local, :boolean, default: true)
field(:actor, :string)
- field(:recipients, {:array, :string})
+ field(:recipients, {:array, :string}
, default: []
)
has_many(:notifications, Notification, on_delete: :delete_all)
# Attention: this is a fake relation, don't try to preload it blindly and expect it to work!
has_many(:notifications, Notification, on_delete: :delete_all)
# Attention: this is a fake relation, don't try to preload it blindly and expect it to work!
@@
-41,8
+42,8
@@
defmodule Pleroma.Activity do
#
# ```
# |> join(:inner, [activity], o in Object,
#
# ```
# |> join(:inner, [activity], o in Object,
- # on: fragment("(?->>'id') = COALESCE((?
-> 'object'::text) ->> 'id'::text
)",
- # o.data, activity.data))
+ # on: fragment("(?->>'id') = COALESCE((?
)->'object'->> 'id', (?)->>'object'
)",
+ # o.data, activity.data
, activity.data
))
# |> preload([activity, object], [object: object])
# ```
#
# |> preload([activity, object], [object: object])
# ```
#
@@
-61,8
+62,9
@@
defmodule Pleroma.Activity do
o in Object,
on:
fragment(
o in Object,
on:
fragment(
- "(?->>'id') = COALESCE(
(? -> 'object'::text) ->> 'id'::text
)",
+ "(?->>'id') = COALESCE(
?->'object'->>'id', ?->>'object'
)",
o.data,
o.data,
+ activity.data,
activity.data
)
)
activity.data
)
)
@@
-78,6
+80,13
@@
defmodule Pleroma.Activity do
)
end
)
end
+ def change(struct, params \\ %{}) do
+ struct
+ |> cast(params, [:data])
+ |> validate_required([:data])
+ |> unique_constraint(:ap_id, name: :activities_unique_apid_index)
+ end
+
def get_by_ap_id_with_object(ap_id) do
Repo.one(
from(
def get_by_ap_id_with_object(ap_id) do
Repo.one(
from(
@@
-86,8
+95,9
@@
defmodule Pleroma.Activity do
left_join: o in Object,
on:
fragment(
left_join: o in Object,
on:
fragment(
- "(?->>'id') = COALESCE(
(? -> 'object'::text) ->> 'id'::text
)",
+ "(?->>'id') = COALESCE(
?->'object'->>'id', ?->>'object'
)",
o.data,
o.data,
+ activity.data,
activity.data
),
preload: [object: o]
activity.data
),
preload: [object: o]
@@
-105,8
+115,9
@@
defmodule Pleroma.Activity do
inner_join: o in Object,
on:
fragment(
inner_join: o in Object,
on:
fragment(
- "(?->>'id') = COALESCE(
(? -> 'object'::text) ->> 'id'::text
)",
+ "(?->>'id') = COALESCE(
?->'object'->>'id', ?->>'object'
)",
o.data,
o.data,
+ activity.data,
activity.data
),
preload: [object: o]
activity.data
),
preload: [object: o]
@@
-182,8
+193,9
@@
defmodule Pleroma.Activity do
inner_join: o in Object,
on:
fragment(
inner_join: o in Object,
on:
fragment(
- "(?->>'id') = COALESCE(
(? -> 'object'::text) ->> 'id'::text
)",
+ "(?->>'id') = COALESCE(
?->'object'->>'id', ?->>'object'
)",
o.data,
o.data,
+ activity.data,
activity.data
),
preload: [object: o]
activity.data
),
preload: [object: o]
@@
-192,21
+204,27
@@
defmodule Pleroma.Activity do
def create_by_object_ap_id_with_object(_), do: nil
def create_by_object_ap_id_with_object(_), do: nil
- def get_create_by_object_ap_id_with_object(ap_id) do
+ def get_create_by_object_ap_id_with_object(ap_id)
when is_binary(ap_id)
do
ap_id
|> create_by_object_ap_id_with_object()
|> Repo.one()
end
ap_id
|> create_by_object_ap_id_with_object()
|> Repo.one()
end
- def normalize(obj) when is_map(obj), do: get_by_ap_id_with_object(obj["id"])
- def normalize(ap_id) when is_binary(ap_id), do: get_by_ap_id_with_object(ap_id)
- def normalize(_), do: nil
+ def get_create_by_object_ap_id_with_object(_), do: nil
+
+ defp get_in_reply_to_activity_from_object(%Object{data: %{"inReplyTo" => ap_id}}) do
+ get_create_by_object_ap_id_with_object(ap_id)
+ end
+
+ defp get_in_reply_to_activity_from_object(_), do: nil
- def get_in_reply_to_activity(%Activity{data: %{"object" =>
%{"inReplyTo" => ap_id}
}}) do
- get_
create_by_object_ap_id(ap_id
)
+ def get_in_reply_to_activity(%Activity{data: %{"object" =>
object
}}) do
+ get_
in_reply_to_activity_from_object(Object.normalize(object)
)
end
end
- def get_in_reply_to_activity(_), do: nil
+ def normalize(obj) when is_map(obj), do: get_by_ap_id_with_object(obj["id"])
+ def normalize(ap_id) when is_binary(ap_id), do: get_by_ap_id_with_object(ap_id)
+ def normalize(_), do: nil
def delete_by_ap_id(id) when is_binary(id) do
by_object_ap_id(id)
def delete_by_ap_id(id) when is_binary(id) do
by_object_ap_id(id)
@@
-214,6
+232,7
@@
defmodule Pleroma.Activity do
|> Repo.delete_all()
|> elem(1)
|> Enum.find(fn
|> Repo.delete_all()
|> elem(1)
|> Enum.find(fn
+ %{data: %{"type" => "Create", "object" => ap_id}} when is_binary(ap_id) -> ap_id == id
%{data: %{"type" => "Create", "object" => %{"id" => ap_id}}} -> ap_id == id
_ -> nil
end)
%{data: %{"type" => "Create", "object" => %{"id" => ap_id}}} -> ap_id == id
_ -> nil
end)