Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 48 additions & 4 deletions config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ services:
- '@phpbb.titania.message'
- '@phpbb.titania.access'
- '@phpbb.titania.subscriptions'
- '@path_helper'
- '@phpbb.titania.attachment.operator'

phpbb.titania.queue.stats:
Expand Down Expand Up @@ -431,18 +432,61 @@ services:
tags:
- { name: titania.contribution.type }

phpbb.titania.notification.type.base:
abstract: true
class: phpbb\titania\notification\type\base
parent: notification.type.base
calls:
- [set_user_loader, ['@user_loader']]

phpbb.titania.notification.type.posted:
class: phpbb\titania\notification\type\posted
shared: false
parent: phpbb.titania.notification.type.base
tags:
- { name: notification.type }

phpbb.titania.notification.type.contribution:
class: phpbb\titania\notification\type\contribution
shared: false
parent: phpbb.titania.notification.type.base
tags:
- { name: notification.type }

phpbb.titania.notification.type.queue:
class: phpbb\titania\notification\type\queue
shared: false
parent: phpbb.titania.notification.type.base
calls:
- [set_type_collection, ['@phpbb.titania.contribution.type.collection']]
tags:
- { name: notification.type }

phpbb.titania.notification.type.queue_move:
class: phpbb\titania\notification\type\queue_move
shared: false
parent: phpbb.titania.notification.type.queue
tags:
- { name: notification.type }

phpbb.titania.notification.type.attention:
class: phpbb\titania\notification\type\attention
shared: false
parent: phpbb.titania.notification.type.base
calls:
- [set_type_collection, ['@phpbb.titania.contribution.type.collection']]
tags:
- { name: notification.type }

phpbb.titania.subscriptions:
class: phpbb\titania\subscriptions
arguments:
- '@dbal.conn'
- '@config'
- '@request'
- '@template'
- '@user'
- '@path_helper'
- '%tables.users%'
- '%core.root_path%'
- '%core.php_ext%'
- '@notification_manager'

phpbb.titania.sync:
class: phpbb\titania\sync
Expand Down
19 changes: 12 additions & 7 deletions controller/contribution/revision.php
Original file line number Diff line number Diff line change
Expand Up @@ -270,13 +270,18 @@ public function add($contrib_type, $contrib)
'U_VIEW' => $this->queue->get_url(),
);

$this->subscriptions->send_notifications(
ext::TITANIA_QUEUE,
$this->contrib->contrib_type,
'subscribe_notify_forum',
$email_vars,
$this->user->data['user_id']
);
$this->subscriptions->send_notifications('queue', array(
'item_id' => $this->queue->queue_id,
'item_parent_id' => $this->contrib->contrib_id,
'watch' => array(array(ext::TITANIA_QUEUE, $this->contrib->contrib_type)),
'exclude_user' => $this->user->data['user_id'],
'lang_key' => 'NOTIFICATION_TITANIA_QUEUE_NEW',
'reference' => $this->contrib->contrib_name . ' ' . $this->revision->revision_version,
'url' => $email_vars['U_VIEW'],
'email_template' => 'subscribe_notify_forum',
'email_vars' => $email_vars,
'actor_id' => $this->user->data['user_id'],
));
}
redirect($this->contrib->get_url());
}
Expand Down
46 changes: 46 additions & 0 deletions event/main_listener.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ static public function getSubscribedEvents()
{
return array(
'core.permissions' => 'add_permissions',
'core.user_setup' => 'load_language',
'core.user_add_modify_notifications_data' => 'add_notifications_data',
'kernel.request' => array(array('startup', -1)),
'core.page_header_after' => 'overwrite_template_vars',
'core.text_formatter_s9e_configure_after' => 'inject_bbcode_code_lang',
Expand Down Expand Up @@ -192,6 +194,50 @@ public function add_permissions($event)
));
}

/**
* Load the notification language file on every page, so the notification
* dropdown and the UCP notification options can render Titania's types.
*
* @param data $event
*/
public function load_language($event)
{
$lang_set_ext = $event['lang_set_ext'];
$lang_set_ext[] = array(
'ext_name' => 'phpbb/titania',
'lang_set' => 'notifications',
);
$event['lang_set_ext'] = $lang_set_ext;
}

