Skip to content

Commit

Permalink
Revamp PM notifications to use alert preferences
Browse files Browse the repository at this point in the history
Not moving PMs to background task since it's
1) E-mail only
2) High priority enough to get handled instantly

Fixes SimpleMachines#2038

Signed-off-by: Shitiz Garg <mail@dragooon.net>
  • Loading branch information
Dragooon committed Aug 15, 2014
1 parent 0aeb64f commit faeba72
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 30 deletions.
2 changes: 1 addition & 1 deletion Sources/Load.php
Original file line number Diff line number Diff line change
Expand Up @@ -1040,7 +1040,7 @@ function loadMemberData($users, $is_name = false, $set = 'normal')
$select_columns .= ', mem.buddy_list, mem.additional_groups';
break;
case 'profile':
$select_columns .= ', mem.additional_groups, mem.id_theme, mem.pm_ignore_list, mem.pm_email_notify, mem.pm_receive_from,
$select_columns .= ', mem.additional_groups, mem.id_theme, mem.pm_ignore_list, mem.pm_receive_from,
mem.time_format, mem.timezone, mem.secret_question, mem.smiley_set,
mem.total_time_logged_in, mem.notify_announcements, mem.notify_regularity, mem.notify_send_body,
mem.notify_types, lo.url, mem.ignore_boards, mem.password_salt, mem.pm_prefs, mem.buddy_list, mem.alerts';
Expand Down
8 changes: 6 additions & 2 deletions Sources/Profile-Modify.php
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,6 @@ function $preload: A function that is used to load data required for this eleme
'preload' => function () use (&$context, $cur_profile)
{
$context['display_mode'] = $cur_profile['pm_prefs'] & 3;
$context['send_email'] = $cur_profile['pm_email_notify'];
$context['receive_from'] = !empty($cur_profile['pm_receive_from']) ? $cur_profile['pm_receive_from'] : 0;

return true;
Expand All @@ -371,7 +370,6 @@ function $preload: A function that is used to load data required for this eleme
// Simple validate and apply the two "sub settings"
$value = max(min($value, 2), 0);

$cur_profile['pm_email_notify'] = $profile_vars['pm_email_notify'] = max(min((int) $_POST['pm_email_notify'], 2), 0);
$cur_profile['pm_receive_from'] = $profile_vars['pm_receive_from'] = max(min((int) $_POST['pm_receive_from'], 4), 0);

return true;
Expand Down Expand Up @@ -1886,6 +1884,12 @@ function alert_configuration($memID)
4 => $txt['notify_send_type_nothing'],
)),
),
'pm' => array(
array('select', 'pm_notify', 'label' => 'before', 'opts' => array(
1 => $txt['email_notify_all'],
2 => $txt['email_notify_buddies'],
)),
),
);
$disabled_options = array();
// There are certain things that are disabled at the group level.
Expand Down
1 change: 0 additions & 1 deletion Sources/Register.php
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,6 @@ function Register2()
'secret_question', 'secret_answer',
);
$possible_ints = array(
'pm_email_notify',
'notify_types',
'id_theme',
);
Expand Down
1 change: 0 additions & 1 deletion Sources/Subs-Members.php
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,6 @@ function registerMember(&$regOptions, $return_errors = false)
'validation_code' => $validation_code,
'real_name' => $regOptions['username'],
'personal_text' => $modSettings['default_personal_text'],
'pm_email_notify' => 1,
'id_theme' => 0,
'id_post_group' => 4,
'lngfile' => '',
Expand Down
24 changes: 20 additions & 4 deletions Sources/Subs-Post.php
Original file line number Diff line number Diff line change
Expand Up @@ -817,7 +817,7 @@ function AddMailQueue($flush = false, $to_array = array(), $subject = '', $messa
*/
function sendpm($recipients, $subject, $message, $store_outbox = false, $from = null, $pm_head = 0)
{
global $scripturl, $txt, $user_info, $language;
global $scripturl, $txt, $user_info, $language, $sourcedir;
global $modSettings, $smcFunc;

// Make sure the PM language file is loaded, we might need something out of it.
Expand Down Expand Up @@ -984,10 +984,14 @@ function sendpm($recipients, $subject, $message, $store_outbox = false, $from =
if (empty($modSettings['permission_enable_deny']))
$disallowed_groups = array();

// Load their alert preferences
require_once($sourcedir . '/Subs-Notify.php');
$notifyPrefs = getNotifyPrefs($all_to, array('pm_new', 'pm_reply', 'pm_notify'));

$request = $smcFunc['db_query']('', '
SELECT
member_name, real_name, id_member, email_address, lngfile,
pm_email_notify, instant_messages,' . (allowedTo('moderate_forum') ? ' 0' : '
member_name, real_name, id_member, email_address, lngfile
instant_messages,' . (allowedTo('moderate_forum') ? ' 0' : '
(pm_receive_from = {int:admins_only}' . (empty($modSettings['enable_buddylist']) ? '' : ' OR
(pm_receive_from = {int:buddies_only} AND FIND_IN_SET({string:from_id}, buddy_list) = 0) OR
(pm_receive_from = {int:not_on_ignore_list} AND FIND_IN_SET({string:from_id}, pm_ignore_list) != 0)') . ')') . ' AS ignored,
Expand All @@ -1013,6 +1017,14 @@ function sendpm($recipients, $subject, $message, $store_outbox = false, $from =
if (isset($deletes[$row['id_member']]))
continue;

// Load the preferences for this member (if any)
$prefs = !empty($notifyPrefs[$row['id_member']]) ? $notifyPrefs[$row['id_member']] : array();
$prefs = array_merge(array(
'pm_new' => 0,
'pm_reply' => 0,
'pm_notify' => 0,
), $prefs);

// We need to know this members groups.
$groups = explode(',', $row['additional_groups']);
$groups[] = $row['id_group'];
Expand Down Expand Up @@ -1061,8 +1073,12 @@ function sendpm($recipients, $subject, $message, $store_outbox = false, $from =
}

// Send a notification, if enabled - taking the buddy list into account.
if (!empty($row['email_address']) && ($row['pm_email_notify'] == 1 || ($row['pm_email_notify'] > 1 && (!empty($modSettings['enable_buddylist']) && $row['is_buddy']))) && $row['is_activated'] == 1)
if (!empty($row['email_address'])
&& ((empty($pm_head) && $prefs['pm_new'] & 0x02) || (!empty($pm_head) && $prefs['pm_reply'] & 0x02))
&& ($prefs['pm_notify'] <= 1 || ($prefs['pm_notify'] > 1 && (!empty($modSettings['enable_buddylist']) && $row['is_buddy']))) && $row['is_activated'] == 1)
{
$notifications[empty($row['lngfile']) || empty($modSettings['userLanguage']) ? $language : $row['lngfile']][] = $row['email_address'];
}

$log['sent'][$row['id_member']] = sprintf(isset($txt['pm_successfully_sent']) ? $txt['pm_successfully_sent'] : '', $row['real_name']);
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/Subs.php
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ function updateMemberData($members, $data)
// Everything is assumed to be a string unless it's in the below.
$knownInts = array(
'date_registered', 'posts', 'id_group', 'last_login', 'instant_messages', 'unread_messages',
'new_pm', 'pm_prefs', 'gender', 'show_online', 'pm_email_notify', 'pm_receive_from',
'new_pm', 'pm_prefs', 'gender', 'show_online', 'pm_receive_from',
'notify_announcements', 'notify_send_body', 'notify_regularity', 'notify_types', 'alerts',
'id_theme', 'is_activated', 'id_msg_last_visit', 'id_post_group', 'total_time_logged_in', 'warning',
);
Expand Down
15 changes: 0 additions & 15 deletions Themes/default/Profile.template.php
Original file line number Diff line number Diff line change
Expand Up @@ -1487,21 +1487,6 @@ function template_profile_pm_settings()
<option value="3"', !empty($context['receive_from']) && $context['receive_from'] > 2 ? ' selected' : '', '>', $txt['pm_receive_from_admins'], '</option>
</select>
</dd>
<dt>
<label for="pm_email_notify">', $txt['email_notify'], '</label>
</dt>
<dd>
<select name="pm_email_notify" id="pm_email_notify">
<option value="0"', empty($context['send_email']) ? ' selected' : '', '>', $txt['email_notify_never'], '</option>
<option value="1"', !empty($context['send_email']) && ($context['send_email'] == 1 || (empty($modSettings['enable_buddylist']) && $context['send_email'] > 1)) ? ' selected' : '', '>', $txt['email_notify_always'], '</option>';

if (!empty($modSettings['enable_buddylist']))
echo '
<option value="2"', !empty($context['send_email']) && $context['send_email'] > 1 ? ' selected' : '', '>', $txt['email_notify_buddies'], '</option>';

echo '
</select>
</dd>
<dt>
<label for="popup_messages">', $txt['popup_messages'], '</label>
</dt>
Expand Down
6 changes: 3 additions & 3 deletions Themes/default/languages/Profile.english.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@
$txt['receive_mail'] = 'Receive email';
$txt['alert_group_board'] = 'Boards and Topics';
$txt['alert_group_msg'] = 'Posts';
$txt['alert_opt_pm_notify'] = 'If enabled, e-mail alerts for:';
$txt['alert_opt_msg_notify_type'] = 'Notify me of:';
$txt['alert_opt_msg_auto_notify'] = 'Follow topics I reply to.';
$txt['alert_opt_msg_notify_pref'] = 'How frequently to tell me:';
Expand Down Expand Up @@ -479,9 +480,8 @@

$txt['pm_settings_desc'] = 'From this page you can change a variety of personal messaging options, including how messages are displayed and who may send them to you.';
$txt['email_notify'] = 'Notify by email every time you receive a personal message:';
$txt['email_notify_never'] = 'Never';
$txt['email_notify_buddies'] = 'From Buddies Only';
$txt['email_notify_always'] = 'Always';
$txt['email_notify_buddies'] = 'Buddies Only';
$txt['email_notify_all'] = 'All members';

$txt['pm_receive_from'] = 'Receive personal messages from:';
$txt['pm_receive_from_everyone'] = 'All members';
Expand Down
1 change: 0 additions & 1 deletion other/install_2-1_mysql.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1214,7 +1214,6 @@ CREATE TABLE {$db_prefix}members (
signature text NOT NULL,
time_offset float NOT NULL default '0',
avatar varchar(255) NOT NULL default '',
pm_email_notify tinyint(4) NOT NULL default '0',
usertitle varchar(255) NOT NULL default '',
notify_announcements tinyint(4) NOT NULL default '1',
notify_regularity tinyint(4) NOT NULL default '1',
Expand Down
1 change: 0 additions & 1 deletion other/install_2-1_postgresql.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1613,7 +1613,6 @@ CREATE TABLE {$db_prefix}members (
signature text NOT NULL,
time_offset float NOT NULL default '0',
avatar varchar(255) NOT NULL,
pm_email_notify smallint NOT NULL default '0',
usertitle varchar(255) NOT NULL,
notify_announcements smallint NOT NULL default '1',
notify_regularity smallint NOT NULL default '1',
Expand Down

0 comments on commit faeba72

Please sign in to comment.