From 46ea203894a7ccf0300298eb2d8a2601516b9a25 Mon Sep 17 00:00:00 2001 From: Dmitriy Simushev Date: Wed, 18 Mar 2015 12:14:22 +0000 Subject: [PATCH] Let the user know that he is banned --- Plugin.php | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/Plugin.php b/Plugin.php index 097f8d6..498d777 100644 --- a/Plugin.php +++ b/Plugin.php @@ -29,6 +29,7 @@ use Mibew\EventDispatcher\Events; use Mibew\Plugin\AbstractPlugin; use Mibew\Plugin\PluginInterface; use Mibew\Settings; +use Mibew\Thread; /** * The main plugin's file definition. @@ -61,6 +62,7 @@ class Plugin extends AbstractPlugin implements PluginInterface $dispatcher = EventDispatcher::getInstance(); $dispatcher->attachListener(Events::USERS_UPDATE_THREADS_ALTER, $this, 'alterThreads'); $dispatcher->attachListener(Events::USERS_UPDATE_VISITORS_ALTER, $this, 'alterVisitors'); + $dispatcher->attachListener(Events::THREAD_UPDATE, $this, 'handleThreadUpdate'); } /** @@ -115,6 +117,34 @@ class Plugin extends AbstractPlugin implements PluginInterface $args['visitors'] = $visitors; } + /** + * A handler for {@link \Mibew\EventDispatcher\Events::THREAD_UPDATE} event. + * + * When the thread is added to the awaiting queue the method sends + * notification about ban if it's needed. + * + * @param array $args Event arguments. + */ + public function handleThreadUpdate($args) + { + $thread = $args['thread']; + $orig_thread = $args['original_thread']; + + if ($thread->state != $orig_thread->state && $thread->state == Thread::STATE_QUEUE) { + // State is change and the thread is in the awaiting queue now. + $ban = Ban::loadByAddress($thread->remote); + if ($ban && !$ban->isExpired()) { + // Operators could not see the user, because he is banned. A + // notification should be sent to let user know that he is + // banned. + $thread->postMessage( + Thread::KIND_INFO, + getlocal('Sorry, but your IP address is banned by some reasons. Try to use another way to contact the support.') + ); + } + } + } + /** * Specify version of the plugin. *