Skip to content

Commit

Permalink
refactor: Replace '_pm' with '_dm' - rebased.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ajnus committed Nov 14, 2024
1 parent a5703a7 commit 84e1bfe
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 32 deletions.
16 changes: 8 additions & 8 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -506,20 +506,20 @@ def pm_template() -> Message:


@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"])
@pytest.fixture(params=["pm_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", "pm_template", "group_dm_template"],
ids=["stream_message", "pm_message", "group_pm_message"],
)
def message_fixture(request: Any) -> Message:
Expand All @@ -536,7 +536,7 @@ def message_fixture(request: Any) -> Message:
def messages_successful_response(
stream_msg_template: Message,
pm_template: Message,
group_pm_template: Message,
group_dm_template: Message,
) -> Dict[str, Any]:
"""
A successful response from a /messages API query.
Expand All @@ -547,7 +547,7 @@ def messages_successful_response(
"messages": [
stream_msg_template,
pm_template,
group_pm_template,
group_dm_template,
],
"result": "success",
"msg": "",
Expand Down Expand Up @@ -1060,7 +1060,7 @@ def initial_index() -> Index:

@pytest.fixture
def empty_index(
stream_msg_template: Message, pm_template: Message, group_pm_template: Message
stream_msg_template: Message, pm_template: Message, group_dm_template: Message
) -> Index:
return deepcopy(
Index(
Expand All @@ -1080,7 +1080,7 @@ def empty_index(
{
stream_msg_template["id"]: stream_msg_template,
pm_template["id"]: pm_template,
group_pm_template["id"]: group_pm_template,
group_dm_template["id"]: group_dm_template,
},
),
)
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
4 changes: 2 additions & 2 deletions tests/core/test_core.py
Original file line number Diff line number Diff line change
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,7 +296,7 @@ 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()
Expand Down
6 changes: 3 additions & 3 deletions tests/model/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -4291,20 +4291,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
4 changes: 2 additions & 2 deletions tests/ui/test_ui_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -960,7 +960,7 @@ def test_keypress_NEXT_UNREAD_PM_stream(
)

@pytest.mark.parametrize("key", keys_for_command("NEXT_UNREAD_PM"))
def test_keypress_NEXT_UNREAD_PM_no_pm(
def test_keypress_NEXT_UNREAD_PM_no_dm(
self, mid_col_view, mocker, key, widget_size
):
size = widget_size(mid_col_view)
Expand Down Expand Up @@ -1128,7 +1128,7 @@ def mock_external_classes(self, mocker):
self.view.model = mocker.Mock()
self.view.model.unread_counts = { # Minimal, though an UnreadCounts
"all_msg": 2,
"all_pms": 0,
"all_dms": 0,
"streams": {
86: 1,
14: 1,
Expand Down
2 changes: 1 addition & 1 deletion zulipterminal/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,7 @@ def narrow_to_all_messages(
) -> 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
22 changes: 11 additions & 11 deletions zulipterminal/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ class Index(TypedDict):

class UnreadCounts(TypedDict):
all_msg: int
all_pms: int
all_dms: int
all_mentions: int
unread_topics: Dict[Tuple[int, str], int] # stream_id, topic
unread_pms: Dict[int, int] # sender_id
Expand Down Expand Up @@ -227,7 +227,7 @@ def _set_count_in_view(
) -> None:
"""
This function for the most part contains the logic for setting the
count in the UI buttons. The later buttons (all_msg, all_pms)
count in the UI buttons. The later buttons (all_msg, all_dms)
additionally set the current count in the model and make use of the
same in the UI.
"""
Expand All @@ -238,7 +238,7 @@ def _set_count_in_view(
toggled_stream_id = controller.view.topic_w.stream_button.stream_id
user_buttons_list = controller.view.user_w.users_btn_list
all_msg = controller.view.home_button
all_pm = controller.view.pm_button
all_dm = controller.view.pm_button
all_mentioned = controller.view.mentioned_button
for message in changed_messages:
user_id = message["sender_id"]
Expand Down Expand Up @@ -277,8 +277,8 @@ def _set_count_in_view(
if user_button.user_id == user_id:
user_button.update_count(user_button.count + new_count)
break
unread_counts["all_pms"] += new_count
all_pm.update_count(unread_counts["all_pms"])
unread_counts["all_dms"] += new_count
all_dm.update_count(unread_counts["all_dms"])

if add_to_counts:
unread_counts["all_msg"] += new_count
Expand Down Expand Up @@ -487,7 +487,7 @@ def classify_unread_counts(model: Any) -> UnreadCounts:

unread_counts = UnreadCounts(
all_msg=0,
all_pms=0,
all_dms=0,
all_mentions=0,
unread_topics=dict(),
unread_pms=dict(),
Expand All @@ -502,7 +502,7 @@ def classify_unread_counts(model: Any) -> UnreadCounts:
count = len(dm["unread_message_ids"])
unread_counts["unread_pms"][dm["sender_id"]] = count
unread_counts["all_msg"] += count
unread_counts["all_pms"] += count
unread_counts["all_dms"] += count

for stream in unread_msg_counts["streams"]:
count = len(stream["unread_message_ids"])
Expand All @@ -522,13 +522,13 @@ def classify_unread_counts(model: Any) -> UnreadCounts:
unread_counts["all_msg"] += count

# store unread count of group dms in `unread_huddles`
for group_pm in unread_msg_counts["huddles"]:
count = len(group_pm["unread_message_ids"])
user_ids = group_pm["user_ids_string"].split(",")
for group in unread_msg_counts["huddles"]:
count = len(group["unread_message_ids"])
user_ids = group["user_ids_string"].split(",")
user_ids = frozenset(map(int, user_ids))
unread_counts["unread_huddles"][user_ids] = count
unread_counts["all_msg"] += count
unread_counts["all_pms"] += count
unread_counts["all_dms"] += count

return unread_counts

Expand Down
4 changes: 2 additions & 2 deletions zulipterminal/server_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def near_stream_message_url(server_url: str, message: Message) -> str:
return full_url


def near_pm_message_url(server_url: str, message: Message) -> str:
def near_dm_message_url(server_url: str, message: Message) -> str:
"""
Returns the complete encoded URL of a message from #narrow/pm-with.
Referred from zerver/lib/url_encoding.py.
Expand Down Expand Up @@ -83,5 +83,5 @@ def near_message_url(server_url: str, message: Message) -> str:
if message["type"] == "stream":
url = near_stream_message_url(server_url, message)
else:
url = near_pm_message_url(server_url, message)
url = near_dm_message_url(server_url, message)
return url
2 changes: 1 addition & 1 deletion zulipterminal/ui_tools/buttons.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def __init__(self, *, controller: Any, count: int) -> None:
label_markup=(None, button_text),
prefix_markup=("title", DIRECT_MESSAGE_MARKER),
suffix_markup=("unread_count", ""),
show_function=controller.narrow_to_all_pm,
show_function=controller.narrow_to_all_dm,
count=count,
)

Expand Down
2 changes: 1 addition & 1 deletion zulipterminal/ui_tools/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -938,7 +938,7 @@ def keypress(self, size: urwid_Size, key: str) -> Optional[str]:
self.model.unset_search_narrow()
if self.message["type"] == "private":
if len(self.model.narrow) == 1 and self.model.narrow[0][0] == "pm-with":
self.model.controller.narrow_to_all_pm(
self.model.controller.narrow_to_all_dm(
contextual_message_id=self.message["id"],
)
else:
Expand Down
2 changes: 1 addition & 1 deletion zulipterminal/ui_tools/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -792,7 +792,7 @@ def menu_view(self) -> Any:
count = self.model.unread_counts.get("all_msg", 0)
self.view.home_button = HomeButton(controller=self.controller, count=count)

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

self.view.mentioned_button = MentionedButton(
Expand Down

0 comments on commit 84e1bfe

Please sign in to comment.