[ticket/11103] Only notify a user once for a single item

Note: The user may be notified multiple times IF they use different
notification options. e.g They are subscribed to topics they have
bookmarked by a notification and subscribed to the topic by
an email notification. In this case, they would receive two notifications.
This occurs because we do not want to omit any more direct types of
notifications (if they want an email, they should _always_ get at least one
email).

PHPBB3-11103
This commit is contained in:
Nathan Guse 2012-09-27 20:05:06 -05:00
parent 07616bfa92
commit 2a5baad61b
13 changed files with 116 additions and 16 deletions

View file

@ -2234,7 +2234,7 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u
switch ($mode)
{
case 'post' :
$phpbb_notifications->add_notifications(array('topic', 'quote'), $notification_data);
$phpbb_notifications->add_notifications(array('quote', 'topic'), $notification_data);
break;
case 'reply' :

View file

@ -256,16 +256,24 @@ class phpbb_notifications_service
* @param string|array $item_type Type identifier or array of item types (only acceptable if the $data is identical for the specified types)
* @param array $data Data specific for this type that will be inserted
*/
public function add_notifications($item_type, $data)
public function add_notifications($item_type, $data, $options = array())
{
$options = array_merge(array(
'ignore_users' => array(),
), $options);
if (is_array($item_type))
{
$notified_users = array();
$temp_options = $options;
foreach ($item_type as $type)
{
$this->add_notifications($type, $data);
$temp_options['ignore_users'] = $options['ignore_users'] + $notified_users;
$notified_users += $this->add_notifications($type, $data, $temp_options);
}
return;
return $notified_users;
}
$item_type_class_name = $this->get_item_type_class_name($item_type);
@ -273,9 +281,11 @@ class phpbb_notifications_service
$item_id = $item_type_class_name::get_item_id($data);
// find out which users want to receive this type of notification
$notify_users = $item_type_class_name::find_users_for_notification($this->phpbb_container, $data);
$notify_users = $item_type_class_name::find_users_for_notification($this->phpbb_container, $data, $options);
$this->add_notifications_for_users($item_type, $data, $notify_users);
return $notify_users;
}
/**

View file

@ -67,8 +67,12 @@ class phpbb_notifications_type_approve_post extends phpbb_notifications_type_pos
*
* @return array
*/
public static function find_users_for_notification(ContainerBuilder $phpbb_container, $post)
public static function find_users_for_notification(ContainerBuilder $phpbb_container, $post, $options = array())
{
$options = array_merge(array(
'ignore_users' => array(),
), $options);
$db = $phpbb_container->get('dbal.conn');
$users = array();
@ -90,6 +94,11 @@ class phpbb_notifications_type_approve_post extends phpbb_notifications_type_pos
$result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result))
{
if (isset($options['ignore_users'][$row['user_id']]) && in_array($row['method'], $options['ignore_users'][$row['user_id']]))
{
continue;
}
if (!isset($rowset[$row['user_id']]))
{
$notify_users[$row['user_id']] = array();

View file

@ -67,8 +67,12 @@ class phpbb_notifications_type_approve_topic extends phpbb_notifications_type_to
*
* @return array
*/
public static function find_users_for_notification(ContainerBuilder $phpbb_container, $post)
public static function find_users_for_notification(ContainerBuilder $phpbb_container, $post, $options = array())
{
$options = array_merge(array(
'ignore_users' => array(),
), $options);
$db = $phpbb_container->get('dbal.conn');
$users = array();
@ -90,6 +94,11 @@ class phpbb_notifications_type_approve_topic extends phpbb_notifications_type_to
$result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result))
{
if (isset($options['ignore_users'][$row['user_id']]) && in_array($row['method'], $options['ignore_users'][$row['user_id']]))
{
continue;
}
if (!isset($rowset[$row['user_id']]))
{
$notify_users[$row['user_id']] = array();

View file

@ -264,8 +264,12 @@ abstract class phpbb_notifications_type_base implements phpbb_notifications_type
*
* @return array
*/
protected static function _find_users_for_notification(ContainerBuilder $phpbb_container, $item_id)
protected static function _find_users_for_notification(ContainerBuilder $phpbb_container, $item_id, $options)
{
$options = array_merge(array(
'ignore_users' => array(),
), $options);
$db = $phpbb_container->get('dbal.conn');
$rowset = array();
@ -277,6 +281,11 @@ abstract class phpbb_notifications_type_base implements phpbb_notifications_type
$result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result))
{
if (isset($options['ignore_users'][$row['user_id']]) && in_array($row['method'], $options['ignore_users'][$row['user_id']]))
{
continue;
}
if (!isset($rowset[$row['user_id']]))
{
$rowset[$row['user_id']] = array();

View file

@ -56,8 +56,12 @@ class phpbb_notifications_type_bookmark extends phpbb_notifications_type_post
*
* @return array
*/
public static function find_users_for_notification(ContainerBuilder $phpbb_container, $post)
public static function find_users_for_notification(ContainerBuilder $phpbb_container, $post, $options = array())
{
$options = array_merge(array(
'ignore_users' => array(),
), $options);
$db = $phpbb_container->get('dbal.conn');
$users = array();
@ -94,6 +98,11 @@ class phpbb_notifications_type_bookmark extends phpbb_notifications_type_post
$result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result))
{
if (isset($options['ignore_users'][$row['user_id']]) && in_array($row['method'], $options['ignore_users'][$row['user_id']]))
{
continue;
}
if (!isset($rowset[$row['user_id']]))
{
$notify_users[$row['user_id']] = array();

View file

@ -27,7 +27,7 @@ interface phpbb_notifications_type_interface
public static function is_available(ContainerBuilder $phpbb_container);
public static function find_users_for_notification(ContainerBuilder $phpbb_container, $type_data);
public static function find_users_for_notification(ContainerBuilder $phpbb_container, $type_data, $options);
public function get_title();

View file

@ -70,8 +70,12 @@ class phpbb_notifications_type_pm extends phpbb_notifications_type_base
*
* @return array
*/
public static function find_users_for_notification(ContainerBuilder $phpbb_container, $pm)
public static function find_users_for_notification(ContainerBuilder $phpbb_container, $pm, $options = array())
{
$options = array_merge(array(
'ignore_users' => array(),
), $options);
$service = $phpbb_container->get('notifications');
$db = $phpbb_container->get('dbal.conn');
$user = $phpbb_container->get('user');
@ -92,6 +96,11 @@ class phpbb_notifications_type_pm extends phpbb_notifications_type_base
$result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result))
{
if (isset($options['ignore_users'][$row['user_id']]) && in_array($row['method'], $options['ignore_users'][$row['user_id']]))
{
continue;
}
if (!isset($rowset[$row['user_id']]))
{
$notify_users[$row['user_id']] = array();

View file

@ -76,8 +76,12 @@ class phpbb_notifications_type_post extends phpbb_notifications_type_base
*
* @return array
*/
public static function find_users_for_notification(ContainerBuilder $phpbb_container, $post)
public static function find_users_for_notification(ContainerBuilder $phpbb_container, $post, $options = array())
{
$options = array_merge(array(
'ignore_users' => array(),
), $options);
// Let's continue to use the phpBB subscriptions system, at least for now.
// It may not be the nicest thing, but it is already working and it would be significant work to replace it
//$users = parent::_find_users_for_notification($phpbb_container, $post['topic_id']);
@ -119,6 +123,11 @@ class phpbb_notifications_type_post extends phpbb_notifications_type_base
$result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result))
{
if (isset($options['ignore_users'][$row['user_id']]) && in_array($row['method'], $options['ignore_users'][$row['user_id']]))
{
continue;
}
if (!isset($rowset[$row['user_id']]))
{
$notify_users[$row['user_id']] = array();

View file

@ -77,8 +77,12 @@ class phpbb_notifications_type_post_in_queue extends phpbb_notifications_type_po
*
* @return array
*/
public static function find_users_for_notification(ContainerBuilder $phpbb_container, $post)
public static function find_users_for_notification(ContainerBuilder $phpbb_container, $post, $options = array())
{
$options = array_merge(array(
'ignore_users' => array(),
), $options);
$db = $phpbb_container->get('dbal.conn');
$auth_approve = $phpbb_container->get('auth')->acl_get_list(false, 'm_approve', $post['forum_id']);
@ -97,6 +101,11 @@ class phpbb_notifications_type_post_in_queue extends phpbb_notifications_type_po
$result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result))
{
if (isset($options['ignore_users'][$row['user_id']]) && in_array($row['method'], $options['ignore_users'][$row['user_id']]))
{
continue;
}
if (!isset($rowset[$row['user_id']]))
{
$notify_users[$row['user_id']] = array();

View file

@ -63,8 +63,12 @@ class phpbb_notifications_type_quote extends phpbb_notifications_type_post
*
* @return array
*/
public static function find_users_for_notification(ContainerBuilder $phpbb_container, $post)
public static function find_users_for_notification(ContainerBuilder $phpbb_container, $post, $options = array())
{
$options = array_merge(array(
'ignore_users' => array(),
), $options);
$db = $phpbb_container->get('dbal.conn');
$usernames = false;
@ -113,6 +117,11 @@ class phpbb_notifications_type_quote extends phpbb_notifications_type_post
$result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result))
{
if (isset($options['ignore_users'][$row['user_id']]) && in_array($row['method'], $options['ignore_users'][$row['user_id']]))
{
continue;
}
if (!isset($rowset[$row['user_id']]))
{
$notify_users[$row['user_id']] = array();

View file

@ -76,8 +76,12 @@ class phpbb_notifications_type_topic extends phpbb_notifications_type_base
*
* @return array
*/
public static function find_users_for_notification(ContainerBuilder $phpbb_container, $topic)
public static function find_users_for_notification(ContainerBuilder $phpbb_container, $topic, $options = array())
{
$options = array_merge(array(
'ignore_users' => array(),
), $options);
// Let's continue to use the phpBB subscriptions system, at least for now.
// It may not be the nicest thing, but it is already working and it would be significant work to replace it
//$users = parent::_find_users_for_notification($phpbb_container, $topic['forum_id']);
@ -119,6 +123,11 @@ class phpbb_notifications_type_topic extends phpbb_notifications_type_base
$result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result))
{
if (isset($options['ignore_users'][$row['user_id']]) && in_array($row['method'], $options['ignore_users'][$row['user_id']]))
{
continue;
}
if (!isset($rowset[$row['user_id']]))
{
$notify_users[$row['user_id']] = array();

View file

@ -77,8 +77,12 @@ class phpbb_notifications_type_topic_in_queue extends phpbb_notifications_type_t
*
* @return array
*/
public static function find_users_for_notification(ContainerBuilder $phpbb_container, $topic)
public static function find_users_for_notification(ContainerBuilder $phpbb_container, $topic, $options = array())
{
$options = array_merge(array(
'ignore_users' => array(),
), $options);
$db = $phpbb_container->get('dbal.conn');
$auth_approve = $phpbb_container->get('auth')->acl_get_list(false, 'm_approve', $topic['forum_id']);
@ -97,6 +101,11 @@ class phpbb_notifications_type_topic_in_queue extends phpbb_notifications_type_t
$result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result))
{
if (isset($options['ignore_users'][$row['user_id']]) && in_array($row['method'], $options['ignore_users'][$row['user_id']]))
{
continue;
}
if (!isset($rowset[$row['user_id']]))
{
$notify_users[$row['user_id']] = array();