diff options
| author | lain <lain@soykaf.club> | 2020-05-05 20:07:47 +0200 | 
|---|---|---|
| committer | lain <lain@soykaf.club> | 2020-05-05 20:07:47 +0200 | 
| commit | 9637cded21cef1e6c531dd46d5f5245c4c3ed03c (patch) | |
| tree | c06f9fcd0626bcc13e2886f2e41a6871cebc8cdd | |
| parent | c23cb8d37a44e4b9ff09655e452122235ded1d84 (diff) | |
| download | pleroma-9637cded21cef1e6c531dd46d5f5245c4c3ed03c.tar.gz pleroma-9637cded21cef1e6c531dd46d5f5245c4c3ed03c.zip  | |
Chat: Fix missing chat id on second 'get'
| -rw-r--r-- | lib/pleroma/chat.ex | 3 | ||||
| -rw-r--r-- | test/chat_test.exs | 13 | 
2 files changed, 14 insertions, 2 deletions
diff --git a/lib/pleroma/chat.ex b/lib/pleroma/chat.ex index 6008196e4..1a092b992 100644 --- a/lib/pleroma/chat.ex +++ b/lib/pleroma/chat.ex @@ -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]      ) diff --git a/test/chat_test.exs b/test/chat_test.exs index 952598c87..943e48111 100644 --- a/test/chat_test.exs +++ b/test/chat_test.exs @@ -26,7 +26,7 @@ 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) @@ -34,6 +34,17 @@ defmodule Pleroma.ChatTest do        {: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      test "a returning chat will have an updated `update_at` field and an incremented unread count" do  | 
