Skip to content

Commit c34a72d

Browse files
committed
buttons/helper/model/themes: Displays unread message counts of muted streams and topics.
Fixes #209
1 parent b281133 commit c34a72d

File tree

4 files changed

+28
-17
lines changed

4 files changed

+28
-17
lines changed

zulipterminal/config/themes.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
light_magenta='#c8f',
6262
white='#fff',
6363
black='g19',
64+
light_gray='#aaa'
6465
)
6566

6667
DEF = dict(DEF_base,
@@ -166,6 +167,8 @@
166167
None, DEF['yellow'], DEF['black']),
167168
('edit_time', 'light blue', 'black',
168169
None, DEF['light_blue'], DEF['black']),
170+
('muted_stream', 'light gray', 'black',
171+
None, DEF['light_gray'], DEF['black']),
169172
],
170173
'gruvbox_dark': [
171174
# default colorscheme on 16 colors, gruvbox colorscheme
@@ -242,6 +245,8 @@
242245
None, YELLOW, BLACK),
243246
('edit_time', 'light blue', 'black',
244247
None, LIGHTBLUE, BLACK),
248+
('muted_stream', 'yellow', 'black',
249+
None, YELLOW, BLACK),
245250
],
246251
'zt_light': [
247252
(None, 'black', 'white'),
@@ -280,6 +285,7 @@
280285
('edit_tag', 'white', 'dark gray'),
281286
('edit_author', 'dark green', 'white'),
282287
('edit_time', 'dark blue', 'white'),
288+
('muted_stream', 'light gray', 'white'),
283289
],
284290
'zt_blue': [
285291
(None, 'black', 'light blue'),
@@ -318,6 +324,7 @@
318324
('edit_tag', 'white', 'dark blue'),
319325
('edit_author', 'dark gray', 'light blue'),
320326
('edit_time', 'dark blue', 'light blue'),
327+
('muted_stream', 'dark gray', 'light blue'),
321328
]
322329
} # type: Dict[str, ThemeSpec]
323330

zulipterminal/helper.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -204,12 +204,9 @@ def _set_count_in_view(controller: Any, new_count: int,
204204
msg_topic = message['subject']
205205
if controller.model.is_muted_stream(stream_id):
206206
add_to_counts = False # if muted, don't add to eg. all_msg
207-
else:
208-
for stream_button in stream_buttons_log:
209-
if stream_button.stream_id == stream_id:
210-
stream_button.update_count(stream_button.count
211-
+ new_count)
212-
break
207+
for stream_button in stream_buttons_log:
208+
if stream_button.stream_id == stream_id:
209+
stream_button.update_count(stream_button.count + new_count)
213210
# FIXME: Update unread_counts['unread_topics']?
214211
if controller.model.is_muted_topic(stream_id, msg_topic):
215212
add_to_counts = False
@@ -438,7 +435,7 @@ def index_messages(messages: List[Message],
438435
def classify_unread_counts(model: Any) -> UnreadCounts:
439436
# TODO: support group pms
440437
unread_msg_counts = model.initial_data['unread_msgs']
441-
438+
topic_muted = False
442439
unread_counts = UnreadCounts(
443440
all_msg=0,
444441
all_pms=0,
@@ -465,14 +462,17 @@ def classify_unread_counts(model: Any) -> UnreadCounts:
465462
if not model.is_user_subscribed_to_stream(stream_id):
466463
continue
467464
if model.is_muted_topic(stream_id, stream['topic']):
468-
continue
465+
if model.is_private:
466+
continue
467+
topic_muted = True
468+
469469
stream_topic = (stream_id, stream['topic'])
470470
unread_counts['unread_topics'][stream_topic] = count
471471
if not unread_counts['streams'].get(stream_id):
472472
unread_counts['streams'][stream_id] = count
473473
else:
474474
unread_counts['streams'][stream_id] += count
475-
if stream_id not in model.muted_streams:
475+
if stream_id not in model.muted_streams and not topic_muted:
476476
unread_counts['all_msg'] += count
477477

478478
# store unread count of group pms in `unread_huddles`

zulipterminal/model.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ def __init__(self, controller: Any) -> None:
8484
self.stream_id = -1
8585
self.recipients = frozenset() # type: FrozenSet[Any]
8686
self.index = initial_index
87+
self.is_private = False
8788

8889
self.user_id = -1
8990
self.user_email = ""

zulipterminal/ui_tools/buttons.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,8 @@ def __init__(self, properties: StreamData,
147147
self.stream_name = properties['name']
148148
self.stream_id = properties['id']
149149
self.color = properties['color']
150-
is_private = properties['invite_only']
151150
self.description = properties['description']
152-
151+
controller.model.is_private = properties['invite_only']
153152
self.model = controller.model
154153
self.count = count
155154
self.view = view
@@ -167,21 +166,24 @@ def __init__(self, properties: StreamData,
167166
super().__init__(controller,
168167
caption=self.stream_name,
169168
show_function=controller.narrow_to_stream,
170-
prefix_character=(
171-
self.color, 'P' if is_private else '#'),
169+
prefix_character=(self.color,
170+
'P' if controller.model.is_private
171+
else '#'),
172172
width=width,
173173
count=count)
174174

175-
# Mark muted streams 'M' during button creation.
175+
# Mark muted streams with different color during button creation.
176176
if self.model.is_muted_stream(self.stream_id):
177-
self.update_widget('M')
177+
self.mark_muted()
178178

179179
def mark_muted(self) -> None:
180-
self.update_widget('M')
180+
self.text_color = 'muted_stream'
181+
self.update_count(self.count)
181182
self.view.home_button.update_count(
182183
self.model.unread_counts['all_msg'])
183184

184185
def mark_unmuted(self, unread_count: int) -> None:
186+
self.text_color = None
185187
self.update_count(unread_count)
186188
self.view.home_button.update_count(
187189
self.model.unread_counts['all_msg'])
@@ -244,7 +246,8 @@ def __init__(self, stream_id: int, topic: str,
244246
self.mark_muted()
245247

246248
def mark_muted(self) -> None:
247-
self.update_widget('M')
249+
self.text_color = 'muted_stream'
250+
self.update_count(self.count)
248251
# TODO: Handle event-based approach for topic-muting.
249252

250253

0 commit comments

Comments
 (0)