mirror of
https://github.com/zulip/zulip.git
synced 2025-11-01 20:44:04 +00:00
Extract get_personal_recipient().
This commit is contained in:
@@ -46,7 +46,7 @@ from zerver.models import Realm, RealmEmoji, Stream, UserProfile, UserActivity,
|
||||
UserHotspot, \
|
||||
Client, DefaultStream, DefaultStreamGroup, UserPresence, PushDeviceToken, \
|
||||
ScheduledEmail, MAX_SUBJECT_LENGTH, \
|
||||
MAX_MESSAGE_LENGTH, get_client, get_stream, get_recipient, get_huddle, \
|
||||
MAX_MESSAGE_LENGTH, get_client, get_stream, get_personal_recipient, get_huddle, \
|
||||
get_user_profile_by_id, PreregistrationUser, get_display_recipient, \
|
||||
get_realm, bulk_get_recipients, get_stream_recipient, \
|
||||
email_allowed_for_realm, email_to_username, display_recipient_cache_key, \
|
||||
@@ -756,7 +756,7 @@ def create_mirror_user_if_needed(realm, email, email_to_fullname):
|
||||
def send_welcome_bot_response(message):
|
||||
# type: (MutableMapping[str, Any]) -> None
|
||||
welcome_bot = get_system_bot(settings.WELCOME_BOT)
|
||||
human_recipient = get_recipient(Recipient.PERSONAL, message['message'].sender.id)
|
||||
human_recipient = get_personal_recipient(message['message'].sender.id)
|
||||
if Message.objects.filter(sender=welcome_bot, recipient=human_recipient).count() < 2:
|
||||
internal_send_private_message(
|
||||
message['realm'], welcome_bot, message['message'].sender,
|
||||
@@ -1499,7 +1499,7 @@ def get_recipient_from_user_ids(recipient_profile_ids, not_forged_mirror_message
|
||||
recipient_profile_ids.add(sender.id)
|
||||
return get_huddle_recipient(recipient_profile_ids)
|
||||
else:
|
||||
return get_recipient(Recipient.PERSONAL, list(recipient_profile_ids)[0])
|
||||
return get_personal_recipient(list(recipient_profile_ids)[0])
|
||||
|
||||
def validate_recipient_user_profiles(user_profiles, sender):
|
||||
# type: (List[UserProfile], UserProfile) -> Set[int]
|
||||
|
||||
@@ -18,7 +18,7 @@ from zerver.lib.utils import generate_random_token
|
||||
from zerver.lib.str_utils import force_text
|
||||
from zerver.lib.send_email import FromAddress
|
||||
from zerver.models import Stream, Recipient, \
|
||||
get_user_profile_by_id, get_display_recipient, get_recipient, \
|
||||
get_user_profile_by_id, get_display_recipient, get_personal_recipient, \
|
||||
Message, Realm, UserProfile, get_system_bot
|
||||
from six import binary_type
|
||||
import talon
|
||||
@@ -108,7 +108,7 @@ def create_missed_message_address(user_profile, message):
|
||||
|
||||
if message.recipient.type == Recipient.PERSONAL:
|
||||
# We need to reply to the sender so look up their personal recipient_id
|
||||
recipient_id = get_recipient(Recipient.PERSONAL, message.sender_id).id
|
||||
recipient_id = get_personal_recipient(message.sender_id).id
|
||||
else:
|
||||
recipient_id = message.recipient_id
|
||||
|
||||
|
||||
@@ -1056,6 +1056,10 @@ def get_stream_recipient(stream_id):
|
||||
# type: (int) -> Recipient
|
||||
return get_recipient(Recipient.STREAM, stream_id)
|
||||
|
||||
def get_personal_recipient(user_profile_id):
|
||||
# type: (int) -> Recipient
|
||||
return get_recipient(Recipient.PERSONAL, user_profile_id)
|
||||
|
||||
def get_huddle_recipient(user_profile_ids):
|
||||
# type: (Set[int]) -> Recipient
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ from sqlalchemy.sql import compiler
|
||||
|
||||
from zerver.models import (
|
||||
Realm, Recipient, Stream, Subscription, UserProfile, Attachment,
|
||||
get_display_recipient, get_recipient, get_realm, get_stream, get_user,
|
||||
get_display_recipient, get_personal_recipient, get_realm, get_stream, get_user,
|
||||
Reaction, UserMessage, get_stream_recipient,
|
||||
)
|
||||
from zerver.lib.message import (
|
||||
@@ -475,8 +475,8 @@ class GetOldMessagesTest(ZulipTestCase):
|
||||
query_ids['scotland_recipient'] = get_stream_recipient(scotland_stream.id).id
|
||||
query_ids['hamlet_id'] = hamlet_user.id
|
||||
query_ids['othello_id'] = othello_user.id
|
||||
query_ids['hamlet_recipient'] = get_recipient(Recipient.PERSONAL, hamlet_user.id).id
|
||||
query_ids['othello_recipient'] = get_recipient(Recipient.PERSONAL, othello_user.id).id
|
||||
query_ids['hamlet_recipient'] = get_personal_recipient(hamlet_user.id).id
|
||||
query_ids['othello_recipient'] = get_personal_recipient(othello_user.id).id
|
||||
|
||||
return query_ids
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ from zerver.lib.utils import statsd
|
||||
from zerver.lib.validator import \
|
||||
check_list, check_int, check_dict, check_string, check_bool
|
||||
from zerver.models import Message, UserProfile, Stream, Subscription, \
|
||||
Realm, RealmDomain, Recipient, UserMessage, bulk_get_recipients, get_recipient, \
|
||||
Realm, RealmDomain, Recipient, UserMessage, bulk_get_recipients, get_personal_recipient, \
|
||||
get_stream, parse_usermessage_flags, email_to_domain, get_realm, get_active_streams, \
|
||||
get_user_including_cross_realm, get_stream_recipient
|
||||
|
||||
@@ -321,7 +321,7 @@ class NarrowBuilder(object):
|
||||
return query.where(maybe_negate(cond))
|
||||
else:
|
||||
# Personal message
|
||||
self_recipient = get_recipient(Recipient.PERSONAL, type_id=self.user_profile.id)
|
||||
self_recipient = get_personal_recipient(self.user_profile.id)
|
||||
if operand == self.user_profile.email:
|
||||
# Personals with self
|
||||
cond = and_(column("sender_id") == self.user_profile.id,
|
||||
@@ -334,7 +334,7 @@ class NarrowBuilder(object):
|
||||
except UserProfile.DoesNotExist:
|
||||
raise BadNarrowOperator('unknown user ' + operand)
|
||||
|
||||
narrow_recipient = get_recipient(Recipient.PERSONAL, narrow_profile.id)
|
||||
narrow_recipient = get_personal_recipient(narrow_profile.id)
|
||||
cond = or_(and_(column("sender_id") == narrow_profile.id,
|
||||
column("recipient_id") == self_recipient.id),
|
||||
and_(column("sender_id") == self.user_profile.id,
|
||||
|
||||
Reference in New Issue
Block a user