/**
* Give new users email delivery for the Titania notification types by
* default, like the core does for the post and topic types, so
* subscribing keeps its historical mail-me meaning.
*
* @param data $event
*/
public function add_notifications_data($event)
{
$notifications_data = $event['notifications_data'];

foreach (ext::get_notification_types() as $type)
{
// queue_move shares the queue type's preferences
if ($type === 'phpbb.titania.notification.type.queue_move')
{
continue;
}

$notifications_data[] = array(
'item_type' => $type,
'method' => 'notification.method.email',
);
}

$event['notifications_data'] = $notifications_data;
}

public function startup($event)
{
if ($event->getRequestType() !== HttpKernelInterface::MASTER_REQUEST ||
Expand Down
76 changes: 76 additions & 0 deletions ext.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,80 @@ public static function get_filtered_repository_branches(): array
{
return [40];
}

/**
* The notification types this extension provides
*
* @return array Array of notification type service names
*/
public static function get_notification_types(): array
{
return [
'phpbb.titania.notification.type.posted',
'phpbb.titania.notification.type.contribution',
'phpbb.titania.notification.type.queue',
'phpbb.titania.notification.type.queue_move',
'phpbb.titania.notification.type.attention',
];
}

/**
* {@inheritdoc}
*/
public function enable_step($old_state)
{
if ($old_state === false)
{
$notification_manager = $this->container->get('notification_manager');

foreach (self::get_notification_types() as $type)
{
$notification_manager->enable_notifications($type);
}

return 'notifications';
}

return parent::enable_step($old_state);
}

/**
* {@inheritdoc}
*/
public function disable_step($old_state)
{
if ($old_state === false)
{
$notification_manager = $this->container->get('notification_manager');

foreach (self::get_notification_types() as $type)
{
$notification_manager->disable_notifications($type);
}

return 'notifications';
}

return parent::disable_step($old_state);
}

/**
* {@inheritdoc}
*/
public function purge_step($old_state)
{
if ($old_state === false)
{
$notification_manager = $this->container->get('notification_manager');

foreach (self::get_notification_types() as $type)
{
$notification_manager->purge_notifications($type);
}

return 'notifications';
}

return parent::purge_step($old_state);
}
}
45 changes: 34 additions & 11 deletions includes/objects/attention.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,12 @@ public function check_auth()

public function submit()
{
// Subscriptions
if (!$this->attention_id)
$is_new = !$this->attention_id;

parent::submit();

// Subscriptions; sent after the parent submit so the attention id exists
if ($is_new)
{
$u_view = $this->controller_helper->route('phpbb.titania.manage.attention.redirect', array(
'type' => $this->attention_type,
Expand All @@ -102,16 +106,35 @@ public function submit()
'NAME' => $this->attention_title,
'U_VIEW' => $this->path_helper->strip_url_params($u_view, 'sid'),
);
$this->subscriptions->send_notifications(
ext::TITANIA_ATTENTION,
0,
'subscribe_notify',
$email_vars,
$this->attention_poster_id
);
}

parent::submit();
switch ($this->attention_type)
{
case ext::TITANIA_ATTENTION_REPORTED:
$lang_key = 'NOTIFICATION_TITANIA_ATTENTION_REPORT';
break;

case ext::TITANIA_ATTENTION_UNAPPROVED:
$lang_key = 'NOTIFICATION_TITANIA_ATTENTION_UNAPPROVED';
break;

default:
$lang_key = 'NOTIFICATION_TITANIA_ATTENTION';
break;
}

$this->subscriptions->send_notifications('attention', array(
'item_id' => $this->attention_id,
'item_parent_id' => $this->attention_object_id,
'watch' => array(array(ext::TITANIA_ATTENTION, 0)),
'exclude_user' => $this->attention_poster_id,
'lang_key' => $lang_key,
'reference' => $this->attention_title,
'url' => $email_vars['U_VIEW'],
'email_template' => 'subscribe_notify',
'email_vars' => $email_vars,
'actor_id' => $this->attention_requester,
));
}
}

/**
Expand Down
37 changes: 23 additions & 14 deletions includes/objects/attention_types/post.php
Original file line number Diff line number Diff line change
Expand Up @@ -273,10 +273,12 @@ protected function approve_post()
$message_vars = array(
'U_VIEW' => $this->path_helper->strip_url_params($u_view, 'sid'),
);
$object_type = array(ext::TITANIA_TOPIC, ext::TITANIA_SUPPORT);
$object_id = array($this->post->topic_id, $this->post->topic->parent_id);
$watch = array(
array(ext::TITANIA_TOPIC, $this->post->topic_id),
array(ext::TITANIA_SUPPORT, $this->post->topic->parent_id),
);

$this->send_notifications($object_type, $object_id, 'subscribe_notify_contrib', $message_vars);
$this->send_notifications($watch, 'NOTIFICATION_TITANIA_REPLY_CONTRIB', 'subscribe_notify_contrib', $message_vars);
}
}

Expand All @@ -296,20 +298,21 @@ protected function approve_topic()
if ($this->post->topic->topic_last_post_id == $this->post->post_id)
{
$message_vars = array('U_VIEW' => $this->post->topic->get_url());
$watch = array(array($this->post->post_type, $this->post->topic->parent_id));

$this->send_notifications($this->post->post_type, $this->post->topic->parent_id, 'subscribe_notify_forum_contrib', $message_vars);
$this->send_notifications($watch, 'NOTIFICATION_TITANIA_TOPIC_CONTRIB', 'subscribe_notify_forum_contrib', $message_vars);
}
}

/**
* Send notifications.
*
* @param int|array $object_type
* @param int|array $object_id
* @param array $watch Array of array(watch_object_type, watch_object_id) pairs
* @param string $lang_key Language key for the board notification title
* @param string $email_template
* @param array $message_vars
*/
public function send_notifications($object_type, $object_id, $email_template, $message_vars)
public function send_notifications($watch, $lang_key, $email_template, $message_vars)
{
$this->load_contrib_object();

Expand All @@ -318,13 +321,19 @@ public function send_notifications($object_type, $object_id, $email_template, $m
'CONTRIB_NAME' => $this->contrib->contrib_name,
));

$this->subscriptions->send_notifications(
$object_type,
$object_id,
$email_template,
$message_vars,
$this->post->post_user_id
);
$this->subscriptions->send_notifications('posted', array(
'item_id' => $this->post->post_id,
'item_parent_id' => $this->post->topic_id,
'watch' => $watch,
'exclude_user' => $this->post->post_user_id,
'lang_key' => $lang_key,
'lang_params' => array($this->contrib->contrib_name),
'reference' => $this->post->topic->topic_subject,
'url' => $message_vars['U_VIEW'],
'email_template' => $email_template,
'email_vars' => $message_vars,
'actor_id' => $this->post->post_user_id,
));
}

