Repository: zulip/zulip-terminal

Issue:
cannot narrow to 'pm_with'
Due to recent changes in [zerver](https://github.com/zulip/zulip/pull/24775/),the narrow operator `pm_with` is not functional and ZT codebase needs to change it's occurrences to  `pm-with`.

Discussion:
zulipbot: Hello @Subhasish-Behera, it seems like you have referenced #1351 in your pull request description, but you have not referenced them in your commit message description(s). Referencing an issue in a commit message automatically closes the corresponding issue when the commit is merged, which makes the issue tracker easier to manage.

Please run `git commit --amend` in your command line client to amend your commit message description with `Fixes #1351.`.

An example of a correctly-formatted commit:

```
commit fabd5e450374c8dde65ec35f02140383940fe146
Author: zulipbot
Date:   Sat Mar 18 13:42:40 2017 -0700

    pull requests: Check PR commits reference when issue is referenced.

    Fixes #51.
```

To learn how to write a great commit message, please refer to our [guide](https://zulip.readthedocs.io/en/latest/contributing/version-control.html#commit-messages).

<!-- fixCommitWarning -->

Subhasish-Behera: @zulipbot add "PR needs review"
zulipbot: Hello @Subhasish-Behera, it seems like you have referenced #1351 in your pull request description, but you have not referenced them in your commit message description(s). Referencing an issue in a commit message automatically closes the corresponding issue when the commit is merged, which makes the issue tracker easier to manage.

Please run `git commit --amend` in your command line client to amend your commit message description with `Fixes #1351.`.

An example of a correctly-formatted commit:

```
commit fabd5e450374c8dde65ec35f02140383940fe146
Author: zulipbot
Date:   Sat Mar 18 13:42:40 2017 -0700

    pull requests: Check PR commits reference when issue is referenced.

    Fixes #51.
```

To learn how to write a great commit message, please refer to our [guide](https://zulip.readthedocs.io/en/latest/contributing/version-control.html#commit-messages).

<!-- fixCommitWarning -->


Patch:
diff --git a/zulipterminal/helper.py b/zulipterminal/helper.py
index 896e813..c9817fc 100644
--- a/zulipterminal/helper.py
+++ b/zulipterminal/helper.py
@@ -423,7 +423,7 @@ def index_messages(messages: List[Message], model: Any, index: Index) -> Index:
                     {recipient["id"] for recipient in msg["display_recipient"]}
                 )
 
-                if narrow[0][0] == "pm_with":
+                if narrow[0][0] == "pm-with":
                     narrow_emails = [
                         model.user_dict[email]["user_id"]
                         for email in narrow[0][1].split(", ")
@@ -678,7 +678,7 @@ def notify_if_message_sent_outside_narrow(
         recipient_emails = [
             controller.model.user_id_email_dict[user_id] for user_id in message["to"]
         ]
-        pm_with_narrow = [["pm_with", ", ".join(recipient_emails)]]
+        pm_with_narrow = [["pm-with", ", ".join(recipient_emails)]]
         check_narrow_and_notify(pm_narrow, pm_with_narrow, controller)
 
 
diff --git a/zulipterminal/model.py b/zulipterminal/model.py
index 999be50..dfc144d 100644
--- a/zulipterminal/model.py
+++ b/zulipterminal/model.py
@@ -300,7 +300,7 @@ class Model:
             frozenset(["stream"]): [["stream", stream]],
             frozenset(["stream", "topic"]): [["stream", stream], ["topic", topic]],
             frozenset(["pms"]): [["is", "private"]],
-            frozenset(["pm_with"]): [["pm_with", pm_with]],
+            frozenset(["pm_with"]): [["pm-with", pm_with]],
             frozenset(["starred"]): [["is", "starred"]],
             frozenset(["mentioned"]): [["is", "mentioned"]],
         }
@@ -314,7 +314,7 @@ class Model:
         if new_narrow != self.narrow:
             self.narrow = new_narrow
 
-            if pm_with is not None and new_narrow[0][0] == "pm_with":
+            if pm_with is not None and new_narrow[0][0] == "pm-with":
                 users = pm_with.split(", ")
                 self.recipients = frozenset(
                     [self.user_dict[user]["user_id"] for user in users] + [self.user_id]
@@ -360,7 +360,7 @@ class Model:
                 ids = index["topic_msg_ids"][stream_id].get(topic, set())
         elif narrow[0][1] == "private":
             ids = index["private_msg_ids"]
-        elif narrow[0][0] == "pm_with":
+        elif narrow[0][0] == "pm-with":
             recipients = self.recipients
             ids = index["private_msg_ids_by_user_ids"].get(recipients, set())
         elif narrow[0][1] == "starred":
@@ -400,7 +400,7 @@ class Model:
             )
             # PM-with
             or (
-                self.narrow[0][0] == "pm_with"
+                self.narrow[0][0] == "pm-with"
                 and message["type"] == "private"
                 and len(self.narrow) == 1
                 and self.recipients
@@ -1380,7 +1380,7 @@ class Model:
         # and the person typing isn't the user themselves
         if (
             len(narrow) == 1
-            and narrow[0][0] == "pm_with"
+            and narrow[0][0] == "pm-with"
             and sender_email in narrow[0][1].split(",")
             and sender_id != self.user_id
         ):
diff --git a/zulipterminal/ui_tools/messages.py b/zulipterminal/ui_tools/messages.py
index 80d20d2..1911dc5 100644
--- a/zulipterminal/ui_tools/messages.py
+++ b/zulipterminal/ui_tools/messages.py
@@ -111,7 +111,7 @@ class MessageBox(urwid.Pile):
 
     def need_recipient_header(self) -> bool:
         # Prevent redundant information in recipient bar
-        if len(self.model.narrow) == 1 and self.model.narrow[0][0] == "pm_with":
+        if len(self.model.narrow) == 1 and self.model.narrow[0][0] == "pm-with":
             return False
         if len(self.model.narrow) == 2 and self.model.narrow[1][0] == "topic":
             return False
@@ -923,7 +923,7 @@ class MessageBox(urwid.Pile):
         elif is_command_key("TOGGLE_NARROW", key):
             self.model.unset_search_narrow()
             if self.message["type"] == "private":
-                if len(self.model.narrow) == 1 and self.model.narrow[0][0] == "pm_with":
+                if len(self.model.narrow) == 1 and self.model.narrow[0][0] == "pm-with":
                     self.model.controller.narrow_to_all_pm(
                         contextual_message_id=self.message["id"],
                     )


Test patch:
diff --git a/tests/core/test_core.py b/tests/core/test_core.py
index 93f005c..17517d7 100644
--- a/tests/core/test_core.py
+++ b/tests/core/test_core.py
@@ -228,7 +228,7 @@ class TestController:
 
         controller.narrow_to_user(recipient_emails=emails)
 
-        assert controller.model.narrow == [["pm_with", user_email]]
+        assert controller.model.narrow == [["pm-with", user_email]]
         controller.view.message_view.log.clear.assert_called_once_with()
         recipients = frozenset([controller.model.user_id, user_id])
         assert controller.model.recipients == recipients
@@ -474,8 +474,8 @@ class TestController:
             ([["search", "BOO"]], [["search", "FOO"]]),
             ([["stream", "PTEST"]], [["stream", "PTEST"], ["search", "FOO"]]),
             (
-                [["pm_with", "foo@zulip.com"], ["search", "BOO"]],
-                [["pm_with", "foo@zulip.com"], ["search", "FOO"]],
+                [["pm-with", "foo@zulip.com"], ["search", "BOO"]],
+                [["pm-with", "foo@zulip.com"], ["search", "FOO"]],
             ),
             (
                 [["stream", "PTEST"], ["topic", "RDS"]],
diff --git a/tests/helper/test_helper.py b/tests/helper/test_helper.py
index e32b996..3c23343 100644
--- a/tests/helper/test_helper.py
+++ b/tests/helper/test_helper.py
@@ -79,7 +79,7 @@ def test_index_messages_narrow_user(
     messages = messages_successful_response["messages"]
     model = mocker.patch(MODEL + ".__init__", return_value=None)
     model.index = initial_index
-    model.narrow = [["pm_with", "boo@zulip.com"]]
+    model.narrow = [["pm-with", "boo@zulip.com"]]
     model.is_search_narrow.return_value = False
     model.user_id = 5140
     model.user_dict = {
@@ -99,7 +99,7 @@ def test_index_messages_narrow_user_multiple(
     messages = messages_successful_response["messages"]
     model = mocker.patch(MODEL + ".__init__", return_value=None)
     model.index = initial_index
-    model.narrow = [["pm_with", "boo@zulip.com, bar@zulip.com"]]
+    model.narrow = [["pm-with", "boo@zulip.com, bar@zulip.com"]]
     model.is_search_narrow.return_value = False
     model.user_id = 5140
     model.user_dict = {
@@ -348,13 +348,13 @@ def test_display_error_if_present(
         ),
         case(
             {"type": "private", "to": [4, 5], "content": "Hi"},
-            [["pm_with", "welcome-bot@zulip.com, notification-bot@zulip.com"]],
+            [["pm-with", "welcome-bot@zulip.com, notification-bot@zulip.com"]],
             False,
             id="group_private_conv__same_group_pm__not_notified",
         ),
         case(
             {"type": "private", "to": [4, 5], "content": "Hi"},
-            [["pm_with", "welcome-bot@zulip.com"]],
+            [["pm-with", "welcome-bot@zulip.com"]],
             True,
             id="private_conv__other_pm__notified",
         ),
@@ -362,7 +362,7 @@ def test_display_error_if_present(
             {"type": "private", "to": [4], "content": ":party_parrot:"},
             [
                 [
-                    "pm_with",
+                    "pm-with",
                     "person1@example.com, person2@example.com, "
                     "welcome-bot@zulip.com",
                 ]
diff --git a/tests/model/test_model.py b/tests/model/test_model.py
index 04a553a..7d858b8 100644
--- a/tests/model/test_model.py
+++ b/tests/model/test_model.py
@@ -337,8 +337,8 @@ class TestModel:
             [],
             [["stream", "hello world"]],
             [["stream", "hello world"], ["topic", "what's it all about?"]],
-            [["pm_with", "FOO@zulip.com"]],
-            [["pm_with", "Foo@zulip.com, Bar@zulip.com"]],
+            [["pm-with", "FOO@zulip.com"]],
+            [["pm-with", "Foo@zulip.com, Bar@zulip.com"]],
             [["is", "private"]],
             [["is", "starred"]],
         ],
@@ -355,8 +355,8 @@ class TestModel:
             [],
             [["stream", "hello world"]],
             [["stream", "hello world"], ["topic", "what's it all about?"]],
-            [["pm_with", "FOO@zulip.com"]],
-            [["pm_with", "Foo@zulip.com, Bar@zulip.com"]],
+            [["pm-with", "FOO@zulip.com"]],
+            [["pm-with", "Foo@zulip.com, Bar@zulip.com"]],
             [["is", "private"]],
             [["is", "starred"]],
         ],
@@ -414,7 +414,7 @@ class TestModel:
             ([["is", "starred"]], dict(starred=True)),
             ([["is", "mentioned"]], dict(mentioned=True)),
             ([["is", "private"]], dict(pms=True)),
-            ([["pm_with", "FOO@zulip.com"]], dict(pm_with="FOO@zulip.com")),
+            ([["pm-with", "FOO@zulip.com"]], dict(pm_with="FOO@zulip.com")),
         ],
     )
     def test_set_narrow_already_set(self, model, narrow, good_args):
@@ -435,7 +435,7 @@ class TestModel:
             ([], [["is", "starred"]], dict(starred=True)),
             ([], [["is", "mentioned"]], dict(mentioned=True)),
             ([], [["is", "private"]], dict(pms=True)),
-            ([], [["pm_with", "FOOBOO@gmail.com"]], dict(pm_with="FOOBOO@gmail.com")),
+            ([], [["pm-with", "FOOBOO@gmail.com"]], dict(pm_with="FOOBOO@gmail.com")),
         ],
     )
     def test_set_narrow_not_already_set(
@@ -466,12 +466,12 @@ class TestModel:
             ),
             ([["is", "private"]], {"private_msg_ids": {0, 1}}, {0, 1}),
             (
-                [["pm_with", "FOO@zulip.com"]],
+                [["pm-with", "FOO@zulip.com"]],
                 {"private_msg_ids_by_user_ids": {frozenset({1, 2}): {0, 1}}},
                 {0, 1},
             ),
             (
-                [["pm_with", "FOO@zulip.com"]],
+                [["pm-with", "FOO@zulip.com"]],
                 {  # Covers recipient empty-set case
                     "private_msg_ids_by_user_ids": {
                         frozenset({1, 3}): {0, 1}  # NOTE {1,3} not {1,2}
@@ -1848,7 +1848,7 @@ class TestModel:
                     "id": 1,
                     "display_recipient": [{"id": 5827}, {"id": 5}],
                 },
-                [["pm_with", "notification-bot@zulip.com"]],
+                [["pm-with", "notification-bot@zulip.com"]],
                 frozenset({5827, 5}),
                 ["msg_w"],
                 id="user_pm_x_appears_in_narrow_with_x",
@@ -1866,7 +1866,7 @@ class TestModel:
                     "id": 1,
                     "display_recipient": [{"id": 5827}, {"id": 3212}],
                 },
-                [["pm_with", "notification-bot@zulip.com"]],
+                [["pm-with", "notification-bot@zulip.com"]],
                 frozenset({5827, 5}),
                 [],
                 id="user_pm_x_does_not_appear_in_narrow_without_x",
@@ -2904,7 +2904,7 @@ class TestModel:
                 id="not_in_pm_narrow",
             ),
             case(
-                [["pm_with", "othello@zulip.com"]],
+                [["pm-with", "othello@zulip.com"]],
                 {
                     "op": "start",
                     "sender": {"user_id": 4, "email": "hamlet@zulip.com"},
@@ -2920,7 +2920,7 @@ class TestModel:
                 id="not_in_pm_narrow_with_sender",
             ),
             case(
-                [["pm_with", "hamlet@zulip.com"]],
+                [["pm-with", "hamlet@zulip.com"]],
                 {
                     "op": "start",
                     "sender": {"user_id": 4, "email": "hamlet@zulip.com"},
@@ -2936,7 +2936,7 @@ class TestModel:
                 id="in_pm_narrow_with_sender_typing:start",
             ),
             case(
-                [["pm_with", "hamlet@zulip.com"]],
+                [["pm-with", "hamlet@zulip.com"]],
                 {
                     "op": "start",
                     "sender": {"user_id": 4, "email": "hamlet@zulip.com"},
@@ -2952,7 +2952,7 @@ class TestModel:
                 id="in_pm_narrow_with_sender_typing:start_while_animation_in_progress",
             ),
             case(
-                [["pm_with", "hamlet@zulip.com"]],
+                [["pm-with", "hamlet@zulip.com"]],
                 {
                     "op": "stop",
                     "sender": {"user_id": 4, "email": "hamlet@zulip.com"},
@@ -2968,7 +2968,7 @@ class TestModel:
                 id="in_pm_narrow_with_sender_typing:stop",
             ),
             case(
-                [["pm_with", "hamlet@zulip.com"]],
+                [["pm-with", "hamlet@zulip.com"]],
                 {
                     "op": "start",
                     "sender": {"user_id": 5, "email": "iago@zulip.com"},
@@ -2984,7 +2984,7 @@ class TestModel:
                 id="in_pm_narrow_with_other_myself_typing:start",
             ),
             case(
-                [["pm_with", "hamlet@zulip.com"]],
+                [["pm-with", "hamlet@zulip.com"]],
                 {
                     "op": "stop",
                     "sender": {"user_id": 5, "email": "iago@zulip.com"},
@@ -3000,7 +3000,7 @@ class TestModel:
                 id="in_pm_narrow_with_other_myself_typing:stop",
             ),
             case(
-                [["pm_with", "iago@zulip.com"]],
+                [["pm-with", "iago@zulip.com"]],
                 {
                     "op": "start",
                     "sender": {"user_id": 5, "email": "iago@zulip.com"},
@@ -3013,7 +3013,7 @@ class TestModel:
                 id="in_pm_narrow_with_oneself:start",
             ),
             case(
-                [["pm_with", "iago@zulip.com"]],
+                [["pm-with", "iago@zulip.com"]],
                 {
                     "op": "stop",
                     "sender": {"user_id": 5, "email": "iago@zulip.com"},
diff --git a/tests/ui_tools/test_messages.py b/tests/ui_tools/test_messages.py
index e0bbe18..78d9d60 100644
--- a/tests/ui_tools/test_messages.py
+++ b/tests/ui_tools/test_messages.py
@@ -911,13 +911,13 @@ class TestMessageBox:
             ([["is", "private"]], 1, "You and ", "All direct messages"),
             ([["is", "private"]], 2, "You and ", "All direct messages"),
             (
-                [["pm_with", "boo@zulip.com"]],
+                [["pm-with", "boo@zulip.com"]],
                 1,
                 "You and ",
                 "Direct message conversation",
             ),
             (
-                [["pm_with", "boo@zulip.com, bar@zulip.com"]],
+                [["pm-with", "boo@zulip.com, bar@zulip.com"]],
                 2,
                 "You and ",
                 "Group direct message conversation",
@@ -1129,7 +1129,7 @@ class TestMessageBox:
             ([["is", "starred"]], False),
             ([["is", "mentioned"]], False),
             ([["is", "private"]], False),
-            ([["pm_with", "notification-bot@zulip.com"]], False),
+            ([["pm-with", "notification-bot@zulip.com"]], False),
         ],
         ids=[
             "all_messages_narrow",