Exclude inactive streams from unread counts.

This commit is contained in:
Steve Howell
2017-08-08 20:22:00 -04:00
committed by Tim Abbott
parent 5f87037bf5
commit c0dec29f5f

View File

@@ -21,6 +21,7 @@ from zerver.models import (
Realm,
Recipient,
Stream,
Subscription,
UserProfile,
UserMessage,
Reaction
@@ -379,10 +380,29 @@ def aggregate_dict(input_rows, lookup_fields, input_field, output_field):
return [lookup_dict[k] for k in sorted_keys]
def get_inactive_recipient_ids(user_profile):
# type: (UserProfile) -> List[int]
rows = Subscription.objects.filter(
user_profile=user_profile,
recipient__type=Recipient.STREAM,
active=False,
).values(
'recipient_id'
)
inactive_recipient_ids = [
row['recipient_id']
for row in rows]
return inactive_recipient_ids
def get_unread_message_ids_per_recipient(user_profile):
# type: (UserProfile) -> Dict[str, List[Dict[str, Any]]]
excluded_recipient_ids = get_inactive_recipient_ids(user_profile)
user_msgs = UserMessage.objects.filter(
user_profile=user_profile
).exclude(
message__recipient_id__in=excluded_recipient_ids
).extra(
where=[UserMessage.where_unread()]
).values(