Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 15
0.00% covered (danger)
0.00%
0 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
EchoHooks
0.00% covered (danger)
0.00%
0 / 15
0.00% covered (danger)
0.00%
0 / 3
72
0.00% covered (danger)
0.00%
0 / 1
 onBeforeEchoEventInsert
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 1
12
 onEchoAbortEmailNotification
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 onBeforeDisplayOrangeAlert
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 1
20
1<?php
2
3namespace Flow;
4
5use MediaWiki\Extension\Notifications\Hooks\BeforeDisplayOrangeAlertHook;
6use MediaWiki\Extension\Notifications\Hooks\BeforeEchoEventInsertHook;
7use MediaWiki\Extension\Notifications\Hooks\EchoAbortEmailNotificationHook;
8use MediaWiki\Extension\Notifications\Model\Event;
9use MediaWiki\Title\Title;
10use MediaWiki\User\User;
11use MediaWiki\User\UserIdentity;
12
13class EchoHooks implements
14    BeforeDisplayOrangeAlertHook,
15    BeforeEchoEventInsertHook,
16    EchoAbortEmailNotificationHook
17{
18
19    /**
20     * Suppress all Echo notifications generated by the Talk page manager user
21     *
22     * @param Event $event
23     * @return bool
24     */
25    public function onBeforeEchoEventInsert( Event $event ) {
26        $agent = $event->getAgent();
27
28        if ( $agent === null ) {
29            return true;
30        }
31
32        if ( Hooks::isTalkpageManagerUser( $agent ) ) {
33            return false;
34        }
35
36        return true;
37    }
38
39    /**
40     * Don't send email notifications that are imported from LiquidThreads.  It will
41     * still be in their web notifications (if enabled), but they will never be
42     * notified via email (regardless of batching settings) for this particular
43     * notification.
44     * @param UserIdentity $user
45     * @param Event $event
46     * @return bool
47     */
48    public function onEchoAbortEmailNotification( UserIdentity $user, Event $event ) {
49        $extra = $event->getExtra();
50        return !isset( $extra['lqtThreadId'] );
51    }
52
53    /**
54     * Hides the orange alert indicating 'You have a new message'
55     * when the user reads flow-topic replies.
56     *
57     * @param User $user
58     * @param Title $title
59     * @return bool true to show the alert, false to hide(abort) the alert
60     */
61    public function onBeforeDisplayOrangeAlert( User $user, Title $title ) {
62        if ( $title->getNamespace() === NS_TOPIC ) {
63            /** @var Data\ObjectManager $storage */
64            $storage = Container::get( 'storage.workflow' );
65            $uuid = WorkflowLoaderFactory::uuidFromTitle( $title );
66            /** @var Model\Workflow $workflow */
67            $workflow = $storage->get( $uuid );
68            if ( $workflow && $user->getTalkPage()->equals( $workflow->getOwnerTitle() ) ) {
69                return false;
70            }
71        }
72
73        return true;
74    }
75}