@@ -330,7 +330,7 @@ def update_stream_message(self, topic: str, msg_id: int,
330330
331331 def get_messages (self , * ,
332332 num_after : int , num_before : int ,
333- anchor : Optional [int ]) -> bool :
333+ anchor : Optional [int ]) -> str :
334334 # anchor value may be specific message (int) or next unread (None)
335335 first_anchor = anchor is None
336336 anchor_value = anchor if anchor is not None else 0
@@ -356,10 +356,10 @@ def get_messages(self, *,
356356 # 'found_newest' flag. Instead, we use this logic:
357357 query_range = num_after + num_before + 1
358358 self .found_newest = len (response ['messages' ]) < query_range
359- return True
360- return False
359+ return ""
360+ return response [ 'msg' ]
361361
362- def get_topics_in_stream (self , stream_list : Iterable [int ]) -> bool :
362+ def get_topics_in_stream (self , stream_list : Iterable [int ]) -> str :
363363 """
364364 Fetch all topics with specified stream_id's and
365365 index their names (Version 1)
@@ -371,15 +371,15 @@ def get_topics_in_stream(self, stream_list: Iterable[int]) -> bool:
371371 self .index ['topics' ][stream_id ] = [topic ['name' ] for
372372 topic in response ['topics' ]]
373373 else :
374- return False
375- return True
374+ return response [ 'msg' ]
375+ return ""
376376
377377 @staticmethod
378- def exception_safe_result (future : 'Future[bool ]' ) -> bool :
378+ def exception_safe_result (future : 'Future[str ]' ) -> str :
379379 try :
380380 return future .result ()
381- except zulip .ZulipError :
382- return False
381+ except zulip .ZulipError as e :
382+ return str ( e )
383383
384384 def fetch_all_topics (self , workers : int ) -> None :
385385 """
@@ -392,17 +392,17 @@ def fetch_all_topics(self, workers: int) -> None:
392392 i : executor .submit (self .get_topics_in_stream ,
393393 list_of_streams [i ::workers ])
394394 for i in range (workers )
395- } # type: Dict[int, Future[bool ]]
395+ } # type: Dict[int, Future[str ]]
396396 wait (thread_objects .values ())
397397
398398 results = {
399399 str (name ): self .exception_safe_result (thread_object )
400400 for name , thread_object in thread_objects .items ()
401- } # type: Dict[str, bool ]
402- if not all (results .values ()):
401+ } # type: Dict[str, str ]
402+ if any (results .values ()):
403403 failures = ['fetch_topics[{}]' .format (name )
404404 for name , result in results .items ()
405- if not result ]
405+ if result ]
406406 raise ServerConnectionFailure (", " .join (failures ))
407407
408408 def is_muted_stream (self , stream_id : int ) -> bool :
@@ -426,22 +426,22 @@ def _update_initial_data(self) -> None:
426426 anchor = None ),
427427 'register' : executor .submit (self ._register_desired_events ,
428428 fetch_data = True ),
429- } # Dict[str, Future[bool ]]
429+ } # type: Dict[str, Future[str ]]
430430
431431 # Wait for threads to complete
432432 wait (futures .values ())
433433
434434 results = {
435435 name : self .exception_safe_result (future )
436436 for name , future in futures .items ()
437- } # type: Dict[str, bool ]
438- if all (results .values ()):
437+ } # type: Dict[str, str ]
438+ if not any (results .values ()):
439439 self .user_id = self .initial_data ['user_id' ]
440440 self .user_email = self .initial_data ['email' ]
441441 self .user_full_name = self .initial_data ['full_name' ]
442442 self .server_name = self .initial_data ['realm_name' ]
443443 else :
444- failures = [name for name , result in results .items () if not result ]
444+ failures = [name for name , result in results .items () if result ]
445445 raise ServerConnectionFailure (", " .join (failures ))
446446
447447 def get_all_users (self ) -> List [Dict [str , Any ]]:
@@ -869,7 +869,7 @@ def update_rendered_view(self, msg_id: int) -> None:
869869 self .controller .update_screen ()
870870 return
871871
872- def _register_desired_events (self , * , fetch_data : bool = False ) -> bool :
872+ def _register_desired_events (self , * , fetch_data : bool = False ) -> str :
873873 fetch_types = None if not fetch_data else [
874874 'realm' ,
875875 'presence' ,
@@ -886,17 +886,17 @@ def _register_desired_events(self, *, fetch_data: bool=False) -> bool:
886886 fetch_event_types = fetch_types ,
887887 client_gravatar = True ,
888888 apply_markdown = True )
889- except zulip .ZulipError :
890- return False
889+ except zulip .ZulipError as e :
890+ return str ( e )
891891
892892 if response ['result' ] == 'success' :
893893 if fetch_data :
894894 self .initial_data .update (response )
895895 self .max_message_id = response ['max_message_id' ]
896896 self .queue_id = response ['queue_id' ]
897897 self .last_event_id = response ['last_event_id' ]
898- return True
899- return False
898+ return ""
899+ return response [ 'msg' ]
900900
901901 @asynch
902902 def poll_for_events (self ) -> None :
0 commit comments