|
23 | 23 | from couchers.email.locales import get_emails_i18next |
24 | 24 | from couchers.i18n import LocalizationContext |
25 | 25 | from couchers.i18n.localize import format_phone_number |
| 26 | +from couchers.markup import markdown_to_plaintext |
26 | 27 | from couchers.notifications.quick_links import generate_quick_decline_link |
27 | 28 | from couchers.proto import conversations_pb2, events_pb2, notification_data_pb2 |
28 | 29 | from couchers.utils import now, to_aware_datetime |
@@ -271,6 +272,9 @@ def get_subject_line(self, loc_context: LocalizationContext) -> str: |
271 | 272 | loc_context, ".subject", {"author": self.author.name, "group": self.group_chat_title or ""} |
272 | 273 | ) |
273 | 274 |
|
| 275 | + def get_preview_line(self, loc_context: LocalizationContext) -> str | None: |
| 276 | + return self.text |
| 277 | + |
274 | 278 | def get_body_blocks(self, loc_context: LocalizationContext) -> list[EmailBlock]: |
275 | 279 | builder = self._body_builder(loc_context) |
276 | 280 | builder.para(".body", {"author": self.author.name, "group": self.group_chat_title or ""}) |
@@ -327,6 +331,11 @@ def string_key_base(self) -> str: |
327 | 331 | def get_subject_line(self, loc_context: LocalizationContext) -> str: |
328 | 332 | return self._localize(loc_context, ".subject") |
329 | 333 |
|
| 334 | + def get_preview_line(self, loc_context: LocalizationContext) -> str | None: |
| 335 | + if len(self.entries) != 1: |
| 336 | + return None |
| 337 | + return self.entries[0].latest_message_text |
| 338 | + |
330 | 339 | def get_body_blocks(self, loc_context: LocalizationContext) -> list[EmailBlock]: |
331 | 340 | builder = self._body_builder(loc_context) |
332 | 341 | for entry in self.entries: |
@@ -391,6 +400,9 @@ def string_key_base(self) -> str: |
391 | 400 | def get_subject_line(self, loc_context: LocalizationContext) -> str: |
392 | 401 | return self._localize(loc_context, ".subject", {"author": self.author.name, "title": self.title}) |
393 | 402 |
|
| 403 | + def get_preview_line(self, loc_context: LocalizationContext) -> str | None: |
| 404 | + return markdown_to_plaintext(self.markdown_text) |
| 405 | + |
394 | 406 | def get_body_blocks(self, loc_context: LocalizationContext) -> list[EmailBlock]: |
395 | 407 | builder = self._body_builder(loc_context) |
396 | 408 | builder.para( |
@@ -451,6 +463,9 @@ def get_subject_line(self, loc_context: LocalizationContext) -> str: |
451 | 463 | loc_context, ".subject", {"author": self.author.name, "discussion_title": self.discussion_title} |
452 | 464 | ) |
453 | 465 |
|
| 466 | + def get_preview_line(self, loc_context: LocalizationContext) -> str | None: |
| 467 | + return markdown_to_plaintext(self.markdown_text) |
| 468 | + |
454 | 469 | def get_body_blocks(self, loc_context: LocalizationContext) -> list[EmailBlock]: |
455 | 470 | builder = self._body_builder(loc_context) |
456 | 471 | builder.para( |
@@ -503,9 +518,6 @@ class DonationReceivedEmail(EmailBase): |
503 | 518 | def string_key_base(self) -> str: |
504 | 519 | return "donation_received" |
505 | 520 |
|
506 | | - def get_preview_line(self, loc_context: LocalizationContext) -> str: |
507 | | - return self._localize(loc_context, ".thanks_amount", {"amount": self.amount}) |
508 | | - |
509 | 521 | def get_body_blocks(self, loc_context: LocalizationContext) -> list[EmailBlock]: |
510 | 522 | builder = self._body_builder(loc_context, standard_closing=False) |
511 | 523 | builder.para(".thanks_amount", {"amount": self.amount}) |
@@ -680,6 +692,9 @@ def get_subject_line(self, loc_context: LocalizationContext) -> str: |
680 | 692 | loc_context, ".subject", {"user": self.inviting_user.name, "title": self.event_info.title} |
681 | 693 | ) |
682 | 694 |
|
| 695 | + def get_preview_line(self, loc_context: LocalizationContext) -> str | None: |
| 696 | + return markdown_to_plaintext(self.event_info.description_markdown) |
| 697 | + |
683 | 698 | def get_body_blocks(self, loc_context: LocalizationContext) -> list[EmailBlock]: |
684 | 699 | builder = self._body_builder(loc_context) |
685 | 700 | if self.community_name: |
@@ -882,6 +897,9 @@ def string_key_base(self) -> str: |
882 | 897 | def get_subject_line(self, loc_context: LocalizationContext) -> str: |
883 | 898 | return self._localize(loc_context, ".subject", {"author": self.author.name, "title": self.event_info.title}) |
884 | 899 |
|
| 900 | + def get_preview_line(self, loc_context: LocalizationContext) -> str | None: |
| 901 | + return markdown_to_plaintext(self.comment_markdown) |
| 902 | + |
885 | 903 | def get_body_blocks(self, loc_context: LocalizationContext) -> list[EmailBlock]: |
886 | 904 | builder = self._body_builder(loc_context) |
887 | 905 | builder.para(".body", {"author": self.author.name, "title": self.event_info.title}) |
@@ -1036,6 +1054,9 @@ def string_key_base(self) -> str: |
1036 | 1054 | def get_subject_line(self, loc_context: LocalizationContext) -> str: |
1037 | 1055 | return self._localize(loc_context, ".subject", {"name": self.from_user.name}) |
1038 | 1056 |
|
| 1057 | + def get_preview_line(self, loc_context: LocalizationContext) -> str | None: |
| 1058 | + return self.text |
| 1059 | + |
1039 | 1060 | def get_body_blocks(self, loc_context: LocalizationContext) -> list[EmailBlock]: |
1040 | 1061 | builder = self._body_builder(loc_context) |
1041 | 1062 | builder.para(".body", {"name": self.from_user.name}) |
@@ -1072,9 +1093,6 @@ def string_key_base(self) -> str: |
1072 | 1093 | def get_subject_line(self, loc_context: LocalizationContext) -> str: |
1073 | 1094 | return self._localize(loc_context, ".subject", {"name": self.befriender.name}) |
1074 | 1095 |
|
1075 | | - def get_preview_line(self, loc_context: LocalizationContext) -> str: |
1076 | | - return self._localize(loc_context, ".body", {"name": self.befriender.name}) |
1077 | | - |
1078 | 1096 | def get_body_blocks(self, loc_context: LocalizationContext) -> list[EmailBlock]: |
1079 | 1097 | builder = self._body_builder(loc_context) |
1080 | 1098 | builder.para(".body", {"name": self.befriender.name}) |
@@ -1111,9 +1129,6 @@ def string_key_base(self) -> str: |
1111 | 1129 | def get_subject_line(self, loc_context: LocalizationContext) -> str: |
1112 | 1130 | return self._localize(loc_context, ".subject", {"name": self.new_friend.name}) |
1113 | 1131 |
|
1114 | | - def get_preview_line(self, loc_context: LocalizationContext) -> str: |
1115 | | - return self._localize(loc_context, ".body", {"name": self.new_friend.name}) |
1116 | | - |
1117 | 1132 | def get_body_blocks(self, loc_context: LocalizationContext) -> list[EmailBlock]: |
1118 | 1133 | builder = self._body_builder(loc_context) |
1119 | 1134 | builder.para(".body", {"name": self.new_friend.name}) |
@@ -1183,6 +1198,9 @@ def string_key_base(self) -> str: |
1183 | 1198 | def get_subject_line(self, loc_context: LocalizationContext) -> str: |
1184 | 1199 | return self._localize(loc_context, ".subject", {"surfer_name": self.surfer.name}) |
1185 | 1200 |
|
| 1201 | + def get_preview_line(self, loc_context: LocalizationContext) -> str | None: |
| 1202 | + return self.text |
| 1203 | + |
1186 | 1204 | def get_body_blocks(self, loc_context: LocalizationContext) -> list[EmailBlock]: |
1187 | 1205 | builder = self._body_builder(loc_context) |
1188 | 1206 | builder.para(".body", {"surfer_name": self.surfer.name}) |
@@ -1301,6 +1319,9 @@ def string_key_base(self) -> str: |
1301 | 1319 | def get_subject_line(self, loc_context: LocalizationContext) -> str: |
1302 | 1320 | return self._localize(loc_context, ".subject", {"other_name": self.other_user.name}) |
1303 | 1321 |
|
| 1322 | + def get_preview_line(self, loc_context: LocalizationContext) -> str | None: |
| 1323 | + return self.text |
| 1324 | + |
1304 | 1325 | def get_body_blocks(self, loc_context: LocalizationContext) -> list[EmailBlock]: |
1305 | 1326 | builder = self._body_builder(loc_context) |
1306 | 1327 | builder.para(".body", {"other_name": self.other_user.name}) |
@@ -1519,6 +1540,9 @@ def string_role_subkey(self) -> str: |
1519 | 1540 | def get_subject_line(self, loc_context: LocalizationContext) -> str: |
1520 | 1541 | return self._localize(loc_context, ".subject", {"name": self.from_user.name}) |
1521 | 1542 |
|
| 1543 | + def get_preview_line(self, loc_context: LocalizationContext) -> str | None: |
| 1544 | + return self.text |
| 1545 | + |
1522 | 1546 | def get_body_blocks(self, loc_context: LocalizationContext) -> list[EmailBlock]: |
1523 | 1547 | builder = self._body_builder(loc_context) |
1524 | 1548 | builder.para(f".{self.string_role_subkey}.body", {"name": self.from_user.name}) |
@@ -2045,6 +2069,9 @@ def get_subject_line(self, loc_context: LocalizationContext) -> str: |
2045 | 2069 | loc_context, ".subject", {"author": self.author.name, "parent_context": self.parent_context} |
2046 | 2070 | ) |
2047 | 2071 |
|
| 2072 | + def get_preview_line(self, loc_context: LocalizationContext) -> str | None: |
| 2073 | + return markdown_to_plaintext(self.markdown_text) |
| 2074 | + |
2048 | 2075 | def get_body_blocks(self, loc_context: LocalizationContext) -> list[EmailBlock]: |
2049 | 2076 | builder = self._body_builder(loc_context) |
2050 | 2077 | builder.para(".body", {"author": self.author.name, "parent_context": self.parent_context}) |
|
0 commit comments