Browse Source

Cleanup Chat and fix an initialisation problem

pull/317/head
Timothée Jaussoin 9 years ago
parent
commit
ba589dd238
  1. 84
      app/widgets/Chat/Chat.php
  2. 10
      app/widgets/Chat/chat.js
  3. 1
      app/widgets/Chats/chats.js

84
app/widgets/Chat/Chat.php

@ -19,8 +19,7 @@ use Movim\Picture;
class Chat extends \Movim\Widget\Base
{
private $_pagination = 30;
private $_wrapper = array();
private $_msgMap = array();
private $_wrapper = [];
function load()
{
@ -206,7 +205,7 @@ class Chat extends \Movim\Widget\Base
RPC::call('MovimUtils.addClass', '#chat_widget', 'fixed');
RPC::call('MovimTpl.fill', '#chat_widget', $html);
RPC::call('MovimTpl.showPanel');
RPC::call('Chat.focus');
RPC::call('Chat.focus', $jid);
$this->prepareMessages($jid);
}
@ -264,13 +263,14 @@ class Chat extends \Movim\Widget\Base
* @param string $message
* @return void
*/
function ajaxSendMessage($to, $message, $muc = false, $resource = false, $replace = false) {
function ajaxSendMessage($to, $message, $muc = false, $resource = false, $replace = false)
{
$body = trim(rawurldecode($message));
if($body == '' || $body == '/me')
return;
$m = new \Modl\Message();
$m = new \Modl\Message;
$m->session = $this->user->getLogin();
$m->jidto = echapJid($to);
$m->jidfrom = $this->user->getLogin();
@ -298,46 +298,41 @@ class Chat extends \Movim\Widget\Base
}
$m->body = $body;
//$promise = $m->checkPicture();
//$promise->done(function() use ($m, $to, $muc, $resource, $replace) {
//$m->html = prepareString($m->body, false, true);
if($resource != false) {
$to = $to . '/' . $resource;
}
// We decode URL codes to send the correct message to the XMPP server
$p = new Publish;
$p->setTo($to);
//$p->setHTML($m->html);
$p->setContent($m->body);
if($resource != false) {
$to = $to . '/' . $resource;
}
if($replace != false) {
$p->setId($m->newid);
$p->setReplace($m->id);
} else {
$p->setId($m->id);
}
// We decode URL codes to send the correct message to the XMPP server
$p = new Publish;
$p->setTo($to);
//$p->setHTML($m->html);
$p->setContent($m->body);
if($muc) {
$p->setMuc();
}
if($replace != false) {
$p->setId($m->newid);
$p->setReplace($m->id);
} else {
$p->setId($m->id);
}
$p->request();
if($muc) {
$p->setMuc();
}
/* Is it really clean ? */
if(!$p->getMuc()) {
if(!preg_match('#^\?OTR#', $m->body)) {
$md = new \Modl\MessageDAO;
$md->set($m);
}
$p->request();
$packet = new Moxl\Xec\Payload\Packet;
$packet->content = $m;
$this->onMessage($packet/*, true*/);
/* Is it really clean ? */
if(!$p->getMuc()) {
if(!preg_match('#^\?OTR#', $m->body)) {
$md = new \Modl\MessageDAO;
$md->set($m);
}
//});
$packet = new \Moxl\Xec\Payload\Packet;
$packet->content = $m;
$this->onMessage($packet);
}
}
/**
@ -415,17 +410,11 @@ class Chat extends \Movim\Widget\Base
foreach($messages as $message) {
if(!preg_match('#^\?OTR#', $message->body)) {
//RPC::call('Chat.appendMessage', $this->prepareMessage($message), true);
//$this->_msgMap[$message->published.$message->jid] = $message;
$this->prepareMessage($message);
}
}
//foreach($this->_msgMap as $message)
// $this->prepareMessage($message);
RPC::call('Chat.appendMessagesWrapper', $this->_wrapper, true);
$this->_wrapper = array();
//RPC::call('Chat.cleanBubbles');
$this->_wrapper = [];
}
}
@ -641,10 +630,11 @@ class Chat extends \Movim\Widget\Base
//fillup $wrapper
if ($message->body != "") {
if (!array_key_exists($date, $this->_wrapper))
if (!array_key_exists($date, $this->_wrapper)) {
$this->_wrapper[$date] = [$message];
else
} else {
array_push($this->_wrapper[$date], $message);
}
}
$pd = new \Modl\PresenceDAO;

10
app/widgets/Chat/chat.js

@ -26,8 +26,12 @@ var Chat = {
}
},
focus: function()
focus: function(jid)
{
if(jid) {
document.querySelector('#chat_widget').dataset.jid = jid;
}
var textarea = document.querySelector('#chat_textarea');
setTimeout(function() {
@ -134,6 +138,7 @@ var Chat = {
if(discussion.dataset.muc != true) {
if(this.scrollTop < 1) {
var chat = document.querySelector('#chat_widget');
console.log(chat.dataset);
Chat_ajaxGetHistory(chat.dataset.jid, Chat.date);
}
}
@ -265,6 +270,7 @@ var Chat = {
var msg = bubble.querySelector('div.bubble > div');
var span = msg.getElementsByTagName('span')[0];
var p = msg.getElementsByTagName('p')[0];
for(var i = 0, len = data.length; i < len; ++i) {
// If there is already a msg in this bubble, create another div (next msg or replacement)
if (bubble.querySelector('div.bubble p')
@ -284,6 +290,7 @@ var Chat = {
// Remove "/me " from beginning of body
data[i].body = data[i].body.substr(4);
}
if (data[i].id != null) {
msg.setAttribute("id", data[i].id);
if (data[i].newid != null)
@ -297,7 +304,6 @@ var Chat = {
p.innerHTML = data[i].body.replace(/\r\n?|\n/g, '<br />');
}
if (data[i].edited) {
span.appendChild(Chat.getEditedIcoHtml());
}

1
app/widgets/Chats/chats.js

@ -16,7 +16,6 @@ var Chats = {
MovimUtils.removeClassInList('active', items);
Notification_ajaxClear('chat|' + this.dataset.jid);
Notification.current('chat|' + this.dataset.jid);
document.querySelector('#chat_widget').dataset.jid = this.dataset.jid;
MovimUtils.addClass(this, 'active');
};

Loading…
Cancel
Save