projects
/
akkoma
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Conversations: Add mix task to 'import' old DMs.
[akkoma]
/
lib
/
pleroma
/
activity.ex
diff --git
a/lib/pleroma/activity.ex
b/lib/pleroma/activity.ex
index 478d163564bc2a4788d711d600218edbfb8e90b4..2b661edc1dc32b0e4f5c60db58eebaef3849f4a3 100644
(file)
--- a/
lib/pleroma/activity.ex
+++ b/
lib/pleroma/activity.ex
@@
-6,14
+6,18
@@
defmodule Pleroma.Activity do
use Ecto.Schema
alias Pleroma.Activity
use Ecto.Schema
alias Pleroma.Activity
+ alias Pleroma.Bookmark
alias Pleroma.Notification
alias Pleroma.Object
alias Pleroma.Repo
alias Pleroma.Notification
alias Pleroma.Object
alias Pleroma.Repo
+ alias Pleroma.User
import Ecto.Changeset
import Ecto.Query
@type t :: %__MODULE__{}
import Ecto.Changeset
import Ecto.Query
@type t :: %__MODULE__{}
+ @type actor :: String.t()
+
@primary_key {:id, Pleroma.FlakeId, autogenerate: true}
# https://github.com/tootsuite/mastodon/blob/master/app/models/notification.rb#L19
@primary_key {:id, Pleroma.FlakeId, autogenerate: true}
# https://github.com/tootsuite/mastodon/blob/master/app/models/notification.rb#L19
@@
-33,6
+37,8
@@
defmodule Pleroma.Activity do
field(:local, :boolean, default: true)
field(:actor, :string)
field(:recipients, {:array, :string}, default: [])
field(:local, :boolean, default: true)
field(:actor, :string)
field(:recipients, {:array, :string}, default: [])
+ # This is a fake relation, do not use outside of with_preloaded_bookmark/get_bookmark
+ has_one(:bookmark, Bookmark)
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!
@@
-71,6
+77,16
@@
defmodule Pleroma.Activity do
|> preload([activity, object], object: object)
end
|> preload([activity, object], object: object)
end
+ def with_preloaded_bookmark(query, %User{} = user) do
+ from([a] in query,
+ left_join: b in Bookmark,
+ on: b.user_id == ^user.id and b.activity_id == a.id,
+ preload: [bookmark: b]
+ )
+ end
+
+ def with_preloaded_bookmark(query, _), do: query
+
def get_by_ap_id(ap_id) do
Repo.one(
from(
def get_by_ap_id(ap_id) do
Repo.one(
from(
@@
-80,6
+96,16
@@
defmodule Pleroma.Activity do
)
end
)
end
+ def get_bookmark(%Activity{} = activity, %User{} = user) do
+ if Ecto.assoc_loaded?(activity.bookmark) do
+ activity.bookmark
+ else
+ Bookmark.get(user.id, activity.id)
+ end
+ end
+
+ def get_bookmark(_, _), do: nil
+
def change(struct, params \\ %{}) do
struct
|> cast(params, [:data])
def change(struct, params \\ %{}) do
struct
|> cast(params, [:data])
@@
-204,12
+230,14
@@
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 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(%Object{data: %{"inReplyTo" => ap_id}}) do
get_create_by_object_ap_id_with_object(ap_id)
end
@@
-230,6
+258,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)
@@
-257,4
+286,9
@@
defmodule Pleroma.Activity do
|> where([s], s.actor == ^actor)
|> Repo.all()
end
|> where([s], s.actor == ^actor)
|> Repo.all()
end
+
+ @spec query_by_actor(actor()) :: Ecto.Query.t()
+ def query_by_actor(actor) do
+ from(a in Activity, where: a.actor == ^actor)
+ end
end
end