Move the notification service into the services directory
This commit is contained in:
parent
387e2fa490
commit
7b6d351282
4 changed files with 39 additions and 43 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
|
||||||
from src.notifications.service import make_notification_service
|
from src.services.notifications import NotificationService, get_notification_service
|
||||||
from src.services.email import get_service as get_email_service
|
from src.services.email import get_service as get_email_service
|
||||||
from src.services.users import get_service as get_user_service
|
from src.services.users import get_service as get_user_service
|
||||||
from src.infra.db import get_database
|
from src.infra.db import get_database
|
||||||
|
|
|
||||||
|
|
@ -1,38 +0,0 @@
|
||||||
from dataclasses import dataclass, field
|
|
||||||
|
|
||||||
URL = str
|
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
|
||||||
class NotificationAction:
|
|
||||||
# A unique identifier for the action
|
|
||||||
action: str
|
|
||||||
# The title to show with the action
|
|
||||||
title: str
|
|
||||||
# Where to navigate to when clicked.
|
|
||||||
navigate: URL | None = None
|
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
|
||||||
class Notification:
|
|
||||||
"""
|
|
||||||
Details to show in a notification
|
|
||||||
|
|
||||||
Much of the data here is intended to match the arguments to the [showNotification](https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerRegistration/showNotification)
|
|
||||||
Web API, but this content is ideally displayable in other contexts (for example in Email or RSS)
|
|
||||||
"""
|
|
||||||
|
|
||||||
# The main title content to show
|
|
||||||
title: str
|
|
||||||
# The content of the notification
|
|
||||||
content: str
|
|
||||||
|
|
||||||
# The UNIX timestamp in milliseconds since the epoch associated with this notification
|
|
||||||
timestamp: int
|
|
||||||
# A list of actions included with this notification
|
|
||||||
actions: list[NotificationAction] = field(default_factory=list)
|
|
||||||
# The location of an icon to show as the icon for this notification
|
|
||||||
icon: URL | None = None
|
|
||||||
|
|
||||||
# The location of an image associated with this notification
|
|
||||||
image: URL | None = None
|
|
||||||
|
|
@ -2,11 +2,45 @@ import abc
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from src.services.email import EmailService
|
from src.services.email import EmailService
|
||||||
from src.config import Config
|
|
||||||
|
|
||||||
from .data import Notification
|
from dataclasses import dataclass, field
|
||||||
|
|
||||||
# MUSTFIX: Needs real users!
|
URL = str
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class NotificationAction:
|
||||||
|
# A unique identifier for the action
|
||||||
|
action: str
|
||||||
|
# The title to show with the action
|
||||||
|
title: str
|
||||||
|
# Where to navigate to when clicked.
|
||||||
|
navigate: URL | None = None
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class Notification:
|
||||||
|
"""
|
||||||
|
Details to show in a notification
|
||||||
|
|
||||||
|
Much of the data here is intended to match the arguments to the [showNotification](https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerRegistration/showNotification)
|
||||||
|
Web API, but this content is ideally displayable in other contexts (for example in Email or RSS)
|
||||||
|
"""
|
||||||
|
|
||||||
|
# The main title content to show
|
||||||
|
title: str
|
||||||
|
# The content of the notification
|
||||||
|
content: str
|
||||||
|
|
||||||
|
# The UNIX timestamp in milliseconds since the epoch associated with this notification
|
||||||
|
timestamp: int
|
||||||
|
# A list of actions included with this notification
|
||||||
|
actions: list[NotificationAction] = field(default_factory=list)
|
||||||
|
# The location of an icon to show as the icon for this notification
|
||||||
|
icon: URL | None = None
|
||||||
|
|
||||||
|
# The location of an image associated with this notification
|
||||||
|
image: URL | None = None
|
||||||
|
|
||||||
|
|
||||||
class NotificationSender(abc.ABC):
|
class NotificationSender(abc.ABC):
|
||||||
|
|
@ -48,7 +82,7 @@ class EmailNotifier(NotificationSender):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def make_notification_service(email_service: EmailService):
|
def get_notification_service(email_service: EmailService):
|
||||||
service = NotificationService()
|
service = NotificationService()
|
||||||
service.register_sender(EmailNotifier(email_service))
|
service.register_sender(EmailNotifier(email_service))
|
||||||
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue