mirror of https://github.com/zulip/zulip.git
Add page_params.unread_msgs.count.
This field is convenient for bankruptcy checks. Clients could calculate it from page_params.unread_msgs before this change, but it would kind of a painful calculation. To add count, we had to simplify the mypy annotations, which weren't really accurate before.
This commit is contained in:
parent
c0dec29f5f
commit
658ac782a2
|
@ -14,6 +14,7 @@ in the register call.
|
|||
|
||||
```
|
||||
{
|
||||
"count": 4,
|
||||
"huddles": [
|
||||
{
|
||||
"user_ids_string": "3,4,6",
|
||||
|
|
|
@ -187,12 +187,13 @@ def fetch_initial_state_data(user_profile, event_types, queue_id,
|
|||
|
||||
|
||||
def remove_message_id_from_unread_mgs(state, remove_id):
|
||||
# type: (Dict[str, Dict[str, List[Any]]], int) -> None
|
||||
# type: (Dict[str, Dict[str, Any]], int) -> None
|
||||
for message_type in ['pms', 'streams', 'huddles']:
|
||||
threads = state['unread_msgs'][message_type]
|
||||
for obj in threads:
|
||||
msg_ids = obj['unread_message_ids']
|
||||
if remove_id in msg_ids:
|
||||
state['unread_msgs']['count'] -= 1
|
||||
msg_ids.remove(remove_id)
|
||||
state['unread_msgs'][message_type] = [
|
||||
obj for obj in threads
|
||||
|
|
|
@ -395,7 +395,7 @@ def get_inactive_recipient_ids(user_profile):
|
|||
return inactive_recipient_ids
|
||||
|
||||
def get_unread_message_ids_per_recipient(user_profile):
|
||||
# type: (UserProfile) -> Dict[str, List[Dict[str, Any]]]
|
||||
# type: (UserProfile) -> Dict[str, Any]
|
||||
|
||||
excluded_recipient_ids = get_inactive_recipient_ids(user_profile)
|
||||
|
||||
|
@ -419,6 +419,7 @@ def get_unread_message_ids_per_recipient(user_profile):
|
|||
user_msgs = list(user_msgs[:MAX_UNREAD_MESSAGES])
|
||||
|
||||
rows = list(reversed(user_msgs))
|
||||
count = len(rows)
|
||||
|
||||
pm_msgs = [
|
||||
dict(
|
||||
|
@ -484,12 +485,15 @@ def get_unread_message_ids_per_recipient(user_profile):
|
|||
streams=stream_objects,
|
||||
huddles=huddle_objects,
|
||||
mentions=mentioned_message_ids,
|
||||
count=count,
|
||||
)
|
||||
|
||||
return result
|
||||
|
||||
def apply_unread_message_event(state, message):
|
||||
# type: (Dict[str, List[Dict[str, Any]]], Dict[str, Any]) -> None
|
||||
# type: (Dict[str, Any], Dict[str, Any]) -> None
|
||||
state['count'] += 1
|
||||
|
||||
message_id = message['id']
|
||||
if message['type'] == 'stream':
|
||||
message_type = 'stream'
|
||||
|
|
Loading…
Reference in New Issue