Browse Source

Update XEP-0402 to urn:xmpp:bookmarks:1 and add xmpp:movim.eu/notifications:0 extension support

pull/978/head
Timothée Jaussoin 5 years ago
parent
commit
08dfe7e78f
  1. 1
      CHANGELOG.md
  2. 33
      app/Conference.php
  3. 14
      app/widgets/Chat/Chat.php
  4. 9
      app/widgets/Chat/_chat_header.tpl
  5. 6
      app/widgets/Presence/Presence.php
  6. 5
      app/widgets/Rooms/_rooms_room.tpl
  7. 4
      app/widgets/Rooms/locales.ini
  8. 18
      app/widgets/RoomsUtils/RoomsUtils.php
  9. 16
      app/widgets/RoomsUtils/_rooms_add.tpl
  10. 32
      app/widgets/RoomsUtils/_rooms_drawer.tpl
  11. 28
      database/migrations/20200714184243_add_notify_and_extensions_to_conferences_table.php
  12. 28
      lib/moxl/src/Stanza/Bookmark2.php
  13. 1
      lib/moxl/src/Utils.php
  14. 3
      lib/moxl/src/Xec/Action/Bookmark2/Delete.php
  15. 10
      lib/moxl/src/Xec/Action/Bookmark2/Get.php
  16. 12
      lib/moxl/src/Xec/Action/Bookmark2/Set.php
  17. 3
      lib/moxl/src/Xec/Handler.php
  18. 6
      lib/moxl/src/Xec/Payload/Bookmark2.php

1
CHANGELOG.md

@ -36,6 +36,7 @@ v0.18 (trunk)
* Improve the Draw widget lines quality (christine-ho-dev)
* New emoji picker (christine-ho-dev)
* Add on-the-fly picture compression for the Picture proxy for larger pictures
* Update XEP-0402 to urn:xmpp:bookmarks:1 and add xmpp:movim.eu/notifications:0 extension support
v0.17.1
---------------------------

33
app/Conference.php

