diff --git a/app/assets/js/movim_tpl.js b/app/assets/js/movim_tpl.js index 4e8e644a3..8f5d7aed9 100755 --- a/app/assets/js/movim_tpl.js +++ b/app/assets/js/movim_tpl.js @@ -74,7 +74,6 @@ var MovimTpl = { //else document.querySelector(selector).innerHTML = ''; }, fill : function(selector, html) { - console.log(selector); target = document.querySelector(selector); if(target) { target.innerHTML = html; diff --git a/app/models/message/Message.php b/app/models/message/Message.php index c74fe1e03..e6f5bc2b4 100755 --- a/app/models/message/Message.php +++ b/app/models/message/Message.php @@ -21,7 +21,8 @@ class Message extends Model { public $color; // Only for chatroom purpose - public function __construct() { + public function __construct() + { $this->_struct = ' { "session" : @@ -50,4 +51,40 @@ class Message extends Model { parent::__construct(); } + + public function set($stanza, $parent = false) + { + if($stanza->body || $stanza->subject) { + $jid = explode('/',(string)$stanza->attributes()->from); + $to = current(explode('/',(string)$stanza->attributes()->to)); + + // This is not very beautiful + $user = new \User; + $this->session = $user->getLogin(); + + $this->jidto = $to; + $this->jidfrom = $jid[0]; + + if(isset($jid[1])) + $this->resource = $jid[1]; + + $this->type = (string)$stanza->attributes()->type; + + $this->body = (string)$stanza->body; + $this->subject = (string)$stanza->subject; + + if($stanza->html) { + $this->html = \cleanHTMLTags($stanza->html->body->asXML()); + $this->html = \fixSelfClosing($m->html); + } + + if($stanza->delay) + $this->published = gmdate('Y-m-d H:i:s', strtotime($stanza->delay->attributes()->stamp)); + elseif($parent && $parent->delay) + $this->published = gmdate('Y-m-d H:i:s', strtotime($parent->delay->attributes()->stamp)); + else + $this->published = gmdate('Y-m-d H:i:s'); + $this->delivered = gmdate('Y-m-d H:i:s'); + } + } } diff --git a/app/models/message/MessageDAO.php b/app/models/message/MessageDAO.php index 07a1003e5..a6d226b19 100755 --- a/app/models/message/MessageDAO.php +++ b/app/models/message/MessageDAO.php @@ -35,7 +35,7 @@ class MessageDAO extends SQL { $this->prepare( 'Message', array( - 'session' => $this->_user, + 'session' => $message->session, 'jidto' => $message->jidto, 'jidfrom' => $message->jidfrom, 'resource' => $message->resource, diff --git a/app/widgets/Api/Api.php b/app/widgets/Api/Api.php index c5d4c191a..dbf47aa5c 100755 --- a/app/widgets/Api/Api.php +++ b/app/widgets/Api/Api.php @@ -65,7 +65,7 @@ class Api extends WidgetBase { array( 'uri' => BASE_URI, 'rewrite' => $rewrite)); - \movim_log($json); + $json = json_decode($json); if(isset($json) && $json->status == 200) { diff --git a/app/widgets/Chat/Chat.php b/app/widgets/Chat/Chat.php index 7122cbf8b..f60878a48 100644 --- a/app/widgets/Chat/Chat.php +++ b/app/widgets/Chat/Chat.php @@ -19,6 +19,7 @@ class Chat extends WidgetBase $this->addcss('chat.css'); $this->registerEvent('carbons', 'onMessage'); $this->registerEvent('message', 'onMessage'); + $this->registerEvent('mamresult', 'onMessageHistory'); $this->registerEvent('composing', 'onComposing'); $this->registerEvent('paused', 'onPaused'); $this->registerEvent('gone', 'onGone'); @@ -48,13 +49,18 @@ class Chat extends WidgetBase } } }*/ + + function onMessageHistory($packet) + { + $this->onMessage($packet, true); + } - function onMessage($packet, $mine = false) + function onMessage($packet, $history = false) { $message = $packet->content; $cd = new \Modl\ContactDAO; - if($message->session == $message->jidto) { + if($message->session == $message->jidto && !$history) { $from = $message->jidfrom; $contact = $cd->getRosterItem($from); @@ -71,21 +77,17 @@ class Chat extends WidgetBase RPC::call('movim_fill', $from.'_state', ''); // If the message is from me - } else { + } /*else { $from = $message->jidto; $contact = $cd->get(); - } + }* $me = $cd->get(); if($me == null) { $me = new \Modl\Contact; - } + }*/ - if(preg_match('#^\?OTR#', $message->body)) { - if(!$mine) { - //RPC::call('ChatOTR.receiveMessage', $message->body); - } - } else { + if(!preg_match('#^\?OTR#', $message->body)) { RPC::call('Chat.appendMessage', $this->prepareMessage($message)); } RPC::call('MovimTpl.scrollPanel'); @@ -174,13 +176,16 @@ class Chat extends WidgetBase /** * @brief Get a discussion - * @parem string $jid + * @param string $jid */ function ajaxGet($jid = null) { if($jid == null) { RPC::call('movim_fill', 'chat_widget', $this->prepareEmpty()); } else { + $chats = new Chats; + $chats->ajaxGetHistory($jid); + $html = $this->prepareChat($jid); $header = $this->prepareHeader($jid); @@ -196,7 +201,7 @@ class Chat extends WidgetBase /** * @brief Get a chatroom - * @parem string $jid + * @param string $jid */ function ajaxGetRoom($room) { @@ -260,7 +265,7 @@ class Chat extends WidgetBase /* Is it really clean ? */ $packet = new Moxl\Xec\Payload\Packet; $packet->content = $m; - $this->onMessage($packet, true); + $this->onMessage($packet/*, true*/); if($resource != false) { $to = $to . '/' . $resource; diff --git a/app/widgets/Chat/chat.js b/app/widgets/Chat/chat.js index 5bbb607df..c5055b73b 100644 --- a/app/widgets/Chat/chat.js +++ b/app/widgets/Chat/chat.js @@ -48,6 +48,8 @@ var Chat = { appendMessage : function(message) { if(message.body == '') return; + + console.log(message); var bubble = null; var id = null; diff --git a/app/widgets/Chats/Chats.php b/app/widgets/Chats/Chats.php index f411ba0ad..f64cc67cc 100644 --- a/app/widgets/Chats/Chats.php +++ b/app/widgets/Chats/Chats.php @@ -59,6 +59,26 @@ class Chats extends WidgetBase } } + /** + * @brief Get history + */ + function ajaxGetHistory($jid) + { + if(!$this->validateJid($jid)) return; + + $md = new \Modl\MessageDAO(); + $messages = $md->getContact(echapJid($jid), 0, 1); + + $g = new \Moxl\Xec\Action\MAM\Get; + $g->setJid($jid); + + if(!empty($messages)) { + $g->setStart(strtotime($messages[0]->published)); + } + + $g->request(); + } + function ajaxOpen($jid) { if(!$this->validateJid($jid)) return; @@ -66,21 +86,25 @@ class Chats extends WidgetBase $chats = Cache::c('chats'); if($chats == null) $chats = array(); + unset($chats[$jid]); + if(!array_key_exists($jid, $chats) && $jid != $this->user->getLogin()) { $chats[$jid] = 1; - } else { - unset($chats[$jid]); - } - $chats[$jid] = 1; + $this->ajaxGetHistory($jid); - Cache::c('chats', $chats); + Cache::c('chats', $chats); - RPC::call('movim_delete', $jid.'_chat_item'); + RPC::call('movim_delete', $jid.'_chat_item'); - RPC::call('movim_prepend', 'chats_widget_list', $this->prepareChat($jid)); - RPC::call('Chats.refresh'); + RPC::call('movim_prepend', 'chats_widget_list', $this->prepareChat($jid)); + RPC::call('Chats.refresh'); + }/* else { + unset($chats[$jid]); + } + + $chats[$jid] = 1;*/ } function ajaxClose($jid) diff --git a/app/widgets/Group/Group.php b/app/widgets/Group/Group.php index 1cffede60..7cde0ed7e 100755 --- a/app/widgets/Group/Group.php +++ b/app/widgets/Group/Group.php @@ -403,5 +403,11 @@ class Group extends WidgetBase function display() { + $this->view->assign('server', false); + $this->view->assign('node', false); + if($this->validateServerNode($this->get('s'), $this->get('n'))) { + $this->view->assign('server', $this->get('s')); + $this->view->assign('node', $this->get('n')); + } } } diff --git a/app/widgets/Group/group.tpl b/app/widgets/Group/group.tpl index 170104f82..50a72707f 100755 --- a/app/widgets/Group/group.tpl +++ b/app/widgets/Group/group.tpl @@ -1,3 +1,12 @@
{$c->prepareEmpty()} + {if="$server && $node"} + + {/if}
diff --git a/app/widgets/Groups/_groups_subscriptions.tpl b/app/widgets/Groups/_groups_subscriptions.tpl index 65fd6283a..ca471ece5 100644 --- a/app/widgets/Groups/_groups_subscriptions.tpl +++ b/app/widgets/Groups/_groups_subscriptions.tpl @@ -18,6 +18,7 @@ {if="$value->description"}class="condensed"{/if} data-server="{$value->server}" data-node="{$value->node}" + title="{$value->server} - {$value->node}" > {$value->node|firstLetterCapitalize} diff --git a/app/widgets/Notification/notification.js b/app/widgets/Notification/notification.js index aa4baf2f1..9d409c80e 100755 --- a/app/widgets/Notification/notification.js +++ b/app/widgets/Notification/notification.js @@ -131,7 +131,7 @@ document.onfocus = function() { Notification_ajaxClear(Notification.notifs_key); } -/* + window.addEventListener('load', function () { DesktopNotification.requestPermission(function (status) { // This allows to use Notification.permission with Chrome/Safari @@ -140,4 +140,3 @@ window.addEventListener('load', function () { } }); }); -*/ diff --git a/app/widgets/Post/Post.php b/app/widgets/Post/Post.php index 70235be5b..514d26193 100644 --- a/app/widgets/Post/Post.php +++ b/app/widgets/Post/Post.php @@ -62,17 +62,20 @@ class Post extends WidgetBase function onComments($packet) { - $nodeid = $packet->content; + list($server, $node, $id) = array_values($packet->content); $p = new \Modl\ContactPostn(); - $p->nodeid = $nodeid; + $p->nodeid = $id; $pd = new \Modl\PostnDAO(); $comments = $pd->getComments($p); $view = $this->tpl(); $view->assign('comments', $comments); - $view->assign('id', $nodeid); + $view->assign('server', $server); + $view->assign('node', $node); + $view->assign('id', $id); + $html = $view->draw('_post_comments', true); RPC::call('movim_fill', 'comments', $html); } @@ -120,14 +123,17 @@ class Post extends WidgetBase } function ajaxGetComments($jid, $id) - { + { + $pd = new \Modl\PostnDAO(); + $pd->deleteNode($jid, "urn:xmpp:microblog:0:comments/".$id); + $c = new CommentsGet; $c->setTo($jid) ->setId($id) ->request(); } - function ajaxPublishComment($form, $id) + function ajaxPublishComment($form, $to, $node, $id) { $comment = trim($form->comment->value); @@ -139,10 +145,10 @@ class Post extends WidgetBase $cp = new CommentPublish; $cp->setTo($to) - ->setFrom($this->user->getLogin()) - ->setParentId($id) - ->setContent(htmlspecialchars(rawurldecode($comment))) - ->request(); + ->setFrom($this->user->getLogin()) + ->setParentId($id) + ->setContent(htmlspecialchars(rawurldecode($comment))) + ->request(); } function prepareEmpty() @@ -183,6 +189,17 @@ class Post extends WidgetBase if(isset($p->commentplace)) { $this->ajaxGetComments($p->commentplace, $p->nodeid); } + + $view->assign('recycled', false); + + // Is it a recycled post ? + if($p->getContact()->jid + && $p->node == 'urn:xmpp:microblog:0' + && ($p->origin != $p->getContact()->jid)) { + $cd = new \Modl\ContactDAO; + $view->assign('recycled', $cd->get($p->origin)); + } + $view->assign('post', $p); $view->assign('attachements', $p->getAttachements()); return $view->draw('_post', true); @@ -190,6 +207,7 @@ class Post extends WidgetBase return $this->prepareEmpty(); } } + function ajaxTogglePrivacy($id) { $validate = Validator::string()->length(6, 128); diff --git a/app/widgets/Post/_post.tpl b/app/widgets/Post/_post.tpl index 909709ddf..17e2f64d4 100644 --- a/app/widgets/Post/_post.tpl +++ b/app/widgets/Post/_post.tpl @@ -10,32 +10,47 @@