Skip to content

Commit 5c3228b

Browse files
committed
messages: Replace direct access to Model.narrow with functions.
This commit replaces all instances which directly access Model.narrow with usage of functions Model.get_narrow() and Model.get_narrow_length() to restrict access to narrow data structure to only Model class.
1 parent b49335f commit 5c3228b

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

zulipterminal/ui_tools/messages.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,11 @@ def __init__(self, message: Message, model: "Model", last_message: Any) -> None:
111111

112112
def need_recipient_header(self) -> bool:
113113
# Prevent redundant information in recipient bar
114-
if len(self.model.narrow) == 1 and self.model.narrow[0][0] == "pm_with":
114+
narrow = self.model.get_narrow()
115+
narrow_length = self.model.get_narrow_length()
116+
if narrow_length == 1 and narrow[0][0] == "pm_with":
115117
return False
116-
if len(self.model.narrow) == 2 and self.model.narrow[1][0] == "topic":
118+
if narrow_length == 2 and narrow[1][0] == "topic":
117119
return False
118120

119121
last_msg = self.last_message
@@ -193,7 +195,7 @@ def top_header_bar(self, message_view: Any) -> Any:
193195
return message_view.private_header()
194196

195197
def top_search_bar(self) -> Any:
196-
curr_narrow = self.model.narrow
198+
curr_narrow = self.model.get_narrow()
197199
is_search_narrow = self.model.is_search_narrow()
198200
if is_search_narrow:
199201
curr_narrow = [
@@ -890,6 +892,8 @@ def mouse_event(
890892
return super().mouse_event(size, event, button, col, row, focus)
891893

892894
def keypress(self, size: urwid_Size, key: str) -> Optional[str]:
895+
narrow = self.model.get_narrow()
896+
narrow_length = self.model.get_narrow_length()
893897
if is_command_key("REPLY_MESSAGE", key):
894898
if self.message["type"] == "private":
895899
self.model.controller.view.write_box.private_box_view(
@@ -902,7 +906,7 @@ def keypress(self, size: urwid_Size, key: str) -> Optional[str]:
902906
stream_id=self.stream_id,
903907
)
904908
elif is_command_key("STREAM_MESSAGE", key):
905-
if len(self.model.narrow) != 0 and self.model.narrow[0][0] == "stream":
909+
if narrow_length != 0 and narrow[0][0] == "stream":
906910
self.model.controller.view.write_box.stream_box_view(
907911
caption=self.message["display_recipient"],
908912
stream_id=self.stream_id,
@@ -923,7 +927,7 @@ def keypress(self, size: urwid_Size, key: str) -> Optional[str]:
923927
elif is_command_key("TOGGLE_NARROW", key):
924928
self.model.unset_search_narrow()
925929
if self.message["type"] == "private":
926-
if len(self.model.narrow) == 1 and self.model.narrow[0][0] == "pm_with":
930+
if narrow_length == 1 and narrow[0][0] == "pm_with":
927931
self.model.controller.narrow_to_all_pm(
928932
contextual_message_id=self.message["id"],
929933
)
@@ -933,7 +937,7 @@ def keypress(self, size: urwid_Size, key: str) -> Optional[str]:
933937
contextual_message_id=self.message["id"],
934938
)
935939
elif self.message["type"] == "stream":
936-
if len(self.model.narrow) > 1: # in a topic
940+
if narrow_length > 1: # in a topic
937941
self.model.controller.narrow_to_stream(
938942
stream_name=self.stream_name,
939943
contextual_message_id=self.message["id"],

0 commit comments

Comments
 (0)