@ -11,6 +11,13 @@ class Conference extends Model
protected $fillable = ['conference', 'name', 'nick', 'autojoin'];
protected $with = ['contact'];
public static $xmlns = 'xmpp:movim.eu/notifications:0';
public static $notifications = [
0 => 'never',
1 => 'quoted',
2 => 'always'
];
protected $attributes = [
'session_id' => SESSION_ID
];
@ -71,6 +78,27 @@ class Conference extends Model
return $this->hasOne('App\Contact', 'id', 'conference');
}
public function set($item)
{
$this->conference = (string)$item->attributes()->id;
$this->name = (string)$item->conference->attributes()->name;
$this->nick = (string)$item->conference->nick;
$this->autojoin = filter_var($item->conference->attributes()->autojoin, FILTER_VALIDATE_BOOLEAN);
$this->bookmarkversion = (int)substr((string)$item->conference->attributes()->xmlns, -1, 1);
if ($item->conference->extensions) {
if ($item->conference->extensions && $item->conference->extensions->notifications
&& $item->conference->extensions->notifications->attributes()->xmlns == self::$xmlns) {
$this->notify = (int)array_flip(self::$notifications)[
(string)$item->conference->extensions->notifications->attributes()->notify
];
unset($item->conference->extensions->notifications);
}
$this->extensions = $item->conference->extensions->asXML();
}
}
public function getServerAttribute()
{
return \explodeJid($this->conference)['server'];
@ -81,6 +109,11 @@ class Conference extends Model
return isset($this->presence);
}
public function getNotificationKeyAttribute()
{
return self::$notifications[$this->notify];
}
public function getSubjectAttribute()
{
$subject = \App\User::me()

14
app/widgets/Chat/Chat.php

@ -118,6 +118,12 @@ class Chat extends \Movim\Widget\Base
$from = $message->jidfrom;
$contact = App\Contact::firstOrNew(['id' => $from]);
$conference = $message->type == 'groupchat'
? $this->user->session
->conferences()->where('conference', $from)
->first()
: null;
if ($contact != null
&& !$message->encrypted
&& $message->type != 'groupchat'
@ -137,12 +143,10 @@ class Chat extends \Movim\Widget\Base
}
// If it's a groupchat message
elseif ($message->type == 'groupchat'
&& $message->quoted
&& $conference
&& (($conference->notify == 1 && $message->quoted) // When quoted
|| $conference->notify == 2) // Always
&& !$receipt) {
$conference = $this->user->session
->conferences()->where('conference', $from)
->first();
Notification::rpcCall('Notification.incomingMessage');
Notification::append(
'chat|'.$from,

9
app/widgets/Chat/_chat_header.tpl

@ -56,6 +56,15 @@
{if="$conference && $conference->name"}
<p class="line active" title="{$jid|echapJS}" onclick="RoomsUtils_ajaxShowSubject('{$jid|echapJS}')">
{$conference->name}
{if="$conference->notify == 0"}
<span class="second" title="{$c->__('room.notify_never')}">
<i class="material-icons">notifications_off</i>
</span>
{elseif="$conference->notify == 2"}
<span class="second" title="{$c->__('room.notify_always')}">
<i class="material-icons">notifications_active</i>
</span>
{/if}
</p>
{else}
<p class="line active" onclick="RoomsUtils_ajaxShowSubject('{$jid|echapJS}')">

6
app/widgets/Presence/Presence.php

@ -154,6 +154,12 @@ class Presence extends Base
$b = new \Moxl\Xec\Action\Bookmark2\Get;
$b->setTo($this->user->id)
->request();
// Also get the old Bookmarks
$b = new \Moxl\Xec\Action\Bookmark2\Get;
$b->setTo($this->user->id)
->setVersion('0')
->request();
}
// We refresh our personnal feed

5
app/widgets/Rooms/_rooms_room.tpl

@ -61,6 +61,11 @@
<span title="{$conference->conference}">{$conference->name}</span>
<span class="second">
{if="$conference->notify == 0"}
<i class="material-icons" title="{$c->__('room.notify_never')}">notifications_off</i>
{elseif="$conference->notify == 2"}
<i class="material-icons" title="{$c->__('room.notify_always')}">notifications_active</i>
{/if}
{if="isset($info) && $info->description"}
{$info->description}
{else}

4
app/widgets/Rooms/locales.ini

@ -58,3 +58,7 @@ public_muc = Public
public_muc_text = This chatroom is publicly discoverable
nonanonymous_muc = Public profiles
nonanonymous_muc_text = "The participants of this chatroom can see each other's profile"
notify_title = Notifications
notify_never = Never notify
notify_quoted = Notify when quoted
notify_always = Always notify

18
app/widgets/RoomsUtils/RoomsUtils.php

@ -199,18 +199,23 @@ class RoomsUtils extends Base
} else {
$this->rpc('Rooms_ajaxExit', $form->jid->value);
$this->user->session->conferences()
$conference = $this->user->session->conferences()
->where('conference', strtolower($form->jid->value))
->delete();
->first();
if (!$conference) $conference = new Conference;
$conference = new Conference;
$conference->conference = strtolower($form->jid->value);
$conference->name = $form->name->value;
$conference->autojoin = $form->autojoin->value;
$conference->nick = $form->nick->value;
$conference->notify = (int)array_flip(Conference::$notifications)[$form->notify->value];
$conferenceSave = clone $conference;
$conference->delete();
$b = new Set;
$b->setConference($conference)
$b->setConference($conferenceSave)
->request();
$this->rpc('Dialog_ajaxClear');
@ -241,8 +246,13 @@ class RoomsUtils extends Base
return;
}
$conference = $this->user->session->conferences()
->where('conference', strtolower($room))
->first();
$d = new Delete;
$d->setId($room)
->setVersion($conference->bookmarkversion)
->request();
}

16
app/widgets/RoomsUtils/_rooms_add.tpl

@ -75,6 +75,22 @@
placeholder="{$username}"/>
<label>{$c->__('chatrooms.nickname')}</label>
</div>
<div>
<div class="select">
<select name="notify">
<option value="never" {if="isset($conference) && $conference->notify == 0"}selected{/if}>
{$c->__('room.notify_never')}
</option>
<option value="quoted" {if="isset($conference) && $conference->notify == 1"}selected{/if}>
{$c->__('room.notify_quoted')}
</option>
<option value="always" {if="isset($conference) && $conference->notify == 2"}selected{/if}>
{$c->__('room.notify_always')}
</option>
</select>
</div>
<label>{$c->__('room.notify_title')}</label>
</div>
<div>
<ul class="list thick fill">
<li class="wide">

32
app/widgets/RoomsUtils/_rooms_drawer.tpl

@ -75,6 +75,38 @@
</div>
</li>
{/if}
{if="$conference->notify == 0"}
<li>
<span class="primary icon gray">
<i class="material-icons">notifications_off</i>
</span>
<div>
<p class="line">{$c->__('room.notify_title')}</p>
<p class="line">{$c->__('room.notify_never')}</p>
</div>
</li>
{elseif="$conference->notify == 2"}
<li>
<span class="primary icon gray">
<i class="material-icons">notifications_active</i>
</span>
<div>
<p class="line">{$c->__('room.notify_title')}</p>
<p class="line">{$c->__('room.notify_always')}</p>
</div>
</li>
{else}
<li>
<span class="primary icon gray">
<i class="material-icons">notifications</i>
</span>
<div>
<p class="line">{$c->__('room.notify_title')}</p>
<p class="line">{$c->__('room.notify_quoted')}</p>
</div>
</li>
{/if}
</ul>
{if="$conference->pictures()->count() > 0"}

28
database/migrations/20200714184243_add_notify_and_extensions_to_conferences_table.php

@ -0,0 +1,28 @@
<?php
use Movim\Migration;
use Illuminate\Database\Schema\Blueprint;
use App\Info;
class AddNotifyAndExtensionsToConferencesTable extends Migration
{
public function up()
{
Info::truncate();
$this->schema->table('conferences', function (Blueprint $table) {
$table->text('extensions')->nullable();
$table->integer('bookmarkversion')->default(0);
$table->integer('notify')->default(1);
});
}
public function down()
{
$this->schema->table('conferences', function (Blueprint $table) {
$table->dropColumn('extensions');
$table->dropColumn('bookmarkversion');
$table->dropColumn('notify');
});
}
}

28
lib/moxl/src/Stanza/Bookmark2.php

