Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
CRAP
0.00% covered (danger)
0.00%
0 / 1
EchoHooks
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
30
0.00% covered (danger)
0.00%
0 / 1
 onBeforeEchoEventInsert
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
30
1<?php
2
3namespace MediaWiki\MassMessage;
4
5use MediaWiki\Extension\Notifications\Hooks\BeforeEchoEventInsertHook;
6use MediaWiki\Extension\Notifications\Model\Event;
7
8/**
9 * All hooks from the Echo extension which is optional to use with this extension.
10 */
11class EchoHooks implements
12    BeforeEchoEventInsertHook
13{
14    /**
15     * @param Event $event
16     * @return bool
17     */
18    public function onBeforeEchoEventInsert( Event $event ): bool {
19        // Don't spam a user with mention notifications if it's a MassMessage
20        if (
21            ( $event->getType() === 'mention' || $event->getType() === 'flow-mention' ) &&
22            // getAgent() can return null, so guard against that
23            $event->getAgent() &&
24            $event->getAgent()->getId() == MassMessage::getMessengerUser()->getId()
25        ) {
26            return false;
27        }
28        return true;
29    }
30}