/**
Expand Down
18 changes: 17 additions & 1 deletion includes/objects/contribution.php
Original file line number Diff line number Diff line change
Expand Up @@ -2313,12 +2313,28 @@ public function delete()
// Change the status to new (handles resetting counts)
$this->change_status(ext::TITANIA_CONTRIB_NEW);

// Remove any attention items
// Remove any attention items and their notifications
$attention_ids = array();
$sql = 'SELECT attention_id FROM ' . TITANIA_ATTENTION_TABLE . '
WHERE attention_object_type = ' . ext::TITANIA_CONTRIB . '
AND attention_object_id = ' . $this->contrib_id;
$result = phpbb::$db->sql_query($sql);
while ($row = phpbb::$db->sql_fetchrow($result))
{
$attention_ids[] = (int) $row['attention_id'];
}
phpbb::$db->sql_freeresult($result);

$sql = 'DELETE FROM ' . TITANIA_ATTENTION_TABLE . '
WHERE attention_object_type = ' . ext::TITANIA_CONTRIB . '
AND attention_object_id = ' . $this->contrib_id;
phpbb::$db->sql_query($sql);

if (!empty($attention_ids))
{
phpbb::$container->get('notification_manager')->delete_notifications('phpbb.titania.notification.type.attention', $attention_ids);
}

// Delete the release topic
if ($this->contrib_release_topic_id)
{
Expand Down
Loading