@ -6,26 +6,26 @@ use App\Conference;
class Bookmark2
{
public static function get()
public static function get($version = '1')
{
$dom = new \DOMDocument('1.0', 'UTF-8');
$pubsub = $dom->createElementNS('http://jabber.org/protocol/pubsub', 'pubsub');
$items = $dom->createElement('items');
$items->setAttribute('node', 'urn:xmpp:bookmarks:0');
$items->setAttribute('node', 'urn:xmpp:bookmarks:'.$version);
$pubsub->appendChild($items);
$xml = \Moxl\API::iqWrapper($pubsub, false, 'get');
\Moxl\API::request($xml);
}
public static function set(Conference $conf)
public static function set(Conference $conf, $version = '1')
{
$dom = new \DOMDocument('1.0', 'UTF-8');
$pubsub = $dom->createElementNS('http://jabber.org/protocol/pubsub', 'pubsub');
$publish = $dom->createElement('publish');
$publish->setAttribute('node', 'urn:xmpp:bookmarks:0');
$publish->setAttribute('node', 'urn:xmpp:bookmarks:'.$version);
$pubsub->appendChild($publish);
$item = $dom->createElement('item');
@ -33,7 +33,7 @@ class Bookmark2
$publish->appendChild($item);
$conference = $dom->createElement('conference');
$conference->setAttribute('xmlns', 'urn:xmpp:bookmarks:0');
$conference->setAttribute('xmlns', 'urn:xmpp:bookmarks:'.$version);
$conference->setAttribute('name', $conf->name);
if ($conf->autojoin) {
$conference->setAttribute('autojoin', 'true');
@ -43,6 +43,24 @@ class Bookmark2
$nick = $dom->createElement('nick', $conf->nick);
$conference->appendChild($nick);
if ($conf->extensions) {
$domExtensions = new \DOMDocument('1.0', 'UTF-8');
$domExtensions->loadXML($conf->extensions);
$extensions = $dom->importNode($domExtensions->documentElement, true);
$conference->appendChild($extensions);
} else if ($conf->notify !== null) {
$extensions = $dom->createElement('extensions');
$conference->appendChild($extensions);
}
if ($conf->notify !== null) {
$notifications = $dom->createElement('notifications');
$notifications->setAttribute('xmlns', Conference::$xmlns);
$notifications->setAttribute('notify', $conf->notificationKey);
$extensions->appendChild($notifications);
}
// Publish option
$publishOption = $dom->createElement('publish-option');
$x = $dom->createElement('x');

1
lib/moxl/src/Utils.php

@ -10,6 +10,7 @@ class Utils
'urn:xmpp:microblog:0',
'urn:xmpp:microblog:0+notify',
'urn:xmpp:bookmarks:0+notify',
'urn:xmpp:bookmarks:1+notify',
'urn:xmpp:pubsub:subscription',
'urn:xmpp:pubsub:subscription+notify',

3
lib/moxl/src/Xec/Action/Bookmark2/Delete.php

@ -8,11 +8,12 @@ use Moxl\Stanza\Pubsub;
class Delete extends Action
{
protected $_id;
protected $_version = '1';
public function request()
{
$this->store();
Pubsub::postDelete(false, 'urn:xmpp:bookmarks:0', $this->_id);
Pubsub::postDelete(false, 'urn:xmpp:bookmarks:'.$this->_version, $this->_id);
}
public function handle($stanza, $parent = false)

10
lib/moxl/src/Xec/Action/Bookmark2/Get.php

@ -9,11 +9,12 @@ use Moxl\Stanza\Bookmark2;
class Get extends Action
{
protected $_to;
protected $_version = '1';
public function request()
{
$this->store();
Bookmark2::get();
Bookmark2::get($this->_version);
}
public function handle($stanza, $parent = false)
@ -22,12 +23,7 @@ class Get extends Action
foreach ($stanza->pubsub->items->item as $c) {
$conference = new Conference;
$conference->conference = (string)$c->attributes()->id;
$conference->name = (string)$c->conference->attributes()->name;
$conference->nick = (string)$c->conference->nick;
$conference->autojoin = filter_var($c->conference->attributes()->autojoin, FILTER_VALIDATE_BOOLEAN);
$conference->set($c);
$conference->save();
}

12
lib/moxl/src/Xec/Action/Bookmark2/Set.php

@ -9,11 +9,21 @@ use Moxl\Stanza\Bookmark2;
class Set extends Action
{
protected $_conference;
protected $_version = '1';
public function request()
{
$this->store();
Bookmark2::set($this->_conference);
// If we set the version 1, ensure to remove 0
if ($this->_version == '1' && $this->_conference->bookmarkversion == 0) {
$d = new Delete;
$d->setId($this->_conference->conference)
->setVersion('0')
->request();
}
Bookmark2::set($this->_conference, $this->_version);
}
public function setConference(Conference $conference)

3
lib/moxl/src/Xec/Handler.php

@ -128,7 +128,8 @@ class Handler
'fd60f5fdd5d2a06d1c4dd723032fb41a' => 'MAMResult', // mam:1
'0e49eb65ba266051d2a2287660e22ab1' => 'MAMResult', // mam:2
'887777451221e69bc638f4659ecfeffb' => 'Bookmark2',
'887777451221e69bc638f4659ecfeffb' => 'Bookmark2', // bookmarks:0
'c539a0a12da7913eef6b8b5292e31e68' => 'Bookmark2', // bookmarks:1
'1040105fc01bfac8a5ab81324875e382' => 'Presence',
'362b908ec9432a506f86bed0bae7bbb6' => 'Presence',// TLS

6
lib/moxl/src/Xec/Payload/Bookmark2.php

@ -17,11 +17,7 @@ class Bookmark2 extends Payload
->delete();
} else {
$conference = new Conference;
$conference->conference = (string)$stanza->items->item->attributes()->id;
$conference->name = (string)$stanza->items->item->conference->attributes()->name;
$conference->nick = (string)$stanza->items->item->conference->nick;
$conference->autojoin = filter_var($stanza->items->item->conference->attributes()->autojoin, FILTER_VALIDATE_BOOLEAN);
$conference->set($stanza->items->item);
\App\User::me()->session->conferences()->where('conference', $conference->conference)->delete();

Loading…
Cancel
Save