---
# Update the homeserver.yaml file with Element Call config

- name: Ensure homeserver.yaml exists
  ansible.builtin.file:
    path: "{{ matrix_homeserver_config_path }}"
    state: file
    mode: 0644

- name: Add listeners section for Element Call to homeserver.yaml
  ansible.builtin.blockinfile:
    path: "{{ matrix_homeserver_config_path }}"
    block: |
      listeners:
        - port: 8008
          tls: false
          type: http
          x_forwarded: true

          resources:
            - names: [client, federation, openid]
              compress: false
    marker: "# ANSIBLE MANAGED BLOCK - Element Call listeners"
    mode: '0644'
    owner: "{{ matrix_user_username }}"
    group: "{{ matrix_user_groupname }}"

- name: Ensure serve_server_wellknown is enabled in homeserver.yaml
  ansible.builtin.lineinfile:
    path: "{{ matrix_homeserver_config_path }}"
    line: "serve_server_wellknown: true"
    insertafter: EOF
    state: present
    mode: '0644'
    owner: "{{ matrix_user_username }}"
    group: "{{ matrix_user_groupname }}"