diff --git a/event-schemas/examples/v1/m.room.message#m.location b/event-schemas/examples/v1/m.room.message#m.location index b192b832c..54198acbf 100644 --- a/event-schemas/examples/v1/m.room.message#m.location +++ b/event-schemas/examples/v1/m.room.message#m.location @@ -17,4 +17,4 @@ "room_id": "!jEsUZKDJdhlrceRyVU:localhost", "type": "m.room.message", "user_id": "@example:localhost" -} \ No newline at end of file +} diff --git a/event-schemas/schema/v1/core b/event-schemas/schema/v1/core index e7a248037..ed374a698 100644 --- a/event-schemas/schema/v1/core +++ b/event-schemas/schema/v1/core @@ -58,6 +58,31 @@ } }, "required": ["state_key"] + }, + "msgtype_infos": { + "image_info": { + "type": "object", + "title": "ImageInfo", + "description": "Metadata about an image.", + "properties": { + "size": { + "type": "integer", + "description": "Size of the image in bytes." + }, + "w": { + "type": "integer", + "description": "The width of the image in pixels." + }, + "h": { + "type": "integer", + "description": "The height of the image in pixels." + }, + "mimetype": { + "type": "string", + "description": "The mimetype of the image, e.g. ``image/jpeg``." + } + } + } } } } diff --git a/event-schemas/schema/v1/m.room.message#m.file b/event-schemas/schema/v1/m.room.message#m.file index c07f17b3e..cf6d65524 100644 --- a/event-schemas/schema/v1/m.room.message#m.file +++ b/event-schemas/schema/v1/m.room.message#m.file @@ -2,7 +2,7 @@ "$schema": "http://json-schema.org/draft-04/schema#", "type": "object", "title": "FileMessage", - "description": "TODO.", + "description": "This message represents a generic file.", "allOf": [{ "$ref": "core#/definitions/room_event" }], @@ -49,24 +49,9 @@ "type": "object", "title": "ImageInfo", "description": "Metadata about the image referred to in ``thumbnail_url``.", - "properties": { - "size": { - "type": "integer", - "description": "Size of the image in bytes." - }, - "w": { - "type": "integer", - "description": "The width of the image in pixels." - }, - "h": { - "type": "integer", - "description": "The height of the image in pixels." - }, - "mimetype": { - "type": "string", - "description": "The mimetype of the image, e.g. ``image/jpeg``." - } - } + "allOf": [{ + "$ref": "core#/definitions/msgtype_infos/image_info" + }] } }, "required": ["msgtype", "body", "url", "filename"] diff --git a/event-schemas/schema/v1/m.room.message#m.image b/event-schemas/schema/v1/m.room.message#m.image index 295524523..8c010b0d7 100644 --- a/event-schemas/schema/v1/m.room.message#m.image +++ b/event-schemas/schema/v1/m.room.message#m.image @@ -30,24 +30,9 @@ "type": "object", "title": "ImageInfo", "description": "Metadata about the image referred to in ``thumbnail_url``.", - "properties": { - "size": { - "type": "integer", - "description": "Size of the image in bytes." - }, - "w": { - "type": "integer", - "description": "The width of the image in pixels." - }, - "h": { - "type": "integer", - "description": "The height of the image in pixels." - }, - "mimetype": { - "type": "string", - "description": "The mimetype of the image, e.g. ``image/jpeg``." - } - } + "allOf": [{ + "$ref": "core#/definitions/msgtype_infos/image_info" + }] }, "info": { "type": "object", diff --git a/event-schemas/schema/v1/m.room.message#m.location b/event-schemas/schema/v1/m.room.message#m.location index d1b951572..cd15f31e4 100644 --- a/event-schemas/schema/v1/m.room.message#m.location +++ b/event-schemas/schema/v1/m.room.message#m.location @@ -28,7 +28,10 @@ }, "thumbnail_info": { "type": "object", - "title": "ImageInfo" + "title": "ImageInfo", + "allOf": [{ + "$ref": "core#/definitions/msgtype_infos/image_info" + }] } }, "required": ["msgtype", "body", "geo_uri"] diff --git a/event-schemas/schema/v1/m.room.message#m.video b/event-schemas/schema/v1/m.room.message#m.video index 960126b8c..222665060 100644 --- a/event-schemas/schema/v1/m.room.message#m.video +++ b/event-schemas/schema/v1/m.room.message#m.video @@ -53,7 +53,10 @@ }, "thumbnail_info": { "type": "object", - "title": "ImageInfo" + "title": "ImageInfo", + "allOf": [{ + "$ref": "core#/definitions/msgtype_infos/image_info" + }] } } } diff --git a/templating/matrix_templates/sections.py b/templating/matrix_templates/sections.py index e42bdf7bc..5e2103718 100644 --- a/templating/matrix_templates/sections.py +++ b/templating/matrix_templates/sections.py @@ -20,7 +20,22 @@ class MatrixSections(Sections): schemas = self.units.get("event_schemas") sections = [] for event_name in sorted(schemas): - if not event_name.startswith("m.room"): + if (not event_name.startswith("m.room") or + event_name.startswith("m.room.message#m.")): + continue + sections.append(template.render( + example=examples[event_name], + event=schemas[event_name] + )) + return "\n\n".join(sections) + + def render_msgtype_events(self): + template = self.env.get_template("msgtypes.tmpl") + examples = self.units.get("event_examples") + schemas = self.units.get("event_schemas") + sections = [] + for event_name in sorted(schemas): + if not event_name.startswith("m.room.message#m."): continue sections.append(template.render( example=examples[event_name], diff --git a/templating/matrix_templates/templates/msgtypes.tmpl b/templating/matrix_templates/templates/msgtypes.tmpl new file mode 100644 index 000000000..633615a72 --- /dev/null +++ b/templating/matrix_templates/templates/msgtypes.tmpl @@ -0,0 +1,23 @@ +``{{event.msgtype}}`` +{{(4 + event.msgtype | length) * '~'}} +{{event.desc | wrap(80)}} +{% for table in event.content_fields -%} +{{"``"+table.title+"``" if table.title else "" }} + +================== ================= =========================================== + {{table.title or "Content"}} Key Type Description +================== ================= =========================================== +{% for row in table.rows -%} +{# -#} +{# Row type needs to prepend spaces to line up with the type column (19 ch) -#} +{# Desc needs to prepend the required text (maybe) and prepend spaces too -#} +{# It also needs to then wrap inside the desc col (43 ch width) -#} +{# -#} +{{row.key}}{{row.type|indent(19-row.key|length)}}{{row.desc|wrap(43,row.req_str | indent(18 - (row.type|length))) |indent_block(37)}} +{% endfor -%} +================== ================= =========================================== + +{% endfor %} +Example:: + + {{example | jsonify(4, 4)}} diff --git a/templating/matrix_templates/units.py b/templating/matrix_templates/units.py index 28fc3f9b8..109223ded 100644 --- a/templating/matrix_templates/units.py +++ b/templating/matrix_templates/units.py @@ -14,6 +14,8 @@ class MatrixUnits(Units): with open(path, "r") as f: core_json = json.loads(f.read()) for event_type in core_json["definitions"]: + if "event" not in event_type: + continue # filter ImageInfo and co event_info = core_json["definitions"][event_type] table = { "title": event_info["title"], @@ -68,7 +70,19 @@ class MatrixUnits(Units): } tables = [fields] - props = obj["properties"] + props = obj.get("properties") + parents = obj.get("allOf") + if not props and not parents: + raise Exception( + "Object %s has no properties or parents." % obj + ) + if not props: # parents only + return [{ + "title": obj["title"], + "parent": parents[0]["$ref"], + "no-table": True + }] + for key_name in sorted(props): value_type = None required = key_name in required_keys @@ -87,7 +101,9 @@ class MatrixUnits(Units): enforce_title=True ) value_type = "{%s}" % nested_object[0]["title"] - tables += nested_object + + if not nested_object[0].get("no-table"): + tables += nested_object elif props[key_name]["type"] == "array": # if the items of the array are objects then recurse if props[key_name]["items"]["type"] == "object": @@ -133,6 +149,7 @@ class MatrixUnits(Units): "type": None, "title": None, "desc": None, + "msgtype": None, "content_fields": [ # { # title: " key" @@ -168,6 +185,13 @@ class MatrixUnits(Units): Units.prop(json_schema, "properties/content") ) + # grab msgtype if it is the right kind of event + msgtype = Units.prop( + json_schema, "properties/content/properties/msgtype/enum" + ) + if msgtype: + schema["msgtype"] = msgtype[0] # enum prop + # Assign state key info if schema["typeof"] == "State Event": skey_desc = Units.prop(