Browse Source

Fix messages handling in Chat widget

pull/617/head
Timothée Jaussoin 8 years ago
parent
commit
04ca0b6b0b
  1. 8
      app/Message.php
  2. 15
      app/widgets/Chat/Chat.php
  3. 6
      app/widgets/Chat/_chat.tpl
  4. 8
      app/widgets/Chat/chat.js
  5. 9
      app/widgets/Stickers/Stickers.php
  6. 1
      database/migrations/20180327203201_create_messages_table.php

8
app/Message.php

@ -107,11 +107,7 @@ class Message extends Model
$this->body = trim(html_entity_decode($this->body));
}
if ($stanza->markable) {
$this->markable = true;
} else {
$this->markable = false;
}
$this->markable = (bool)($stanza->markable);
if ($stanza->subject) {
$this->subject = (string)$stanza->subject;
@ -211,6 +207,8 @@ class Message extends Model
if ($stanza->replace
&& $this->user->messages()->where('id', $this->id)->count() == 0) {
$this->oldid = (string)$stanza->replace->attributes()->id;
$this->edited = true;
Message::where('id', (string)$stanza->replace->attributes()->id)->update([
'id' => $this->id,
'edited' => true

15
app/widgets/Chat/Chat.php

@ -375,10 +375,6 @@ class Chat extends \Movim\Widget\Base
/* Is it really clean ? */
if (!$p->getMuc()) {
/*if (!$m->isOTR()) {
$md = new \Modl\MessageDAO;
$md->set($m);
}*/
$m->save();
$m->oldid = $oldid;
@ -525,7 +521,7 @@ class Chat extends \Movim\Widget\Base
/**
* @brief Get the subject form of a chatroom
*/
function ajaxGetSubject($room)
/*function ajaxGetSubject($room)
{
if (!$this->validateJid($room)) return;
@ -538,12 +534,12 @@ class Chat extends \Movim\Widget\Base
$view->assign('subject', $s);
Dialog::fill($view->draw('_chat_subject', true));
}
}*/
/**
* @brief Change the subject of a chatroom
*/
function ajaxSetSubject($room, $form)
/*function ajaxSetSubject($room, $form)
{
if (!$this->validateJid($room)) return;
@ -554,7 +550,7 @@ class Chat extends \Movim\Widget\Base
$p->setTo($room)
->setSubject($form->subject->value)
->request();
}
}*/
/**
* @brief Set last displayed message
@ -610,12 +606,11 @@ class Chat extends \Movim\Widget\Base
$view->assign('info', $info);
if ($muc) {
$md = new \Modl\MessageDAO;
$cd = new \Modl\ConferenceDAO;
$pd = new \Modl\PresenceDAO;
$view->assign('room', $jid);
$view->assign('subject', $md->getRoomSubject($jid));
//$view->assign('subject', $md->getRoomSubject($jid));
$view->assign('conference', $this->user->session->conferences
->where('conference', $jid)
->first());

6
app/widgets/Chat/_chat.tpl

@ -63,12 +63,12 @@
<ul class="list context_menu active">
{if="$conference->presence && $conference->presence->mucrole == 'moderator' && !$anon"}
<li onclick="Chat_ajaxGetRoomConfig('{$room}')">
<li class="divided" onclick="Chat_ajaxGetRoomConfig('{$room}')">
<p class="normal">{$c->__('chatroom.administration')}</p>
</li>
<li class="divided" onclick="Chat_ajaxGetSubject('{$room}')">
<!--<li class="divided" onclick="Chat_ajaxGetSubject('{$room}')">
<p class="normal">{$c->__('chatroom.subject')}</p>
</li>
</li>-->
{/if}
{if="!$anon"}
<li onclick="Rooms_ajaxRemoveConfirm('{$room}')">

8
app/widgets/Chat/chat.js

@ -373,8 +373,8 @@ var Chat = {
if (msgStack != null
&& msgStack.parentNode == refBubble
&& data.file === null
&& data.sticker === null
&& (data.file === undefined || data.file === null)
&& (data.sticker === undefined || data.sticker === null)
&& !refBubble.querySelector('div.bubble').classList.contains('sticker')
&& !refBubble.querySelector('div.bubble').classList.contains('file')
){
@ -465,6 +465,10 @@ var Chat = {
msg.appendChild(span);
var elem = document.getElementById(data.oldid);
if (!elem) {
elem = document.getElementById(data.id);
}
if (elem) {
elem.parentElement.replaceChild(msg, elem);
mergeMsg = true;

9
app/widgets/Stickers/Stickers.php

@ -57,10 +57,10 @@ class Stickers extends \Movim\Widget\Base
}
// Creating a message
$m = new \Modl\Message;
$m->session = $this->user->getLogin();
$m = new \App\Message;
$m->user_id = $this->user->id;
$m->jidto = echapJid($to);
$m->jidfrom = $this->user->getLogin();
$m->jidfrom = $this->user->id;
$m->sticker = $key;
$m->body = $this->__('sticker.sent');
@ -87,8 +87,7 @@ class Stickers extends \Movim\Widget\Base
$p->request();
$md = new \Modl\MessageDAO;
$md->set($m);
$m->save();
// Sending it to Chat
$packet = new Moxl\Xec\Payload\Packet;

1
database/migrations/20180327203201_create_messages_table.php

@ -10,6 +10,7 @@ class CreateMessagesTable extends Migration
$this->schema->create('messages', function(Blueprint $table) {
$table->string('user_id', 64);
$table->string('id', 64);
$table->string('oldid', 64)->nullable();
$table->string('jidto', 96);
$table->string('jidfrom', 96);
$table->string('resource', 96)->nullable();

Loading…
Cancel
Save