mirror of
https://github.com/Mibew/mibew.git
synced 2025-01-31 13:24:41 +03:00
Add "threadGetMessagesAlter" event
This commit is contained in:
parent
c0232e6fce
commit
22699f1ed5
@ -373,6 +373,19 @@ final class Events
|
||||
*/
|
||||
const THREAD_POST_MESSAGE = 'threadPostMessage';
|
||||
|
||||
/**
|
||||
* Related with a thread messages are loaded.
|
||||
*
|
||||
* This event is triggered after messages related with a thread are loaded.
|
||||
* It provides an ability for plugins to alter messages set. An associative
|
||||
* array with the following items is passed to the event handlers:
|
||||
* - "thread": an instance of {@link \Mibew\Thread}.
|
||||
* - "messages": array, list of messages. Each message is an associative
|
||||
* array. See {@link \Mibew\Thread::getMessages()} return value for
|
||||
* details of its structure.
|
||||
*/
|
||||
const THREAD_GET_MESSAGES_ALTER = 'threadGetMessagesAlter';
|
||||
|
||||
/**
|
||||
* Threads list is ready to be sent to client.
|
||||
*
|
||||
|
@ -846,14 +846,24 @@ class Thread
|
||||
} else {
|
||||
$messages[$key]['data'] = array();
|
||||
}
|
||||
}
|
||||
|
||||
// Get last message ID
|
||||
// Trigger the "alter" event
|
||||
$args = array(
|
||||
'messages' => $messages,
|
||||
'thread' => $this,
|
||||
);
|
||||
EventDispatcher::getInstance()->triggerEvent(Events::THREAD_GET_MESSAGES_ALTER, $args);
|
||||
$altered_messages = $args['messages'];
|
||||
|
||||
// Get ID of the last message
|
||||
foreach ($altered_messages as $msg) {
|
||||
if ($msg['id'] > $last_id) {
|
||||
$last_id = $msg['id'];
|
||||
}
|
||||
}
|
||||
|
||||
return $messages;
|
||||
return $altered_messages;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user