Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial room_type work, MSC3288 implementation #375

Merged
merged 12 commits into from
Sep 3, 2021
1 change: 1 addition & 0 deletions changelog.d/375.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Experimental support for [MSC3288](https://github.com/matrix-org/matrix-doc/pull/3288), receiving `room_type` for 3pid invites over the `/store-invite` API and using it in Jinja templates for Space invites.
1 change: 1 addition & 0 deletions matrix_is_test/launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
[email]
email.tlsmode = 0
email.invite.subject = %(sender_display_name)s has invited you to chat
email.invite.subject_space = %(sender_display_name)s has invited you to a space
email.smtphost = localhost
email.from = Sydent Validation <noreply@localhost>
email.smtpport = 9925
Expand Down
4 changes: 2 additions & 2 deletions res/matrix-org/invite_template.eml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Matrix client from https://matrix.org/docs/projects/try-matrix-now.html or use
the single-click link below to join via Element (requires Chrome, Firefox,
Safari, iOS or Android)

%(web_client_location)s/#/room/%(room_id_forurl)s?email=%(to_forurl)s&signurl=https%%3A%%2F%%2Fmatrix.org%%2F_matrix%%2Fidentity%%2Fapi%%2Fv1%%2Fsign-ed25519%%3Ftoken%%3D%(token)s%%26private_key%%3D%(ephemeral_private_key)s&room_name=%(room_name_forurl)s&room_avatar_url=%(room_avatar_url_forurl)s&inviter_name=%(sender_display_name_forurl)s&guest_access_token=%(guest_access_token_forurl)s&guest_user_id=%(guest_user_id_forurl)s
%(web_client_location)s/#/room/%(room_id_forurl)s?email=%(to_forurl)s&signurl=https%%3A%%2F%%2Fmatrix.org%%2F_matrix%%2Fidentity%%2Fapi%%2Fv1%%2Fsign-ed25519%%3Ftoken%%3D%(token)s%%26private_key%%3D%(ephemeral_private_key)s&room_name=%(room_name_forurl)s&room_avatar_url=%(room_avatar_url_forurl)s&inviter_name=%(sender_display_name_forurl)s&guest_access_token=%(guest_access_token_forurl)s&guest_user_id=%(guest_user_id_forurl)s&room_type=%(room_type_forurl)s


About Matrix:
Expand Down Expand Up @@ -113,7 +113,7 @@ or iOS or Android on mobile.)</p>

<p>
<a
href="%(web_client_location)s/#/room/%(room_id_forurl)s?email=%(to_forurl)s&signurl=https%%3A%%2F%%2Fmatrix.org%%2F_matrix%%2Fidentity%%2Fapi%%2Fv1%%2Fsign-ed25519%%3Ftoken%%3D%(token)s%%26private_key%%3D%(ephemeral_private_key)s&room_name=%(room_name_forurl)s&room_avatar_url=%(room_avatar_url_forurl)s&inviter_name=%(sender_display_name_forurl)s&guest_access_token=%(guest_access_token_forurl)s&guest_user_id=%(guest_user_id_forurl)s">Join the conversation.</a>
href="%(web_client_location)s/#/room/%(room_id_forurl)s?email=%(to_forurl)s&signurl=https%%3A%%2F%%2Fmatrix.org%%2F_matrix%%2Fidentity%%2Fapi%%2Fv1%%2Fsign-ed25519%%3Ftoken%%3D%(token)s%%26private_key%%3D%(ephemeral_private_key)s&room_name=%(room_name_forurl)s&room_avatar_url=%(room_avatar_url_forurl)s&inviter_name=%(sender_display_name_forurl)s&guest_access_token=%(guest_access_token_forurl)s&guest_user_id=%(guest_user_id_forurl)s&room_type=%(room_type_forurl)s">Join the conversation.</a>
</p>

<br>
Expand Down
8 changes: 4 additions & 4 deletions res/matrix-org/invite_template.eml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ Content-Disposition: inline

Hi,

{{ sender_display_name|safe }} {{ bracketed_verified_sender|safe }}has invited you into a room
{{ sender_display_name|safe }} {{ bracketed_verified_sender|safe }}has invited you into a {% if room_type == "m.space" %}space{% else %}room{% endif %}
{{ bracketed_room_name|safe }}on Matrix. To join the conversation, either pick a
Matrix client from https://matrix.org/docs/projects/try-matrix-now.html or use
the single-click link below to join via Element (requires Chrome, Firefox,
Safari, iOS or Android)


