Skip to content

Commit ab56996

Browse files
committed
model: Notify user if a request fails.
This commit displays an error message in the footer for server requests involving user interactions. By this the user can be notified for different failures like: * Hitting API rate limits. * Posting in streams where user doesn't have the required permissions. * Message sending/editing errors. * Toggling reaction errors. * etc. Error responses from some requests are not displayed, since they are not triggered directly by a user action. Example of these include event polling requests, event registration, and updating presence. Fixes #427.
1 parent d806f4f commit ab56996

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

zulipterminal/helper.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -630,3 +630,10 @@ def notify(title: str, html_text: str) -> str:
630630
# This likely means the notification command could not be found
631631
return command_list[0]
632632
return ""
633+
634+
635+
def display_error_if_present(response: Dict[str, Any], controller: Any) -> bool:
636+
if response['result'] == 'error':
637+
controller.view.set_footer_text(response['msg'], 3)
638+
return True
639+
return False

zulipterminal/model.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from zulipterminal.config.keys import keys_for_command
1515
from zulipterminal.helper import (
1616
Message, asynch, canonicalize_color, classify_unread_counts,
17-
index_messages, initial_index, notify, set_count,
17+
index_messages, initial_index, notify, display_error_if_present, set_count,
1818
)
1919
from zulipterminal.ui_tools.utils import create_msg_box_list
2020

@@ -227,6 +227,7 @@ def _notify_server_of_presence(self) -> Dict[str, Any]:
227227
}
228228
)
229229
self.new_user_input = False
230+
display_error_if_present(response, self.controller)
230231
return response
231232

232233
@asynch
@@ -269,6 +270,7 @@ def react_to_message(self,
269270
response = self.client.remove_reaction(reaction_to_toggle_spec)
270271
else:
271272
response = self.client.add_reaction(reaction_to_toggle_spec)
273+
display_error_if_present(response, self.controller)
272274

273275
@asynch
274276
def toggle_message_star_status(self, message: Message) -> None:
@@ -283,11 +285,12 @@ def toggle_message_star_status(self, message: Message) -> None:
283285
def mark_message_ids_as_read(self, id_list: List[int]) -> None:
284286
if not id_list:
285287
return
286-
self.client.update_message_flags({
288+
response = self.client.update_message_flags({
287289
'messages': id_list,
288290
'flag': 'read',
289291
'op': 'add',
290292
})
293+
display_error_if_present(response, self.controller)
291294

292295
def send_private_message(self, recipients: str,
293296
content: str) -> bool:
@@ -297,6 +300,7 @@ def send_private_message(self, recipients: str,
297300
'content': content,
298301
}
299302
response = self.client.send_message(request)
303+
display_error_if_present(response, self.controller)
300304
return response['result'] == 'success'
301305

302306
def send_stream_message(self, stream: str, topic: str,
@@ -308,6 +312,7 @@ def send_stream_message(self, stream: str, topic: str,
308312
'content': content,
309313
}
310314
response = self.client.send_message(request)
315+
display_error_if_present(response, self.controller)
311316
return response['result'] == 'success'
312317

313318
def update_private_message(self, msg_id: int, content: str) -> bool:
@@ -316,6 +321,7 @@ def update_private_message(self, msg_id: int, content: str) -> bool:
316321
"content": content,
317322
}
318323
response = self.client.update_message(request)
324+
display_error_if_present(response, self.controller)
319325
return response['result'] == 'success'
320326

321327
def update_stream_message(self, topic: str, msg_id: int,
@@ -328,6 +334,7 @@ def update_stream_message(self, topic: str, msg_id: int,
328334
"subject": topic,
329335
}
330336
response = self.client.update_message(request)
337+
display_error_if_present(response, self.controller)
331338
return response['result'] == 'success'
332339

333340
def get_messages(self, *,
@@ -359,6 +366,7 @@ def get_messages(self, *,
359366
query_range = num_after + num_before + 1
360367
self.found_newest = len(response['messages']) < query_range
361368
return ""
369+
display_error_if_present(response, self.controller)
362370
return response['msg']
363371

364372
def get_topics_in_stream(self, stream_list: Iterable[int]) -> str:
@@ -373,6 +381,7 @@ def get_topics_in_stream(self, stream_list: Iterable[int]) -> str:
373381
self.index['topics'][stream_id] = [topic['name'] for
374382
topic in response['topics']]
375383
else:
384+
display_error_if_present(response, self.controller)
376385
return response['msg']
377386
return ""
378387

@@ -609,6 +618,7 @@ def toggle_stream_muted_status(self, stream_id: int) -> bool:
609618
# True for muting and False for unmuting.
610619
}]
611620
response = self.client.update_subscription_settings(request)
621+
display_error_if_present(response, self.controller)
612622
return response['result'] == 'success'
613623

614624
def _handle_subscription_event(self, event: Event) -> None:
@@ -962,6 +972,7 @@ def _register_desired_events(self, *, fetch_data: bool=False) -> str:
962972
self.queue_id = response['queue_id']
963973
self.last_event_id = response['last_event_id']
964974
return ""
975+
display_error_if_present(response, self.controller)
965976
return response['msg']
966977

967978
@asynch

0 commit comments

Comments
 (0)