mirror of
https://github.com/Mibew/mibew.git
synced 2025-04-25 15:56:07 +03:00
Add "threadPostMessage" event
This commit is contained in:
parent
30da4ae75e
commit
3f27aea2ea
@ -305,6 +305,21 @@ final class Events
|
|||||||
*/
|
*/
|
||||||
const THREAD_CLOSE = 'threadClose';
|
const THREAD_CLOSE = 'threadClose';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A message is posted.
|
||||||
|
*
|
||||||
|
* This event is triggered before a message has been posted to thread. It
|
||||||
|
* provides an ability for plugins to alter message, its kind or options. An
|
||||||
|
* associative array with the following items is passed to the event
|
||||||
|
* handlers:
|
||||||
|
* - "thread": an instance of {@link \Mibew\Thread}.
|
||||||
|
* - "message_kind": int, message kind.
|
||||||
|
* - "message_body": string, message body.
|
||||||
|
* - "message_options": associative array, list of options passed to
|
||||||
|
* {@link \Mibew\Thread::postMessage()} method as the third argument.
|
||||||
|
*/
|
||||||
|
const THREAD_POST_MESSAGE = 'threadPostMessage';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Threads list is ready to be sent to client.
|
* Threads list is ready to be sent to client.
|
||||||
*
|
*
|
||||||
|
@ -808,6 +808,9 @@ class Thread
|
|||||||
* One can also set plugin item of the $options array to indicate that
|
* One can also set plugin item of the $options array to indicate that
|
||||||
* message was sent by a plugin.
|
* message was sent by a plugin.
|
||||||
*
|
*
|
||||||
|
* Triggers {@link \Mibew\EventDispatcher\Events::THREAD_POST_MESSAGE}
|
||||||
|
* event.
|
||||||
|
*
|
||||||
* @param int $kind Message kind. One of the Thread::KIND_*
|
* @param int $kind Message kind. One of the Thread::KIND_*
|
||||||
* @param string $message Message body
|
* @param string $message Message body
|
||||||
* @param array $options List of additional options. It may contain
|
* @param array $options List of additional options. It may contain
|
||||||
@ -837,10 +840,20 @@ class Thread
|
|||||||
*/
|
*/
|
||||||
public function postMessage($kind, $message, $options = array())
|
public function postMessage($kind, $message, $options = array())
|
||||||
{
|
{
|
||||||
$options = is_array($options) ? $options : array();
|
$event_args = array(
|
||||||
|
'thread' => $this,
|
||||||
|
'message_kind' => $kind,
|
||||||
|
'message_body' => $message,
|
||||||
|
'message_options' => (is_array($options) ? $options : array()),
|
||||||
|
);
|
||||||
|
EventDispatcher::getInstance()->triggerEvent(Events::THREAD_POST_MESSAGE, $event_args);
|
||||||
|
|
||||||
// Send message
|
// Send message
|
||||||
return $this->saveMessage($kind, $message, $options);
|
return $this->saveMessage(
|
||||||
|
$event_args['message_kind'],
|
||||||
|
$event_args['message_body'],
|
||||||
|
$event_args['message_options']
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user