chat/utils/clients/gooyal_notifications_client/models/push_message.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

121 lines
3.2 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="PushMessage")
@_attrs_define
class PushMessage:
"""
Attributes:
push_user (UUID):
application (Union[None, UUID]):
title (str):
message (str):
priority (Union[Unset, int]):
extras (Union[Unset, Any]):
"""
push_user: UUID
application: Union[None, UUID]
title: str
message: str
priority: Union[Unset, int] = UNSET
extras: Union[Unset, Any] = UNSET
additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)
def to_dict(self) -> dict[str, Any]:
push_user = str(self.push_user)
application: Union[None, str]
if isinstance(self.application, UUID):
application = str(self.application)
else:
application = self.application
title = self.title
message = self.message
priority = self.priority
extras = self.extras
field_dict: dict[str, Any] = {}
field_dict.update(self.additional_properties)
field_dict.update(
{
"push_user": push_user,
"application": application,
"title": title,
"message": message,
}
)
if priority is not UNSET:
field_dict["priority"] = priority
if extras is not UNSET:
field_dict["extras"] = extras
return field_dict
@classmethod
def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
d = dict(src_dict)
push_user = UUID(d.pop("push_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"))
title = d.pop("title")
message = d.pop("message")
priority = d.pop("priority", UNSET)
extras = d.pop("extras", UNSET)
push_message = cls(
push_user=push_user,
application=application,
title=title,
message=message,
priority=priority,
extras=extras,
)
push_message.additional_properties = d
return push_message
@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