Refactor with Chat.for_user_query/1
This commit is contained in:
parent
fb0de07343
commit
c41430b23e
3 changed files with 15 additions and 14 deletions
|
|
@ -6,7 +6,9 @@ defmodule Pleroma.Chat do
|
|||
use Ecto.Schema
|
||||
|
||||
import Ecto.Changeset
|
||||
import Ecto.Query
|
||||
|
||||
alias Pleroma.Chat
|
||||
alias Pleroma.Repo
|
||||
alias Pleroma.User
|
||||
|
||||
|
|
@ -69,4 +71,14 @@ defmodule Pleroma.Chat do
|
|||
conflict_target: [:user_id, :recipient]
|
||||
)
|
||||
end
|
||||
|
||||
@spec for_user_query(FlakeId.Ecto.CompatType.t()) :: Ecto.Query.t()
|
||||
def for_user_query(user_id) do
|
||||
from(c in Chat,
|
||||
where: c.user_id == ^user_id,
|
||||
order_by: [desc: c.updated_at],
|
||||
inner_join: u in User,
|
||||
on: u.ap_id == c.recipient
|
||||
)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue