2021-09-15 15:19:48 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace OCA\UPschooling\Service;
|
|
|
|
|
|
|
|
use Aryess\PhpMatrixSdk\Exceptions\MatrixException;
|
2021-09-18 17:28:10 +00:00
|
|
|
use Aryess\PhpMatrixSdk\Exceptions\MatrixRequestException;
|
2021-09-15 15:19:48 +00:00
|
|
|
use Aryess\PhpMatrixSdk\MatrixClient;
|
|
|
|
use Aryess\PhpMatrixSdk\Room;
|
2021-09-18 17:28:10 +00:00
|
|
|
use Psr\Log\LoggerInterface;
|
2021-09-15 15:19:48 +00:00
|
|
|
|
|
|
|
class MatrixService
|
|
|
|
{
|
|
|
|
|
|
|
|
/** @var LoggerInterface */
|
|
|
|
private $logger;
|
|
|
|
|
|
|
|
/** @var string */
|
|
|
|
private $channel;
|
|
|
|
|
|
|
|
/** @var MatrixClient */
|
|
|
|
private $client;
|
|
|
|
|
|
|
|
/** @var string */
|
|
|
|
private $token;
|
|
|
|
|
|
|
|
/** @var Room */
|
|
|
|
private $room;
|
|
|
|
|
|
|
|
public function __construct(LoggerInterface $logger) {
|
|
|
|
$this->logger = $logger;
|
|
|
|
$this->channel = "#issue:synapse";
|
|
|
|
$this->client = new MatrixClient("http://synapse:8008");
|
|
|
|
$this->token = $this->client->login("upschooling", "secret");
|
2021-09-18 19:15:03 +00:00
|
|
|
// try {
|
|
|
|
// $this->room = $this->client->createRoom($this->channel, false, array());
|
|
|
|
// } catch (MatrixException $createE) {
|
|
|
|
// try {
|
|
|
|
// $this->room = $this->client->joinRoom($this->channel);
|
|
|
|
// } catch (MatrixException $e) {
|
|
|
|
// $this->logger->error(
|
|
|
|
// "Could not create room ".$this->channel,
|
|
|
|
// array('exception' => $e, 'causedBy' => $createE)
|
|
|
|
// );
|
|
|
|
// }
|
|
|
|
// }
|
2021-09-15 15:19:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets a property on a channel.
|
|
|
|
*
|
|
|
|
* @param string $eventType a unique property identifier with reverse domain notation, e.g. com.example.property.
|
|
|
|
* @param array $content the contents as a JSON serializable array.
|
|
|
|
* @throws MatrixException
|
|
|
|
*/
|
|
|
|
public function setProperty(string $eventType, array $content)
|
|
|
|
{
|
|
|
|
$this->room->sendStateEvent($eventType, $content);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $eventType a unique property identifier with reverse domain notation, e.g. com.example.property.
|
|
|
|
* @return array the contents of the room state.
|
|
|
|
* @throws MatrixException|MatrixRequestException
|
|
|
|
*/
|
|
|
|
public function getProperty(string $eventType): array
|
|
|
|
{
|
|
|
|
// first parameter should be $this->room->roomId
|
|
|
|
return $this->client->api()->getStateEvent($this->channel, $eventType);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|