# Copyright 2016 OpenMarket Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
openapi: 3.1.0
info:
  title: Matrix Client-Server Sync Guest API
  version: 1.0.0
paths:
  # With an extra " " to disambiguate from the getEvents endpoint
  # The extra space makes it sort first for what I'm sure is a good reason.
  "/events ":
    get:
      summary: Listen on the event stream of a particular room.
      description: |-
        This will listen for new events related to a particular room and return
        them to the caller. This will block until an event is received, or until
        the `timeout` is reached.

        This API is the same as the normal `/events` endpoint, but can be
        called by users who have not joined the room.

        Note that the normal `/events` endpoint has been deprecated. This
        API will also be deprecated at some point, but its replacement is not
        yet known.
      operationId: peekEvents
      security:
        - accessTokenQuery: []
        - accessTokenBearer: []
      parameters:
        - in: query
          name: from
          description: |-
            The token to stream from. This token is either from a previous
            request to this API or from the initial sync API.
          required: false
          example: s3456_9_0
          schema:
            type: string
        - in: query
          name: timeout
          description: The maximum time in milliseconds to wait for an event.
          required: false
          example: 35000
          schema:
            type: integer
        - in: query
          name: room_id
          description: The room ID for which events should be returned.
          example: "!somewhere:over.the.rainbow"
          schema:
            type: string
      responses:
        "200":
          description: The events received, which may be none.
          content:
            application/json:
              schema:
                type: object
                properties:
                  start:
                    type: string
                    description: |-
                      A token which correlates to the first value in `chunk`. This
                      is usually the same token supplied to `from=`.
                  end:
                    type: string
                    description: |-
                      A token which correlates to the last value in `chunk`. This
                      token should be used in the next request to `/events`.
                  chunk:
                    type: array
                    description: An array of events.
                    items:
                      type: object
                      title: Event
                      allOf:
                        - $ref: definitions/client_event.yaml
              examples:
                response:
                  value: {
                    "start": "s3456_9_0",
                    "end": "s3457_9_0",
                    "chunk": [
                      {
                        "room_id": "!somewhere:over.the.rainbow",
                        "$ref": "../../event-schemas/examples/m.room.message$m.text.yaml"
                      }
                    ]
                  }
        "400":
          description: Bad pagination `from` parameter.
      tags:
        - Room participation
servers:
  - url: "{protocol}://{hostname}{basePath}"
    variables:
      protocol:
        enum:
          - http
          - https
        default: https
      hostname:
        default: localhost:8008
      basePath:
        default: /_matrix/client/v3
components:
  securitySchemes:
    accessTokenQuery:
      $ref: definitions/security.yaml#/accessTokenQuery
    accessTokenBearer:
      $ref: definitions/security.yaml#/accessTokenBearer
