mirror of
https://github.com/zulip/zulip.git
synced 2025-11-03 05:23:35 +00:00
push_notifications: Return token from add_push_device_token().
This commit is contained in:
committed by
Tim Abbott
parent
b885678881
commit
8ebff434fb
@@ -371,7 +371,7 @@ def num_push_devices_for_user(user_profile: UserProfile, kind: Optional[int]=Non
|
|||||||
def add_push_device_token(user_profile: UserProfile,
|
def add_push_device_token(user_profile: UserProfile,
|
||||||
token_str: str,
|
token_str: str,
|
||||||
kind: int,
|
kind: int,
|
||||||
ios_app_id: Optional[str]=None) -> None:
|
ios_app_id: Optional[str]=None) -> PushDeviceToken:
|
||||||
logger.info("Registering push device: %d %r %d %r",
|
logger.info("Registering push device: %d %r %d %r",
|
||||||
user_profile.id, token_str, kind, ios_app_id)
|
user_profile.id, token_str, kind, ios_app_id)
|
||||||
|
|
||||||
@@ -382,7 +382,7 @@ def add_push_device_token(user_profile: UserProfile,
|
|||||||
# keys for mobile push notifications.
|
# keys for mobile push notifications.
|
||||||
try:
|
try:
|
||||||
with transaction.atomic():
|
with transaction.atomic():
|
||||||
PushDeviceToken.objects.create(
|
token = PushDeviceToken.objects.create(
|
||||||
user_id=user_profile.id,
|
user_id=user_profile.id,
|
||||||
kind=kind,
|
kind=kind,
|
||||||
token=token_str,
|
token=token_str,
|
||||||
@@ -390,7 +390,11 @@ def add_push_device_token(user_profile: UserProfile,
|
|||||||
# last_updated is to be renamed to date_created.
|
# last_updated is to be renamed to date_created.
|
||||||
last_updated=timezone_now())
|
last_updated=timezone_now())
|
||||||
except IntegrityError:
|
except IntegrityError:
|
||||||
pass
|
token = PushDeviceToken.objects.get(
|
||||||
|
user_id=user_profile.id,
|
||||||
|
kind=kind,
|
||||||
|
token=token_str,
|
||||||
|
)
|
||||||
|
|
||||||
# If we're sending things to the push notification bouncer
|
# If we're sending things to the push notification bouncer
|
||||||
# register this user with them here
|
# register this user with them here
|
||||||
@@ -409,6 +413,8 @@ def add_push_device_token(user_profile: UserProfile,
|
|||||||
# Calls zilencer.views.register_remote_push_device
|
# Calls zilencer.views.register_remote_push_device
|
||||||
send_to_push_bouncer('POST', 'push/register', post_data)
|
send_to_push_bouncer('POST', 'push/register', post_data)
|
||||||
|
|
||||||
|
return token
|
||||||
|
|
||||||
def remove_push_device_token(user_profile: UserProfile, token_str: str, kind: int) -> None:
|
def remove_push_device_token(user_profile: UserProfile, token_str: str, kind: int) -> None:
|
||||||
try:
|
try:
|
||||||
token = PushDeviceToken.objects.get(token=token_str, kind=kind, user=user_profile)
|
token = PushDeviceToken.objects.get(token=token_str, kind=kind, user=user_profile)
|
||||||
|
|||||||
Reference in New Issue
Block a user