mirror of
https://git.pleroma.social/pleroma/pleroma.git
synced 2024-12-23 08:36:29 +00:00
Chat: Fix missing chat id on second 'get'
This commit is contained in:
parent
c23cb8d37a
commit
9637cded21
2 changed files with 14 additions and 2 deletions
|
@ -46,7 +46,8 @@ defmodule Pleroma.Chat do
|
|||
%__MODULE__{}
|
||||
|> creation_cng(%{user_id: user_id, recipient: recipient})
|
||||
|> Repo.insert(
|
||||
on_conflict: :nothing,
|
||||
# Need to set something, otherwise we get nothing back at all
|
||||
on_conflict: [set: [recipient: recipient]],
|
||||
returning: true,
|
||||
conflict_target: [:user_id, :recipient]
|
||||
)
|
||||
|
|
|
@ -26,13 +26,24 @@ defmodule Pleroma.ChatTest do
|
|||
assert chat.id
|
||||
end
|
||||
|
||||
test "it returns a chat for a user and recipient if it already exists" do
|
||||
test "it returns and bumps a chat for a user and recipient if it already exists" do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
|
||||
{:ok, chat} = Chat.bump_or_create(user.id, other_user.ap_id)
|
||||
{:ok, chat_two} = Chat.bump_or_create(user.id, other_user.ap_id)
|
||||
|
||||
assert chat.id == chat_two.id
|
||||
assert chat_two.unread == 2
|
||||
end
|
||||
|
||||
test "it returns a chat for a user and recipient if it already exists" do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
|
||||
{:ok, chat} = Chat.get_or_create(user.id, other_user.ap_id)
|
||||
{:ok, chat_two} = Chat.get_or_create(user.id, other_user.ap_id)
|
||||
|
||||
assert chat.id == chat_two.id
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue