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

Migrate internal code to use Direct Message terminology #1553

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
2 changes: 1 addition & 1 deletion docs/FAQ.md
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ through autocomplete depend upon the context automatically.
* `P` (with stream color) if the stream is valid and private,
* `✗` if the stream is invalid.

![PM recipients header](https://user-images.githubusercontent.com/55916430/118403345-9d422800-b68b-11eb-9005-6d2af74adab9.png)
![DM recipients header](https://user-images.githubusercontent.com/55916430/118403345-9d422800-b68b-11eb-9005-6d2af74adab9.png)

**NOTE:** If a direct message recipient's name contains comma(s) (`,`), they
are currently treated as comma-separated recipients.
Expand Down
6 changes: 3 additions & 3 deletions docs/developer-feature-tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

This tutorial shows how typing indicator was implemented in the client. The process for adding a new feature to zulip terminal varies greatly depending on the feature. This tutorial is intended to make you familiar with the general process.

Since the typing indicator data for the other user in pm cannot be generated locally, it should be received from the client.
Since the typing indicator data for the other user in dm cannot be generated locally, it should be received from the client.

A quick google search for `zulip typing indicator` points to https://zulip.readthedocs.io/en/latest/subsystems/typing-indicators.html. This document explains how typing indicator is implemented on the web client and is useful in understanding how typing indicator works internally.

Expand Down Expand Up @@ -113,9 +113,9 @@ To check for the above conditions, we create a function in `ui.py`:
```python

def handle_typing_event(self, event: Dict['str', Any]) -> None:
# If the user is in pm narrow with the person typing
# If the user is in dm narrow with the person typing
if len(self.model.narrow) == 1 and\
self.model.narrow[0][0] == 'pm_with' and\
self.model.narrow[0][0] == 'dm_with' and\
event['sender']['email'] in self.model.narrow[0][1].split(','):
if event['op'] == 'start':
user = self.model.user_dict[event['sender']['email']]
Expand Down
6 changes: 3 additions & 3 deletions docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ If you want to show you agree with the current message, type <kbd>+</kbd> to add

Let's try sending a direct message to the author of a message. Select the message you sent to the [#test here](https://chat.zulip.org/#narrow/stream/7-test-here) stream earlier and press <kbd>shift</kbd><kbd>r</kbd> to send a direct message to yourself. Type your message in the message editor that appears at the bottom of the middle column and then type <kbd>ctrl</kbd><kbd>d</kbd> to send. Press the <kbd>shift</kbd><kbd>p</kbd> hotkey as we did earlier in the tutorial to narrow to your direct messages and make sure everything worked properly.

<img src="getting-started-imgs/send-pm.png" width="85%">
<img src="getting-started-imgs/send-dm.png" width="85%">

### Send a Direct Message to Someone New

Expand All @@ -159,8 +159,8 @@ Try following the steps above to send a message to the Welcome Bot!

> It's best to use <kbd>ctrl</kbd><kbd>f</kbd> to autocomplete the name and Zulip address of the person (or bot) you want to message; if you just type in their full name, Zulip Terminal does not know for sure who you are trying to send to - and there may be multiple people with that name!

<img src="getting-started-imgs/send-pm-autocomplete1.png" width="85%">
<img src="getting-started-imgs/send-pm-autocomplete2.png" width="85%">
<img src="getting-started-imgs/send-dm-autocomplete1.png" width="85%">
<img src="getting-started-imgs/send-dm-autocomplete2.png" width="85%">

### Create a New Topic

Expand Down
2 changes: 1 addition & 1 deletion tests/config/test_keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def test_display_key_for_urwid_key(urwid_key: str, display_key: str) -> None:
COMMAND_TO_DISPLAY_KEYS = [
("NEXT_LINE", ["Down", "Ctrl n"]),
("TOGGLE_STAR_STATUS", ["Ctrl s", "*"]),
("ALL_PM", ["P"]),
("ALL_DM", ["P"]),
]


Expand Down
52 changes: 26 additions & 26 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ def msg_template_factory(
"""
Generate message template for all types of messages(stream/PM/group)
"""
# TODO: Separate Message into distinct types for stream and private messages.
# TODO: Separate Message into distinct types for stream and direct messages.
message = Message(
id=msg_id,
sender_full_name="Foo Foo",
Expand Down Expand Up @@ -500,31 +500,31 @@ def extra_stream_msg_template() -> Message:


@pytest.fixture
def pm_template() -> Message:
def dm_template() -> Message:
recipients = display_recipient_factory([(5179, "Boo Boo"), (5140, "Foo Foo")])
return msg_template_factory(537287, "private", 1520918736, recipients=recipients)


@pytest.fixture
def group_pm_template() -> Message:
def group_dm_template() -> Message:
recipients = display_recipient_factory(
[(5179, "Boo Boo"), (5140, "Foo Foo"), (5180, "Bar Bar")]
)
return msg_template_factory(537288, "private", 1520918737, recipients=recipients)


@pytest.fixture(params=["pm_template", "group_pm_template"])
def private_message_fixture(request: Any) -> Message:
@pytest.fixture(params=["dm_template", "group_dm_template"])
def direct_message_fixture(request: Any) -> Message:
return request.getfixturevalue(request.param)


@pytest.fixture(
params=["stream_msg_template", "pm_template", "group_pm_template"],
params=["stream_msg_template", "dm_template", "group_dm_template"],
ids=["stream_message", "pm_message", "group_pm_message"],
)
def message_fixture(request: Any) -> Message:
"""
Acts as a parametrize fixture for stream msg, pms and group_pms.
Acts as a parametrize fixture for stream msg, dms and group_pms.
"""
# `request` currently does not have an exported Pytest type.
# TODO: Use the exported type when it's made available.
Expand All @@ -535,8 +535,8 @@ def message_fixture(request: Any) -> Message:
@pytest.fixture
def messages_successful_response(
stream_msg_template: Message,
pm_template: Message,
group_pm_template: Message,
dm_template: Message,
group_dm_template: Message,
) -> Dict[str, Any]:
"""
A successful response from a /messages API query.
Expand All @@ -546,8 +546,8 @@ def messages_successful_response(
"anchor": 10000000000000000,
"messages": [
stream_msg_template,
pm_template,
group_pm_template,
dm_template,
group_dm_template,
],
"result": "success",
"msg": "",
Expand Down Expand Up @@ -1060,16 +1060,16 @@ def initial_index() -> Index:

@pytest.fixture
def empty_index(
stream_msg_template: Message, pm_template: Message, group_pm_template: Message
stream_msg_template: Message, dm_template: Message, group_dm_template: Message
) -> Index:
return deepcopy(
Index(
pointer=dict(),
all_msg_ids=set(),
starred_msg_ids=set(),
mentioned_msg_ids=set(),
private_msg_ids=set(),
private_msg_ids_by_user_ids=defaultdict(set, {}),
direct_msg_ids=set(),
direct_msg_ids_by_user_ids=defaultdict(set, {}),
stream_msg_ids_by_stream_id=defaultdict(set, {}),
topic_msg_ids=defaultdict(dict, {}),
edited_messages=set(),
Expand All @@ -1079,8 +1079,8 @@ def empty_index(
lambda: {},
{
stream_msg_template["id"]: stream_msg_template,
pm_template["id"]: pm_template,
group_pm_template["id"]: group_pm_template,
dm_template["id"]: dm_template,
group_dm_template["id"]: group_dm_template,
},
),
)
Expand All @@ -1104,7 +1104,7 @@ def index_stream(empty_index: Index) -> Index:
"""
index = empty_index
index["stream_msg_ids_by_stream_id"] = defaultdict(set, {205: {537286}})
index["private_msg_ids"] = {537287, 537288}
index["direct_msg_ids"] = {537287, 537288}
return index


Expand Down Expand Up @@ -1140,26 +1140,26 @@ def index_multiple_topic_msg(
@pytest.fixture
def index_user(empty_index: Index) -> Index:
"""
Expected index of initial_data when model.narrow = [['pm_with',
Expected index of initial_data when model.narrow = [['dm_with',
'[email protected]'],
"""
user_ids = frozenset({5179, 5140})
index = empty_index
index["private_msg_ids_by_user_ids"] = defaultdict(set, {user_ids: {537287}})
index["private_msg_ids"] = {537287, 537288}
index["direct_msg_ids_by_user_ids"] = defaultdict(set, {user_ids: {537287}})
index["direct_msg_ids"] = {537287, 537288}
return index


@pytest.fixture
def index_user_multiple(empty_index: Index) -> Index:
"""
Expected index of initial_data when model.narrow = [['pm_with',
Expected index of initial_data when model.narrow = [['dm_with',
'[email protected], [email protected]'],
"""
user_ids = frozenset({5179, 5140, 5180})
index = empty_index
index["private_msg_ids_by_user_ids"] = defaultdict(set, {user_ids: {537288}})
index["private_msg_ids"] = {537287, 537288}
index["direct_msg_ids_by_user_ids"] = defaultdict(set, {user_ids: {537288}})
index["direct_msg_ids"] = {537287, 537288}
return index


Expand All @@ -1178,7 +1178,7 @@ def index_all_starred(empty_index: Index, request: Any) -> Index:
msgs_with_stars = request.param
index = empty_index
index["starred_msg_ids"] = msgs_with_stars
index["private_msg_ids"] = {537287, 537288}
index["direct_msg_ids"] = {537287, 537288}
for msg_id, msg in index["messages"].items():
if msg_id in msgs_with_stars and "starred" not in msg["flags"]:
msg["flags"].append("starred")
Expand All @@ -1192,7 +1192,7 @@ def index_all_mentions(
mentioned_messages, wildcard_mentioned_messages = mentioned_messages_combination
index = empty_index
index["mentioned_msg_ids"] = mentioned_messages | wildcard_mentioned_messages
index["private_msg_ids"] = {537287, 537288}
index["direct_msg_ids"] = {537287, 537288}
for msg_id, msg in index["messages"].items():
if msg_id in mentioned_messages and "mentioned" not in msg["flags"]:
msg["flags"].append("mentioned")
Expand Down Expand Up @@ -1468,7 +1468,7 @@ def classified_unread_counts() -> Dict[str, Any]:
"""
return {
"all_msg": 12,
"all_pms": 8,
"all_dms": 8,
"unread_topics": {
(1000, "Some general unread topic"): 3,
(99, "Some private unread topic"): 1,
Expand Down
10 changes: 5 additions & 5 deletions tests/core/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ def test_narrow_to_user(
recipients = frozenset([controller.model.user_id, user_id])
assert controller.model.recipients == recipients
widget = controller.view.message_view.log.extend.call_args_list[0][0][0][0]
id_list = index_user["private_msg_ids_by_user_ids"][recipients]
id_list = index_user["direct_msg_ids_by_user_ids"][recipients]
assert {widget.original_widget.message["id"]} == id_list

@pytest.mark.parametrize(
Expand Down Expand Up @@ -287,7 +287,7 @@ def test_narrow_to_all_messages(
assert msg_ids == id_list
assert final_focus_msg_id == expected_final_focus_msg_id

def test_narrow_to_all_pm(
def test_narrow_to_all_dm(
self, mocker: MockerFixture, controller: Controller, index_user: Index
) -> None:
controller.model.narrow = []
Expand All @@ -296,13 +296,13 @@ def test_narrow_to_all_pm(
controller.model.user_id = 1
controller.model.user_email = "some@email"

controller.narrow_to_all_pm() # FIXME: Add id narrowing test
controller.narrow_to_all_dm() # FIXME: Add id narrowing test

assert controller.model.narrow == [["is", "private"]]
controller.view.message_view.log.clear.assert_called_once_with()

widgets = controller.view.message_view.log.extend.call_args_list[0][0][0]
id_list = index_user["private_msg_ids"]
id_list = index_user["direct_msg_ids"]
msg_ids = {widget.original_widget.message["id"] for widget in widgets}
assert msg_ids == id_list

Expand Down Expand Up @@ -514,7 +514,7 @@ def test_stream_muting_confirmation_popup(
"Default_all_msg_search",
"redo_default_search",
"search_within_stream",
"pm_search_again",
"dm_search_again",
"search_within_topic_narrow",
],
)
Expand Down
4 changes: 2 additions & 2 deletions tests/helper/test_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ def test_index_starred(
model.narrow = [["is", "starred"]]
model.is_search_narrow.return_value = False
expected_index: Dict[str, Any] = dict(
empty_index, private_msg_ids={537287, 537288}, starred_msg_ids=msgs_with_stars
empty_index, direct_msg_ids={537287, 537288}, starred_msg_ids=msgs_with_stars
)
for msg_id, msg in expected_index["messages"].items():
if msg_id in msgs_with_stars and "starred" not in msg["flags"]:
Expand Down Expand Up @@ -211,7 +211,7 @@ def test_index_mentioned_messages(
model.is_search_narrow.return_value = False
expected_index: Dict[str, Any] = dict(
empty_index,
private_msg_ids={537287, 537288},
direct_msg_ids={537287, 537288},
mentioned_msg_ids=(mentioned_messages | wildcard_mentioned_messages),
)

Expand Down
26 changes: 13 additions & 13 deletions tests/model/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,9 +407,9 @@ def test_is_search_narrow(self, model, narrow, is_search_narrow):
"bad_args",
[
dict(topic="some topic"),
dict(stream="foo", pm_with="someone"),
dict(topic="blah", pm_with="someone"),
dict(pm_with="someone", topic="foo"),
dict(stream="foo", dm_with="someone"),
dict(topic="blah", dm_with="someone"),
dict(dm_with="someone", topic="foo"),
],
)
def test_set_narrow_bad_input(self, model, bad_args):
Expand All @@ -428,7 +428,7 @@ def test_set_narrow_bad_input(self, model, bad_args):
([["is", "starred"]], dict(starred=True)),
([["is", "mentioned"]], dict(mentioned=True)),
([["is", "private"]], dict(pms=True)),
([["pm-with", "[email protected]"]], dict(pm_with="[email protected]")),
([["pm-with", "[email protected]"]], dict(dm_with="[email protected]")),
],
)
def test_set_narrow_already_set(self, model, narrow, good_args):
Expand All @@ -449,7 +449,7 @@ def test_set_narrow_already_set(self, model, narrow, good_args):
([], [["is", "starred"]], dict(starred=True)),
([], [["is", "mentioned"]], dict(mentioned=True)),
([], [["is", "private"]], dict(pms=True)),
([], [["pm-with", "[email protected]"]], dict(pm_with="[email protected]")),
([], [["pm-with", "[email protected]"]], dict(dm_with="[email protected]")),
],
)
def test_set_narrow_not_already_set(
Expand Down Expand Up @@ -478,16 +478,16 @@ def test_set_narrow_not_already_set(
{"topic_msg_ids": {1: {"BOO": {0, 1}}}},
set(),
),
([["is", "private"]], {"private_msg_ids": {0, 1}}, {0, 1}),
([["is", "private"]], {"direct_msg_ids": {0, 1}}, {0, 1}),
(
[["pm-with", "[email protected]"]],
{"private_msg_ids_by_user_ids": {frozenset({1, 2}): {0, 1}}},
{"direct_msg_ids_by_user_ids": {frozenset({1, 2}): {0, 1}}},
{0, 1},
),
(
[["pm-with", "[email protected]"]],
{ # Covers recipient empty-set case
"private_msg_ids_by_user_ids": {
"direct_msg_ids_by_user_ids": {
frozenset({1, 3}): {0, 1} # NOTE {1,3} not {1,2}
}
},
Expand Down Expand Up @@ -2283,12 +2283,12 @@ def test_notify_users_enabled(
[(True, "New direct message from Foo Foo"), (False, "private content here.")],
)
def test_notify_users_hides_PM_content_based_on_user_setting(
self, mocker, model, private_message_fixture, hide_content, expected_content
self, mocker, model, direct_message_fixture, hide_content, expected_content
):
notify = mocker.patch(MODULE + ".notify")
model._user_settings["pm_content_in_desktop_notifications"] = not hide_content

message = private_message_fixture
message = direct_message_fixture
message["user_id"] = 5179
message["flags"] = []

Expand Down Expand Up @@ -4521,20 +4521,20 @@ def test_next_unread_topic_from_message__empty_narrow(

assert unread_topic == next_unread_topic

def test_get_next_unread_pm(self, model):
def test_get_next_unread_dm(self, model):
model.unread_counts = {"unread_pms": {1: 1, 2: 1}}
return_value = model.get_next_unread_pm()
assert return_value == 1
assert model.last_unread_pm == 1

def test_get_next_unread_pm_again(self, model):
def test_get_next_unread_dm_again(self, model):
model.unread_counts = {"unread_pms": {1: 1, 2: 1}}
model.last_unread_pm = 1
return_value = model.get_next_unread_pm()
assert return_value == 2
assert model.last_unread_pm == 2

def test_get_next_unread_pm_no_unread(self, model):
def test_get_next_unread_dm_no_unread(self, model):
model.unread_counts = {"unread_pms": {}}
return_value = model.get_next_unread_pm()
assert return_value is None
Expand Down
Loading
Loading