mirror of https://github.com/zulip/zulip.git
Inline get_recipient_user_ids() into two callers.
This sets us up a subsequent commit where we need more data from the Subscription table to build recipient info, so the function boundary doesn't work any more for get_recipient_info, which is part of the heavily optimized send-message path. We used to share code here with typing notifications, but typing notifications need a lot less data than the send-message path, so it's useful to decouple these two things. The idioms that are duplicated here are pretty simple one-liners.
This commit is contained in:
parent
191bb4c20f
commit
41e3a819da
|
@ -714,24 +714,6 @@ def render_incoming_message(message, content, user_ids, realm):
|
|||
raise JsonableError(_('Unable to render message'))
|
||||
return rendered_content
|
||||
|
||||
def get_recipient_user_ids(recipient, sender_id):
|
||||
# type: (Recipient, int) -> List[int]
|
||||
if recipient.type == Recipient.PERSONAL:
|
||||
# The sender and recipient may be the same id, so
|
||||
# de-duplicate using a set.
|
||||
user_ids = list({recipient.type_id, sender_id})
|
||||
assert(len(user_ids) in [1, 2])
|
||||
return user_ids
|
||||
|
||||
elif (recipient.type == Recipient.STREAM or recipient.type == Recipient.HUDDLE):
|
||||
user_ids = Subscription.objects.filter(
|
||||
recipient=recipient,
|
||||
active=True,
|
||||
).order_by('user_profile_id').values_list('user_profile_id', flat=True)
|
||||
return user_ids
|
||||
|
||||
raise ValueError('Bad recipient type')
|
||||
|
||||
def get_typing_user_profiles(recipient, sender_id):
|
||||
# type: (Recipient, int) -> List[UserProfile]
|
||||
if recipient.type == Recipient.STREAM:
|
||||
|
@ -742,7 +724,21 @@ def get_typing_user_profiles(recipient, sender_id):
|
|||
'''
|
||||
raise ValueError('Typing indicators not supported for streams')
|
||||
|
||||
user_ids = get_recipient_user_ids(recipient, sender_id)
|
||||
if recipient.type == Recipient.PERSONAL:
|
||||
# The sender and recipient may be the same id, so
|
||||
# de-duplicate using a set.
|
||||
user_ids = list({recipient.type_id, sender_id})
|
||||
assert(len(user_ids) in [1, 2])
|
||||
|
||||
elif recipient.type == Recipient.HUDDLE:
|
||||
user_ids = Subscription.objects.filter(
|
||||
recipient=recipient,
|
||||
active=True,
|
||||
).order_by('user_profile_id').values_list('user_profile_id', flat=True)
|
||||
|
||||
else:
|
||||
raise ValueError('Bad recipient type')
|
||||
|
||||
users = [get_user_profile_by_id(user_id) for user_id in user_ids]
|
||||
return users
|
||||
|
||||
|
@ -757,7 +753,26 @@ RecipientInfoResult = TypedDict('RecipientInfoResult', {
|
|||
|
||||
def get_recipient_info(recipient, sender_id):
|
||||
# type: (Recipient, int) -> RecipientInfoResult
|
||||
user_ids = get_recipient_user_ids(recipient, sender_id)
|
||||
if recipient.type == Recipient.PERSONAL:
|
||||
# The sender and recipient may be the same id, so
|
||||
# de-duplicate using a set.
|
||||
user_ids = list({recipient.type_id, sender_id})
|
||||
assert(len(user_ids) in [1, 2])
|
||||
|
||||
elif recipient.type == Recipient.STREAM:
|
||||
user_ids = Subscription.objects.filter(
|
||||
recipient=recipient,
|
||||
active=True,
|
||||
).order_by('user_profile_id').values_list('user_profile_id', flat=True)
|
||||
|
||||
elif recipient.type == Recipient.HUDDLE:
|
||||
user_ids = Subscription.objects.filter(
|
||||
recipient=recipient,
|
||||
active=True,
|
||||
).order_by('user_profile_id').values_list('user_profile_id', flat=True)
|
||||
|
||||
else:
|
||||
raise ValueError('Bad recipient type')
|
||||
|
||||
query = UserProfile.objects.filter(
|
||||
id__in=user_ids
|
||||
|
|
Loading…
Reference in New Issue