Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Update the notification email subject when invited to a space. #10426

Merged
merged 3 commits into from
Jul 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/10426.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Email notifications now state whether an invitation is to a room or a space.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure this is really "feature"-worthy?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd say it is since it's a user-facing change (that's not a bugfix)

4 changes: 3 additions & 1 deletion synapse/config/emailconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,13 @@
"messages_from_person_and_others": "[%(app)s] You have messages on %(app)s from %(person)s and others...",
"invite_from_person": "[%(app)s] %(person)s has invited you to chat on %(app)s...",
"invite_from_person_to_room": "[%(app)s] %(person)s has invited you to join the %(room)s room on %(app)s...",
"invite_from_person_to_space": "[%(app)s] %(person)s has invited you to join the %(space)s space on %(app)s...",
"password_reset": "[%(server_name)s] Password reset",
"email_validation": "[%(server_name)s] Validate your email",
}


@attr.s
@attr.s(slots=True, frozen=True)
class EmailSubjectConfig:
message_from_person_in_room = attr.ib(type=str)
message_from_person = attr.ib(type=str)
Expand All @@ -54,6 +55,7 @@ class EmailSubjectConfig:
messages_from_person_and_others = attr.ib(type=str)
invite_from_person = attr.ib(type=str)
invite_from_person_to_room = attr.ib(type=str)
invite_from_person_to_space = attr.ib(type=str)
password_reset = attr.ib(type=str)
email_validation = attr.ib(type=str)

Expand Down
18 changes: 17 additions & 1 deletion synapse/push/mailer.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import bleach
import jinja2

from synapse.api.constants import EventTypes, Membership
from synapse.api.constants import EventTypes, Membership, RoomTypes
from synapse.api.errors import StoreError
from synapse.config.emailconfig import EmailSubjectConfig
from synapse.events import EventBase
Expand Down Expand Up @@ -600,6 +600,22 @@ async def _make_summary_text_single_room(
"app": self.app_name,
}

# If the room is a space, it gets a slightly different topic.
create_event_id = room_state_ids.get(("m.room.create", ""))
if create_event_id:
create_event = await self.store.get_event(
create_event_id, allow_none=True
)
if (
create_event
and create_event.content.get("room_type") == RoomTypes.SPACE
):
return self.email_subjects.invite_from_person_to_space % {
"person": inviter_name,
"space": room_name,
"app": self.app_name,
}

return self.email_subjects.invite_from_person_to_room % {
"person": inviter_name,
"room": room_name,
Expand Down