Browse Source
Fix #130
Fix #130
- Add a little state machine to handle outgoing chat states - Fix id for composing and paused states in XMPP stanza - Handle the timeout for the pause on the PHP side only - Add a little timout on the JS side to don't spam the server at each key pressed - Cleanuppull/826/head
8 changed files with 96 additions and 48 deletions
-
32app/widgets/Chat/Chat.php
-
22app/widgets/Chat/chat.js
-
4lib/XMPPtoForm.php
-
1lib/moxl/src/Moxl/Xec/Action/Message/Composing.php
-
1lib/moxl/src/Moxl/Xec/Action/Message/Paused.php
-
4lib/moxl/src/Moxl/Xec/Payload/Message.php
-
78src/Movim/ChatOwnState.php
-
2src/Movim/ChatStates.php
@ -0,0 +1,78 @@ |
|||
<?php |
|||
|
|||
namespace Movim; |
|||
|
|||
use Movim\Widget\Wrapper; |
|||
use React\EventLoop\Timer\Timer; |
|||
|
|||
use Moxl\Xec\Action\Message\Composing; |
|||
use Moxl\Xec\Action\Message\Paused; |
|||
|
|||
/** |
|||
* This class handle all the outgoing chatstates |
|||
*/ |
|||
class ChatOwnState |
|||
{ |
|||
protected static $instance; |
|||
private $_to = null; |
|||
private $_muc = false; |
|||
private $_timer; |
|||
private $_timeout = 5; |
|||
|
|||
public static function getInstance() |
|||
{ |
|||
if (!isset(self::$instance)) { |
|||
self::$instance = new self(); |
|||
} |
|||
|
|||
return self::$instance; |
|||
} |
|||
|
|||
public function composing(string $to, bool $muc = false) |
|||
{ |
|||
global $loop; |
|||
|
|||
if ($this->_to !== $to) { |
|||
$mc = new Composing; |
|||
|
|||
if ($muc) { |
|||
$mc->setMuc(); |
|||
} |
|||
|
|||
$mc->setTo($to)->request(); |
|||
|
|||
if ($this->_to !== null) { |
|||
$this->paused($this->_to, $this->_muc); |
|||
} |
|||
|
|||
$this->_to = $to; |
|||
$this->_muc = $muc; |
|||
} |
|||
|
|||
if ($this->_timer) { |
|||
$loop->cancelTimer($this->_timer); |
|||
} |
|||
|
|||
$this->_timer = $loop->addTimer($this->_timeout, function () use ($to, $muc) { |
|||
$this->paused($to, $muc); |
|||
}); |
|||
} |
|||
|
|||
private function paused(string $to, bool $muc = false) |
|||
{ |
|||
global $loop; |
|||
|
|||
$mp = new Paused; |
|||
|
|||
$this->_to = null; |
|||
$this->_muc = false; |
|||
|
|||
$loop->cancelTimer($this->_timer); |
|||
|
|||
if ($muc) { |
|||
$mp->setMuc(); |
|||
} |
|||
|
|||
$mp->setTo($to)->request(); |
|||
} |
|||
} |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue