projects
/
akkoma
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
twitterapi: use order constraint to force descending order
[akkoma]
/
lib
/
pleroma
/
activity.ex
diff --git
a/lib/pleroma/activity.ex
b/lib/pleroma/activity.ex
index e432fcb0738c9a333a068a6f8035e4c332c8a4e1..2b661edc1dc32b0e4f5c60db58eebaef3849f4a3 100644
(file)
--- a/
lib/pleroma/activity.ex
+++ b/
lib/pleroma/activity.ex
@@
-10,6
+10,7
@@
defmodule Pleroma.Activity do
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
import Ecto.Changeset
import Ecto.Query
@@
-36,8
+37,9
@@
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)
has_many(:notifications, Notification, on_delete: :delete_all)
- has_many(:bookmarks, Bookmark, on_delete: :delete_all)
# Attention: this is a fake relation, don't try to preload it blindly and expect it to work!
# The foreign key is embedded in a jsonb field.
# Attention: this is a fake relation, don't try to preload it blindly and expect it to work!
# The foreign key is embedded in a jsonb field.
@@
-73,14
+75,18
@@
defmodule Pleroma.Activity do
)
)
|> preload([activity, object], object: object)
)
)
|> preload([activity, object], object: object)
- |> with_preloaded_bookmarks()
end
end
- def with_preloaded_bookmarks(query) do
- query
- |> preload(:bookmarks)
+ 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
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(
@@
-90,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])
@@
-112,7
+128,6
@@
defmodule Pleroma.Activity do
),
preload: [object: o]
)
),
preload: [object: o]
)
- |> with_preloaded_bookmarks()
)
end
)
end
@@
-133,7
+148,6
@@
defmodule Pleroma.Activity do
),
preload: [object: o]
)
),
preload: [object: o]
)
- |> with_preloaded_bookmarks()
|> Repo.one()
end
|> Repo.one()
end
@@
-210,8
+224,7
@@
defmodule Pleroma.Activity do
activity.data,
activity.data
),
activity.data,
activity.data
),
- preload: [object: o],
- preload: :bookmarks
+ preload: [object: o]
)
end
)
end