|
20 | 20 | update_event, |
21 | 21 | update_ticket, |
22 | 22 | ) |
23 | | -from .models import Ticket |
| 23 | +from .models import Event, Ticket |
24 | 24 |
|
25 | 25 | DEFAULT_NOSTR_RELAYS = [ |
26 | 26 | "wss://relay.damus.io", |
@@ -55,16 +55,7 @@ async def _send_ticket_notification(ticket: Ticket) -> None: |
55 | 55 | logger.warning(f"Event {ticket.event} not found for ticket notification.") |
56 | 56 | return |
57 | 57 |
|
58 | | - ticket_url = _ticket_url(ticket) |
59 | | - subject = ( |
60 | | - event.extra.notification_subject.strip() |
61 | | - or f"Your ticket for '{event.name}' is ready" |
62 | | - ) |
63 | | - body = ( |
64 | | - event.extra.notification_body.strip() |
65 | | - or f"Your ticket for '{event.name}' is ready." |
66 | | - ) |
67 | | - message = f"{body}\n\nOpen it here: {ticket_url}" |
| 58 | + subject, message = _ticket_notification_message(ticket, event) |
68 | 59 | updated = False |
69 | 60 |
|
70 | 61 | if ( |
@@ -97,6 +88,35 @@ async def _send_ticket_notification(ticket: Ticket) -> None: |
97 | 88 | await update_ticket(ticket) |
98 | 89 |
|
99 | 90 |
|
| 91 | +async def resend_ticket_email_notification(ticket: Ticket) -> Ticket: |
| 92 | + event = await get_event(ticket.event) |
| 93 | + if not event: |
| 94 | + raise ValueError("Event does not exist.") |
| 95 | + if not settings.lnbits_email_notifications_enabled: |
| 96 | + raise ValueError("Email notifications are not enabled.") |
| 97 | + if not ticket.email: |
| 98 | + raise ValueError("Ticket does not have an email address.") |
| 99 | + |
| 100 | + subject, message = _ticket_notification_message(ticket, event) |
| 101 | + await send_email_notification([ticket.email], message, subject) |
| 102 | + ticket.extra.email_notification_sent = True |
| 103 | + return await update_ticket(ticket) |
| 104 | + |
| 105 | + |
| 106 | +def _ticket_notification_message(ticket: Ticket, event: Event) -> tuple[str, str]: |
| 107 | + ticket_url = _ticket_url(ticket) |
| 108 | + subject = ( |
| 109 | + event.extra.notification_subject.strip() |
| 110 | + or f"Your ticket for '{event.name}' is ready" |
| 111 | + ) |
| 112 | + body = ( |
| 113 | + event.extra.notification_body.strip() |
| 114 | + or f"Your ticket for '{event.name}' is ready." |
| 115 | + ) |
| 116 | + |
| 117 | + return subject, f"{body}\n\nOpen it here: {ticket_url}" |
| 118 | + |
| 119 | + |
100 | 120 | async def _send_nostr_ticket_notification(identifier: str, message: str) -> None: |
101 | 121 | if "@" in identifier: |
102 | 122 | await send_user_notification( |
|
0 commit comments