Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
devices events: Use DeviceAdd/Remove pydantic types.
Evy Kassirer6257cd9d13ad
diff --git a/zerver/actions/devices.py b/zerver/actions/devices.pyindex c4cc878154a..437c4e56d5a 100644--- a/zerver/actions/devices.py+++ b/zerver/actions/devices.py@@ -1,4 +1,5 @@from zerver.lib.devices import check_device_id+from zerver.lib.event_types import DeviceAddEvent, DeviceRemoveEventfrom zerver.models.devices import Devicefrom zerver.models.users import UserProfilefrom zerver.tornado.django_api import send_event_on_commit@@ -6,11 +7,7 @@ from zerver.tornado.django_api import send_event_on_commitdef do_register_device(user_profile: UserProfile) -> int:device = Device.objects.create(user=user_profile)- event = dict(- type="device",- op="add",- device_id=device.id,- )+ event = DeviceAddEvent(device_id=device.id)send_event_on_commit(user_profile.realm, event, [user_profile.id])return device.id@@ -19,9 +16,5 @@ def do_remove_device(user_profile: UserProfile, device_id: int) -> None:device = check_device_id(device_id, user_profile.id)device.delete()- event = dict(- type="device",- op="remove",- device_id=device_id,- )+ event = DeviceRemoveEvent(device_id=device_id)send_event_on_commit(user_profile.realm, event, [user_profile.id])diff --git a/zerver/lib/event_types.py b/zerver/lib/event_types.pyindex 7fe813ffb97..00ad39dbe7b 100644--- a/zerver/lib/event_types.py+++ b/zerver/lib/event_types.py@@ -293,20 +293,20 @@ class OnboardingStepsEvent(BaseEvent):class DeviceAddEvent(BaseEvent):- type: Literal["device"]- op: Literal["add"]+ type: Literal["device"] = "device"+ op: Literal["add"] = "add"device_id: intclass DeviceRemoveEvent(BaseEvent):- type: Literal["device"]- op: Literal["remove"]+ type: Literal["device"] = "device"+ op: Literal["remove"] = "remove"device_id: intclass DeviceUpdateEvent(BaseEvent):- type: Literal["device"]- op: Literal["update"]+ type: Literal["device"] = "device"+ op: Literal["update"] = "update"device_id: intpush_key_id: int | None = Nonepush_token_id: str | None = None