Browse Source

Add the <idle> element from XEP-0319 in Away presences

pull/937/head
Timothée Jaussoin 5 years ago
parent
commit
9664a2eabd
  1. 1
      app/Roster.php
  2. 5
      app/widgets/Presence/Presence.php
  3. 14
      lib/moxl/src/Moxl/Stanza/Presence.php
  4. 4
      lib/moxl/src/Moxl/Xec/Action/Presence/Away.php
  5. 3
      src/Movim/Daemon/Session.php

1
app/Roster.php

@ -28,6 +28,7 @@ class Roster extends Model
public function presences()
{
return $this->hasMany('App\Presence', 'jid', 'jid')
->where('resource', '!=', '')
->where('session_id', $this->session_id);
}

5
app/widgets/Presence/Presence.php

@ -11,6 +11,8 @@ use Moxl\Xec\Action\Storage\Get;
use Moxl\Xec\Action\PubsubSubscription\Get as GetPubsubSubscriptions;
use Moxl\Stanza\Stream;
use Movim\Daemon\Session;
class Presence extends Base
{
public function load()
@ -32,7 +34,8 @@ class Presence extends Base
public function onSessionDown()
{
$p = new Away;
$p->request();
$p->setLast(Session::DOWN_TIMER)
->request();
}
public function onMyPresence($packet)

14
lib/moxl/src/Moxl/Stanza/Presence.php

@ -9,7 +9,7 @@ class Presence
/*
* The presence builder
*/
public static function maker($to = false, $status = false, $show = false, $priority = 0, $type = false, $muc = false, $mam = false)
public static function maker($to = false, $status = false, $show = false, $priority = 0, $type = false, $muc = false, $mam = false, $last = 0)
{
$session = Session::start();
@ -48,6 +48,14 @@ class Presence
$root->appendChild($priority);
}
// https://xmpp.org/extensions/xep-0319.html#last-interact
if ($last > 0) {
$timestamp = time() - $last;
$idle = $dom->createElementNS('urn:xmpp:idle:1', 'idle');
$idle->setAttribute('since', gmdate(DATE_ISO8601, $timestamp));
$root->appendChild($idle);
}
if ($muc) {
$x = $dom->createElementNS('http://jabber.org/protocol/muc', 'x');
@ -135,9 +143,9 @@ class Presence
/*
* Go away
*/
public static function away($status = false)
public static function away($status = false, $last = 0)
{
$xml = self::maker(false, $status, 'away', false, false);
$xml = self::maker(false, $status, 'away', false, false, false, false, $last);
\Moxl\API::request($xml);
}

4
lib/moxl/src/Moxl/Xec/Action/Presence/Away.php

@ -10,12 +10,12 @@ use App\PresenceBuffer;
class Away extends Action
{
protected $_status;
protected $_last;
public function request()
{
$this->store();
Presence::away($this->_status);
Presence::away($this->_status, $this->_last);
}
public function handle($stanza, $parent = false)

3
src/Movim/Daemon/Session.php

@ -6,6 +6,7 @@ use App\Session as DBSession;
class Session
{
const DOWN_TIMER = 20;
protected $clients; // Browser Websockets
public $timestamp;
protected $sid; // Session id
@ -86,7 +87,7 @@ class Session
}
if ($this->countClients() == 0) {
$loop->addPeriodicTimer(20, function ($timer) use ($loop) {
$loop->addPeriodicTimer(Session::DOWN_TIMER, function ($timer) use ($loop) {
if ($this->countClients() == 0) {
$this->stateOut('down');
}

Loading…
Cancel
Save