Skip to content
Permalink
Browse files

Add support for XEP-0402: Bookmarks 2 + migration button

  • Loading branch information...
edhelas committed Sep 28, 2019
1 parent db89281 commit 2b32cde26c27417d075f7696ee04da94e5df3df3
@@ -1,7 +1,7 @@
Movim Changelog
================

v0.15.1 (trunk)
v0.16 (trunk)
---------------------------
* Cleanup the unanswered IQ requests after 60 seconds
* Simplify the Moxl handler
@@ -27,6 +27,7 @@ v0.15.1 (trunk)
* Allow Visio notification to also open pop-up
* Clear all candidates when terminating or starting a new Visio
* Fix a compatibility issue between Phinx and symphony/console v4.3.4
* Add support for XEP-0402: Bookmarks 2 and a migration button

v0.15 – Donati
---------------------------
@@ -1 +1 @@
0.15
0.16alpha1
@@ -1,5 +1,5 @@
var Init = {
version: 4,
version: 5,

checkNode : function() {
// TODO : very ugly, need to refactor this
@@ -11,6 +11,7 @@ var Init = {
if (init.initialized != 'true') {
Init_ajaxCreatePersistentStorage('storage:bookmarks');
Init_ajaxCreatePersistentStorage('urn:xmpp:pubsub:movim-public-subscription', 1000);
Init_ajaxCreatePersistentStorage('urn:xmpp:bookmarks:0', 1000);
Init_ajaxCreatePersistentPEPStorage('urn:xmpp:vcard4');
Init_ajaxCreatePersistentPEPStorage('urn:xmpp:avatar:data');
Init_ajaxCreatePersistentPEPStorage('http://jabber.org/protocol/geoloc');
@@ -148,7 +148,7 @@ public function ajaxProfileRefresh()
// We refresh the bookmarks
public function ajaxBookmarksGet()
{
$b = new \Moxl\Xec\Action\Bookmark\Get;
$b = new \Moxl\Xec\Action\Bookmark2\Get;
$b->setTo($this->user->id)
->request();
}
@@ -1,7 +1,8 @@
<?php
use Moxl\Xec\Action\Presence\Muc;
use Moxl\Xec\Action\Bookmark\Set;
use Moxl\Xec\Action\Bookmark2\Set;
use Moxl\Xec\Action\Bookmark2\Delete;
use Moxl\Xec\Action\Presence\Unavailable;
use Moxl\Xec\Action\Message\Invite;
use Moxl\Xec\Action\Disco\Request;
@@ -26,8 +27,10 @@ public function load()
$this->addjs('rooms.js');
$this->addcss('rooms.css');
$this->registerEvent('message', 'onMessage');
$this->registerEvent('bookmark_get_handle', 'onBookmarkGet');
$this->registerEvent('bookmark_set_handle', 'onBookmarkSet');
$this->registerEvent('bookmark2_get_handle', 'onBookmarkGet');
$this->registerEvent('bookmark2_set_handle', 'onBookmarkSet');
$this->registerEvent('bookmark2_delete_handle', 'onBookmarkSet');
$this->registerEvent('bookmark_synchronize_handle', 'onBookmarkSynchronized');
$this->registerEvent('disco_items_nosave_handle', 'onDiscoGateway');
$this->registerEvent('disco_items_nosave_error', 'onDiscoGatewayError');
$this->registerEvent('vcard_set_handle', 'onAvatarSet', 'chat');
@@ -109,11 +112,15 @@ public function onBookmarkGet()
$this->refreshRooms();
}
public function onBookmarkSynchronized($packet)
{
Notification::toast($this->__('chatrooms.synchronized', $packet->content));
}
public function onBookmarkSet()
{
Notification::toast($this->__('bookmarks.updated'));
$this->refreshRooms();
(new Chat)->ajaxGet();
}
public function onConnected($packet)
@@ -403,9 +410,9 @@ public function ajaxRemove($room)
return;
}
$this->user->session->conferences()->where('conference', $room)->delete();
$this->setBookmark();
$d = new Delete;
$d->setId($room)
->request();
}
/**
@@ -509,45 +516,27 @@ public function ajaxChatroomAdd($form)
->where('conference', strtolower($form->jid->value))
->delete();
$item = [
'type' => 'conference',
'name' => $form->name->value,
'autojoin' => $form->autojoin->value,
'nick' => $form->nick->value,
'jid' => strtolower($form->jid->value)
];
$this->setBookmark($item);
$conference = new Conference;
$conference->conference = strtolower($form->jid->value);
$conference->name = $form->name->value;
$conference->autojoin = $form->autojoin->value;
$conference->nick = $form->nick->value;
$b = new Set;
$b->setConference($conference)
->request();
$this->rpc('Dialog_ajaxClear');
}
}
public function setBookmark($item = false)
/**
* Synchronize Bookmark 1 to Bookmark 2
*/
public function ajaxSyncBookmark()
{
$arr = [];
if ($item) {
array_push($arr, $item);
}
$conferences = $this->user->session->conferences()->get();
if ($conferences) {
foreach ($conferences as $c) {
array_push(
$arr,
[
'type' => 'conference',
'name' => $c->name,
'autojoin' => $c->autojoin,
'nick' => $c->nick,
'jid' => $c->conference
]
);
}
}
$b = new Set;
$b->setArr($arr)
->request();
$s = new \Moxl\Xec\Action\Bookmark\Synchronize;
$s->request();
}
public function prepareRooms($edit = false, $all = false)
@@ -126,6 +126,18 @@
<p>{$c->__('rooms.empty_text1')}</p>
<p>{$c->__('rooms.empty_text2')}</p>
</li>
<li>
<span class="primary icon purple">
<i class="material-icons">help</i>
</span>
<span class="control icon active" onclick="Rooms_ajaxSyncBookmark()">
<i class="material-icons">sync</i>
</span>
<p>{$c->__('rooms.empty_synchronize_title')}</p>
<p>
{$c->__('rooms.empty_synchronize_text')}
</p>
</li>
</ul>
{/if}

@@ -3,6 +3,9 @@ add = Add a chatroom
edit = Edit a chatroom
empty_text1 = You don’t have any chatroom yet.
empty_text2 = Add one by clicking on the add button.
empty_synchronize_title = You had some rooms previously listed?
empty_synchronize_text = Try to synchronize them to the new room bookmarking system
empty_synchronize_button = Synchronize
type_room = Type of room
default_room = Standard room
gateway_room = Gateway room
@@ -21,6 +24,7 @@ remove_title = Remove a chatroom
remove_text = You are going to remove the following chatroom. Please confirm your action.
connected = Connected to the chatroom
disconnected = Disconnected from the chatroom
synchronized = "%s rooms synchronized"
users = Users in the room
bad_nickname = Please enter a correct nickname (2 to 40 characters)
conflict = Username already taken
@@ -384,6 +384,13 @@
<xmpp:version>0.2.1</xmpp:version>
</xmpp:SupportedXep>
</implements>
<implements>
<xmpp:SupportedXep>
<xmpp:xep rdf:resource="https://xmpp.org/extensions/xep-0402.html"/>
<xmpp:status>complete</xmpp:status>
<xmpp:version>0.16</xmpp:version>
</xmpp:SupportedXep>
</implements>

<release>
<Version>
@@ -16,60 +16,4 @@ public static function get()
$xml = \Moxl\API::iqWrapper($pubsub, false, 'get');
\Moxl\API::request($xml);
}
public static function set($arr)
{
$dom = new \DOMDocument('1.0', 'UTF-8');
$pubsub = $dom->createElementNS('http://jabber.org/protocol/pubsub', 'pubsub');
$publish = $dom->createElement('publish');
$pubsub->appendChild($publish);
$item = $dom->createElement('item');
$publish->appendChild($item);
$storage = $dom->createElement('storage');
$item->appendChild($storage);
$storage->setAttribute('xmlns', 'storage:bookmarks');
$publish->setAttribute('node', 'storage:bookmarks');
$item->setAttribute('id', 'current');
foreach ($arr as $elt) {
switch ($elt['type']) {
case 'conference':
$conference = $dom->createElement('conference');
$nick = $dom->createElement('nick', $elt['nick']);
$conference->appendChild($nick);
$conference->setAttribute('name', $elt['name']);
if ($elt['autojoin']) {
$conference->setAttribute('autojoin', $elt['autojoin']);
}
$conference->setAttribute('jid', $elt['jid']);
$storage->appendChild($conference);
break;
/*case 'url':
$xml .= '
<url name="'.$elt['name'].'"
url="'.$elt['url'].'"/>';
break;*/
case 'subscription':
$subscription = $dom->createElement('subscription');
$storage->appendChild($subscription);
$subscription->setAttribute('xmlns', 'urn:xmpp:pubsub:subscription:0');
$title = $dom->createElement('title', $elt['title']);
$subscription->appendChild($title);
$subscription->setAttribute('server', $elt['server']);
$subscription->setAttribute('node', $elt['node']);
$subscription->setAttribute('subid', $elt['subid']);
break;
}
}
$xml = \Moxl\API::iqWrapper($pubsub, false, 'set');
\Moxl\API::request($xml);
}
}
@@ -0,0 +1,73 @@
<?php
namespace Moxl\Stanza;
use App\Conference;
class Bookmark2
{
public static function get()
{
$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');
$pubsub->appendChild($items);
$xml = \Moxl\API::iqWrapper($pubsub, false, 'get');
\Moxl\API::request($xml);
}
public static function set(Conference $conf)
{
$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');
$pubsub->appendChild($publish);
$item = $dom->createElement('item');
$item->setAttribute('id', $conf->conference);
$publish->appendChild($item);
$conference = $dom->createElement('conference');
$conference->setAttribute('name', $conf->name);
if ($conf->autojoin) {
$conference->setAttribute('autojoin', 'true');
}
$item->appendChild($conference);
$nick = $dom->createElement('nick', $conf->nick);
$conference->appendChild($nick);
// Publish option
$publishOption = $dom->createElement('publish-option');
$x = $dom->createElement('x');
$x->setAttribute('xmlns', 'jabber:x:data');
$x->setAttribute('type', 'submit');
$publishOption->appendChild($x);
$field = $dom->createElement('field');
$field->setAttribute('var', 'FORM_TYPE');
$field->setAttribute('type', 'hidden');
$field->appendChild($dom->createElement('value', 'http://jabber.org/protocol/pubsub#publish-options'));
$x->appendChild($field);
$field = $dom->createElement('field');
$field->setAttribute('var', 'pubsub#persist_items');
$field->appendChild($dom->createElement('value', 'true'));
$x->appendChild($field);
$field = $dom->createElement('field');
$field->setAttribute('var', 'pubsub#access_model');
$field->appendChild($dom->createElement('value', 'whitelist'));
$x->appendChild($field);
$pubsub->appendChild($publishOption);
$xml = \Moxl\API::iqWrapper($pubsub, false, 'set');
\Moxl\API::request($xml);
}
}

0 comments on commit 2b32cde

Please sign in to comment.
You can’t perform that action at this time.