# 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 Presence API
  version: 1.0.0
paths:
  "/presence/{userId}/status":
    put:
      summary: Update this user's presence state.
      description: |-
        This API sets the given user's presence state. When setting the status,
        the activity time is updated to reflect that activity; the client does
        not need to specify the `last_active_ago` field. You cannot set the
        presence state of another user.
      operationId: setPresence
      security:
        - accessTokenQuery: []
        - accessTokenBearer: []
      parameters:
        - in: path
          name: userId
          description: The user whose presence state to update.
          required: true
          example: "@alice:example.com"
          schema:
            type: string
      requestBody:
        content:
          application/json:
            schema:
              type: object
              example: {
                "presence": "online",
                "status_msg": "I am here."
              }
              properties:
                presence:
                  type: string
                  enum:
                    - online
                    - offline
                    - unavailable
                  description: The new presence state.
                status_msg:
                  type: string
                  description: The status message to attach to this state.
              required:
                - presence
        description: The updated presence state.
        required: true
      responses:
        "200":
          description: The new presence state was set.
          content:
            application/json:
              schema:
                type: object  # empty json object
              examples:
                response:
                  value: {}
        "429":
          description: This request was rate-limited.
          content:
            application/json:
              schema:
                $ref: definitions/errors/rate_limited.yaml
      tags:
        - Presence
    get:
      summary: Get this user's presence state.
      description: Get the given user's presence state.
      operationId: getPresence
      security:
        - accessTokenQuery: []
        - accessTokenBearer: []
      parameters:
        - in: path
          name: userId
          description: The user whose presence state to get.
          required: true
          example: "@alice:example.com"
          schema:
            type: string
      responses:
        "200":
          description: The presence state for this user.
          content:
            application/json:
              schema:
                type: object
                properties:
                  presence:
                    type: string
                    enum:
                      - online
                      - offline
                      - unavailable
                    description: This user's presence.
                  last_active_ago:
                    type: integer
                    description: |-
                      The length of time in milliseconds since an action was performed
                      by this user.
                  status_msg:
                    description: The state message for this user if one was set.
                    type: ["string", "null"]
                  currently_active:
                    type: boolean
                    description: Whether the user is currently active
                required:
                  - presence
              examples:
                response:
                  value: {
                    "presence": "unavailable",
                    "last_active_ago": 420845
                  }
        "403":
          description: You are not allowed to see this user's presence status.
          content:
            application/json:
              schema:
                $ref: definitions/errors/error.yaml
              examples:
                response:
                  value: {
                    "errcode": "M_FORBIDDEN",
                    "error": "You are not allowed to see their presence"
                  }
        "404":
          description: |-
            There is no presence state for this user. This user may not exist or
            isn't exposing presence information to you.
          content:
            application/json:
              schema:
                $ref: definitions/errors/error.yaml
      tags:
        - Presence
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
