Take user_ids in get_userids_for_missed_messages().

This helps us phase out the need for getting lots of UserProfile
objects.
This commit is contained in:
Steve Howell
2017-09-08 19:14:28 -07:00
committed by Tim Abbott
parent 06c388774f
commit 82b2bd8b65
2 changed files with 9 additions and 9 deletions

View File

@@ -942,7 +942,7 @@ def do_send_messages(messages_maybe_none):
realm=sender.realm, realm=sender.realm,
sender_id=sender.id, sender_id=sender.id,
message_type=message_type, message_type=message_type,
active_recipients=message['active_recipients'], active_user_ids=message['active_user_ids'],
user_flags=user_flags, user_flags=user_flags,
) )
@@ -3191,20 +3191,20 @@ def gather_subscriptions(user_profile):
return (subscribed, unsubscribed) return (subscribed, unsubscribed)
def get_userids_for_missed_messages(realm, sender_id, message_type, active_recipients, user_flags): def get_userids_for_missed_messages(realm, sender_id, message_type, active_user_ids, user_flags):
# type: (Realm, int, str, List[UserProfile], Dict[int, List[str]]) -> List[int] # type: (Realm, int, str, Set[int], Dict[int, List[str]]) -> List[int]
if realm.presence_disabled: if realm.presence_disabled:
return [] return []
is_pm = message_type == 'private' is_pm = message_type == 'private'
user_ids = set() user_ids = set()
for user in active_recipients: for user_id in active_user_ids:
flags = user_flags.get(user.id, []) # type: Iterable[str] flags = user_flags.get(user_id, []) # type: Iterable[str]
mentioned = 'mentioned' in flags mentioned = 'mentioned' in flags
received_pm = is_pm and user.id != sender_id received_pm = is_pm and user_id != sender_id
if mentioned or received_pm: if mentioned or received_pm:
user_ids.add(user.id) user_ids.add(user_id)
if not user_ids: if not user_ids:
return [] return []

View File

@@ -2110,7 +2110,7 @@ class MissedMessageTest(ZulipTestCase):
realm = sender.realm realm = sender.realm
hamlet = self.example_user('hamlet') hamlet = self.example_user('hamlet')
othello = self.example_user('othello') othello = self.example_user('othello')
recipients = [hamlet, othello] recipient_ids = {hamlet.id, othello.id}
message_type = 'stream' message_type = 'stream'
user_flags = {} # type: Dict[int, List[str]] user_flags = {} # type: Dict[int, List[str]]
@@ -2120,7 +2120,7 @@ class MissedMessageTest(ZulipTestCase):
realm=realm, realm=realm,
sender_id=sender.id, sender_id=sender.id,
message_type=message_type, message_type=message_type,
active_recipients=recipients, active_user_ids=recipient_ids,
user_flags=user_flags, user_flags=user_flags,
) )
self.assertEqual(sorted(user_ids), sorted(missed_message_userids)) self.assertEqual(sorted(user_ids), sorted(missed_message_userids))