Skip to content

Commit a2621db

Browse files
committed
buttons/helper/model: Display unread counts of muted streams and topics.
Fixes #209
1 parent 35ad81b commit a2621db

File tree

3 files changed

+27
-18
lines changed

3 files changed

+27
-18
lines changed

zulipterminal/helper.py

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,8 @@ def _set_count_in_view(controller: Any, new_count: int,
194194
continue
195195

196196
msg_type = message['type']
197-
add_to_counts = True
197+
text_color = None
198+
unread_count_color = 'unread_count'
198199
if 'mentioned' in message['flags']:
199200
unread_counts['all_mentions'] += new_count
200201
all_mentioned.update_count(unread_counts['all_mentions'])
@@ -203,23 +204,28 @@ def _set_count_in_view(controller: Any, new_count: int,
203204
stream_id = message['stream_id']
204205
msg_topic = message['subject']
205206
if controller.model.is_muted_stream(stream_id):
206-
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+
controller.model.add_to_counts = False
208+
# if muted, don't add to eg. all_msg
209+
text_color = 'muted'
210+
unread_count_color = 'muted'
211+
for stream_button in stream_buttons_log:
212+
if stream_button.stream_id == stream_id:
213+
stream_button.update_count(stream_button.count
214+
+ new_count, text_color,
215+
unread_count_color)
213216
# FIXME: Update unread_counts['unread_topics']?
214217
if controller.model.is_muted_topic(stream_id, msg_topic):
215-
add_to_counts = False
218+
controller.model.add_to_counts = False
219+
text_color = 'muted'
220+
unread_count_color = 'muted'
216221
if is_open_topic_view and stream_id == toggled_stream_id:
217222
# If topic_view is open for incoming messages's stream,
218223
# We update the respective TopicButton count accordingly.
219224
for topic_button in topic_buttons_log:
220225
if topic_button.topic_name == msg_topic:
221226
topic_button.update_count(topic_button.count
222-
+ new_count)
227+
+ new_count, text_color,
228+
unread_count_color)
223229
else:
224230
for user_button in user_buttons_log:
225231
if user_button.user_id == user_id:
@@ -228,7 +234,7 @@ def _set_count_in_view(controller: Any, new_count: int,
228234
unread_counts['all_pms'] += new_count
229235
all_pm.update_count(unread_counts['all_pms'])
230236

231-
if add_to_counts:
237+
if controller.model.add_to_counts:
232238
unread_counts['all_msg'] += new_count
233239
all_msg.update_count(unread_counts['all_msg'])
234240

zulipterminal/model.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ def __init__(self, controller: Any) -> None:
8686
self.stream_id = -1
8787
self.recipients = frozenset() # type: FrozenSet[Any]
8888
self.index = initial_index
89+
self.add_to_counts = True
8990

9091
self.user_id = -1
9192
self.user_email = ""
@@ -754,11 +755,13 @@ def get_stream_by_id(streams: List[StreamData], stream_id: int
754755
unread_count = self.unread_counts['streams'][stream_id]
755756
if event['value']: # Unmuting streams
756757
self.muted_streams.remove(stream_id)
757-
self.unread_counts['all_msg'] += unread_count
758+
if self.add_to_counts:
759+
self.unread_counts['all_msg'] += unread_count
758760
stream_button.mark_unmuted(unread_count)
759761
else: # Muting streams
760762
self.muted_streams.add(stream_id)
761-
self.unread_counts['all_msg'] -= unread_count
763+
if self.add_to_counts:
764+
self.unread_counts['all_msg'] -= unread_count
762765
stream_button.mark_muted()
763766
self.controller.update_screen()
764767
elif event.get('property', None) == 'pin_to_top':

zulipterminal/ui_tools/buttons.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
from typing_extensions import TypedDict
77

88
from zulipterminal.config.keys import is_command_key, primary_key_for_command
9-
from zulipterminal.config.symbols import MUTE_MARKER
109
from zulipterminal.helper import (
1110
StreamData, edit_mode_captions, hash_util_decode,
1211
)
@@ -49,15 +48,16 @@ def __init__(self, controller: Any, caption: str,
4948
self.controller = controller
5049
urwid.connect_signal(self, 'click', self.activate)
5150

52-
def update_count(self, count: int, text_color: Optional[str]=None) -> None:
51+
def update_count(self, count: int, text_color: Optional[str]=None,
52+
unread_count_color: str='unread_count') -> None:
5353
new_color = self.original_color if text_color is None else text_color
5454

5555
self.count = count
5656
if count == 0:
5757
count_text = ''
5858
else:
5959
count_text = str(count)
60-
self.update_widget(('unread_count', count_text), new_color)
60+
self.update_widget((unread_count_color, count_text), new_color)
6161

6262
def update_widget(self, count_text: Tuple[str, str],
6363
text_color: Optional[str]) -> Any:
@@ -181,7 +181,7 @@ def __init__(self, properties: StreamData,
181181
self.mark_muted()
182182

183183
def mark_muted(self) -> None:
184-
self.update_widget(('muted', MUTE_MARKER), 'muted')
184+
self.update_count(self.count, 'muted', 'muted')
185185
self.view.home_button.update_count(
186186
self.model.unread_counts['all_msg'])
187187

@@ -252,7 +252,7 @@ def __init__(self, stream_id: int, topic: str,
252252
self.mark_muted()
253253

254254
def mark_muted(self) -> None:
255-
self.update_widget(('muted', MUTE_MARKER), 'muted')
255+
self.update_count(self.count, 'muted', 'muted')
256256
# TODO: Handle event-based approach for topic-muting.
257257

258258

0 commit comments

Comments
 (0)