Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bugfix: Fix wildcard_mentions not showing in mentions narrow. #1038

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
157 changes: 147 additions & 10 deletions tests/model/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -888,6 +888,8 @@ def test_toggle_stream_muted_status(
(["read"], "add"),
(["read", "starred"], "remove"),
(["starred", "read"], "remove"),
(["read", "mentioned", "wildcard_mentioned"], "add"),
(["mentioned", "wildcard_mentioned", "starred"], "remove"),
],
)
def test_toggle_message_star_status(
Expand Down Expand Up @@ -1311,7 +1313,8 @@ def test_notify_users_enabled(
assert notify.called == is_notify_called

@pytest.mark.parametrize(
"event, expected_times_messages_rerendered, expected_index, topic_view_enabled",
"event, expected_times_messages_rerendered, expected_index, topic_view_enabled,"
"initial_flags, mentioned_msg_ids",
[
case(
{ # Only subject of 1 message is updated.
Expand All @@ -1328,18 +1331,23 @@ def test_notify_users_enabled(
"stream_id": 10,
"content": "old content",
"subject": "new subject",
"flags": ["read"],
},
2: {
"id": 2,
"stream_id": 10,
"content": "old content",
"subject": "old subject",
"flags": ["read"],
},
},
"edited_messages": {1},
"topics": {10: []},
"mentioned_msg_ids": set(),
},
False,
["read"],
set(),
id="Only subject of 1 message is updated",
),
case(
Expand All @@ -1357,77 +1365,94 @@ def test_notify_users_enabled(
"stream_id": 10,
"content": "old content",
"subject": "new subject",
"flags": ["read"],
},
2: {
"id": 2,
"stream_id": 10,
"content": "old content",
"subject": "new subject",
"flags": ["read"],
},
},
"edited_messages": {1},
"topics": {10: []},
"mentioned_msg_ids": set(),
},
False,
["read"],
set(),
id="Subject of 2 messages is updated",
),
case(
{ # Message content is updated
{ # Message content is updated, wildcard-mention added
"message_id": 1,
"stream_id": 10,
"rendered_content": "<p>new content</p>",
"flags": ["read", "wildcard_mentioned"],
},
1,
2,
{
"messages": {
1: {
"id": 1,
"stream_id": 10,
"content": "<p>new content</p>",
"subject": "old subject",
"flags": ["read", "wildcard_mentioned"],
},
2: {
"id": 2,
"stream_id": 10,
"content": "old content",
"subject": "old subject",
"flags": ["read"],
},
},
"edited_messages": {1},
"topics": {10: ["old subject"]},
"mentioned_msg_ids": {1},
},
False,
id="Message content is updated",
["read"],
set(),
id="Message content is updated, wildcard-mention added",
),
case(
{ # Both message content and subject is updated.
{ # Both message content and subject is updated, mention added.
"message_id": 1,
"rendered_content": "<p>new content</p>",
"subject": "new subject",
"stream_id": 10,
"message_ids": [1],
"flags": ["read", "mentioned"],
},
2,
3,
{ # 2=update of subject & content
"messages": {
1: {
"id": 1,
"stream_id": 10,
"content": "<p>new content</p>",
"subject": "new subject",
"flags": ["read", "mentioned"],
},
2: {
"id": 2,
"stream_id": 10,
"content": "old content",
"subject": "old subject",
"flags": ["read"],
},
},
"edited_messages": {1},
"topics": {10: []},
"mentioned_msg_ids": {1},
},
False,
id="Both message content and subject is updated",
["read"],
set(),
id="Both message content and subject is updated, mention added",
),
case(
{ # Some new type of update which we don't handle yet.
Expand All @@ -1442,18 +1467,23 @@ def test_notify_users_enabled(
"stream_id": 10,
"content": "old content",
"subject": "old subject",
"flags": ["read"],
},
2: {
"id": 2,
"stream_id": 10,
"content": "old content",
"subject": "old subject",
"flags": ["read"],
},
},
"edited_messages": {1},
"topics": {10: ["old subject"]},
"mentioned_msg_ids": set(),
},
False,
["read"],
set(),
id="Some new type of update which we don't handle yet",
),
case(
Expand All @@ -1472,18 +1502,23 @@ def test_notify_users_enabled(
"stream_id": 10,
"content": "old content",
"subject": "old subject",
"flags": ["read"],
},
2: {
"id": 2,
"stream_id": 10,
"content": "old content",
"subject": "old subject",
"flags": ["read"],
},
},
"edited_messages": set(),
"topics": {10: []}, # This resets the cache
"mentioned_msg_ids": set(),
},
False,
["read"],
set(),
id="message_id not present in index, topic view closed",
),
case(
Expand All @@ -1502,49 +1537,132 @@ def test_notify_users_enabled(
"stream_id": 10,
"content": "old content",
"subject": "old subject",
"flags": ["read"],
},
2: {
"id": 2,
"stream_id": 10,
"content": "old content",
"subject": "old subject",
"flags": ["read"],
},
},
"edited_messages": set(),
"topics": {10: ["new subject", "old subject"]},
"mentioned_msg_ids": set(),
},
True,
["read"],
set(),
id="message_id not present in index, topic view is enabled",
),
case(
{ # Message content is updated and topic view is enabled.
{ # Message content updated and topic view is enabled, mention removed.
"message_id": 1,
"rendered_content": "<p>new content</p>",
"subject": "new subject",
"stream_id": 10,
"message_ids": [1],
"flags": ["read"],
},
2,
3,
{
"messages": {
1: {
"id": 1,
"stream_id": 10,
"content": "<p>new content</p>",
"subject": "new subject",
"flags": ["read"],
},
2: {
"id": 2,
"stream_id": 10,
"content": "old content",
"subject": "old subject",
"flags": ["read"],
},
},
"edited_messages": {1},
"topics": {10: ["new subject", "old subject"]},
"mentioned_msg_ids": set(),
},
True,
id="Message content is updated and topic view is enabled",
["read", "mentioned"],
{1},
id="Message content updated and topic view is enabled, mention removed",
),
case(
{ # wildcard_mentioned flag added with no subject change
"message_id": 1,
"rendered_content": "<p>new content @**stream**</p>",
"subject": "old subject",
"stream_id": 10,
"message_ids": [1],
"flags": ["read", "wildcard_mentioned"],
},
3,
{
"messages": {
1: {
"id": 1,
"stream_id": 10,
"content": "<p>new content @**stream**</p>",
"subject": "old subject",
"flags": ["read", "wildcard_mentioned"],
},
2: {
"id": 2,
"stream_id": 10,
"content": "old content",
"subject": "old subject",
"flags": ["read"],
},
},
"mentioned_msg_ids": {1},
"edited_messages": {1},
"topics": {10: []},
},
False,
["read"],
set(),
id="wildcard_mentioned flag added with no subject change",
),
case(
{ # wildcard_mentioned flag removed with no subject change.
"message_id": 1,
"rendered_content": "<p>new content</p>",
"subject": "old subject",
"stream_id": 10,
"message_ids": [1],
"flags": ["read"],
},
3,
{
"messages": {
1: {
"id": 1,
"stream_id": 10,
"content": "<p>new content</p>",
"subject": "old subject",
"flags": ["read"],
},
2: {
"id": 2,
"stream_id": 10,
"content": "old content",
"subject": "old subject",
"flags": ["read"],
},
},
"mentioned_msg_ids": set(),
"edited_messages": {1},
"topics": {10: []},
},
False,
["read", "wildcard_mentioned"],
{1},
id="wildcard_mentioned flag removed with no subject change",
),
],
)
Expand All @@ -1556,6 +1674,8 @@ def test__handle_update_message_event(
expected_index,
expected_times_messages_rerendered,
topic_view_enabled,
initial_flags,
mentioned_msg_ids,
):
event["type"] = "update_message"

