push_notifications: Declare token of type str, not bytes.

Declaring a CharField of type bytes made no sense.

Signed-off-by: Anders Kaseorg <andersk@zulipchat.com>
This commit is contained in:
Anders Kaseorg
2019-11-12 21:54:30 -08:00
parent f8855ca179
commit b0a7b33f9b
4 changed files with 14 additions and 14 deletions

View File

@@ -46,11 +46,11 @@ else: # nocoverage -- Not convenient to add test for this.
DeviceToken = Union[PushDeviceToken, RemotePushDeviceToken]
# We store the token as b64, but apns-client wants hex strings
def b64_to_hex(data: bytes) -> str:
def b64_to_hex(data: str) -> str:
return binascii.hexlify(base64.b64decode(data)).decode('utf-8')
def hex_to_b64(data: str) -> bytes:
return base64.b64encode(binascii.unhexlify(data.encode('utf-8')))
def hex_to_b64(data: str) -> str:
return base64.b64encode(binascii.unhexlify(data)).decode()
#
# Sending to APNs, for iOS
@@ -362,7 +362,7 @@ def num_push_devices_for_user(user_profile: UserProfile, kind: Optional[int]=Non
return PushDeviceToken.objects.filter(user=user_profile, kind=kind).count()
def add_push_device_token(user_profile: UserProfile,
token_str: bytes,
token_str: str,
kind: int,
ios_app_id: Optional[str]=None) -> None:
logger.info("Registering push device: %d %r %d %r",
@@ -398,7 +398,7 @@ def add_push_device_token(user_profile: UserProfile,
except IntegrityError:
pass
def remove_push_device_token(user_profile: UserProfile, token_str: bytes, kind: int) -> None:
def remove_push_device_token(user_profile: UserProfile, token_str: str, kind: int) -> None:
# If we're sending things to the push notification bouncer
# unregister this user with them here