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

Sort VoIP events semantically #1967

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Sort VoIP events semantically.
1 change: 1 addition & 0 deletions changelogs/internal/newsfragments/1967.clarification
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add `x-weight` property for sorting events rendered with the `event-group` shortcode.
Johennes marked this conversation as resolved.
Show resolved Hide resolved
1 change: 1 addition & 0 deletions data/event-schemas/schema/m.call.answer.yaml
Johennes marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"type": "object",
"description": "This event is sent by the callee when they wish to answer the call.",
"x-weight": 40,
"allOf": [{
"$ref": "core-event-schema/room_event.yaml"
}],
Expand Down
1 change: 1 addition & 0 deletions data/event-schemas/schema/m.call.candidates.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ description: |-
This event is sent by callers after sending an invite and by the callee after
answering. Its purpose is to give the other party additional ICE candidates to
try using to communicate.
x-weight: 20
allOf:
- $ref: core-event-schema/room_event.yaml
properties:
Expand Down
1 change: 1 addition & 0 deletions data/event-schemas/schema/m.call.hangup.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ description: |
the new call unless the user had specifically chosen to do so.
* `unknown_error`: Some other failure occurred that meant the client was unable to continue the call
rather than the user choosing to end it.
x-weight: 70
allOf:
- "$ref": core-event-schema/room_event.yaml
properties:
Expand Down
1 change: 1 addition & 0 deletions data/event-schemas/schema/m.call.invite.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"type": "object",
"description": "This event is sent by the caller when they wish to establish a call.",
"x-weight": 10,
"allOf": [{
"$ref": "core-event-schema/room_event.yaml"
}],
Expand Down
1 change: 1 addition & 0 deletions data/event-schemas/schema/m.call.negotiate.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ description: |
attempt to validate the `type` field, but simply pass the object into the
WebRTC API.
x-addedInMatrixVersion: "1.7"
x-weight: 60
allOf:
- "$ref": core-event-schema/room_event.yaml
properties:
Expand Down
1 change: 1 addition & 0 deletions data/event-schemas/schema/m.call.reject.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ description: |
Note that, unlike `m.call.hangup`, this event has no `reason` field: the rejection of
a call is always implicitly because the user chose not to answer it.
x-addedInMatrixVersion: "1.7"
x-weight: 30
allOf:
- "$ref": core-event-schema/room_event.yaml
properties:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
type: object
x-addedInMatrixVersion: "1.11"
x-weight: 60
description: |-
This event is sent by callers when they wish to update a stream's metadata
but no negotiation is required.
Expand Down
1 change: 1 addition & 0 deletions data/event-schemas/schema/m.call.select_answer.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"type": "object",
"description": "This event is sent by the caller's client once it has decided which other client to talk to, by selecting one of multiple possible incoming `m.call.answer` events. Its `selected_party_id` field indicates the answer it's chosen. The `call_id` and `party_id` of the caller is also included. If the callee's client sees a `select_answer` for an answer with party ID other than the one it sent, it ends the call and informs the user the call was answered elsewhere. It does not send any events. Media can start flowing before this event is seen or even sent. Clients that implement previous versions of this specification will ignore this event and behave as they did before.",
"x-addedInMatrixVersion": "1.7",
"x-weight": 50,
"allOf": [{
"$ref": "core-event-schema/room_event.yaml"
}],
Expand Down
20 changes: 12 additions & 8 deletions layouts/shortcodes/event-group.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,24 @@

{{ $base_path := "event-schemas/schema" }}

{{ $events := index .Site.Data "event-schemas" "schema" }}
{{ $group_name := .Params.group_name }}

{{ range $event_name, $event_data := $events }}

{{/* Filter events and prepare them for sorting */}}
{{ $events := slice }}
{{ range $event_name, $event_data := index .Site.Data "event-schemas" "schema" }}
{{ $prefix := substr $event_name 0 (len $group_name) }}
{{ if eq $prefix $group_name }}
{{ $events = $events | append (dict "event_name" $event_name "event_data" $event_data) }}
{{ end }}
{{ end }}

{{ $path := delimit (slice $base_path $event_name) "/" }}
{{ $event_data = partial "json-schema/resolve-refs" (dict "schema" $event_data "path" $path) }}
{{ $event_data := partial "json-schema/resolve-allof" $event_data }}
{{/* Render the events sorted by x-weight or otherwise their event name */}}
{{ range sort $events "event_data.x-weight" "event_name" }}
Copy link
Member

Choose a reason for hiding this comment

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

Does this work? It looks like the only thing you can put as the third argument to sort is "asc" or "desc": https://gohugo.io/functions/collections/sort/


{{ partial "events/render-event" (dict "event_name" $event_name "event_data" $event_data)}}
{{ $path := delimit (slice $base_path .event_name) "/" }}
{{ $event_data := partial "json-schema/resolve-refs" (dict "schema" .event_data "path" $path) }}
{{ $event_data := partial "json-schema/resolve-allof" $event_data }}

{{ end }}
{{ partial "events/render-event" (dict "event_name" .event_name "event_data" $event_data)}}

{{ end }}