{{ web_client_location }}/#/room/{{ room_id|urlencode }}?email={{ to|urlencode }}&signurl=https%3A%2F%2Fmatrix.org%2F_matrix%2Fidentity%2Fapi%2Fv1%2Fsign-ed25519%3Ftoken%3D{{ token|urlencode }}%26private_key%3D{{ ephemeral_private_key|urlencode }}&room_name={{ room_name|urlencode }}&room_avatar_url={{ room_avatar_url|urlencode }}&inviter_name={{ sender_display_name|urlencode }}&guest_access_token={{ guest_access_token|urlencode }}&guest_user_id={{ guest_user_id|urlencode }}
{{ web_client_location }}/#/room/{{ room_id|urlencode }}?email={{ to|urlencode }}&signurl=https%3A%2F%2Fmatrix.org%2F_matrix%2Fidentity%2Fapi%2Fv1%2Fsign-ed25519%3Ftoken%3D{{ token|urlencode }}%26private_key%3D{{ ephemeral_private_key|urlencode }}&room_name={{ room_name|urlencode }}&room_avatar_url={{ room_avatar_url|urlencode }}&inviter_name={{ sender_display_name|urlencode }}&guest_access_token={{ guest_access_token|urlencode }}&guest_user_id={{ guest_user_id|urlencode }}&room_type={{ room_type|urlencode }}


