Skip to content

Commit f9d0982

Browse files
Rohitth007neiljp
authored andcommitted
refactor: model: Move list of initial data to fetch into __init__.
This dictionary was previously in `_register_desired_events` which made it look like those were the events being registered while actually they were initial fetch events. The function `_update_initial_data()` has been given a more apt name `_fetch_initial_data()`.
1 parent 11a2c96 commit f9d0982

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

zulipterminal/model.py

+20-16
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,23 @@ def __init__(self, controller: Any) -> None:
8888

8989
self._notified_user_of_notification_failure = False
9090

91+
# Events fetched once at startup
92+
self.initial_data_to_fetch: List[str] = [
93+
'realm',
94+
'presence',
95+
'subscription',
96+
'message',
97+
'update_message_flags',
98+
'muted_topics',
99+
'realm_user', # Enables cross_realm_bots
100+
'realm_user_groups',
101+
'update_display_settings',
102+
# zulip_version and zulip_feature_level are always returned in
103+
# POST /register from Feature level 3.
104+
'zulip_version',
105+
]
106+
107+
# Events desired with their corresponding callback
91108
self.event_actions: 'OrderedDict[str, Callable[[Event], None]]' = (
92109
OrderedDict([
93110
('message', self._handle_message_event),
@@ -106,7 +123,7 @@ def __init__(self, controller: Any) -> None:
106123

107124
# Register to the queue before initializing further so that we don't
108125
# lose any updates while messages are being fetched.
109-
self._update_initial_data()
126+
self._fetch_initial_data()
110127

111128
self.server_version = self.initial_data['zulip_version']
112129
self.server_feature_level = (
@@ -567,7 +584,7 @@ def is_muted_topic(self, stream_id: int, topic: str) -> bool:
567584
topic_to_search = (stream_name, topic)
568585
return topic_to_search in self._muted_topics.keys()
569586

570-
def _update_initial_data(self) -> None:
587+
def _fetch_initial_data(self) -> None:
571588
# Thread Processes to reduce start time.
572589
# NOTE: Exceptions do not work well with threads
573590
with ThreadPoolExecutor(max_workers=1) as executor:
@@ -1267,20 +1284,7 @@ def _handle_update_display_settings_event(self, event: Event) -> None:
12671284
self.controller.update_screen()
12681285

12691286
def _register_desired_events(self, *, fetch_data: bool=False) -> str:
1270-
fetch_types = None if not fetch_data else [
1271-
'realm',
1272-
'presence',
1273-
'subscription',
1274-
'message',
1275-
'update_message_flags',
1276-
'muted_topics',
1277-
'realm_user', # Enables cross_realm_bots
1278-
'realm_user_groups',
1279-
'update_display_settings',
1280-
# zulip_version and zulip_feature_level are always returned in
1281-
# POST /register from Feature level 3.
1282-
'zulip_version',
1283-
]
1287+
fetch_types = None if not fetch_data else self.initial_data_to_fetch
12841288
event_types = list(self.event_actions)
12851289
try:
12861290
response = self.client.register(event_types=event_types,

0 commit comments

Comments
 (0)