Skip to content

Commit bbdfd8a

Browse files
committed
bugfix: ui: Use a queue to manage footer reset durations.
Currently, if multiple calls are made to set the footer along with a duration to reset it (for example, when tries to edit an uneditable message too often by pressing the key too many times) then it leads to repeated footer updates because all those calls lead to resetting the footer. The goal of this commit is to change that, and reset the footer only once, by ignoring other updates. A queue is maintained containing number of sleep threads currently active, and if there are none left then the footer is reset. This ensures that only the last call to set_footer_text() resets the footer, thus avoiding multiple resets. Also, note that it is not strictly necessary to store the duration in the queue, we could any number we like. However it is kept this way in case we would like to do more with this in the future, say, spacing out tight reset calls with only a small duration between them. Test added. Fixes zulip#647.
1 parent 899511b commit bbdfd8a

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

tests/ui/test_ui.py

+12
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import time
2+
13
import pytest
24

35
from zulipterminal.config.keys import keys_for_command
@@ -84,6 +86,16 @@ def _reset_footer_text(self, view, mocker, duration=46.2):
8486
mock_sleep.assert_called_once_with(duration)
8587
view.set_footer_text.assert_called_once_with()
8688

89+
def _reset_footer_text_multiple_resets(self, view, mocker, duration=1):
90+
91+
# Multiple simultaneous calls for resetting footer.
92+
view._reset_footer_text(duration)
93+
view._reset_footer_text(duration)
94+
view._reset_footer_text(duration)
95+
96+
assert time.sleep.call_count == 3
97+
view.set_footer_text.assert_called_once_with()
98+
8799
@pytest.mark.parametrize('suggestions, state, truncated, footer_text', [
88100
([], None, False, [' [No matches found]']),
89101
(['some', 'text'], None, False, [[' '], ' some ', ' text ']),

zulipterminal/ui.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import queue
12
import random
23
import re
34
import time
@@ -30,6 +31,7 @@ def __init__(self, controller: Any) -> None:
3031
self.unpinned_streams = self.model.unpinned_streams
3132
self.write_box = WriteBox(self)
3233
self.search_box = SearchBox(self.controller)
34+
self.footer_reset_threads = queue.Queue() # type: queue.Queue[float]
3335
super().__init__(self.main_window())
3436

3537
def left_column_view(self) -> Any:
@@ -78,8 +80,12 @@ def set_footer_text(self, text_list: Optional[List[Any]]=None,
7880
@asynch
7981
def _reset_footer_text(self, duration: float) -> None:
8082
assert duration > 0
83+
self.footer_reset_threads.put(duration)
8184
time.sleep(duration)
82-
self.set_footer_text()
85+
self.footer_reset_threads.get()
86+
87+
if self.footer_reset_threads.empty():
88+
self.set_footer_text()
8389

8490
@asynch
8591
def set_typeahead_footer(self, suggestions: List[str],

0 commit comments

Comments
 (0)