Skip to content

Commit

Permalink
buttons: Mark muted streams during button creation.
Browse files Browse the repository at this point in the history
Before we used to set stream as muted based on unread messages.
On startup this caused no stream to be marked as 'M'.
Now, we mark them as muted during button creation.

Tests amended.

Fixes: zulip#272, zulip#236
  • Loading branch information
sumanthvrao committed Feb 28, 2019
1 parent 4c6ee5b commit 225ed89
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
11 changes: 11 additions & 0 deletions tests/ui/test_ui_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from urwid import AttrWrap, Columns, Padding, Text

VIEWS = "zulipterminal.ui_tools.views"
TOPBUTTON = "zulipterminal.ui_tools.buttons.TopButton"


class TestMessageView:
Expand Down Expand Up @@ -782,6 +783,8 @@ def test_menu_view(self, mocker, width=40):
pm_button = mocker.patch(VIEWS + ".PMButton")
mocker.patch(VIEWS + ".urwid.ListBox")
mocker.patch(VIEWS + ".urwid.SimpleFocusListWalker")
mocker.patch(TOPBUTTON + ".set_muted_streams",
return_value=None)
left_col_view = LeftColumnView(width, self.view)
home_button.assert_called_once_with(left_col_view.controller,
count=2, width=width)
Expand All @@ -798,6 +801,8 @@ def test_streams_view(self, mocker, streams, pinned, width=40):
stream_view = mocker.patch(VIEWS + '.StreamsView')
line_box = mocker.patch(VIEWS + '.urwid.LineBox')
divider = mocker.patch(VIEWS + '.urwid.Divider')
mocker.patch(TOPBUTTON + '.set_muted_streams',
return_value=None)

left_col_view = LeftColumnView(width, self.view)

Expand Down Expand Up @@ -1210,6 +1215,8 @@ class TestTopButton:
def test_text_content(self, mocker,
prefix,
width, count, short_text, caption='caption'):
mocker.patch(TOPBUTTON + '.set_muted_streams',
return_value=None)
show_function = mocker.Mock()

if isinstance(prefix, tuple):
Expand Down Expand Up @@ -1278,6 +1285,8 @@ class TestStreamButton:
def test_text_content(self, mocker,
is_private, expected_prefix,
width, count, short_text, caption='caption'):
mocker.patch(TOPBUTTON + '.set_muted_streams',
return_value=None)
properties = [caption, 5, '#ffffff', is_private]
view_mock = mocker.Mock()
view_mock.palette = [(None, 'black', 'white')]
Expand Down Expand Up @@ -1328,6 +1337,8 @@ class TestUserButton:
])
def test_text_content(self, mocker,
width, count, short_text, caption='caption'):
mocker.patch(TOPBUTTON + '.set_muted_streams',
return_value=None)
user = {
'email': 'some_email', # value unimportant
'user_id': 5, # value unimportant
Expand Down
6 changes: 6 additions & 0 deletions zulipterminal/ui_tools/buttons.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,14 @@ def __init__(self, controller: Any, caption: str,
super().__init__("")
self._w = self.widget(count)
self.controller = controller
self.set_muted_streams()
urwid.connect_signal(self, 'click', self.activate)

def set_muted_streams(self) -> None:
if self.caption in [self.controller.model.stream_dict[ele]['name']
for ele in self.controller.model.muted_streams]:
self.update_count(-1)

def update_count(self, count: int) -> None:
self.count = count
self._w = self.widget(count)
Expand Down

0 comments on commit 225ed89

Please sign in to comment.