Browse Source

Don't use the parent id attribute anymore but respect https://xmpp.org/extensions/xep-0201.html#new for the Reply mechanism

pull/978/head
Timothée Jaussoin 5 years ago
parent
commit
de59740a58
  1. 13
      app/Message.php
  2. 5
      app/widgets/Chat/Chat.php
  3. 35
      database/migrations/20201106101328_add_parent_mid_to_messages_table.php
  4. 7
      lib/moxl/src/Stanza/Message.php
  5. 5
      lib/moxl/src/Xec/Action/Message/Publish.php

13
app/Message.php

@ -39,7 +39,7 @@ class Message extends Model
public function parent()
{
return $this->belongsTo('App\Message', 'parentthread', 'thread');
return $this->belongsTo('App\Message', 'parentmid', 'mid');
}
public function from()
@ -222,8 +222,15 @@ class Message extends Model
if ($stanza->thread) {
$this->thread = (string)$stanza->thread;
if ($stanza->thread->attributes()->parent) {
$this->parentthread = (string)$stanza->thread->attributes()->parent;
// Resolve the parent message if it exists
$parent = $this->user->messages()
->jid($this->jidfrom)
->where('thread', $this->thread)
->orderBy('published', 'asc')
->first();
if ($parent) {
$this->parentmid = $parent->mid;
}
}

5
app/widgets/Chat/Chat.php

@ -414,7 +414,9 @@ class Chat extends \Movim\Widget\Base
->first();
if ($reply) {
$m->parentthread = $reply->thread;
// See https://xmpp.org/extensions/xep-0201.html#new
$m->thread = $reply->thread;
$m->parentmid = $reply->mid;
}
}
@ -449,7 +451,6 @@ class Chat extends \Movim\Widget\Base
$p->setId($m->id);
$p->setThreadid($m->thread);
$p->setParentthreadid($m->parentthread);
$p->setOriginid($m->originid);
if ($muc) {

35
database/migrations/20201106101328_add_parent_mid_to_messages_table.php

@ -0,0 +1,35 @@
<?php
use Movim\Migration;
use Illuminate\Database\Schema\Blueprint;
class AddParentMidToMessagesTable extends Migration
{
public function up()
{
$this->disableForeignKeyCheck();
$this->schema->table('messages', function (Blueprint $table) {
$table->integer('parentmid')->unsigned()->nullable();
$table->dropColumn('parentthread');
$table->foreign('parentmid')
->references('mid')->on('messages')
->onDelete('set null');
});
$this->enableForeignKeyCheck();
}
public function down()
{
$this->disableForeignKeyCheck();
$this->schema->table('messages', function (Blueprint $table) {
$table->dropColumn('parentmid');
$table->string('parentthread', 128)->nullable();
});
$this->enableForeignKeyCheck();
}
}

7
lib/moxl/src/Stanza/Message.php

@ -20,8 +20,7 @@ class Message
$parentId = false,
array $reactions = [],
$originId = false,
$threadid = false,
$parentthreadid = false
$threadid = false
) {
$session = Session::start();
@ -55,10 +54,6 @@ class Message
if ($threadid) {
$thread = $dom->createElement('thread', $threadid);
if ($parentthreadid) {
$thread->setAttribute('parent', $parentthreadid);
}
$root->appendChild($thread);
}

5
lib/moxl/src/Xec/Action/Message/Publish.php

@ -18,7 +18,6 @@ class Publish extends Action
protected $_attachid = false;
protected $_originid = false;
protected $_threadid = false;
protected $_parentthreadid = false;
public function request()
{
@ -26,11 +25,11 @@ class Publish extends Action
if ($this->_muc) {
Muc::message($this->_to, $this->_content, $this->_html, $this->_id,
$this->_file, $this->_attachid, [], $this->_originid,
$this->_threadid, $this->_parentthreadid);
$this->_threadid);
} else {
Message::message($this->_to, $this->_content, $this->_html, $this->_id,
$this->_replace, $this->_file, $this->_attachid, [],
$this->_originid, $this->_threadid, $this->_parentthreadid);
$this->_originid, $this->_threadid);
}
}

Loading…
Cancel
Save