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 73e63bb144b6e83ef5cce904ade31ca6e452a0a5..2b661edc1dc32b0e4f5c60db58eebaef3849f4a3 100644
(file)
--- a/
lib/pleroma/activity.ex
+++ b/
lib/pleroma/activity.ex
@@
-6,9
+6,11
@@
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
import Ecto.Changeset
import Ecto.Query
@@
-35,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!
@@
-73,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(
@@
-82,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])