# Copyright 2016 OpenMarket Ltd
# Copyright 2022 The Matrix.org Foundation C.I.C.
#
# 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 Receipts API
  version: 1.0.0
paths:
  "/rooms/{roomId}/receipt/{receiptType}/{eventId}":
    post:
      summary: Send a receipt for the given event ID.
      description: |-
        This API updates the marker for the given receipt type to the event ID
        specified.
      operationId: postReceipt
      security:
        - accessTokenQuery: []
        - accessTokenBearer: []
      parameters:
        - in: path
          name: roomId
          description: The room in which to send the event.
          required: true
          example: "!wefuh21ffskfuh345:example.com"
          schema:
            type: string
        - in: path
          name: receiptType
          description: |-
            The type of receipt to send. This can also be `m.fully_read` as an
            alternative to [`/read_markers`](/client-server-api/#post_matrixclientv3roomsroomidread_markers).

            Note that `m.fully_read` does not appear under `m.receipt`: this endpoint
            effectively calls `/read_markers` internally when presented with a receipt
            type of `m.fully_read`.
          required: true
          x-changedInMatrixVersion:
            "1.4": |
              Allow `m.read.private` receipts and `m.fully_read` markers to be set.
          example: m.read
          schema:
            type: string
            enum:
              - m.read
              - m.read.private
              - m.fully_read
        - in: path
          name: eventId
          description: The event ID to acknowledge up to.
          required: true
          example: $1924376522eioj:example.com
          schema:
            type: string
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                thread_id:
                  type: string
                  x-addedInMatrixVersion: "1.4"
                  description: |-
                    The root thread event's ID (or `main`) for which
                    thread this receipt is intended to be under. If
                    not specified, the read receipt is *unthreaded*
                    (default).
              example: {
                "thread_id": "main"
              }
        description: |-
          Extra receipt information to attach to `content` if any. The
          server will automatically set the `ts` field.
        required: true
      responses:
        "200":
          description: The receipt was sent.
          content:
            application/json:
              schema:
                type: object
                maxProperties: 0  # empty json object
              examples:
                response:
                  value: {}
        "400":
          description: |-
            The `thread_id` is invalid in some way. For example:
            * It is not a string.
            * It is empty.
            * It is provided for an incompatible receipt type.
            * The `event_id` is not related to the `thread_id`.
          content:
            application/json:
              schema:
                $ref: definitions/errors/error.yaml
              examples:
                response:
                  value: {
                    "errcode": "M_INVALID_PARAM",
                    "error": "thread_id field must be a non-empty string"
                  }
        "429":
          description: This request was rate-limited.
          content:
            application/json:
              schema:
                $ref: definitions/errors/rate_limited.yaml
      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
