Add "threadGetMessagesAlter" event

This commit is contained in:
Dmitriy Simushev 2014-10-30 10:19:08 +00:00
parent c0232e6fce
commit 22699f1ed5
2 changed files with 25 additions and 2 deletions

View File

@ -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.
*

View File

@ -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;
}
/**