mirror of
https://github.com/zulip/zulip.git
synced 2025-11-02 04:53:36 +00:00
Send push notifications regardless of idle status for robinhood.io, zulip.com
(imported from commit 49d2c954f6537d28ef3f8ccad669c56430afdbde)
This commit is contained in:
@@ -248,6 +248,11 @@ def log_message(message):
|
||||
if not message.sending_client.name.startswith("test:"):
|
||||
log_event(message.to_log_dict())
|
||||
|
||||
def always_push_notify(user):
|
||||
# robinhood.io asked to get push notifications for **all** notifyable
|
||||
# messages, regardless of idle status
|
||||
return user.realm.domain in ['zulip.com', 'robinhood.io']
|
||||
|
||||
# Helper function. Defaults here are overriden by those set in do_send_messages
|
||||
def do_send_message(message, rendered_content = None, no_log = False, stream = None, local_id = None):
|
||||
return do_send_messages([{'message': message,
|
||||
@@ -301,9 +306,10 @@ def do_send_messages(messages):
|
||||
fields = [
|
||||
'user_profile__id',
|
||||
'user_profile__email',
|
||||
'user_profile__is_active'
|
||||
'user_profile__is_active',
|
||||
'user_profile__realm__domain'
|
||||
]
|
||||
query = Subscription.objects.select_related("user_profile").only(*fields).filter(
|
||||
query = Subscription.objects.select_related("user_profile", "user_profile__realm").only(*fields).filter(
|
||||
recipient=message['message'].recipient, active=True)
|
||||
message['recipients'] = [s.user_profile for s in query]
|
||||
else:
|
||||
@@ -362,8 +368,10 @@ def do_send_messages(messages):
|
||||
type = 'new_message',
|
||||
message = message['message'].id,
|
||||
presences = presences,
|
||||
users = [{'id': user.id, 'flags': user_flags.get(user.id, [])}
|
||||
for user in message['active_recipients']])
|
||||
users = [{'id': user.id,
|
||||
'flags': user_flags.get(user.id, []),
|
||||
'always_push_notify': always_push_notify(user)}
|
||||
for user in message['active_recipients']])
|
||||
if message['message'].recipient.type == Recipient.STREAM:
|
||||
# Note: This is where authorization for single-stream
|
||||
# get_updates happens! We only attach stream data to the
|
||||
|
||||
@@ -122,12 +122,16 @@ def process_new_message(data):
|
||||
received_pm = message.recipient.type in (Recipient.PERSONAL, Recipient.HUDDLE) and \
|
||||
user_profile_id != message.sender.id
|
||||
mentioned = 'mentioned' in flags
|
||||
if (received_pm or mentioned) and receiver_is_idle(user_profile_id, realm_presences):
|
||||
idle = receiver_is_idle(user_profile_id, realm_presences)
|
||||
always_push_notify = user_data.get('always_push_notify', False)
|
||||
if (received_pm or mentioned) and (idle or always_push_notify):
|
||||
event = build_offline_notification_event(user_profile_id, message.id)
|
||||
|
||||
# We require RabbitMQ to do this, as we can't call the email handler
|
||||
# from the Tornado process. So if there's no rabbitmq support do nothing
|
||||
queue_json_publish("missedmessage_emails", event, lambda event: None)
|
||||
# Don't send missed message emails if always_push_notify is True
|
||||
if idle:
|
||||
# We require RabbitMQ to do this, as we can't call the email handler
|
||||
# from the Tornado process. So if there's no rabbitmq support do nothing
|
||||
queue_json_publish("missedmessage_emails", event, lambda event: None)
|
||||
queue_json_publish("missedmessage_mobile_notifications", event, lambda event: None)
|
||||
|
||||
for client_data in send_to_clients.itervalues():
|
||||
|
||||
Reference in New Issue
Block a user