Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 
 
 

137 linhas
4.7 KiB

  1. # Copyright 2021 The Matrix.org Foundation C.I.C.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. from typing import List, Optional
  15. from typing_extensions import TypedDict
  16. class EmailReason(TypedDict, total=False):
  17. """
  18. Information on the event that triggered the email to be sent
  19. room_id: the ID of the room the event was sent in
  20. now: timestamp in ms when the email is being sent out
  21. room_name: a human-readable name for the room the event was sent in
  22. received_at: the time in milliseconds at which the event was received
  23. delay_before_mail_ms: the amount of time in milliseconds Synapse always waits
  24. before ever emailing about a notification (to give the user a chance to respond
  25. to other push or notice the window)
  26. last_sent_ts: the time in milliseconds at which a notification was last sent
  27. for an event in this room
  28. throttle_ms: the minimum amount of time in milliseconds between two
  29. notifications can be sent for this room
  30. """
  31. room_id: str
  32. now: int
  33. room_name: Optional[str]
  34. received_at: int
  35. delay_before_mail_ms: int
  36. last_sent_ts: int
  37. throttle_ms: int
  38. class MessageVars(TypedDict, total=False):
  39. """
  40. Details about a specific message to include in a notification
  41. event_type: the type of the event
  42. is_historical: a boolean, which is `False` if the message is the one
  43. that triggered the notification, `True` otherwise
  44. id: the ID of the event
  45. ts: the time in milliseconds at which the event was sent
  46. sender_name: the display name for the event's sender
  47. sender_avatar_url: the avatar URL (as a `mxc://` URL) for the event's
  48. sender
  49. sender_hash: a hash of the user ID of the sender
  50. msgtype: the type of the message
  51. body_text_html: html representation of the message
  52. body_text_plain: plaintext representation of the message
  53. image_url: mxc url of an image, when "msgtype" is "m.image"
  54. """
  55. event_type: str
  56. is_historical: bool
  57. id: str
  58. ts: int
  59. sender_name: str
  60. sender_avatar_url: Optional[str]
  61. sender_hash: int
  62. msgtype: Optional[str]
  63. body_text_html: str
  64. body_text_plain: str
  65. image_url: str
  66. class NotifVars(TypedDict):
  67. """
  68. Details about an event we are about to include in a notification
  69. link: a `matrix.to` link to the event
  70. ts: the time in milliseconds at which the event was received
  71. messages: a list of messages containing one message before the event, the
  72. message in the event, and one message after the event.
  73. """
  74. link: str
  75. ts: Optional[int]
  76. messages: List[MessageVars]
  77. class RoomVars(TypedDict):
  78. """
  79. Represents a room containing events to include in the email.
  80. title: a human-readable name for the room
  81. hash: a hash of the ID of the room
  82. invite: a boolean, which is `True` if the room is an invite the user hasn't
  83. accepted yet, `False` otherwise
  84. notifs: a list of events, or an empty list if `invite` is `True`.
  85. link: a `matrix.to` link to the room
  86. avator_url: url to the room's avator
  87. """
  88. title: Optional[str]
  89. hash: int
  90. invite: bool
  91. notifs: List[NotifVars]
  92. link: str
  93. avatar_url: Optional[str]
  94. class TemplateVars(TypedDict, total=False):
  95. """
  96. Generic structure for passing to the email sender, can hold all the fields used in email templates.
  97. app_name: name of the app/service this homeserver is associated with
  98. server_name: name of our own homeserver
  99. link: a link to include into the email to be sent
  100. user_display_name: the display name for the user receiving the notification
  101. unsubscribe_link: the link users can click to unsubscribe from email notifications
  102. summary_text: a summary of the notification(s). The text used can be customised
  103. by configuring the various settings in the `email.subjects` section of the
  104. configuration file.
  105. rooms: a list of rooms containing events to include in the email
  106. reason: information on the event that triggered the email to be sent
  107. """
  108. app_name: str
  109. server_name: str
  110. link: str
  111. user_display_name: str
  112. unsubscribe_link: str
  113. summary_text: str
  114. rooms: List[RoomVars]
  115. reason: EmailReason