From 51fd41ebcbfd898799501008cf680b3357fd6131 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaussoin=20Timoth=C3=A9e?= Date: Fri, 24 Apr 2015 17:31:45 +0200 Subject: [PATCH] - Edit the chatroom subject - Add/Delete a group - Manage the browsers with a new session hash in the database - Some CSS fixs --- app/models/message/MessageDAO.php | 4 +- app/models/presence/PresenceDAO.php | 22 +++++++- app/models/sessionx/Sessionx.php | 3 ++ app/models/sessionx/SessionxDAO.php | 25 ++++++++- app/widgets/Chat/Chat.php | 53 +++++++++++++++++-- app/widgets/Chat/_chat_header_room.tpl | 17 ++++--- app/widgets/Chat/_chat_subject.tpl | 21 ++++++++ app/widgets/Chat/chat.js | 7 +++ app/widgets/Chat/locales.ini | 2 + app/widgets/Group/Group.php | 30 +++++++++++ app/widgets/Group/_group_delete.tpl | 18 +++++++ app/widgets/Group/_group_header.tpl | 3 ++ app/widgets/Group/locales.ini | 2 + app/widgets/Groups/Groups.php | 62 +++++++++++++++++++++-- app/widgets/Groups/_groups_add.tpl | 21 ++++++++ app/widgets/Groups/_groups_server.tpl | 3 ++ app/widgets/Groups/locales.ini | 5 ++ app/widgets/Login/Login.php | 5 +- app/widgets/Login/login.js | 8 ++- app/widgets/Post/_post_comments_error.tpl | 2 +- app/widgets/Rooms/Rooms.php | 2 +- app/widgets/Rooms/_rooms_remove.tpl | 2 +- system/Sessionx.php | 10 ++-- themes/material/css/list.css | 2 +- themes/material/css/style.css | 8 ++- 25 files changed, 307 insertions(+), 30 deletions(-) create mode 100644 app/widgets/Chat/_chat_subject.tpl create mode 100644 app/widgets/Group/_group_delete.tpl create mode 100644 app/widgets/Groups/_groups_add.tpl diff --git a/app/models/message/MessageDAO.php b/app/models/message/MessageDAO.php index 40fbad609..6a7a8fbde 100755 --- a/app/models/message/MessageDAO.php +++ b/app/models/message/MessageDAO.php @@ -98,7 +98,9 @@ class MessageDAO extends SQL { $this->_sql = ' select * from message where jidfrom = :jidfrom - and subject != \'\''; + and subject != \'\' + order by published desc + limit 1'; $this->prepare( 'Message', diff --git a/app/models/presence/PresenceDAO.php b/app/models/presence/PresenceDAO.php index 2d70acbb2..769d22a68 100755 --- a/app/models/presence/PresenceDAO.php +++ b/app/models/presence/PresenceDAO.php @@ -122,8 +122,7 @@ class PresenceDAO extends SQL { $this->prepare('Presence'); return $this->run('Presence'); } - - + function getPresence($jid, $resource) { $this->_sql = ' select * from presence @@ -143,6 +142,25 @@ class PresenceDAO extends SQL { return $this->run('Presence', 'item'); } + + function getMyPresenceRoom($jid) { + $this->_sql = ' + select * from presence + where + session = :session + and jid = :jid + and mucjid = :session'; + + $this->prepare( + 'Presence', + array( + 'session' => $this->_user, + 'jid' => $jid, + ) + ); + + return $this->run('Presence', 'item'); + } function getJid($jid) { $this->_sql = ' diff --git a/app/models/sessionx/Sessionx.php b/app/models/sessionx/Sessionx.php index cfa305a07..02b84b927 100755 --- a/app/models/sessionx/Sessionx.php +++ b/app/models/sessionx/Sessionx.php @@ -6,6 +6,7 @@ class Sessionx extends Model { public $session; public $username; public $password; + public $hash; public $resource; public $rid; public $sid; @@ -28,6 +29,8 @@ class Sessionx extends Model { {"type":"string", "size":64 }, "password" : {"type":"string", "size":64 }, + "hash" : + {"type":"string", "size":128 }, "resource" : {"type":"string", "size":64 }, "rid" : diff --git a/app/models/sessionx/SessionxDAO.php b/app/models/sessionx/SessionxDAO.php index b0db2ba5e..d40ec1b8e 100755 --- a/app/models/sessionx/SessionxDAO.php +++ b/app/models/sessionx/SessionxDAO.php @@ -8,7 +8,8 @@ class SessionxDAO extends SQL { update sessionx set username = :username, password = :password, - resource = :resource, + hash = :hash, + resource = :resource, rid = :rid, sid = :sid, id = :id, @@ -28,7 +29,8 @@ class SessionxDAO extends SQL { 'session' => $s->session, 'username' => $s->username, 'password' => $s->password, - 'resource' => $s->resource, + 'hash' => $s->hash, + 'resource' => $s->resource, 'rid' => $s->rid, 'sid' => $s->sid, 'id' => $s->id, @@ -51,6 +53,7 @@ class SessionxDAO extends SQL { (session, username, password, + hash, resource, rid, sid, @@ -67,6 +70,7 @@ class SessionxDAO extends SQL { (:session, :username, :password, + :hash, :resource, :rid, :sid, @@ -86,6 +90,7 @@ class SessionxDAO extends SQL { 'session' => $s->session, 'username' => $s->username, 'password' => $s->password, + 'hash' => $s->hash, 'resource' => $s->resource, 'rid' => $s->rid, 'sid' => $s->sid, @@ -142,6 +147,22 @@ class SessionxDAO extends SQL { return $this->run('Sessionx', 'item'); } + function getHash($hash) { + $this->_sql = ' + select * from sessionx + where + hash = :hash'; + + $this->prepare( + 'Sessionx', + array( + 'hash' => $hash + ) + ); + + return $this->run('Sessionx', 'item'); + } + function getId($session) { $this->_sql = ' select id from sessionx diff --git a/app/widgets/Chat/Chat.php b/app/widgets/Chat/Chat.php index d453887e7..3eda58f8f 100644 --- a/app/widgets/Chat/Chat.php +++ b/app/widgets/Chat/Chat.php @@ -6,6 +6,7 @@ use Moxl\Xec\Action\Message\Publish; use Moxl\Xec\Action\Muc\GetConfig; use Moxl\Xec\Action\Muc\SetConfig; +use Moxl\Xec\Action\Muc\SetSubject; use Respect\Validation\Validator; @@ -21,9 +22,10 @@ class Chat extends WidgetCommon $this->registerEvent('composing', 'onComposing'); $this->registerEvent('paused', 'onPaused'); $this->registerEvent('gone', 'onGone'); - $this->registerEvent('conference_subject', 'onConferenceSubject'); + $this->registerEvent('subject', 'onConferenceSubject'); $this->registerEvent('muc_getconfig_handle', 'onRoomConfig'); $this->registerEvent('muc_setconfig_handle', 'onRoomConfigSaved'); + //$this->registerEvent('muc_setsubject_handle', 'onRoomSubjectChanged'); //$this->registerEvent('presence', 'onPresence'); } @@ -104,9 +106,9 @@ class Chat extends WidgetCommon $this->setState($array, $this->__('message.gone')); } - function onConferenceSubject($message) + function onConferenceSubject($packet) { - $header = $this->prepareHeaderRoom($message->jidfrom); + $header = $this->prepareHeaderRoom($packet->content->jidfrom); Header::fill($header); } @@ -129,7 +131,12 @@ class Chat extends WidgetCommon { Notification::append(false, $this->__('chatroom.config_saved')); } - +/* + function onRoomSubjectChanged($packet) + { + Notification::append(false, $this->__('chatroom.suject_changed')); + } +*/ private function setState($array, $message) { list($from, $to) = $array; @@ -319,6 +326,40 @@ class Chat extends WidgetCommon ->request(); } + /** + * @brief Get the subject form of a chatroom + */ + function ajaxGetSubject($room) + { + if(!$this->validateJid($room)) return; + + $view = $this->tpl(); + + $md = new \Modl\MessageDAO; + $s = $md->getRoomSubject($room); + + $view->assign('room', $room); + $view->assign('subject', $s); + + Dialog::fill($view->draw('_chat_subject', true)); + } + + /** + * @brief Change the subject of a chatroom + */ + function ajaxSetSubject($room, $form) + { + if(!$this->validateJid($room)) return; + + $validate_subject = Validator::string()->length(0, 200); + if(!$validate_subject->validate($form->subject->value)) return; + + $p = new SetSubject; + $p->setTo($room) + ->setSubject($form->subject->value) + ->request(); + } + /** * @brief Prepare the contact header * @@ -358,8 +399,12 @@ class Chat extends WidgetCommon $cd = new \Modl\ConferenceDAO; $c = $cd->get($room); + $pd = new \Modl\PresenceDAO; + $p = $pd->getMyPresenceRoom($room); + $view->assign('room', $room); $view->assign('subject', $s); + $view->assign('presence', $p); $view->assign('conference', $c); return $view->draw('_chat_header_room', true); diff --git a/app/widgets/Chat/_chat_header_room.tpl b/app/widgets/Chat/_chat_header_room.tpl index a4e9d0897..9316bcb72 100644 --- a/app/widgets/Chat/_chat_header_room.tpl +++ b/app/widgets/Chat/_chat_header_room.tpl @@ -37,11 +37,16 @@
  • {$c->__('chatroom.members')}
  • -
  • - {$c->__('button.delete')} -
  • -
  • - {$c->__('chatroom.config')} -
  • + {if="$presence->mucrole == 'moderator'"} +
  • + {$c->__('button.delete')} +
  • +
  • + {$c->__('chatroom.config')} +
  • +
  • + {$c->__('chatroom.subject')} +
  • + {/if} diff --git a/app/widgets/Chat/_chat_subject.tpl b/app/widgets/Chat/_chat_subject.tpl new file mode 100644 index 000000000..fbb6bc576 --- /dev/null +++ b/app/widgets/Chat/_chat_subject.tpl @@ -0,0 +1,21 @@ +
    +
    +

    {$c->__('chatroom.subject')}

    + +
    + + +
    +
    +
    + + {$c->__('button.close')} + + + {$c->__('button.save')} + +
    + + diff --git a/app/widgets/Chat/chat.js b/app/widgets/Chat/chat.js index 5f00b07f3..5bbb607df 100644 --- a/app/widgets/Chat/chat.js +++ b/app/widgets/Chat/chat.js @@ -54,12 +54,19 @@ var Chat = { if(message.type == 'groupchat') { bubble = Chat.room; id = message.jidfrom + '_conversation'; + + if(message.body.match(/^\/me/)) { + bubble.querySelector('div').className = 'quote'; + message.body = message.body.substr(4); + } + bubble.querySelector('div').innerHTML = message.body; bubble.querySelector('span.info').innerHTML = message.published; bubble.querySelector('span.user').className = 'user ' + message.color; bubble.querySelector('span.user').innerHTML = message.resource; movim_append(id, bubble.outerHTML); + bubble.querySelector('div').className = ''; } else { if(message.session == message.jidfrom) { bubble = Chat.right; diff --git a/app/widgets/Chat/locales.ini b/app/widgets/Chat/locales.ini index ad59d2213..1d4ff455e 100644 --- a/app/widgets/Chat/locales.ini +++ b/app/widgets/Chat/locales.ini @@ -17,3 +17,5 @@ chatroom.connected = 'Connected to the chatroom' chatroom.disconnected = 'Disconnected from the chatroom' chatroom.config = 'Configuration' chatroom.config_saved = 'Configuration saved' +chatroom.subject = 'Subject' +chatroom.subject_changed= 'Subject changed' diff --git a/app/widgets/Group/Group.php b/app/widgets/Group/Group.php index 563734465..80982e57e 100755 --- a/app/widgets/Group/Group.php +++ b/app/widgets/Group/Group.php @@ -10,6 +10,8 @@ use Moxl\Xec\Action\Pubsub\Unsubscribe; use Moxl\Xec\Action\Pubsub\GetConfig; use Moxl\Xec\Action\Pubsub\SetConfig; +use Moxl\Xec\Action\Pubsub\Delete; + use Respect\Validation\Validator; class Group extends WidgetCommon @@ -29,6 +31,8 @@ class Group extends WidgetCommon $this->registerEvent('pubsub_getaffiliations_handle', 'onAffiliations'); $this->registerEvent('pubsub_getsubscriptions_handle', 'onSubscriptions'); + $this->registerEvent('pubsub_delete_handle', 'onDelete'); + $this->registerEvent('pubsub_getconfig_handle', 'onConfig'); $this->registerEvent('pubsub_setconfig_handle', 'onConfigSaved'); $this->registerEvent('bookmark_set_handle', 'onBookmark'); @@ -43,6 +47,11 @@ class Group extends WidgetCommon RPC::call('MovimTpl.showPanel'); } + function onDelete($packet) + { + $this->ajaxClear(); + } + function onBookmark() { $this->ajaxClear(); @@ -161,6 +170,27 @@ class Group extends WidgetCommon RPC::call('movim_fill', 'group_widget', $html); } + + function ajaxDelete($server, $node) + { + if(!$this->validateServerNode($server, $node)) return; + + $view = $this->tpl(); + $view->assign('server', $server); + $view->assign('node', $node); + + Dialog::fill($view->draw('_group_delete', true)); + } + + function ajaxDeleteConfirm($server, $node) + { + if(!$this->validateServerNode($server, $node)) return; + + $d = new Delete; + $d->setTo($server)->setNode($node) + ->request(); + } + function ajaxGetMetadata($server, $node) { if(!$this->validateServerNode($server, $node)) return; diff --git a/app/widgets/Group/_group_delete.tpl b/app/widgets/Group/_group_delete.tpl new file mode 100644 index 000000000..0cf097058 --- /dev/null +++ b/app/widgets/Group/_group_delete.tpl @@ -0,0 +1,18 @@ +
    +

    {$c->__('group.delete_title')}

    +
    +

    {$c->__('group.delete_text')}

    +
    +

    {$node}

    +
    +
    + + {$c->__('button.cancel')} + + + {$c->__('button.remove')} + +
    diff --git a/app/widgets/Group/_group_header.tpl b/app/widgets/Group/_group_header.tpl index 47f780c45..979ba3008 100644 --- a/app/widgets/Group/_group_header.tpl +++ b/app/widgets/Group/_group_header.tpl @@ -57,6 +57,9 @@
  • {$c->__('group.subscriptions')}
  • +
  • + {$c->__('button.delete')} +
  • {/if} diff --git a/app/widgets/Group/locales.ini b/app/widgets/Group/locales.ini index b3cd49260..941e997b5 100755 --- a/app/widgets/Group/locales.ini +++ b/app/widgets/Group/locales.ini @@ -10,6 +10,8 @@ group.empty_title = 'Groups' group.empty_text = 'Discover, follow and share' group.empty = 'Something bad happened to this group' group.config_saved = 'Group configuration saved' +group.delete_title = 'Delete the group' +group.delete_text = 'You are going to delete the following group. Please confirm your action.' group.configuration = 'Configuration' group.subscriptions = 'Subscriptions' diff --git a/app/widgets/Groups/Groups.php b/app/widgets/Groups/Groups.php index 5b15557d1..c158388ac 100644 --- a/app/widgets/Groups/Groups.php +++ b/app/widgets/Groups/Groups.php @@ -3,6 +3,7 @@ use Moxl\Xec\Action\Pubsub\GetItems; use Moxl\Xec\Action\Pubsub\DiscoItems; use Respect\Validation\Validator; +use Moxl\Xec\Action\Pubsub\Create; class Groups extends WidgetCommon { @@ -12,6 +13,8 @@ class Groups extends WidgetCommon { $this->registerEvent('pubsub_discoitems_handle', 'onDisco'); $this->registerEvent('pubsub_discoitems_error', 'onDiscoError'); + $this->registerEvent('pubsub_create_handle', 'onCreate'); + $this->registerEvent('pubsub_delete_handle', 'onDelete'); $this->addjs('groups.js'); } @@ -21,6 +24,22 @@ class Groups extends WidgetCommon $this->displayServer($server); } + function onCreate($packet) + { + Notification::append(null, $this->__('groups.created')); + + list($server, $node) = array_values($packet->content); + $this->ajaxDisco($server); + } + + function onDelete($packet) + { + Notification::append(null, $this->__('groups.deleted')); + + list($server, $node) = array_values($packet->content); + $this->displayServer($server); + } + function onDiscoError($packet) { // Display a nice error @@ -47,17 +66,39 @@ class Groups extends WidgetCommon function ajaxDisco($server) { - $validate_server = Validator::string()->noWhitespace()->length(6, 40); - if(!$validate_server->validate($server)) return; - + if(!$this->validateServer($server)) return; + $r = new DiscoItems; $r->setTo($server)->request(); } + function ajaxAdd($server) + { + if(!$this->validateServer($server)) return; + + $view = $this->tpl(); + $view->assign('server', $server); + + Dialog::fill($view->draw('_groups_add', true)); + } + + function ajaxAddConfirm($server, $form) + { + if(!$this->validateServer($server)) return; + + $validate_name = Validator::string()->length(6, 80); + if(!$validate_name->validate($form->name->value)) return; + + $uri = stringToUri($form->name->value); + + $c = new Create; + $c->setTo($server)->setNode($uri)->setData($form->name->value) + ->request(); + } + private function displayServer($server) { - $validate_server = Validator::string()->noWhitespace()->length(6, 40); - if(!$validate_server->validate($server)) return; + if(!$this->validateServer($server)) return; $html = $this->prepareServer($server); @@ -108,6 +149,17 @@ class Groups extends WidgetCommon } return $servers; } + /** + * @brief Validate the server + * + * @param string $server + */ + private function validateServer($server) + { + $validate_server = Validator::string()->noWhitespace()->length(6, 40); + if(!$validate_server->validate($server)) return false; + else return true; + } function display() { diff --git a/app/widgets/Groups/_groups_add.tpl b/app/widgets/Groups/_groups_add.tpl new file mode 100644 index 000000000..e5011285d --- /dev/null +++ b/app/widgets/Groups/_groups_add.tpl @@ -0,0 +1,21 @@ +
    + +

    {$c->__('groups.add')}

    + +
    + + +
    +
    +
    + + {$c->__('button.close')} + + + {$c->__('button.add')} + +
    + + diff --git a/app/widgets/Groups/_groups_server.tpl b/app/widgets/Groups/_groups_server.tpl index 97a8fca1a..019077307 100644 --- a/app/widgets/Groups/_groups_server.tpl +++ b/app/widgets/Groups/_groups_server.tpl @@ -37,3 +37,6 @@ {/loop} + + + diff --git a/app/widgets/Groups/locales.ini b/app/widgets/Groups/locales.ini index 1e26c644e..938e96e91 100644 --- a/app/widgets/Groups/locales.ini +++ b/app/widgets/Groups/locales.ini @@ -3,6 +3,11 @@ groups.contact_post = 'Contact post' groups.empty_text1 = "You don't have any subscriptions yet, select a group server above to start exploring." groups.empty_text2 = "Subscribe to your favorite feeds by bookmarking them." groups.subscriptions = 'My Subscriptions' +groups.add = 'Create a new Group' +groups.name = 'Group name' +groups.name_example = 'My Little Pony - Fan Club' +groups.created = 'Group created successfully' +groups.deleted = 'Group deleted successfully' groups.sub = '%s subscribers' groups.num = '%s posts' diff --git a/app/widgets/Login/Login.php b/app/widgets/Login/Login.php index 9d2e3c2b7..8527e9a32 100755 --- a/app/widgets/Login/Login.php +++ b/app/widgets/Login/Login.php @@ -188,9 +188,12 @@ class Login extends WidgetBase // We check if we already have an open session $sd = new \Modl\SessionxDAO; - $here = $sd->checkConnected($username, $host); + //$here = $sd->checkConnected($username, $host); + $here = $sd->getHash(sha1($username.$password.$host)); if($here) { + RPC::call('Login.setCookie', $here->session); + RPC::call('movim_redirect', Route::urlize('main')); $this->showErrorBlock('conflict'); return; } diff --git a/app/widgets/Login/login.js b/app/widgets/Login/login.js index 9a1637377..dacdc9ba4 100755 --- a/app/widgets/Login/login.js +++ b/app/widgets/Login/login.js @@ -122,8 +122,14 @@ var Login = { Login.rememberSession(jid); localStorage.postStart = 1; movim_reload(url); - } + }, + /** + * @brief Set the Movim cookie + */ + setCookie : function(value) { + document.cookie = 'MOVIM_SESSION_ID='+value; + } } MovimWebsocket.attach(function() diff --git a/app/widgets/Post/_post_comments_error.tpl b/app/widgets/Post/_post_comments_error.tpl index 22c40d1a8..ede766810 100644 --- a/app/widgets/Post/_post_comments_error.tpl +++ b/app/widgets/Post/_post_comments_error.tpl @@ -1,4 +1,4 @@ -