Merge branch '2081-deleted-user-chats' into 'develop'
ChatController: Don't die if the recipient is gone. Closes #2081 See merge request pleroma/pleroma!2926
This commit is contained in:
commit
1c05819c9b
@ -149,7 +149,9 @@ def index(%{assigns: %{user: %{id: user_id} = user}} = conn, _params) do
|
|||||||
from(c in Chat,
|
from(c in Chat,
|
||||||
where: c.user_id == ^user_id,
|
where: c.user_id == ^user_id,
|
||||||
where: c.recipient not in ^blocked_ap_ids,
|
where: c.recipient not in ^blocked_ap_ids,
|
||||||
order_by: [desc: c.updated_at]
|
order_by: [desc: c.updated_at],
|
||||||
|
inner_join: u in User,
|
||||||
|
on: u.ap_id == c.recipient
|
||||||
)
|
)
|
||||||
|> Repo.all()
|
|> Repo.all()
|
||||||
|
|
||||||
|
@ -267,6 +267,21 @@ test "it returns a chat", %{conn: conn, user: user} do
|
|||||||
describe "GET /api/v1/pleroma/chats" do
|
describe "GET /api/v1/pleroma/chats" do
|
||||||
setup do: oauth_access(["read:chats"])
|
setup do: oauth_access(["read:chats"])
|
||||||
|
|
||||||
|
test "it does not return chats with deleted users", %{conn: conn, user: user} do
|
||||||
|
recipient = insert(:user)
|
||||||
|
{:ok, _} = Chat.get_or_create(user.id, recipient.ap_id)
|
||||||
|
|
||||||
|
Pleroma.Repo.delete(recipient)
|
||||||
|
User.invalidate_cache(recipient)
|
||||||
|
|
||||||
|
result =
|
||||||
|
conn
|
||||||
|
|> get("/api/v1/pleroma/chats")
|
||||||
|
|> json_response_and_validate_schema(200)
|
||||||
|
|
||||||
|
assert length(result) == 0
|
||||||
|
end
|
||||||
|
|
||||||
test "it does not return chats with users you blocked", %{conn: conn, user: user} do
|
test "it does not return chats with users you blocked", %{conn: conn, user: user} do
|
||||||
recipient = insert(:user)
|
recipient = insert(:user)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user