Skip to content

Commit

Permalink
refactor: Replace 'PM' with 'DM'.
Browse files Browse the repository at this point in the history
refactor: Lint - Type consistency (mypy).

refactor: Install & test - CPython 3.7 (ubuntu), codecov.

refactor: Install & test - CPython 3.7 (ubuntu), codecov (2).

refactor: Install & test - CPython 3.7 (ubuntu), codeco (3).

refactor: Install & test - CPython 3.7 (ubuntu), codeco (4).
  • Loading branch information
Ajnus committed Nov 13, 2024
1 parent 9df9a74 commit 021759f
Show file tree
Hide file tree
Showing 15 changed files with 52 additions and 52 deletions.
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
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
36 changes: 18 additions & 18 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -500,13 +500,13 @@ def extra_stream_msg_template() -> Message:


@pytest.fixture
def dm_template() -> Message:
def pm_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_dm_template() -> Message:
def group_pm_template() -> Message:
recipients = display_recipient_factory(
[(5179, "Boo Boo"), (5140, "Foo Foo"), (5180, "Bar Bar")]
)
Expand All @@ -519,12 +519,12 @@ def private_message_fixture(request: Any) -> Message:


@pytest.fixture(
params=["stream_msg_template", "dm_template", "group_dm_template"],
ids=["stream_message", "dm_message", "group_dm_message"],
params=["stream_msg_template", "pm_template", "group_pm_template"],
ids=["stream_message", "pm_message", "group_pm_message"],
)
def message_fixture(request: Any) -> Message:
"""
Acts as a parametrize fixture for stream msg, dms and group_dms.
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,
dm_template: Message,
group_dm_template: Message,
pm_template: Message,
group_pm_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,
dm_template,
group_dm_template,
pm_template,
group_pm_template,
],
"result": "success",
"msg": "",
Expand Down Expand Up @@ -634,10 +634,10 @@ def topics() -> List[str]:
],
ids=[
"stream_mention__stream_wildcard",
"stream+dm_mention__no_wildcard",
"no_mention__stream+dm_wildcard",
"stream+group_mention__dm_wildcard",
"dm_mention__stream+group_wildcard",
"stream+pm_mention__no_wildcard",
"no_mention__stream+pm_wildcard",
"stream+group_mention__pm_wildcard",
"pm_mention__stream+group_wildcard",
"group_mention__all_wildcard",
"all_mention__stream_wildcard",
"stream+group_mention__wildcard",
Expand Down Expand Up @@ -1060,7 +1060,7 @@ def initial_index() -> Index:

@pytest.fixture
def empty_index(
stream_msg_template: Message, dm_template: Message, group_dm_template: Message
stream_msg_template: Message, pm_template: Message, group_pm_template: Message
) -> Index:
return deepcopy(
Index(
Expand All @@ -1079,8 +1079,8 @@ def empty_index(
lambda: {},
{
stream_msg_template["id"]: stream_msg_template,
dm_template["id"]: dm_template,
group_dm_template["id"]: group_dm_template,
pm_template["id"]: pm_template,
group_pm_template["id"]: group_pm_template,
},
),
)
Expand Down Expand Up @@ -1140,7 +1140,7 @@ def index_multiple_topic_msg(
@pytest.fixture
def index_user(empty_index: Index) -> Index:
"""
Expected index of initial_data when model.narrow = [['dm_with',
Expected index of initial_data when model.narrow = [['pm_with',
'boo@zulip.com'],
"""
user_ids = frozenset({5179, 5140})
Expand All @@ -1153,7 +1153,7 @@ def index_user(empty_index: Index) -> Index:
@pytest.fixture
def index_user_multiple(empty_index: Index) -> Index:
"""
Expected index of initial_data when model.narrow = [['dm_with',
Expected index of initial_data when model.narrow = [['pm_with',
'boo@zulip.com, bar@zulip.com'],
"""
user_ids = frozenset({5179, 5140, 5180})
Expand Down
2 changes: 1 addition & 1 deletion tests/model/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -3989,7 +3989,7 @@ def test__handle_user_settings_event(self, mocker, model, value):

@pytest.mark.parametrize("setting", [True, False])
def test_update_pm_content_in_desktop_notifications(self, mocker, model, setting):
setting_name = "dm_content_in_desktop_notifications"
setting_name = "pm_content_in_desktop_notifications"
event = {
"type": "update_global_notifications",
"notification_name": setting_name,
Expand Down
10 changes: 5 additions & 5 deletions tests/ui/test_ui_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -942,8 +942,8 @@ def test_keypress_NEXT_UNREAD_TOPIC_no_stream(
assert mid_col_view.controller.narrow_to_topic.called is False
assert return_value == key

@pytest.mark.parametrize("key", keys_for_command("NEXT_UNREAD_PM"))
def test_keypress_NEXT_UNREAD_PM_stream(
@pytest.mark.parametrize("key", keys_for_command("NEXT_UNREAD_DM"))
def test_keypress_NEXT_UNREAD_DM_stream(
self, mid_col_view, mocker, key, widget_size
):
size = widget_size(mid_col_view)
Expand All @@ -959,8 +959,8 @@ def test_keypress_NEXT_UNREAD_PM_stream(
contextual_message_id=1,
)

@pytest.mark.parametrize("key", keys_for_command("NEXT_UNREAD_PM"))
def test_keypress_NEXT_UNREAD_PM_no_dm(
@pytest.mark.parametrize("key", keys_for_command("NEXT_UNREAD_DM"))
def test_keypress_NEXT_UNREAD_DM_no_dm(
self, mid_col_view, mocker, key, widget_size
):
size = widget_size(mid_col_view)
Expand Down Expand Up @@ -1152,7 +1152,7 @@ def mock_external_classes(self, mocker):
def test_menu_view(self, mocker):
self.streams_view = mocker.patch(VIEWS + ".LeftColumnView.streams_view")
home_button = mocker.patch(VIEWS + ".HomeButton")
dm_button = mocker.patch(VIEWS + ".PMButton")
dm_button = mocker.patch(VIEWS + ".DMButton")
starred_button = mocker.patch(VIEWS + ".StarredButton")
mocker.patch(VIEWS + ".urwid.ListBox")
mocker.patch(VIEWS + ".urwid.SimpleFocusListWalker")
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
@pytest.mark.parametrize(
"msg, narrow, muted_streams, is_muted_topic_return_value, muted",
[
( # PM TEST
( # DM TEST
{
"type": "private",
# ...
Expand Down
8 changes: 4 additions & 4 deletions tests/ui_tools/test_buttons.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
from zulipterminal.config.symbols import CHECK_MARK, MUTE_MARKER
from zulipterminal.ui_tools.buttons import (
DecodedStream,
DMButton,
EmojiButton,
MessageLinkButton,
ParsedNarrowLink,
PMButton,
StarredButton,
StreamButton,
TopButton,
Expand Down Expand Up @@ -179,13 +179,13 @@ def test_update_widget(
set_attr_map.assert_called_once_with({None: top_button.label_style})


class TestPMButton:
class TestDMButton:
def test_button_text_length(self, mocker: MockerFixture, count: int = 10) -> None:
dm_button = PMButton(controller=mocker.Mock(), count=count)
dm_button = DMButton(controller=mocker.Mock(), count=count)
assert len(dm_button.label_text) == 20

def test_button_text_title(self, mocker: MockerFixture, count: int = 10) -> None:
dm_button = PMButton(controller=mocker.Mock(), count=count)
dm_button = DMButton(controller=mocker.Mock(), count=count)
title_text = dm_button.label_text[:-3].strip()
assert title_text == "Direct messages"

Expand Down
6 changes: 3 additions & 3 deletions tests/ui_tools/test_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -827,7 +827,7 @@ def test_main_view_renders_slash_me(self, mocker, message, content, is_me_messag
ids=[
"different_stream_before",
"different_topic_before",
"PM_before",
"DM_before",
],
)
def test_main_view_generates_stream_header(
Expand Down Expand Up @@ -887,7 +887,7 @@ def test_main_view_generates_stream_header(
"stream_before",
],
)
def test_main_view_generates_PM_header(
def test_main_view_generates_DM_header(
self, mocker, message, to_vary_in_last_message
):
last_message = dict(message, **to_vary_in_last_message)
Expand Down Expand Up @@ -1041,7 +1041,7 @@ def test_msg_generates_search_and_header_bar(
assert header_bar[0].text.startswith(assert_header_bar)
assert search_bar.text_to_fill == assert_search_bar

# Assume recipient (PM/stream/topic) header is unchanged below
# Assume recipient (DM/stream/topic) header is unchanged below
@pytest.mark.parametrize(
"message",
[
Expand Down
6 changes: 3 additions & 3 deletions zulipterminal/config/keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ class KeyBinding(TypedDict):
'help_text': 'View all messages',
'key_category': 'narrowing',
},
'ALL_PM': {
'ALL_DM': {
'keys': ['P'],
'help_text': 'View all direct messages',
'key_category': 'narrowing',
Expand All @@ -234,7 +234,7 @@ class KeyBinding(TypedDict):
'help_text': 'Next unread topic',
'key_category': 'narrowing',
},
'NEXT_UNREAD_PM': {
'NEXT_UNREAD_DM': {
'keys': ['p'],
'help_text': 'Next unread direct message',
'key_category': 'narrowing',
Expand Down Expand Up @@ -346,7 +346,7 @@ class KeyBinding(TypedDict):
'help_text': 'Show/hide user information',
'key_category': 'user_list',
},
'NARROW_TO_USER_PM': {
'NARROW_TO_USER_DM': {
# Added to clarify functionality of button activation,
# as opposed to opening user profile or other effects.
# Implementation uses ACTIVATE_BUTTON command.
Expand Down
4 changes: 2 additions & 2 deletions zulipterminal/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -645,15 +645,15 @@ def narrow_to_user(
) -> None:
self._narrow_to(
anchor=contextual_message_id,
dm_with=", ".join(recipient_emails),
pm_with=", ".join(recipient_emails),
)

def narrow_to_all_messages(
self, *, contextual_message_id: Optional[int] = None
) -> None:
self._narrow_to(anchor=contextual_message_id)

def narrow_to_all_pm(self, *, contextual_message_id: Optional[int] = None) -> None:
def narrow_to_all_dm(self, *, contextual_message_id: Optional[int] = None) -> None:
self._narrow_to(anchor=contextual_message_id, pms=True)

def narrow_to_all_starred(self) -> None:
Expand Down
4 changes: 2 additions & 2 deletions zulipterminal/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ def keypress(self, size: urwid_Box, key: str) -> Optional[str]:
elif (
is_command_key("SEARCH_MESSAGES", key)
or is_command_key("NEXT_UNREAD_TOPIC", key)
or is_command_key("NEXT_UNREAD_PM", key)
or is_command_key("NEXT_UNREAD_DM", key)
or is_command_key("STREAM_MESSAGE", key)
or is_command_key("DIRECT_MESSAGE", key)
):
Expand All @@ -269,7 +269,7 @@ def keypress(self, size: urwid_Box, key: str) -> Optional[str]:
self.body.focus_col = 1
self.middle_column.keypress(size, key)
return key
elif is_command_key("ALL_PM", key):
elif is_command_key("ALL_DM", key):
self.dm_button.activate(key)
elif is_command_key("ALL_STARRED", key):
self.starred_button.activate(key)
Expand Down
8 changes: 4 additions & 4 deletions zulipterminal/ui_tools/boxes.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,12 @@ def __init__(self, view: Any) -> None:
# Set to int for stream box only
self.stream_id: Optional[int]

# Used in PM and stream boxes
# (empty list implies PM box empty, or not initialized)
# Used in DM and stream boxes
# (empty list implies DM box empty, or not initialized)
# Prioritizes autocomplete in message body
self.recipient_user_ids: List[int]

# Updates server on PM typing events
# Updates server on DM typing events
# Is separate from recipient_user_ids because we
# don't include the user's own id in this list
self.typing_recipient_user_ids: List[int]
Expand Down Expand Up @@ -168,7 +168,7 @@ def _set_regular_and_typing_recipient_user_ids(
self.typing_recipient_user_ids = list()

def send_stop_typing_status(self) -> None:
# Send 'stop' updates only for PM narrows, when there are recipients
# Send 'stop' updates only for DM narrows, when there are recipients
# to send to and a prior 'start' status has already been sent.
if (
self.compose_box_status == "open_with_private"
Expand Down
4 changes: 2 additions & 2 deletions zulipterminal/ui_tools/buttons.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,9 @@ def __init__(self, *, controller: Any, count: int) -> None:
)


class PMButton(TopButton):
class DMButton(TopButton):
def __init__(self, *, controller: Any, count: int) -> None:
button_text = f"Direct messages [{primary_display_key_for_command('ALL_PM')}]"
button_text = f"Direct messages [{primary_display_key_for_command('ALL_DM')}]"

super().__init__(
controller=controller,
Expand Down
2 changes: 1 addition & 1 deletion zulipterminal/ui_tools/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def create_msg_box_list(

# The SIM114 warnings are ignored here since combining the branches would be less clear
def is_muted(msg: Message, model: Any) -> bool:
# PMs cannot be muted
# DMs cannot be muted
if msg["type"] == "private": # noqa: SIM114
return False
# In a topic narrow
Expand Down
8 changes: 4 additions & 4 deletions zulipterminal/ui_tools/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@
from zulipterminal.server_url import near_message_url
from zulipterminal.ui_tools.boxes import PanelSearchBox
from zulipterminal.ui_tools.buttons import (
DMButton,
EmojiButton,
HomeButton,
MentionedButton,
MessageLinkButton,
PMButton,
StarredButton,
StreamButton,
TopicButton,
Expand Down Expand Up @@ -629,7 +629,7 @@ def keypress(self, size: urwid_Size, key: str) -> Optional[str]:
topic_name=topic,
)
return key
elif is_command_key("NEXT_UNREAD_PM", key):
elif is_command_key("NEXT_UNREAD_DM", key):
# narrow to next unread dm
dm = self.model.get_next_unread_pm()
if dm is None:
Expand All @@ -640,7 +640,7 @@ def keypress(self, size: urwid_Size, key: str) -> Optional[str]:
contextual_message_id=dm,
)
elif is_command_key("DIRECT_MESSAGE", key):
# Create new PM message
# Create new DM message
self.footer.private_box_view()
self.set_focus("footer")
self.footer.focus_position = 0
Expand Down Expand Up @@ -793,7 +793,7 @@ def menu_view(self) -> Any:
self.view.home_button = HomeButton(controller=self.controller, count=count)

count = self.model.unread_counts.get("all_dms", 0)
self.view.dm_button = PMButton(controller=self.controller, count=count)
self.view.dm_button = DMButton(controller=self.controller, count=count)

self.view.mentioned_button = MentionedButton(
controller=self.controller,
Expand Down

0 comments on commit 021759f

Please sign in to comment.