Browse Source

- Merge with edhelas

pull/16/head
Jaussoin Timothée 11 years ago
parent
commit
014f31c50e
  1. 1
      app/assets/js/movim_tpl.js
  2. 39
      app/models/message/Message.php
  3. 2
      app/models/message/MessageDAO.php
  4. 2
      app/widgets/Api/Api.php
  5. 31
      app/widgets/Chat/Chat.php
  6. 2
      app/widgets/Chat/chat.js
  7. 40
      app/widgets/Chats/Chats.php
  8. 6
      app/widgets/Group/Group.php
  9. 9
      app/widgets/Group/group.tpl
  10. 1
      app/widgets/Groups/_groups_subscriptions.tpl
  11. 3
      app/widgets/Notification/notification.js
  12. 36
      app/widgets/Post/Post.php
  13. 74
      app/widgets/Post/_post.tpl
  14. 2
      app/widgets/Post/_post_comments.tpl
  15. 2
      app/widgets/Post/locales.ini
  16. 15
      src/Movim/Daemon/Session.php
  17. 2
      system/Route.php

1
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;

39
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');
}
}
}

2
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,

2
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) {

31
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;

2
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;

40
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)

6
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'));
}
}
}

9
app/widgets/Group/group.tpl

@ -1,3 +1,12 @@
<div id="group_widget" class="divided spinner">
{$c->prepareEmpty()}
{if="$server && $node"}
<script type="text/javascript">
MovimWebsocket.attach(function() {
Group_ajaxGetItems('{$server}', '{$node}');
Group_ajaxGetMetadata('{$server}', '{$node}');
Group_ajaxGetAffiliations('{$server}', '{$node}');
});
</script>
{/if}
</div>

1
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}"
>
<span class="icon bubble color {$value->node|stringToColor}">{$value->node|firstLetterCapitalize}</span>
<span>

3
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 () {
}
});
});
*/

36
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);

74
app/widgets/Post/_post.tpl

@ -10,32 +10,47 @@
<header>
<ul class="thick">
<li class="condensed">
{if="$recycled"}
{$contact = $recycled}
{else}
{$contact = $post->getContact()}
{/if}
{if="$post->node == 'urn:xmpp:microblog:0'"}
<a href="{$c->route('contact', $post->getContact()->jid)}">
{$url = $post->getContact()->getPhoto('s')}
<a href="{$c->route('contact', $contact->jid)}">
{$url = $contact->getPhoto('s')}
{if="$url"}
<span class="icon bubble">
<img src="{$url}">
</span>
{else}
<span class="icon bubble color {$post->getContact()->jid|stringToColor}">
<span class="icon bubble color {$contact->jid|stringToColor}">
<i class="md md-person"></i>
</span>
{/if}
</a>
{else}
<span class="icon bubble color {$post->node|stringToColor}">{$post->node|firstLetterCapitalize}</span>
<a href="{$c->route('group', array($post->origin, $post->node))}">
<span class="icon bubble color {$post->node|stringToColor}">{$post->node|firstLetterCapitalize}</span>
</a>
{/if}
<span {if="$post->title != null"}title="{$post->title|strip_tags}"{/if}>
<h2 {if="$post->title != null"}title="{$post->title|strip_tags}"{/if}>
{if="$post->title != null"}
{$post->title}
{else}
{$c->__('post.default_title')}
{/if}
</span>
</h2>
<p>
{if="$post->node == 'urn:xmpp:microblog:0' && $post->getContact()->getTrueName() != ''"}
<a href="{$c->route('contact', $post->getContact()->jid)}">{$post->getContact()->getTrueName()}</a> -
{if="$contact->getTrueName() != ''"}
<a href="{$c->route('contact', $contact->jid)}">
<i class="md md-person"></i> {$contact->getTrueName()}
</a> –
{/if}
{if="$post->node != 'urn:xmpp:microblog:0'"}
<a href="{$c->route('group', array($post->origin, $post->node))}">
<i class="md md-pages"></i> {$post->node}
</a> –
{/if}
{$post->published|strtotime|prepareDate}
</p>
@ -51,14 +66,16 @@
<ul class="middle divided spaced">
{if="isset($attachements.links)"}
{loop="$attachements.links"}
<li>
<span class="icon">
<img src="http://icons.duckduckgo.com/ip2/{$value.url.host}.ico"/>
</span>
<a href="{$value.href}" class="alternate" target="_blank">
<span>{$value.href|urldecode}</span>
</a>
</li>
{if="substr($value.href, 0, 5) != 'xmpp:'"}
<li>
<span class="icon">
<img src="http://icons.duckduckgo.com/ip2/{$value.url.host}.ico"/>
</span>
<a href="{$value.href}" class="alternate" target="_blank">
<span>{$value.href|urldecode}</span>
</a>
</li>
{/if}
{/loop}
{/if}
{if="isset($attachements.files)"}
@ -123,5 +140,30 @@
{/if}
</footer>
{if="$recycled"}
<a href="{$c->route('contact', $post->getContact()->jid)}">
<ul class="active middle">
<li class="condensed action">
<div class="action">
<i class="md md-chevron-right"></i>
</div>
{$url = $post->getContact()->getPhoto('s')}
{if="$url"}
<span class="icon bubble" style="background-image: url('{$url}');">
<i class="md md-loop"></i>
</span>
{else}
<span class="icon bubble color {$post->getContact()->jid|stringToColor}">
<i class="md md-loop"></i>
</span>
{/if}
<span>{$c->__('post.repost', $post->getContact()->getTrueName())}</span>
<p>{$c->__('post.repost_profile', $post->getContact()->getTrueName())}</p>
</li>
</ul>
</a>
{/if}
<div id="comments"></div>
</article>

2
app/widgets/Post/_post_comments.tpl

@ -29,7 +29,7 @@
</li>
{/loop}
<li class="action">
<div class="action" onclick="Post_ajaxPublishComment(movim_form_to_json('comment'),'{$id}')">
<div class="action" onclick="Post_ajaxPublishComment(movim_form_to_json('comment'),'{$server}', '{$node}', '{$id}')">
<i class="md md-send"></i>
</div>
<span class="icon gray">

2
app/widgets/Post/locales.ini

@ -17,6 +17,8 @@ post.gallery = 'This picture will be added to your gallery'
post.hot = "What's Hot"
post.new = 'New post'
post.embed_tip = 'You can also use services like Imgur or Flickr to host your picture and paste the link here.'
post.repost = 'This is a re-post from %s'
post.repost_profile = 'See %s profile'
[manage]
post.public = 'Publish this post on your public feed?'

15
src/Movim/Daemon/Session.php

@ -4,13 +4,13 @@ namespace Movim\Daemon;
use Ratchet\ConnectionInterface;
class Session {
protected $clients;
public $timestamp;
protected $sid;
protected $baseuri;
public $process;
protected $clients;
public $timestamp;
protected $sid;
protected $baseuri;
public $process;
protected $buffer;
protected $buffer;
public function __construct($loop, $sid, $baseuri)
{
@ -72,6 +72,9 @@ class Session {
echo colorize($this->sid, 'yellow'). " : ".colorize("linker killed \n", 'red');
$me->process = null;
$me->closeAll();
$sd = new \Modl\SessionxDAO;
$sd->delete($this->sid);
});
// Debug only, if the linker output some errors

2
system/Route.php

@ -15,7 +15,7 @@ class Route extends \BaseController {
'contact' => array('f'),
'disconnect' => array('err'),
'feed' => array('f'),
'group' => array('g'),
'group' => array('s', 'n'),
'help' => false,
'infos' => false,
'login' => array('err'),

Loading…
Cancel
Save