legacy mode

This commit is contained in:
groug 2024-03-11 15:31:59 +00:00
parent ae5d0c7800
commit ba0b240d4f

View File

@ -17,6 +17,9 @@ class MatrixClient
/** @var int Update period in microseconds */
private $update_period = 1000000;
/** @var bool Enable legacy mode for matrix API */
private $legacy_mode_enabled = false;
/**
* @param string $matrix_server Matrix server (https://domain.tld)
*/
@ -63,6 +66,15 @@ class MatrixClient
$this->update_period = intval($seconds * 1000000);
}
/**
* Change legacy mode
* @param bool $mode Enabled if true
*/
public function set_legacy_mode_enabled($mode)
{
$this->legacy_mode_enabled = $mode;
}
/**
* Try to login to Matrix API and get an access token.
* Will throw a MatrixRequestException if it fails
@ -162,8 +174,14 @@ class MatrixClient
{
$txn_id = $this->get_new_transaction_id();
$room_id = curl_escape($this->ch, $room_id);
$path = "/_matrix/client/v3/rooms/{$room_id}/send/{$event_type}/{$txn_id}";
return $this->query($path, "PUT", $body);
if ($this->legacy_mode_enabled) {
$path = "/_matrix/client/r0/rooms/{$room_id}/send/{$event_type}";
return $this->query($path, "POST", $body);
}
else {
$path = "/_matrix/client/v3/rooms/{$room_id}/send/{$event_type}/{$txn_id}";
return $this->query($path, "PUT", $body);
}
}
/**