diff options
| author | lain <lain@soykaf.club> | 2019-11-08 13:27:11 +0100 | 
|---|---|---|
| committer | lain <lain@soykaf.club> | 2019-11-08 13:27:11 +0100 | 
| commit | b22ee9d9666c49d1a3b1757b275e9d303eed4afc (patch) | |
| tree | e7b4138a82c7382f2e2819f0a52481ec39cb12f3 /test/conversation | |
| parent | d7f9679ff2c9c4bd2b9967d7a32b5a4fe145305e (diff) | |
| parent | 278674223d36f4d789dce92cd541c47b7e19b674 (diff) | |
| download | pleroma-b22ee9d9666c49d1a3b1757b275e9d303eed4afc.tar.gz pleroma-b22ee9d9666c49d1a3b1757b275e9d303eed4afc.zip  | |
Merge remote-tracking branch 'origin/develop' into reactions
Diffstat (limited to 'test/conversation')
| -rw-r--r-- | test/conversation/participation_test.exs | 179 | 
1 files changed, 178 insertions, 1 deletions
diff --git a/test/conversation/participation_test.exs b/test/conversation/participation_test.exs index f430bdf75..863270022 100644 --- a/test/conversation/participation_test.exs +++ b/test/conversation/participation_test.exs @@ -23,6 +23,39 @@ defmodule Pleroma.Conversation.ParticipationTest do      assert %Pleroma.Conversation{} = participation.conversation    end +  test "for a new conversation or a reply, it doesn't mark the author's participation as unread" do +    user = insert(:user) +    other_user = insert(:user) + +    {:ok, _} = +      CommonAPI.post(user, %{"status" => "Hey @#{other_user.nickname}.", "visibility" => "direct"}) + +    user = User.get_cached_by_id(user.id) +    other_user = User.get_cached_by_id(other_user.id) + +    [%{read: true}] = Participation.for_user(user) +    [%{read: false} = participation] = Participation.for_user(other_user) + +    assert User.get_cached_by_id(user.id).unread_conversation_count == 0 +    assert User.get_cached_by_id(other_user.id).unread_conversation_count == 1 + +    {:ok, _} = +      CommonAPI.post(other_user, %{ +        "status" => "Hey @#{user.nickname}.", +        "visibility" => "direct", +        "in_reply_to_conversation_id" => participation.id +      }) + +    user = User.get_cached_by_id(user.id) +    other_user = User.get_cached_by_id(other_user.id) + +    [%{read: false}] = Participation.for_user(user) +    [%{read: true}] = Participation.for_user(other_user) + +    assert User.get_cached_by_id(user.id).unread_conversation_count == 1 +    assert User.get_cached_by_id(other_user.id).unread_conversation_count == 0 +  end +    test "for a new conversation, it sets the recipents of the participation" do      user = insert(:user)      other_user = insert(:user) @@ -32,7 +65,7 @@ defmodule Pleroma.Conversation.ParticipationTest do        CommonAPI.post(user, %{"status" => "Hey @#{other_user.nickname}.", "visibility" => "direct"})      user = User.get_cached_by_id(user.id) -    other_user = User.get_cached_by_id(user.id) +    other_user = User.get_cached_by_id(other_user.id)      [participation] = Participation.for_user(user)      participation = Pleroma.Repo.preload(participation, :recipients) @@ -100,6 +133,20 @@ defmodule Pleroma.Conversation.ParticipationTest do      refute participation.read    end +  test "it marks all the user's participations as read" do +    user = insert(:user) +    other_user = insert(:user) +    participation1 = insert(:participation, %{read: false, user: user}) +    participation2 = insert(:participation, %{read: false, user: user}) +    participation3 = insert(:participation, %{read: false, user: other_user}) + +    {:ok, _, [%{read: true}, %{read: true}]} = Participation.mark_all_as_read(user) + +    assert Participation.get(participation1.id).read == true +    assert Participation.get(participation2.id).read == true +    assert Participation.get(participation3.id).read == false +  end +    test "gets all the participations for a user, ordered by updated at descending" do      user = insert(:user)      {:ok, activity_one} = CommonAPI.post(user, %{"status" => "x", "visibility" => "direct"}) @@ -169,4 +216,134 @@ defmodule Pleroma.Conversation.ParticipationTest do      assert user in participation.recipients      assert other_user in participation.recipients    end + +  describe "blocking" do +    test "when the user blocks a recipient, the existing conversations with them are marked as read" do +      blocker = insert(:user) +      blocked = insert(:user) +      third_user = insert(:user) + +      {:ok, _direct1} = +        CommonAPI.post(third_user, %{ +          "status" => "Hi @#{blocker.nickname}", +          "visibility" => "direct" +        }) + +      {:ok, _direct2} = +        CommonAPI.post(third_user, %{ +          "status" => "Hi @#{blocker.nickname}, @#{blocked.nickname}", +          "visibility" => "direct" +        }) + +      {:ok, _direct3} = +        CommonAPI.post(blocked, %{ +          "status" => "Hi @#{blocker.nickname}", +          "visibility" => "direct" +        }) + +      {:ok, _direct4} = +        CommonAPI.post(blocked, %{ +          "status" => "Hi @#{blocker.nickname}, @#{third_user.nickname}", +          "visibility" => "direct" +        }) + +      assert [%{read: false}, %{read: false}, %{read: false}, %{read: false}] = +               Participation.for_user(blocker) + +      assert User.get_cached_by_id(blocker.id).unread_conversation_count == 4 + +      {:ok, blocker} = User.block(blocker, blocked) + +      # The conversations with the blocked user are marked as read +      assert [%{read: true}, %{read: true}, %{read: true}, %{read: false}] = +               Participation.for_user(blocker) + +      assert User.get_cached_by_id(blocker.id).unread_conversation_count == 1 + +      # The conversation is not marked as read for the blocked user +      assert [_, _, %{read: false}] = Participation.for_user(blocked) +      assert User.get_cached_by_id(blocked.id).unread_conversation_count == 1 + +      # The conversation is not marked as read for the third user +      assert [%{read: false}, _, _] = Participation.for_user(third_user) +      assert User.get_cached_by_id(third_user.id).unread_conversation_count == 1 +    end + +    test "the new conversation with the blocked user is not marked as unread " do +      blocker = insert(:user) +      blocked = insert(:user) +      third_user = insert(:user) + +      {:ok, blocker} = User.block(blocker, blocked) + +      # When the blocked user is the author +      {:ok, _direct1} = +        CommonAPI.post(blocked, %{ +          "status" => "Hi @#{blocker.nickname}", +          "visibility" => "direct" +        }) + +      assert [%{read: true}] = Participation.for_user(blocker) +      assert User.get_cached_by_id(blocker.id).unread_conversation_count == 0 + +      # When the blocked user is a recipient +      {:ok, _direct2} = +        CommonAPI.post(third_user, %{ +          "status" => "Hi @#{blocker.nickname}, @#{blocked.nickname}", +          "visibility" => "direct" +        }) + +      assert [%{read: true}, %{read: true}] = Participation.for_user(blocker) +      assert User.get_cached_by_id(blocker.id).unread_conversation_count == 0 + +      assert [%{read: false}, _] = Participation.for_user(blocked) +      assert User.get_cached_by_id(blocked.id).unread_conversation_count == 1 +    end + +    test "the conversation with the blocked user is not marked as unread on a reply" do +      blocker = insert(:user) +      blocked = insert(:user) +      third_user = insert(:user) + +      {:ok, _direct1} = +        CommonAPI.post(blocker, %{ +          "status" => "Hi @#{third_user.nickname}, @#{blocked.nickname}", +          "visibility" => "direct" +        }) + +      {:ok, blocker} = User.block(blocker, blocked) +      assert [%{read: true}] = Participation.for_user(blocker) +      assert User.get_cached_by_id(blocker.id).unread_conversation_count == 0 + +      assert [blocked_participation] = Participation.for_user(blocked) + +      # When it's a reply from the blocked user +      {:ok, _direct2} = +        CommonAPI.post(blocked, %{ +          "status" => "reply", +          "visibility" => "direct", +          "in_reply_to_conversation_id" => blocked_participation.id +        }) + +      assert [%{read: true}] = Participation.for_user(blocker) +      assert User.get_cached_by_id(blocker.id).unread_conversation_count == 0 + +      assert [third_user_participation] = Participation.for_user(third_user) + +      # When it's a reply from the third user +      {:ok, _direct3} = +        CommonAPI.post(third_user, %{ +          "status" => "reply", +          "visibility" => "direct", +          "in_reply_to_conversation_id" => third_user_participation.id +        }) + +      assert [%{read: true}] = Participation.for_user(blocker) +      assert User.get_cached_by_id(blocker.id).unread_conversation_count == 0 + +      # Marked as unread for the blocked user +      assert [%{read: false}] = Participation.for_user(blocked) +      assert User.get_cached_by_id(blocked.id).unread_conversation_count == 1 +    end +  end  end  | 
