Skip to content

Commit 47f5171

Browse files
committed
initial commit: addded stream button.
1 parent 9b9dd9b commit 47f5171

File tree

7 files changed

+46
-3
lines changed

7 files changed

+46
-3
lines changed

zulipterminal/core.py

+3
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,9 @@ def narrow_to_all_messages(
612612
def narrow_to_all_pm(self, *, contextual_message_id: Optional[int] = None) -> None:
613613
self._narrow_to(anchor=contextual_message_id, pms=True)
614614

615+
def narrow_to_all_streams(self, *, contextual_message_id: Optional[int] = None) -> None:
616+
self._narrow_to(anchor=contextual_message_id, stream_messages = True)
617+
615618
def narrow_to_all_starred(self) -> None:
616619
# NOTE: Should we allow maintaining anchor focus here?
617620
# (nothing currently requires narrowing around a message id)

zulipterminal/helper.py

+8
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,11 @@ def index_messages(messages: List[Message], model: Any, index: Index) -> Index:
415415
if narrow[0][1] == "mentioned":
416416
if {"mentioned", "wildcard_mentioned"} & set(msg["flags"]):
417417
index["mentioned_msg_ids"].add(msg["id"])
418+
419+
if narrow[0][1] == "stream_messages":
420+
index["stream_msg_ids"].add(msg["id"])
421+
if msg["type"] == "stream":
422+
index["stream_msg_ids"].add(msg["id"])
418423

419424
if msg["type"] == "private":
420425
index["private_msg_ids"].add(msg["id"])
@@ -690,6 +695,9 @@ def notify_if_message_sent_outside_narrow(
690695
]
691696
pm_with_narrow = [["pm_with", ", ".join(recipient_emails)]]
692697
check_narrow_and_notify(pm_narrow, pm_with_narrow, controller)
698+
elif message["type"] == "stream_messages":
699+
stream_narrow = [["is", "stream_messages"]]
700+
693701

694702

695703
def hash_util_decode(string: str) -> str:

zulipterminal/model.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,7 @@ def set_narrow(
282282
topic: Optional[str] = None,
283283
pms: bool = False,
284284
pm_with: Optional[str] = None,
285+
stream_messages: bool = False,
285286
starred: bool = False,
286287
mentioned: bool = False,
287288
active_button: Any = None,
@@ -292,6 +293,7 @@ def set_narrow(
292293
frozenset(["stream"]): [["stream", stream]],
293294
frozenset(["stream", "topic"]): [["stream", stream], ["topic", topic]],
294295
frozenset(["pms"]): [["is", "private"]],
296+
frozenset(["stream_messages"]): [["is", "stream_messages"]],
295297
frozenset(["pm_with"]): [["pm_with", pm_with]],
296298
frozenset(["starred"]): [["is", "starred"]],
297299
frozenset(["mentioned"]): [["is", "mentioned"]],
@@ -365,13 +367,18 @@ def get_message_ids_in_current_narrow(self) -> Set[int]:
365367
ids = index["topic_msg_ids"][stream_id].get(topic, set())
366368
elif narrow[0][1] == "private":
367369
ids = index["private_msg_ids"]
370+
elif narrow[0][1] == "stream_messages":
371+
stream_ids = [ids for ids in index["all_msg_ids"] if ids not in index["private_msg_ids"]]
372+
index["stream_msg_ids"] = stream_ids
373+
ids = stream_ids
368374
elif narrow[0][0] == "pm_with":
369375
recipients = self.recipients
370376
ids = index["private_msg_ids_by_user_ids"].get(recipients, set())
371-
elif narrow[0][1] == "starred":
377+
elif narrow[0][1] == "starred":
372378
ids = index["starred_msg_ids"]
373379
elif narrow[0][1] == "mentioned":
374380
ids = index["mentioned_msg_ids"]
381+
375382
return ids.copy()
376383

377384
def current_narrow_contains_message(self, message: Message) -> bool:

zulipterminal/ui.py

+2
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,8 @@ def keypress(self, size: urwid_Box, key: str) -> Optional[str]:
256256
self.starred_button.activate(key)
257257
elif is_command_key("ALL_MENTIONS", key):
258258
self.mentioned_button.activate(key)
259+
elif is_command_key("STREAM_NARROW", key):
260+
self.all_streams_button.activate(key)
259261
elif is_command_key("SEARCH_PEOPLE", key):
260262
# Start User Search if not in editor_mode
261263
self.show_left_panel(visible=False)

zulipterminal/ui_tools/boxes.py

+5
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@
5858
if typing.TYPE_CHECKING:
5959
from zulipterminal.model import Model
6060

61+
from zulipterminal.platform_code import notify
62+
6163

6264
class _MessageEditState(NamedTuple):
6365
message_id: int
@@ -1064,6 +1066,7 @@ def top_search_bar(self) -> Any:
10641066
]
10651067
else:
10661068
self.model.controller.view.search_box.text_box.set_edit_text("")
1069+
notify(str(curr_narrow), "Helo")
10671070
if curr_narrow == []:
10681071
text_to_fill = "All messages"
10691072
elif len(curr_narrow) == 1 and curr_narrow[0][1] == "private":
@@ -1072,6 +1075,8 @@ def top_search_bar(self) -> Any:
10721075
text_to_fill = "Starred messages"
10731076
elif len(curr_narrow) == 1 and curr_narrow[0][1] == "mentioned":
10741077
text_to_fill = "Mentions"
1078+
elif len(curr_narrow) == 1 and curr_narrow[0][1] == "stream_messages":
1079+
text_to_fill = "All Stream messages"
10751080
elif self.message["type"] == "stream":
10761081
assert self.stream_id is not None
10771082
bar_color = self.model.stream_dict[self.stream_id]["color"]

zulipterminal/ui_tools/buttons.py

+12
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,18 @@ def __init__(self, *, controller: Any, count: int) -> None:
141141
count_style="unread_count",
142142
)
143143

144+
class StreamMessagesButton(TopButton):
145+
def __init__(self, *, controller:Any, count: int) -> None:
146+
button_text = f"Streams [{primary_key_for_command('STREAM_NARROW')}]"
147+
148+
super().__init__(
149+
controller = controller,
150+
caption = button_text,
151+
show_function=controller.narrow_to_all_streams,
152+
prefix_character="",
153+
count = count,
154+
count_style = "unread_count",
155+
)
144156

145157
class StarredButton(TopButton):
146158
def __init__(self, *, controller: Any, count: int) -> None:

zulipterminal/ui_tools/views.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
MessageLinkButton,
4848
PMButton,
4949
StarredButton,
50+
StreamMessagesButton,
5051
StreamButton,
5152
TopicButton,
5253
UserButton,
@@ -801,7 +802,7 @@ def __init__(self, view: Any) -> None:
801802
self.stream_v = self.streams_view()
802803

803804
self.is_in_topic_view = False
804-
contents = [(4, self.menu_v), self.stream_v]
805+
contents = [(5, self.menu_v), self.stream_v]
805806
super().__init__(contents)
806807

807808
def menu_view(self) -> Any:
@@ -815,7 +816,11 @@ def menu_view(self) -> Any:
815816
controller=self.controller,
816817
count=self.model.unread_counts["all_mentions"],
817818
)
818-
819+
820+
count = self.model.unread_counts.get("all_msg", 0) - self.model.unread_counts.get("all_pms", 0)
821+
self.view.all_streams_button = StreamMessagesButton(
822+
controller = self.controller, count = count
823+
)
819824
# Starred messages are by definition read already
820825
count = len(self.model.initial_data["starred_messages"])
821826
self.view.starred_button = StarredButton(
@@ -825,6 +830,7 @@ def menu_view(self) -> Any:
825830
self.view.home_button,
826831
self.view.pm_button,
827832
self.view.mentioned_button,
833+
self.view.all_streams_button,
828834
self.view.starred_button,
829835
]
830836
w = urwid.ListBox(urwid.SimpleFocusListWalker(menu_btn_list))

0 commit comments

Comments
 (0)