Add server notices support
As per [MSC1452](https://github.com/matrix-org/matrix-doc/issues/1452) Fixes https://github.com/matrix-org/matrix-doc/issues/1254 Although MSC1452 focuses on just the warnings part of the server notices, the base for notices has not been established in the spec. This commit adds the needed support to be able to handle notices. No intentional divergences from the proposal are included in this changeset. There are a few additions which are used in practice although not defined in the proposal, such as who is responsible for aesthetics, sending notices, and other misc rules.
This commit is contained in:
parent
5c268ef21f
commit
5eea4a477f
9 changed files with 154 additions and 5 deletions
|
@ -110,12 +110,13 @@ class MatrixSections(Sections):
|
|||
# Special function: Returning a dict will specify multiple sections where
|
||||
# the key is the section name and the value is the value of the section
|
||||
def render_group_events(self):
|
||||
# map all event schemata to the form $EVENTTYPE_event with s/./_/g
|
||||
# e.g. m_room_topic_event
|
||||
# map all event schemata to the form $EVENTTYPE_event with s/.#/_/g
|
||||
# e.g. m_room_topic_event or m_room_message_m_text_event
|
||||
schemas = self.units.get("event_schemas")
|
||||
renders = {}
|
||||
for event_type in schemas:
|
||||
renders[event_type.replace(".", "_") + "_event"] = self._render_events(
|
||||
underscored_event_type = event_type.replace(".", "_").replace("#", "_")
|
||||
renders[underscored_event_type + "_event"] = self._render_events(
|
||||
lambda x: x == event_type, sorted
|
||||
)
|
||||
return renders
|
||||
|
@ -141,9 +142,15 @@ class MatrixSections(Sections):
|
|||
"m.room.message#m.notice", "m.room.message#m.image",
|
||||
"m.room.message#m.file"
|
||||
]
|
||||
excluded_types = [
|
||||
# We exclude server notices from here because we handle them in a
|
||||
# dedicated module. We do not want to confuse developers this early
|
||||
# in the spec.
|
||||
"m.room.message#m.server_notice",
|
||||
]
|
||||
other_msgtypes = [
|
||||
k for k in schemas.keys() if k.startswith("m.room.message#") and
|
||||
k not in msgtype_order
|
||||
k not in msgtype_order and k not in excluded_types
|
||||
]
|
||||
for event_name in (msgtype_order + other_msgtypes):
|
||||
if not event_name.startswith("m.room.message#m."):
|
||||
|
|
|
@ -1,7 +1,14 @@
|
|||
{% import 'tables.tmpl' as tables -%}
|
||||
|
||||
{% if (event.type_with_msgtype) %}
|
||||
``{{event.type_with_msgtype}}``
|
||||
{{(4 + event.type_with_msgtype | length) * title_kind}}
|
||||
{% endif -%}
|
||||
|
||||
{% if (not event.type_with_msgtype) %}
|
||||
``{{event.type}}``
|
||||
{{(4 + event.type | length) * title_kind}}
|
||||
{% endif -%}
|
||||
|
||||
{% if (event.typeof | length) %}
|
||||
*{{event.typeof}}*
|
||||
|
|
|
@ -846,6 +846,7 @@ class MatrixUnits(Units):
|
|||
"title": None,
|
||||
"desc": None,
|
||||
"msgtype": None,
|
||||
"type_with_msgtype": None, # for the template's sake
|
||||
"content_fields": [
|
||||
# <TypeTable>
|
||||
]
|
||||
|
@ -884,6 +885,7 @@ class MatrixUnits(Units):
|
|||
)
|
||||
if msgtype:
|
||||
schema["msgtype"] = msgtype[0] # enum prop
|
||||
schema["type_with_msgtype"] = schema["type"] + " (" + msgtype[0] + ")"
|
||||
|
||||
# link to msgtypes for m.room.message
|
||||
if schema["type"] == "m.room.message" and not msgtype:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue