@@ -330,7 +330,7 @@ def update_stream_message(self, topic: str, msg_id: int,
330
330
331
331
def get_messages (self , * ,
332
332
num_after : int , num_before : int ,
333
- anchor : Optional [int ]) -> bool :
333
+ anchor : Optional [int ]) -> str :
334
334
# anchor value may be specific message (int) or next unread (None)
335
335
first_anchor = anchor is None
336
336
anchor_value = anchor if anchor is not None else 0
@@ -356,10 +356,10 @@ def get_messages(self, *,
356
356
# 'found_newest' flag. Instead, we use this logic:
357
357
query_range = num_after + num_before + 1
358
358
self .found_newest = len (response ['messages' ]) < query_range
359
- return True
360
- return False
359
+ return ""
360
+ return response [ 'msg' ]
361
361
362
- def get_topics_in_stream (self , stream_list : Iterable [int ]) -> bool :
362
+ def get_topics_in_stream (self , stream_list : Iterable [int ]) -> str :
363
363
"""
364
364
Fetch all topics with specified stream_id's and
365
365
index their names (Version 1)
@@ -371,15 +371,15 @@ def get_topics_in_stream(self, stream_list: Iterable[int]) -> bool:
371
371
self .index ['topics' ][stream_id ] = [topic ['name' ] for
372
372
topic in response ['topics' ]]
373
373
else :
374
- return False
375
- return True
374
+ return response [ 'msg' ]
375
+ return ""
376
376
377
377
@staticmethod
378
- def exception_safe_result (future : 'Future[bool ]' ) -> bool :
378
+ def exception_safe_result (future : 'Future[str ]' ) -> str :
379
379
try :
380
380
return future .result ()
381
- except zulip .ZulipError :
382
- return False
381
+ except zulip .ZulipError as e :
382
+ return str ( e )
383
383
384
384
def fetch_all_topics (self , workers : int ) -> None :
385
385
"""
@@ -392,17 +392,17 @@ def fetch_all_topics(self, workers: int) -> None:
392
392
i : executor .submit (self .get_topics_in_stream ,
393
393
list_of_streams [i ::workers ])
394
394
for i in range (workers )
395
- } # type: Dict[int, Future[bool ]]
395
+ } # type: Dict[int, Future[str ]]
396
396
wait (thread_objects .values ())
397
397
398
398
results = {
399
399
str (name ): self .exception_safe_result (thread_object )
400
400
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 ()):
403
403
failures = ['fetch_topics[{}]' .format (name )
404
404
for name , result in results .items ()
405
- if not result ]
405
+ if result ]
406
406
raise ServerConnectionFailure (", " .join (failures ))
407
407
408
408
def is_muted_stream (self , stream_id : int ) -> bool :
@@ -426,22 +426,22 @@ def _update_initial_data(self) -> None:
426
426
anchor = None ),
427
427
'register' : executor .submit (self ._register_desired_events ,
428
428
fetch_data = True ),
429
- } # Dict[str, Future[bool ]]
429
+ } # type: Dict[str, Future[str ]]
430
430
431
431
# Wait for threads to complete
432
432
wait (futures .values ())
433
433
434
434
results = {
435
435
name : self .exception_safe_result (future )
436
436
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 ()):
439
439
self .user_id = self .initial_data ['user_id' ]
440
440
self .user_email = self .initial_data ['email' ]
441
441
self .user_full_name = self .initial_data ['full_name' ]
442
442
self .server_name = self .initial_data ['realm_name' ]
443
443
else :
444
- failures = [name for name , result in results .items () if not result ]
444
+ failures = [name for name , result in results .items () if result ]
445
445
raise ServerConnectionFailure (", " .join (failures ))
446
446
447
447
def get_all_users (self ) -> List [Dict [str , Any ]]:
@@ -869,7 +869,7 @@ def update_rendered_view(self, msg_id: int) -> None:
869
869
self .controller .update_screen ()
870
870
return
871
871
872
- def _register_desired_events (self , * , fetch_data : bool = False ) -> bool :
872
+ def _register_desired_events (self , * , fetch_data : bool = False ) -> str :
873
873
fetch_types = None if not fetch_data else [
874
874
'realm' ,
875
875
'presence' ,
@@ -886,17 +886,17 @@ def _register_desired_events(self, *, fetch_data: bool=False) -> bool:
886
886
fetch_event_types = fetch_types ,
887
887
client_gravatar = True ,
888
888
apply_markdown = True )
889
- except zulip .ZulipError :
890
- return False
889
+ except zulip .ZulipError as e :
890
+ return str ( e )
891
891
892
892
if response ['result' ] == 'success' :
893
893
if fetch_data :
894
894
self .initial_data .update (response )
895
895
self .max_message_id = response ['max_message_id' ]
896
896
self .queue_id = response ['queue_id' ]
897
897
self .last_event_id = response ['last_event_id' ]
898
- return True
899
- return False
898
+ return ""
899
+ return response [ 'msg' ]
900
900
901
901
@asynch
902
902
def poll_for_events (self ) -> None :
0 commit comments