Expand All @@ -1566,9 +1686,11 @@ def test__handle_update_message_event(
"stream_id": 10,
"content": "old content",
"subject": "old subject",
"flags": initial_flags if message_id == 1 else ["read"],
}
for message_id in [1, 2]
},
"mentioned_msg_ids": mentioned_msg_ids,
"edited_messages": set(),
"topics": {10: ["old subject"]},
}
Expand Down Expand Up @@ -1870,11 +1992,18 @@ def test_update_star_status_invalid_operation(
("add", 1, ["read"], ["read", "starred"]),
("add", 1, ["starred"], ["starred"]),
("add", 1, ["read", "starred"], ["read", "starred"]),
("add", 1, ["mentioned"], ["mentioned", "starred"]),
("add", 1, ["mentioned", "starred"], ["mentioned", "starred"]),
("add", 1, ["wildcard_mentioned"], ["wildcard_mentioned", "starred"]),
("remove", -1, [], []),
("remove", -1, ["read"], ["read"]),
("remove", -1, ["starred"], []),
("remove", -1, ["read", "starred"], ["read"]),
("remove", -1, ["starred", "read"], ["read"]),
("remove", -1, ["mentioned"], ["mentioned"]),
("remove", -1, ["wildcard_mentioned"], ["wildcard_mentioned"]),
("remove", -1, ["mentioned", "starred"], ["mentioned"]),
("remove", -1, ["wildcard_mentioned", "starred"], ["wildcard_mentioned"]),
zee-bit marked this conversation as resolved.
Show resolved Hide resolved
],
)
def test_update_star_status(
Expand Down Expand Up @@ -1953,11 +2082,19 @@ def test_update_star_status(
("add", ["read"], ["read"]),
("add", ["starred"], ["starred", "read"]),
("add", ["read", "starred"], ["read", "starred"]),
("add", ["mentioned"], ["mentioned", "read"]),
("add", ["read", "mentioned"], ["read", "mentioned"]),
("add", ["mentioned", "starred"], ["mentioned", "starred", "read"]),
("add", ["wildcard_mentioned"], ["wildcard_mentioned", "read"]),
("remove", [], []),
("remove", ["read"], ["read"]), # msg cannot be marked 'unread'
("remove", ["starred"], ["starred"]),
("remove", ["mentioned"], ["mentioned"]),
("remove", ["starred", "read"], ["starred", "read"]),
("remove", ["read", "starred"], ["read", "starred"]),
("remove", ["read", "mentioned"], ["read", "mentioned"]),
("remove", ["wildcard_mentioned"], ["wildcard_mentioned"]),
("remove", ["read", "wildcard_mentioned"], ["read", "wildcard_mentioned"]),
],
)
def test_update_read_status(
Expand Down
1 change: 1 addition & 0 deletions zulipterminal/api_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ class UpdateMessageEvent(TypedDict):
message_ids: List[int]
subject: str
stream_id: int
flags: List[MessageFlag]
zee-bit marked this conversation as resolved.
Show resolved Hide resolved


class ReactionEvent(TypedDict):
Expand Down
Loading