About Matrix:
Expand Down Expand Up @@ -105,7 +105,7 @@ pre, code {

<p>Hi,</p>

<p>{{ sender_display_name }} <span class="low-contrast">{{ bracketed_verified_sender }}</span> has invited you into a room {{ bracketed_room_name }} on
<p>{{ sender_display_name }} <span class="low-contrast">{{ bracketed_verified_sender }}</span> has invited you into a {% if room_type == "m.space" %}space{% else %}room{% endif %} {{ bracketed_room_name }} on
Matrix. To join the conversation, either <a href="https://matrix.org/docs/projects/try-matrix-now.html">pick a Matrix client</a> or use the single-click
link below to join via Element (requires
<a href="https://www.google.com/chrome">Chrome</a>,
Expand All @@ -116,7 +116,7 @@ or iOS or Android on mobile.)</p>

<p>
<a
href="{{ web_client_location }}/#/room/{{ room_id|urlencode }}?email={{ to|urlencode }}&signurl=https%3A%2F%2Fmatrix.org%2F_matrix%2Fidentity%2Fapi%2Fv1%2Fsign-ed25519%3Ftoken%3D{{ token|urlencode }}%26private_key%3D{{ ephemeral_private_key|urlencode }}&room_name={{ room_name|urlencode }}&room_avatar_url={{ room_avatar_url|urlencode }}&inviter_name={{ sender_display_name|urlencode }}&guest_access_token={{ guest_access_token|urlencode }}&guest_user_id={{ guest_user_id|urlencode }}">Join the conversation.</a>
href="{{ web_client_location }}/#/room/{{ room_id|urlencode }}?email={{ to|urlencode }}&signurl=https%3A%2F%2Fmatrix.org%2F_matrix%2Fidentity%2Fapi%2Fv1%2Fsign-ed25519%3Ftoken%3D{{ token|urlencode }}%26private_key%3D{{ ephemeral_private_key|urlencode }}&room_name={{ room_name|urlencode }}&room_avatar_url={{ room_avatar_url|urlencode }}&inviter_name={{ sender_display_name|urlencode }}&guest_access_token={{ guest_access_token|urlencode }}&guest_user_id={{ guest_user_id|urlencode }}&room_type={{ room_type|urlencode }}">Join the conversation.</a>
</p>

<br>
Expand Down
4 changes: 2 additions & 2 deletions res/vector-im/invite_template.eml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Hi,
%(bracketed_room_name)son Element. To join the conversation please follow the
link below.

%(web_client_location)s/#/room/%(room_id_forurl)s?email=%(to_forurl)s&signurl=https%%3A%%2F%%2Fvector.im%%2F_matrix%%2Fidentity%%2Fapi%%2Fv1%%2Fsign-ed25519%%3Ftoken%%3D%(token)s%%26private_key%%3D%(ephemeral_private_key)s&room_name=%(room_name_forurl)s&room_avatar_url=%(room_avatar_url_forurl)s&inviter_name=%(sender_display_name_forurl)s&guest_access_token=%(guest_access_token_forurl)s&guest_user_id=%(guest_user_id_forurl)s
%(web_client_location)s/#/room/%(room_id_forurl)s?email=%(to_forurl)s&signurl=https%%3A%%2F%%2Fvector.im%%2F_matrix%%2Fidentity%%2Fapi%%2Fv1%%2Fsign-ed25519%%3Ftoken%%3D%(token)s%%26private_key%%3D%(ephemeral_private_key)s&room_name=%(room_name_forurl)s&room_avatar_url=%(room_avatar_url_forurl)s&inviter_name=%(sender_display_name_forurl)s&guest_access_token=%(guest_access_token_forurl)s&guest_user_id=%(guest_user_id_forurl)s&room_type=%(room_type_forurl)s

Element is an open source collaboration app built on the Matrix.org
open standard for interoperable communication: supporting group chat,
Expand Down Expand Up @@ -128,7 +128,7 @@ room %(bracketed_room_name_forhtml)s on Element.</p>

<p>
<a
href="%(web_client_location)s/#/room/%(room_id_forurl)s?email=%(to_forurl)s&signurl=https%%3A%%2F%%2Fvector.im%%2F_matrix%%2Fidentity%%2Fapi%%2Fv1%%2Fsign-ed25519%%3Ftoken%%3D%(token)s%%26private_key%%3D%(ephemeral_private_key)s&room_name=%(room_name_forurl)s&room_avatar_url=%(room_avatar_url_forurl)s&inviter_name=%(sender_display_name_forurl)s&guest_access_token=%(guest_access_token_forurl)s&guest_user_id=%(guest_user_id_forurl)s">Join the conversation.</a>
href="%(web_client_location)s/#/room/%(room_id_forurl)s?email=%(to_forurl)s&signurl=https%%3A%%2F%%2Fvector.im%%2F_matrix%%2Fidentity%%2Fapi%%2Fv1%%2Fsign-ed25519%%3Ftoken%%3D%(token)s%%26private_key%%3D%(ephemeral_private_key)s&room_name=%(room_name_forurl)s&room_avatar_url=%(room_avatar_url_forurl)s&inviter_name=%(sender_display_name_forurl)s&guest_access_token=%(guest_access_token_forurl)s&guest_user_id=%(guest_user_id_forurl)s&room_type=%(room_type_forurl)s">Join the conversation.</a>
</p>

<p>Element is an open source collaboration app built on the Matrix.org
Expand Down
8 changes: 4 additions & 4 deletions res/vector-im/invite_template.eml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ Content-Disposition: inline

Hi,

{{ sender_display_name|safe }} {{ bracketed_verified_sender|safe }}has invited you into a room
{{ sender_display_name|safe }} {{ bracketed_verified_sender|safe }}has invited you into a {% if room_type == "m.space" %}space{% else %}room{% endif %}
{{ bracketed_room_name|safe }}on Element. To join the conversation please follow the
link below.

{{ web_client_location }}/#/room/{{ room_id|urlencode }}?email={{ to|urlencode }}&signurl=https%3A%2F%2Fvector.im%2F_matrix%2Fidentity%2Fapi%2Fv1%2Fsign-ed25519%3Ftoken%3D{{ token|urlencode }}%26private_key%3D{{ ephemeral_private_key|urlencode }}&room_name={{ room_name|urlencode }}&room_avatar_url={{ room_avatar_url|urlencode }}&inviter_name={{ sender_display_name|urlencode }}&guest_access_token={{ guest_access_token|urlencode }}&guest_user_id={{ guest_user_id|urlencode }}
{{ web_client_location }}/#/room/{{ room_id|urlencode }}?email={{ to|urlencode }}&signurl=https%3A%2F%2Fvector.im%2F_matrix%2Fidentity%2Fapi%2Fv1%2Fsign-ed25519%3Ftoken%3D{{ token|urlencode }}%26private_key%3D{{ ephemeral_private_key|urlencode }}&room_name={{ room_name|urlencode }}&room_avatar_url={{ room_avatar_url|urlencode }}&inviter_name={{ sender_display_name|urlencode }}&guest_access_token={{ guest_access_token|urlencode }}&guest_user_id={{ guest_user_id|urlencode }}&room_type={{ room_type|urlencode }}

Element is an open source collaboration app built on the Matrix.org
open standard for interoperable communication: supporting group chat,
Expand Down Expand Up @@ -124,11 +124,11 @@ pre, code {
<p>Hi,</p>

<p>{{ sender_display_name }} <span class="low-contrast">{{ bracketed_verified_sender }}</span> has invited you into a
room {{ bracketed_room_name }} on Element.</p>
{% if room_type == "m.space" %}space{% else %}room{% endif %} {{ bracketed_room_name }} on Element.</p>

<p>
<a
href="{{ web_client_location }}/#/room/{{ room_id|urlencode }}?email={{ to|urlencode }}&signurl=https%3A%2F%2Fvector.im%2F_matrix%2Fidentity%2Fapi%2Fv1%2Fsign-ed25519%3Ftoken%3D{{ token|urlencode }}%26private_key%3D{{ ephemeral_private_key|urlencode }}&room_name={{ room_name|urlencode }}&room_avatar_url={{ room_avatar_url|urlencode }}&inviter_name={{ sender_display_name|urlencode }}&guest_access_token={{ guest_access_token|urlencode }}&guest_user_id={{ guest_user_id|urlencode }}">Join the conversation.</a>
href="{{ web_client_location }}/#/room/{{ room_id|urlencode }}?email={{ to|urlencode }}&signurl=https%3A%2F%2Fvector.im%2F_matrix%2Fidentity%2Fapi%2Fv1%2Fsign-ed25519%3Ftoken%3D{{ token|urlencode }}%26private_key%3D{{ ephemeral_private_key|urlencode }}&room_name={{ room_name|urlencode }}&room_avatar_url={{ room_avatar_url|urlencode }}&inviter_name={{ sender_display_name|urlencode }}&guest_access_token={{ guest_access_token|urlencode }}&guest_user_id={{ guest_user_id|urlencode }}&room_type={{ room_type|urlencode }}">Join the conversation.</a>
</p>

<p>Element is an open source collaboration app built on the Matrix.org
Expand Down
13 changes: 12 additions & 1 deletion sydent/http/servlets/store_invite_servlet.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,11 @@ def render_POST(self, request: Request) -> JsonDict:
for k in extra_substitutions:
substitutions.setdefault(k, "")

# MSC3288
substitutions["room_type"] = substitutions.pop(
"org.matrix.msc3288.room_type", ""
)
Comment on lines +128 to +131
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm guessing these lines will go away when we move out of unstable

Copy link
Member

Choose a reason for hiding this comment

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

Something like that. We'll probably have Synapse send both for a while and update Sydent to use just room_type? Or fallback to org.matrix.msc3288.room_type. 🤷


substitutions["bracketed_verified_sender"] = ""
if verified_sender:
substitutions["bracketed_verified_sender"] = "(%s) " % (verified_sender,)
Expand All @@ -140,7 +145,13 @@ def render_POST(self, request: Request) -> JsonDict:
)

subject_header = Header(
self.sydent.cfg.get("email", "email.invite.subject", raw=True)
self.sydent.cfg.get(
"email",
"email.invite.subject_space"
if substitutions["room_type"] == "m.space"
else "email.invite.subject",
raw=True,
)
% substitutions,
"utf8",
)
Expand Down
1 change: 1 addition & 0 deletions sydent/sydent.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@
"email.from": "Sydent Validation <noreply@{hostname}>",
"email.subject": "Your Validation Token",
"email.invite.subject": "%(sender_display_name)s has invited you to chat",
"email.invite.subject_space": "%(sender_display_name)s has invited you to a space",
"email.smtphost": "localhost",
"email.smtpport": "25",
"email.smtpusername": "",
Expand Down
6 changes: 4 additions & 2 deletions tests/test_jinja_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ def test_jinja_vector_invite(self):
"token": "a_token",
"ephemeral_private_key": "mystery_key",
"web_client_location": "https://app.element.io",
"room_type": "",
}

templateFile = self.sydent.get_branded_template(
Expand Down Expand Up @@ -90,7 +91,7 @@ def test_jinja_vector_invite(self):
+ urllib.parse.quote("mxc://example.org/s0meM3dia")
+ "&inviter_name="
+ urllib.parse.quote("<Bob Smith>")
+ "&guest_access_token=&guest_user_id="
+ "&guest_access_token=&guest_user_id=&room_type="
)
text = email_contents.splitlines()
link = text[19]
Expand All @@ -113,6 +114,7 @@ def test_jinja_matrix_invite(self):
"token": "a_token",
"ephemeral_private_key": "mystery_key",
"web_client_location": "https://matrix.org",
"room_type": "",
}

templateFile = self.sydent.get_branded_template(
Expand Down Expand Up @@ -152,7 +154,7 @@ def test_jinja_matrix_invite(self):
+ urllib.parse.quote("mxc://example.org/s0meM3dia")
+ "&inviter_name="
+ urllib.parse.quote("<Bob Smith>")
+ "&guest_access_token=&guest_user_id="
+ "&guest_access_token=&guest_user_id=&room_type="
)
text = email_contents.splitlines()
link = text[22]
Expand Down