Skip to content

Commit c7026b3

Browse files
kaustubh-nairneiljp
authored andcommitted
boxes/model: Maintain stream_id in WriteBox for stream box view.
The stream id is useful for referring to a specific stream in a way that is independent of its name, which can vary over time. The stream_id needs to be synchronized in case a user manually modifies the stream name in the recipient box. This will be important for implementing message drafts and autocompleting topics. A new helper method is added to Model to fetch stream_id using its name.
1 parent cf00776 commit c7026b3

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

zulipterminal/model.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -642,6 +642,12 @@ def toggle_stream_muted_status(self, stream_id: int) -> bool:
642642
display_error_if_present(response, self.controller)
643643
return response['result'] == 'success'
644644

645+
def stream_id_from_name(self, stream_name: str) -> int:
646+
for stream_id, stream in self.stream_dict.items():
647+
if stream['name'] == stream_name:
648+
return stream_id
649+
raise RuntimeError("Invalid stream name.")
650+
645651
def is_pinned_stream(self, stream_id: int) -> bool:
646652
return stream_id in list(stream[1] for stream in self.pinned_streams)
647653

zulipterminal/ui_tools/boxes.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ def __init__(self, view: Any) -> None:
3333
self.view = view
3434
self.msg_edit_id = None # type: Optional[int]
3535
self.is_in_typeahead_mode = False
36+
self.stream_id = None # type: Optional[int]
3637
self.recipient_user_ids = [] # type: List[int]
3738

3839
def main_view(self, new: bool) -> Any:
@@ -72,6 +73,7 @@ def private_box_view(self, button: Any=None, email: str='',
7273
def stream_box_view(self, stream_id: int, caption: str='', title: str='',
7374
) -> None:
7475
self.set_editor_mode()
76+
self.stream_id = stream_id
7577
self.recipient_user_ids = self.model.get_other_subscribers_in_stream(
7678
stream_id=stream_id)
7779
self.to_write_box = None
@@ -271,6 +273,8 @@ def keypress(self, size: urwid_Size, key: str) -> Optional[str]:
271273
user_ids = self.model.get_other_subscribers_in_stream(
272274
stream_name=stream_name)
273275
self.recipient_user_ids = user_ids
276+
self.stream_id = self.model.stream_id_by_name(
277+
stream_name)
274278

275279
header.focus_col = 1
276280
return key

0 commit comments

Comments
 (0)