ChatMessageReferences: Move tests
This commit is contained in:
parent
f3ccd50a33
commit
2591745fc2
3 changed files with 29 additions and 50 deletions
|
|
@ -6,9 +6,7 @@ defmodule Pleroma.Chat do
|
|||
use Ecto.Schema
|
||||
|
||||
import Ecto.Changeset
|
||||
import Ecto.Query
|
||||
|
||||
alias Pleroma.Object
|
||||
alias Pleroma.Repo
|
||||
alias Pleroma.User
|
||||
|
||||
|
|
@ -26,38 +24,6 @@ defmodule Pleroma.Chat do
|
|||
timestamps()
|
||||
end
|
||||
|
||||
def last_message_for_chat(chat) do
|
||||
messages_for_chat_query(chat)
|
||||
|> order_by(desc: :id)
|
||||
|> limit(1)
|
||||
|> Repo.one()
|
||||
end
|
||||
|
||||
def messages_for_chat_query(chat) do
|
||||
chat =
|
||||
chat
|
||||
|> Repo.preload(:user)
|
||||
|
||||
from(o in Object,
|
||||
where: fragment("?->>'type' = ?", o.data, "ChatMessage"),
|
||||
where:
|
||||
fragment(
|
||||
"""
|
||||
(?->>'actor' = ? and ?->'to' = ?)
|
||||
OR (?->>'actor' = ? and ?->'to' = ?)
|
||||
""",
|
||||
o.data,
|
||||
^chat.user.ap_id,
|
||||
o.data,
|
||||
^[chat.recipient],
|
||||
o.data,
|
||||
^chat.recipient,
|
||||
o.data,
|
||||
^[chat.user.ap_id]
|
||||
)
|
||||
)
|
||||
end
|
||||
|
||||
def creation_cng(struct, params) do
|
||||
struct
|
||||
|> cast(params, [:user_id, :recipient, :unread])
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue