{{/*

  This template is used to render the `m.room.message` events.

  It replaces the old {{msgtype_events}} template.

*/}}

{{ $compact := false }}

{{/*
  The old template starts with an explicit list of events, presumably
  to define the order in which they are rendered.
*/}}
{{ $msgtypes := (slice "m.room.message$m.text" "m.room.message$m.emote" "m.room.message$m.notice" "m.room.message$m.image" "m.room.message$m.file") }}

{{/*
  It excludes `m.room.message$m.server_notice` and `m.room.message$m.key.verification.request`
  since they are in their own modules.
*/}}
{{ $excluded := slice "m.room.message$m.server_notice" "m.room.message$m.key.verification.request" }}

{{/*
  It then adds any other events that start with `m.room.message`.
*/}}
{{ $events := index .Site.Data "event-schemas" "schema" }}
{{ $expected_prefix := "m.room.message$"}}
{{ range $object_name, $event_data := $events }}

    {{ $prefix := substr $object_name 0 (len $expected_prefix) }}
    {{ if and (eq $prefix $expected_prefix) (not (in $excluded $object_name)) (not (in $msgtypes $object_name))  }}
        {{ $msgtypes = $msgtypes | append $object_name }}
    {{ end }}

{{ end }}

{{ $site_data := .Site.Data }}

{{ range $msgtypes }}

    {{ $event_data := index $site_data "event-schemas" "schema" . }}
    {{ $path := delimit (slice "event-schemas/schema" .) "/" }}
    {{ $event_data = partial "json-schema/resolve-refs" (dict "schema" $event_data "path" $path) }}
    {{ $event_data := partial "json-schema/resolve-allof" $event_data }}

    {{ $event_name := index (split . "$") 1 }}
    {{ partial "events/render-event" (dict "event_name" $event_name "desired_example_name" . "event_data" $event_data)}}

{{ end }}
