mirror of https://github.com/zulip/zulip.git
get_apns_payload: Require a UserProfile object for the recipient.
This is preparatory work for being able to display an unread count badge on iOS, in which case we need to know who the current user is.
This commit is contained in:
parent
a4df001cef
commit
695d8d0bd1
|
@ -522,7 +522,7 @@ def get_common_payload(message: Message) -> Dict[str, Any]:
|
|||
|
||||
return data
|
||||
|
||||
def get_apns_payload(message: Message) -> Dict[str, Any]:
|
||||
def get_apns_payload(user_profile: UserProfile, message: Message) -> Dict[str, Any]:
|
||||
zulip_data = get_common_payload(message)
|
||||
zulip_data.update({
|
||||
'message_ids': [message.id],
|
||||
|
@ -640,7 +640,7 @@ def handle_push_notification(user_profile_id: int, missed_message: Dict[str, Any
|
|||
message.trigger = missed_message['trigger']
|
||||
message.stream_name = missed_message.get('stream_name', None)
|
||||
|
||||
apns_payload = get_apns_payload(message)
|
||||
apns_payload = get_apns_payload(user_profile, message)
|
||||
gcm_payload = get_gcm_payload(user_profile, message)
|
||||
logging.info("Sending push notification to user %s" % (user_profile_id,))
|
||||
|
||||
|
|
|
@ -769,12 +769,13 @@ class TestGetAlertFromMessage(PushNotificationTest):
|
|||
|
||||
class TestGetAPNsPayload(PushNotificationTest):
|
||||
def test_get_apns_payload(self) -> None:
|
||||
user_profile = self.example_user("othello")
|
||||
message_id = self.send_huddle_message(
|
||||
self.sender.email,
|
||||
[self.example_email('othello'), self.example_email('cordelia')])
|
||||
message = Message.objects.get(id=message_id)
|
||||
message.trigger = 'private_message'
|
||||
payload = apn.get_apns_payload(message)
|
||||
payload = apn.get_apns_payload(user_profile, message)
|
||||
expected = {
|
||||
'alert': {
|
||||
'title': "New private group message from King Hamlet",
|
||||
|
@ -801,11 +802,12 @@ class TestGetAPNsPayload(PushNotificationTest):
|
|||
|
||||
def test_get_apns_payload_stream(self):
|
||||
# type: () -> None
|
||||
user_profile = self.example_user("othello")
|
||||
stream = Stream.objects.filter(name='Verona').get()
|
||||
message = self.get_message(Recipient.STREAM, stream.id)
|
||||
message.trigger = 'mentioned'
|
||||
message.stream_name = 'Verona'
|
||||
payload = apn.get_apns_payload(message)
|
||||
payload = apn.get_apns_payload(user_profile, message)
|
||||
expected = {
|
||||
'alert': {
|
||||
'title': "New mention from King Hamlet",
|
||||
|
@ -830,12 +832,13 @@ class TestGetAPNsPayload(PushNotificationTest):
|
|||
|
||||
@override_settings(PUSH_NOTIFICATION_REDACT_CONTENT = True)
|
||||
def test_get_apns_payload_redacted_content(self) -> None:
|
||||
user_profile = self.example_user("othello")
|
||||
message_id = self.send_huddle_message(
|
||||
self.sender.email,
|
||||
[self.example_email('othello'), self.example_email('cordelia')])
|
||||
message = Message.objects.get(id=message_id)
|
||||
message.trigger = 'private_message'
|
||||
payload = apn.get_apns_payload(message)
|
||||
payload = apn.get_apns_payload(user_profile, message)
|
||||
expected = {
|
||||
'alert': {
|
||||
'title': "New private group message from King Hamlet",
|
||||
|
|
Loading…
Reference in New Issue