Users are sent notifications when images they have uploaded are ready for review within the Special:SuggestedTags page. Since users often upload files in batches, we want to ensure notifications are bundled so that folks don't get spammed with alerts.
Right now web-based notifications are bundling correctly, but email-based notifications are still getting sent out as individual emails (one per file), despite the fact that `email` has been set to `true` in the Echo configuration. Is there something missing from the presentation model perhaps?
I have been able to reproduce this issue locally using `$wgSMTP` on my local dev environment.
**Steps to Reproduce: **
# Sign up for email notifications for "Suggested Tags" in user settings
# Upload a series of images
**Actual Results:**
User gets one email for every image.
**Expected Results:**
User should get a "bundled" email for a batch of images (I'm not sure what this should actually look like).
**Relevant Code**
Here's the current echo configuration and presentation model we are using:
1. MachineVision's `extension.json` defines two echo-related hooks: `BeforeCreateEchoEvent` and `EchoGetBundleRules`.
2. Those hooks are implemented in the `Hooks.php` file. Here's the code for each hook method:
```
/**
* @param array &$notifications
* @param array &$notificationCategories
* @param array &$icons
*/
public static function onBeforeCreateEchoEvent(
&$notifications,
&$notificationCategories,
&$icons
) {
// 1. Define notification categories: $notificationCategories[ '...' ]
$notificationCategories[ 'machinevision' ] = [
'priority' => 3,
'tooltip' => 'echo-pref-tooltip-machinevision-suggestions-ready',
];
// 2. Define the event: $notifications[ '...' ]
$notifications[ 'machinevision-suggestions-ready'] = [
'category' => 'machinevision',
'group' => 'positive',
'section' => 'alert',
'presentation-model' => Notifications\SuggestionsReadyPresentationModel::class,
'user-locators' => [ 'EchoUserLocator::locateEventAgent' ],
'canNotifyAgent' => true,
'bundle' => [
'web' => true,
'email' => true,
'expandable' => false
]
];
$icons['suggestions-ready']['path'] = 'MachineVision/resources/icons/suggestions-ready-icon.svg';
}
```
```
/**
* @param EchoEvent $event
* @param string &$bundleString
* @return bool
*/
public static function onEchoGetBundleRules( EchoEvent $event, &$bundleString ) {
if ( $event->getType() === 'machinevision-suggestions-ready' ) {
$bundleString = 'machinevision';
}
return true;
}
```
3. A simple presentation model is defined for our notifications in `SuggestionsReadyPresentationModel.php`. Here's the code for the model:
```
<?php
namespace MediaWiki\Extension\MachineVision\Notifications;
use EchoEventPresentationModel;
use Message;
use MWException;
class SuggestionsReadyPresentationModel extends EchoEventPresentationModel {
/**
* @return string
*/
public function getIconType() {
return 'suggestions-ready';
}
/**
* @return Message
*/
public function getHeaderMessage() {
$user = $this->getViewingUserForGender();
$title = $this->event->getTitle()->getText();
if ( $this->isBundled() ) {
return $this->msg(
'echo-machinevision-suggestions-ready-notification-header',
$user
);
} else {
return $this->msg(
'echo-machinevision-suggestions-ready-notification-header-compact',
$user,
$title
);
}
}
/**
* @return Message
*/
public function getCompactHeaderMessage() {
$user = $this->getViewingUserForGender();
$title = $this->event->getTitle()->getText();
return $this->msg(
'echo-machinevision-suggestions-ready-notification-header-compact',
$user,
$title
);
}
/**
* @return bool|Message
*/
public function getBodyMessage() {
$user = $this->getViewingUserForGender();
return $this->msg(
'echo-machinevision-suggestions-ready-notification-body',
$user
);
}
/**
* @return array|false
* @throws MWException
*/
public function getPrimaryLink() {
$url = \SpecialPage::getTitleFor( 'SuggestedTags', false, 'user' );
return [
'url' => $url->getLinkURL(),
'label' => $this->msg( 'machinevision-machineaidedtagging' )
];
}
}
```
If anyone who is more familiar with Echo can take a look and let me know if anything is missing here, it would be greatly appreciated.