Some checks failed
Code scanning / CodeQL (push) Failing after 15s
Zulip production suite / Ubuntu 22.04 production build (push) Failing after 26s
Zulip production suite / Debian 12 production install with custom db name and user (push) Has been skipped
Zulip production suite / Ubuntu 22.04 production install and PostgreSQL upgrade with pgroonga (push) Has been skipped
Zulip production suite / Ubuntu 24.04 production install (push) Has been skipped
Zulip production suite / Ubuntu 26.04 production install (push) Has been skipped
Zulip production suite / Debian 13 production install (push) Has been skipped
Zulip production suite / 7.0 Version Upgrade (push) Has been skipped
Zulip production suite / 8.0 Version Upgrade (push) Has been skipped
Zulip production suite / 6.0 Version Upgrade (push) Has been skipped
Zulip production suite / 10.0 Version Upgrade (push) Has been skipped
Zulip production suite / 9.0 Version Upgrade (push) Has been skipped
Zulip production suite / 12.0 Version Upgrade (push) Has been skipped
Zulip production suite / 11.0 Version Upgrade (push) Has been skipped
GitHub Actions Security Analysis with zizmor / zizmor (push) Failing after 3s
Zulip CI / Debian 12 (Python 3.11, backend + documentation) (push) Failing after 26s
Zulip CI / Ubuntu 22.04 (Python 3.10, backend + frontend) (push) Failing after 3s
Zulip CI / Ubuntu 24.04 (Python 3.12, backend) (push) Failing after 25s
Zulip CI / Ubuntu 26.04 (Python 3.14, backend) (push) Failing after 25s
Zulip CI / Debian 13 (Python 3.13, backend) (push) Failing after 28s
Zulip production suite / Required jobs (push) Has been cancelled
Zulip CI / Required jobs (push) Has been cancelled
API Documentation Update Check / check-feature-level-updated (push) Has been cancelled
API Documentation Update Check / notify-if-api-docs-changed (push) Has been cancelled
71 lines
2.7 KiB
Python
71 lines
2.7 KiB
Python
from django.db import models
|
|
from django.db.models import Q
|
|
|
|
from zerver.lib.exceptions import (
|
|
InvalidBouncerPublicKeyError,
|
|
InvalidEncryptedPushRegistrationError,
|
|
RequestExpiredError,
|
|
)
|
|
from zerver.models.users import UserProfile
|
|
|
|
|
|
class Device(models.Model):
|
|
"""Core zulip server table storing logged-in devices.
|
|
|
|
Currently, only used by mobile apps for E2EE push notifications.
|
|
"""
|
|
|
|
# The user on this server to whom this Device belongs.
|
|
user = models.ForeignKey(UserProfile, on_delete=models.CASCADE)
|
|
|
|
# Key to use to encrypt notifications for delivery to this device.
|
|
# Consists of a 1-byte prefix identifying the symmetric cryptosystem
|
|
# in use, followed by the secret key.
|
|
# Prefix Cryptosystem
|
|
# 0x31 libsodium's `crypto_secretbox_easy`
|
|
push_key = models.BinaryField(null=True)
|
|
# ID to reference the `push_key` - unsigned 32-bit integer.
|
|
push_key_id = models.PositiveBigIntegerField(null=True)
|
|
|
|
# ID to reference the token provided by FCM/APNs, registered to bouncer.
|
|
push_token_id = models.BigIntegerField(null=True)
|
|
# ID to reference the token provided by FCM/APNs, registration in progress to bouncer.
|
|
pending_push_token_id = models.BigIntegerField(null=True)
|
|
|
|
# The last time when `pending_push_token_id` was set to a new value.
|
|
push_token_last_updated_timestamp = models.DateTimeField(null=True)
|
|
|
|
class PushTokenKind(models.TextChoices):
|
|
APNS = "apns", "APNs"
|
|
FCM = "fcm", "FCM"
|
|
|
|
push_token_kind = models.CharField(max_length=4, choices=PushTokenKind.choices, null=True)
|
|
|
|
class PushRegistrationErrorCode(models.TextChoices):
|
|
INVALID_BOUNCER_PUBLIC_KEY = InvalidBouncerPublicKeyError.code.name
|
|
INVALID_ENCRYPTED_PUSH_REGISTRATION = InvalidEncryptedPushRegistrationError.code.name
|
|
REQUEST_EXPIRED = RequestExpiredError.code.name
|
|
|
|
# The error code returned when registration to bouncer fails.
|
|
push_registration_error_code = models.CharField(
|
|
max_length=100, choices=PushRegistrationErrorCode.choices, null=True
|
|
)
|
|
|
|
class Meta:
|
|
constraints = [
|
|
models.CheckConstraint(
|
|
condition=Q(push_key_id__lte=2**32 - 1),
|
|
name="push_key_id_lte_max_push_key_id",
|
|
)
|
|
]
|
|
indexes = [
|
|
models.Index(
|
|
# Used in 'get_recipient_info', `do_clear_mobile_push_notifications_for_ids`,
|
|
# `prepare_payload_and_send_push_notifications`, `send_push_notifications`,
|
|
# and `send_e2ee_test_push_notification_api`.
|
|
fields=["user", "push_token_id"],
|
|
condition=Q(push_token_id__isnull=False),
|
|
name="zerver_device_user_push_token_id_idx",
|
|
),
|
|
]
|