Merge branch 'issue/2069' into 'develop'
[#2069] unread_conversation_count See merge request pleroma/pleroma!2939
This commit is contained in:
commit
131f3219e6
9 changed files with 92 additions and 94 deletions
|
|
@ -37,9 +37,8 @@ defmodule Pleroma.Conversation.ParticipationTest do
|
|||
|
||||
[%{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
|
||||
assert Participation.unread_count(user) == 0
|
||||
assert Participation.unread_count(other_user) == 1
|
||||
|
||||
{:ok, _} =
|
||||
CommonAPI.post(other_user, %{
|
||||
|
|
@ -54,8 +53,8 @@ defmodule Pleroma.Conversation.ParticipationTest do
|
|||
[%{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
|
||||
assert Participation.unread_count(user) == 1
|
||||
assert Participation.unread_count(other_user) == 0
|
||||
end
|
||||
|
||||
test "for a new conversation, it sets the recipents of the participation" do
|
||||
|
|
@ -264,7 +263,7 @@ defmodule Pleroma.Conversation.ParticipationTest do
|
|||
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
|
||||
assert Participation.unread_count(blocker) == 4
|
||||
|
||||
{:ok, _user_relationship} = User.block(blocker, blocked)
|
||||
|
||||
|
|
@ -272,15 +271,15 @@ defmodule Pleroma.Conversation.ParticipationTest do
|
|||
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
|
||||
assert Participation.unread_count(blocker) == 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
|
||||
assert Participation.unread_count(blocker) == 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
|
||||
assert Participation.unread_count(third_user) == 1
|
||||
end
|
||||
|
||||
test "the new conversation with the blocked user is not marked as unread " do
|
||||
|
|
@ -298,7 +297,7 @@ defmodule Pleroma.Conversation.ParticipationTest do
|
|||
})
|
||||
|
||||
assert [%{read: true}] = Participation.for_user(blocker)
|
||||
assert User.get_cached_by_id(blocker.id).unread_conversation_count == 0
|
||||
assert Participation.unread_count(blocker) == 0
|
||||
|
||||
# When the blocked user is a recipient
|
||||
{:ok, _direct2} =
|
||||
|
|
@ -308,10 +307,10 @@ defmodule Pleroma.Conversation.ParticipationTest do
|
|||
})
|
||||
|
||||
assert [%{read: true}, %{read: true}] = Participation.for_user(blocker)
|
||||
assert User.get_cached_by_id(blocker.id).unread_conversation_count == 0
|
||||
assert Participation.unread_count(blocker) == 0
|
||||
|
||||
assert [%{read: false}, _] = Participation.for_user(blocked)
|
||||
assert User.get_cached_by_id(blocked.id).unread_conversation_count == 1
|
||||
assert Participation.unread_count(blocked) == 1
|
||||
end
|
||||
|
||||
test "the conversation with the blocked user is not marked as unread on a reply" do
|
||||
|
|
@ -327,8 +326,8 @@ defmodule Pleroma.Conversation.ParticipationTest do
|
|||
|
||||
{:ok, _user_relationship} = User.block(blocker, blocked)
|
||||
assert [%{read: true}] = Participation.for_user(blocker)
|
||||
assert User.get_cached_by_id(blocker.id).unread_conversation_count == 0
|
||||
|
||||
assert Participation.unread_count(blocker) == 0
|
||||
assert [blocked_participation] = Participation.for_user(blocked)
|
||||
|
||||
# When it's a reply from the blocked user
|
||||
|
|
@ -340,8 +339,8 @@ defmodule Pleroma.Conversation.ParticipationTest do
|
|||
})
|
||||
|
||||
assert [%{read: true}] = Participation.for_user(blocker)
|
||||
assert User.get_cached_by_id(blocker.id).unread_conversation_count == 0
|
||||
|
||||
assert Participation.unread_count(blocker) == 0
|
||||
assert [third_user_participation] = Participation.for_user(third_user)
|
||||
|
||||
# When it's a reply from the third user
|
||||
|
|
@ -353,11 +352,12 @@ defmodule Pleroma.Conversation.ParticipationTest do
|
|||
})
|
||||
|
||||
assert [%{read: true}] = Participation.for_user(blocker)
|
||||
assert User.get_cached_by_id(blocker.id).unread_conversation_count == 0
|
||||
assert Participation.unread_count(blocker) == 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
|
||||
|
||||
assert Participation.unread_count(blocked) == 1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
defmodule Pleroma.Web.MastodonAPI.ConversationControllerTest do
|
||||
use Pleroma.Web.ConnCase
|
||||
|
||||
alias Pleroma.Conversation.Participation
|
||||
alias Pleroma.User
|
||||
alias Pleroma.Web.CommonAPI
|
||||
|
||||
|
|
@ -28,10 +29,10 @@ defmodule Pleroma.Web.MastodonAPI.ConversationControllerTest do
|
|||
user_three: user_three,
|
||||
conn: conn
|
||||
} do
|
||||
assert User.get_cached_by_id(user_two.id).unread_conversation_count == 0
|
||||
assert Participation.unread_count(user_two) == 0
|
||||
{:ok, direct} = create_direct_message(user_one, [user_two, user_three])
|
||||
|
||||
assert User.get_cached_by_id(user_two.id).unread_conversation_count == 1
|
||||
assert Participation.unread_count(user_two) == 1
|
||||
|
||||
{:ok, _follower_only} =
|
||||
CommonAPI.post(user_one, %{
|
||||
|
|
@ -59,7 +60,7 @@ defmodule Pleroma.Web.MastodonAPI.ConversationControllerTest do
|
|||
assert is_binary(res_id)
|
||||
assert unread == false
|
||||
assert res_last_status["id"] == direct.id
|
||||
assert User.get_cached_by_id(user_one.id).unread_conversation_count == 0
|
||||
assert Participation.unread_count(user_one) == 0
|
||||
end
|
||||
|
||||
test "observes limit params", %{
|
||||
|
|
@ -134,8 +135,8 @@ defmodule Pleroma.Web.MastodonAPI.ConversationControllerTest do
|
|||
user_two = insert(:user)
|
||||
{:ok, direct} = create_direct_message(user_one, [user_two])
|
||||
|
||||
assert User.get_cached_by_id(user_one.id).unread_conversation_count == 0
|
||||
assert User.get_cached_by_id(user_two.id).unread_conversation_count == 1
|
||||
assert Participation.unread_count(user_one) == 0
|
||||
assert Participation.unread_count(user_two) == 1
|
||||
|
||||
user_two_conn =
|
||||
build_conn()
|
||||
|
|
@ -155,8 +156,8 @@ defmodule Pleroma.Web.MastodonAPI.ConversationControllerTest do
|
|||
|> post("/api/v1/conversations/#{direct_conversation_id}/read")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert User.get_cached_by_id(user_one.id).unread_conversation_count == 0
|
||||
assert User.get_cached_by_id(user_two.id).unread_conversation_count == 0
|
||||
assert Participation.unread_count(user_one) == 0
|
||||
assert Participation.unread_count(user_two) == 0
|
||||
|
||||
# The conversation is marked as unread on reply
|
||||
{:ok, _} =
|
||||
|
|
@ -171,8 +172,8 @@ defmodule Pleroma.Web.MastodonAPI.ConversationControllerTest do
|
|||
|> get("/api/v1/conversations")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert User.get_cached_by_id(user_one.id).unread_conversation_count == 1
|
||||
assert User.get_cached_by_id(user_two.id).unread_conversation_count == 0
|
||||
assert Participation.unread_count(user_one) == 1
|
||||
assert Participation.unread_count(user_two) == 0
|
||||
|
||||
# A reply doesn't increment the user's unread_conversation_count if the conversation is unread
|
||||
{:ok, _} =
|
||||
|
|
@ -182,8 +183,8 @@ defmodule Pleroma.Web.MastodonAPI.ConversationControllerTest do
|
|||
in_reply_to_status_id: direct.id
|
||||
})
|
||||
|
||||
assert User.get_cached_by_id(user_one.id).unread_conversation_count == 1
|
||||
assert User.get_cached_by_id(user_two.id).unread_conversation_count == 0
|
||||
assert Participation.unread_count(user_one) == 1
|
||||
assert Participation.unread_count(user_two) == 0
|
||||
end
|
||||
|
||||
test "(vanilla) Mastodon frontend behaviour", %{user: user_one, conn: conn} do
|
||||
|
|
|
|||
|
|
@ -121,7 +121,7 @@ defmodule Pleroma.Web.PleromaAPI.ConversationControllerTest do
|
|||
[participation2, participation1] = Participation.for_user(other_user)
|
||||
assert Participation.get(participation2.id).read == false
|
||||
assert Participation.get(participation1.id).read == false
|
||||
assert User.get_cached_by_id(other_user.id).unread_conversation_count == 2
|
||||
assert Participation.unread_count(other_user) == 2
|
||||
|
||||
[%{"unread" => false}, %{"unread" => false}] =
|
||||
conn
|
||||
|
|
@ -131,6 +131,6 @@ defmodule Pleroma.Web.PleromaAPI.ConversationControllerTest do
|
|||
[participation2, participation1] = Participation.for_user(other_user)
|
||||
assert Participation.get(participation2.id).read == true
|
||||
assert Participation.get(participation1.id).read == true
|
||||
assert User.get_cached_by_id(other_user.id).unread_conversation_count == 0
|
||||
assert Participation.unread_count(other_user) == 0
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue