Browse Source

Change Messages primary key (add jidfrom)

Fix events handling to prevent filtering issues
Update the dependencies
pull/647/head
Timothée Jaussoin 8 years ago
parent
commit
33384f5600
  1. 15
      app/Message.php
  2. 8
      app/widgets/Chat/Chat.php
  3. 4
      app/widgets/Chat/_chat.tpl
  4. 3
      app/widgets/Chats/chats.js
  5. 2
      app/widgets/Rooms/Rooms.php
  6. 2
      composer.json
  7. 10
      composer.lock
  8. 23
      database/migrations/20180515205626_change_messages_primary_key.php
  9. 14
      src/Movim/Widget/Base.php
  10. 6
      src/Movim/Widget/Wrapper.php

15
app/Message.php

@ -11,7 +11,7 @@ class Message extends Model
{
use HasCompositePrimaryKey;
protected $primaryKey = ['user_id', 'id'];
protected $primaryKey = ['user_id', 'jidfrom', 'id'];
public $incrementing = false;
protected $guarded = [];
@ -59,7 +59,8 @@ class Message extends Model
if (!empty($id)) {
return self::firstOrNew([
'user_id' => \App\User::me()->id,
'id' => $id
'id' => $id,
'jidfrom' => current(explode('/',(string)$stanza->attributes()->from))
]);
}
@ -230,10 +231,16 @@ class Message extends Model
}
if ($stanza->replace
&& $this->user->messages()->where('id', $this->id)->count() == 0) {
&& $this->user->messages()
->where('jidfrom', $this->jidfrom)
->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([
Message::where('id', (string)$stanza->replace->attributes()->id)
->where('jidfrom', $this->jidfrom)
->update([
'id' => $this->id,
'edited' => true
]);

8
app/widgets/Chat/Chat.php

@ -35,7 +35,8 @@ class Chat extends \Movim\Widget\Base
$this->registerEvent('message', 'onMessage');
$this->registerEvent('receiptack', 'onMessageReceipt');
$this->registerEvent('displayed', 'onMessage', 'chat');
$this->registerEvent('mamresult', 'onMessageHistory', 'chat');
//$this->registerEvent('mamresult', 'onMessageHistory', 'chat');
$this->registerEvent('mam_get_handle', 'onMAMRetrieved', 'chat');
$this->registerEvent('composing', 'onComposing', 'chat');
$this->registerEvent('paused', 'onPaused', 'chat');
$this->registerEvent('gone', 'onGone', 'chat');
@ -161,6 +162,11 @@ class Chat extends \Movim\Widget\Base
$this->ajaxGetRoom($packet->content->jidfrom);
}
function onMAMRetrieved($packet)
{
$this->ajaxGetRoom($packet->content);
}
function onMucConnected($packet)
{
$this->ajaxGetRoom($packet->content->jid);

4
app/widgets/Chat/_chat.tpl

@ -6,7 +6,7 @@
{if="!$anon"}
onclick="
MovimTpl.hidePanel();
Notification.current('');
Notification.current('chat');
Chat_ajaxGet();"
{/if}>
@ -104,7 +104,7 @@
<li id="chat_header">
<span onclick="
MovimTpl.hidePanel();
Notification.current('');
Notification.current('chat');
Chat_ajaxGet();"
id="back" class="primary icon active">
<i class="zmdi zmdi-arrow-back"></i>

3
app/widgets/Chats/chats.js

@ -23,7 +23,7 @@ var Chats = {
items[i].onmousedown = function(e) {
if (e.which == 2) {
Notification_ajaxClear('chat|' + this.dataset.jid);
Notification.current('');
Notification.current('chat');
Chats_ajaxClose(this.dataset.jid);
delete document.querySelector('#chat_widget').dataset.jid;
MovimTpl.hidePanel();
@ -48,4 +48,5 @@ var Chats = {
MovimWebsocket.attach(function() {
Chats_ajaxGet();
Notification.current('chat');
});

2
app/widgets/Rooms/Rooms.php

@ -77,6 +77,8 @@ class Rooms extends \Movim\Widget\Base
$this->ajaxJoin($room->conference, $room->nick);
}
}
$this->refreshRooms();
}
function onBookmark()

2
composer.json

@ -17,7 +17,7 @@
"rain/raintpl": "dev-master",
"michelf/php-markdown": "^1.8",
"movim/moxl": "dev-master#0f7b829eaaa0b6418aec039021f51004230c3883",
"movim/moxl": "dev-master#09d770797bdb8fd2c3b7dc05bc37f1649f981bd3",
"embed/embed": "^v3.3",
"heyupdate/emoji": "dev-twemoji2#99dda1bed08472046cac1498221f08684ad83d55",

10
composer.lock

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
"content-hash": "53f998a60356772a3d6092093c995bdb",
"content-hash": "7c1549affc2c23412cdbb19fa1ec4f0d",
"packages": [
{
"name": "cboden/ratchet",
@ -1498,12 +1498,12 @@
"source": {
"type": "git",
"url": "https://github.com/movim/moxl.git",
"reference": "0f7b829eaaa0b6418aec039021f51004230c3883"
"reference": "09d770797bdb8fd2c3b7dc05bc37f1649f981bd3"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/movim/moxl/zipball/0f7b829eaaa0b6418aec039021f51004230c3883",
"reference": "0f7b829eaaa0b6418aec039021f51004230c3883",
"url": "https://api.github.com/repos/movim/moxl/zipball/09d770797bdb8fd2c3b7dc05bc37f1649f981bd3",
"reference": "09d770797bdb8fd2c3b7dc05bc37f1649f981bd3",
"shasum": ""
},
"require": {
@ -1536,7 +1536,7 @@
"php",
"xmpp"
],
"time": "2018-05-13 21:23:01"
"time": "2018-05-15 21:31:42"
},
{
"name": "nesbot/carbon",

23
database/migrations/20180515205626_change_messages_primary_key.php

@ -0,0 +1,23 @@
<?php
use Movim\Migration;
use Illuminate\Database\Schema\Blueprint;
class ChangeMessagesPrimaryKey extends Migration
{
public function up()
{
$this->schema->table('messages', function(Blueprint $table) {
$table->dropPrimary('messages_pkey');
$table->primary(['user_id', 'jidfrom', 'id']);
});
}
public function down()
{
$this->schema->table('messages', function(Blueprint $table) {
$table->dropPrimary('messages_pkey');
$table->primary(['user_id', 'id']);
});
}
}

14
src/Movim/Widget/Base.php

@ -281,24 +281,24 @@ class Base
/**
* @brief Registers an event handler.
* @param $type The event key
* @param $function The function to call
* @param $key The event key
* @param $method The function to call
* @param $filter Only call this function if the session notif_key is good
*/
protected function registerEvent($type, $function, $filter = null)
protected function registerEvent($key, $method, $filter = null)
{
if (!is_array($this->events)
|| !array_key_exists($type, $this->events)) {
$this->events[$type] = [$function];
|| !array_key_exists($key, $this->events)) {
$this->events[$key] = [$method];
} else {
$this->events[$type][] = $function;
$this->events[$key][] = $method;
}
if ($filter != null) {
if (!is_array($this->filters)) {
$this->filters = [];
}
$this->filters[$function] = $filter;
$this->filters[$key . '_' . $method] = $filter;
}
}
}

6
src/Movim/Widget/Wrapper.php

@ -159,6 +159,7 @@ class Wrapper
if (array_key_exists($key, $this->_events)) {
foreach($this->_events[$key] as $widget_name) {
$widget = new $widget_name(true);
if (array_key_exists($key, $widget->events)) {
foreach($widget->events[$key] as $method) {
/*
@ -166,7 +167,7 @@ class Wrapper
* session notifs_key is set to a specific value
*/
if (is_array($widget->filters)
&& array_key_exists($method, $widget->filters)) {
&& array_key_exists($key . '_' . $method, $widget->filters)) {
$session = Session::start();
$notifs_key = $session->get('notifs_key');
@ -175,7 +176,8 @@ class Wrapper
} else {
$explode = explode('|', $notifs_key);
$notif_key = reset($explode);
if ($notif_key == $widget->filters[$method]) {
if ($notif_key == $widget->filters[$key . '_' . $method]) {
$widget->{$method}($data);
}
}

Loading…
Cancel
Save