chat/utils/clients/gooyal_notifications_client/models/email.py
Ali Asadi 0d262c68eb Send push notifications on new chat messages
Ports the gooyal notifications client (as already used by advertising)
and wires it into the previously-empty PushPublisher: on each message
send, the other conversation participant(s) get a push notification
with the sender's name and a message preview. Failures are swallowed
per-recipient so a down notifications service degrades silently rather
than breaking message sending.

Requires NOTIFICATIONS_BASE_PUBLIC_URL and the
notifications.application.push:send OAuth2 scope to be configured
before it will actually deliver.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-08-01 14:10:56 +03:30

133 lines
3.5 KiB
Python

from collections.abc import Mapping
from typing import Any, TypeVar, Union, cast
from uuid import UUID
from attrs import define as _attrs_define
from attrs import field as _attrs_field
from ..types import UNSET, Unset
T = TypeVar("T", bound="Email")
@_attrs_define
class Email:
"""
Attributes:
title (str):
message (str):
user (UUID):
application (Union[None, UUID]):
queue (Union[None, UUID, Unset]):
"""
title: str
message: str
user: UUID
application: Union[None, UUID]
queue: Union[None, UUID, Unset] = UNSET
additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)
def to_dict(self) -> dict[str, Any]:
title = self.title
message = self.message
user = str(self.user)
application: Union[None, str]
if isinstance(self.application, UUID):
application = str(self.application)
else:
application = self.application
queue: Union[None, Unset, str]
if isinstance(self.queue, Unset):
queue = UNSET
elif isinstance(self.queue, UUID):
queue = str(self.queue)
else:
queue = self.queue
field_dict: dict[str, Any] = {}
field_dict.update(self.additional_properties)
field_dict.update(
{
"title": title,
"message": message,
"user": user,
"application": application,
}
)
if queue is not UNSET:
field_dict["queue"] = queue
return field_dict
@classmethod
def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
d = dict(src_dict)
title = d.pop("title")
message = d.pop("message")
user = UUID(d.pop("user"))
def _parse_application(data: object) -> Union[None, UUID]:
if data is None:
return data
try:
if not isinstance(data, str):
raise TypeError()
application_type_0 = UUID(data)
return application_type_0
except: # noqa: E722
pass
return cast(Union[None, UUID], data)
application = _parse_application(d.pop("application"))
def _parse_queue(data: object) -> Union[None, UUID, Unset]:
if data is None:
return data
if isinstance(data, Unset):
return data
try:
if not isinstance(data, str):
raise TypeError()
queue_type_0 = UUID(data)
return queue_type_0
except: # noqa: E722
pass
return cast(Union[None, UUID, Unset], data)
queue = _parse_queue(d.pop("queue", UNSET))
email = cls(
title=title,
message=message,
user=user,
application=application,
queue=queue,
)
email.additional_properties = d
return email
@property
def additional_keys(self) -> list[str]:
return list(self.additional_properties.keys())
def __getitem__(self, key: str) -> Any:
return self.additional_properties[key]
def __setitem__(self, key: str, value: Any) -> None:
self.additional_properties[key] = value
def __delitem__(self, key: str) -> None:
del self.additional_properties[key]
def __contains__(self, key: str) -> bool:
return key in self.additional_properties