Browse Source
Fix #1164 Implement XEP-0410: MUC Self-Ping (Schrödinger's Chat) basic behavior
pull/1323/head
Fix #1164 Implement XEP-0410: MUC Self-Ping (Schrödinger's Chat) basic behavior
pull/1323/head
8 changed files with 131 additions and 26 deletions
-
1CHANGELOG.md
-
17app/widgets/Rooms/Rooms.php
-
57src/Movim/ChatroomPings.php
-
4src/Moxl/Stanza/Ping.php
-
34src/Moxl/Xec/Action/Ping/Room.php
-
2src/Moxl/Xec/Action/Ping/Server.php
-
39src/Moxl/Xec/Payload/Message.php
-
3src/Moxl/Xec/Payload/Presence.php
@ -0,0 +1,57 @@ |
|||
<?php |
|||
/* |
|||
* SPDX-FileCopyrightText: 2024 Jaussoin Timothée |
|||
* SPDX-License-Identifier: AGPL-3.0-or-later |
|||
*/ |
|||
|
|||
namespace Movim; |
|||
|
|||
use Moxl\Xec\Action\Ping\Room; |
|||
|
|||
/** |
|||
* Handling XEP-0410: MUC Self-Ping (Schrödinger's Chat) pings and timeouts |
|||
*/ |
|||
class ChatroomPings |
|||
{ |
|||
protected static $instance; |
|||
private $_chatrooms = []; |
|||
private $_timeout = 5 * 60; |
|||
|
|||
public static function getInstance() |
|||
{ |
|||
if (!isset(self::$instance)) { |
|||
self::$instance = new self(); |
|||
} |
|||
|
|||
return self::$instance; |
|||
} |
|||
|
|||
public function touch(string $from) |
|||
{ |
|||
global $loop; |
|||
|
|||
$this->clear($from); |
|||
|
|||
$this->_chatrooms[$from] = $loop->addTimer($this->_timeout, function () use ($from) { |
|||
$presence = \App\User::me()->session->conferences() |
|||
->where('conference', $from) |
|||
->first()?->presence; |
|||
|
|||
if ($presence) { |
|||
$pingRoom = new Room; |
|||
$pingRoom->setResource($from . '/' . $presence->resource) |
|||
->setRoom($from) |
|||
->request(); |
|||
} |
|||
}); |
|||
} |
|||
|
|||
public function clear(string $from) |
|||
{ |
|||
global $loop; |
|||
|
|||
if (array_key_exists($from, $this->_chatrooms)) { |
|||
$loop->cancelTimer($this->_chatrooms[$from]); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,34 @@ |
|||
<?php |
|||
|
|||
namespace Moxl\Xec\Action\Ping; |
|||
|
|||
use Movim\ChatroomPings; |
|||
use Moxl\Xec\Action; |
|||
use Moxl\Stanza\Ping; |
|||
use Rooms; |
|||
use SimpleXMLElement; |
|||
|
|||
/** |
|||
* XEP-0410: MUC Self-Ping (Schrödinger's Chat) |
|||
*/ |
|||
class Room extends Action |
|||
{ |
|||
protected ?string $_room = null; |
|||
protected ?string $_resource = null; |
|||
|
|||
public function request() |
|||
{ |
|||
$this->store(); |
|||
Ping::entity($this->_resource); |
|||
} |
|||
|
|||
public function handle(?SimpleXMLElement $stanza = null, ?SimpleXMLElement $parent = null) |
|||
{ |
|||
ChatroomPings::getInstance()->touch($this->_room); |
|||
} |
|||
|
|||
public function error(string $errorId, ?string $message = null) |
|||
{ |
|||
(new Rooms())->ajaxExit($this->_room); |
|||
} |
|||
} |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue