Fixed a whole lot of brokenness in Inbox SMS/Email notifications
WebGUI::Inbox::Message::create now passes isInbox flag to WebGUI::Mail::Send::create so that per-user notification settings get used SMS Gateway setting field is now 'text' instead of 'email' so that user can enter a properly formed value (such as 'myemailgateway.com', which is not an email address). Added SMS notification template as distinct from email notification template because SMSs should not be HTML and in general you will want to make your SMS notification message a lot shorter than your html email notification message (160 char limits in many countries). As a result, SMSs are now sent as separate emails to gateway rather than being CCd on email notification. Added smsGatewaySubject setting because many SMS Gateways use email subject for authentication. For consistency, also added Email notification email subject. Fixed handling of different combinations of site-wide sendInboxNotificationsOnly with per-user receiveInboxEmailNotifications and receiveInboxSmsEmailNotifications. * sendInboxNotificationsOnly && receiveInboxEmailNotifications = email notification * sendInboxNotificationsOnly && !receiveInboxEmailNotifications = no email * !sendInboxNotificationsOnly = ignore receiveInboxEmailNotifications * In all cases, SMS is optional and only dependent on receiveInboxSmsEmailNotifications Updated tests and i18n
This commit is contained in:
parent
3cc02af6bb
commit
388a0b1267
12 changed files with 264 additions and 109 deletions
|
|
@ -237,6 +237,12 @@ sub editSettingsForm {
|
|||
hoverHelp => $i18n->get('send inbox notifications only help'),
|
||||
defaultValue => $setting->get('sendInboxNotificationsOnly'),
|
||||
);
|
||||
$f->text(
|
||||
name => 'inboxNotificationsSubject',
|
||||
label => $i18n->get('inbox notifications subject'),
|
||||
hoverHelp => $i18n->get('inbox notifications subject help'),
|
||||
defaultValue => $setting->get('inboxNotificationsSubject'),
|
||||
);
|
||||
$f->template(
|
||||
name => 'inboxNotificationTemplateId',
|
||||
label => $i18n->get('inbox notification template'),
|
||||
|
|
@ -244,6 +250,13 @@ sub editSettingsForm {
|
|||
defaultValue => $self->getInboxNotificationTemplateId,
|
||||
namespace => 'Account/Inbox/Notification',
|
||||
);
|
||||
$f->template(
|
||||
name => 'inboxSmsNotificationTemplateId',
|
||||
label => $i18n->get('inbox sms notification template'),
|
||||
hoverHelp => $i18n->get('inbox sms notification template help'),
|
||||
defaultValue => $self->getInboxSmsNotificationTemplateId,
|
||||
namespace => 'Account/Inbox/Notification',
|
||||
);
|
||||
|
||||
return $f->printRowsOnly;
|
||||
}
|
||||
|
|
@ -284,12 +297,14 @@ sub editSettingsFormSave {
|
|||
$setting->set("inboxInviteUserTemplateId", $form->process("inboxInviteUserTemplateId", "template"));
|
||||
$setting->set("inboxInviteUserConfirmTemplateId", $form->process("inboxInviteUserConfirmTemplateId", "template"));
|
||||
#General Inbox Settings
|
||||
$setting->set("inboxRichEditId", $form->process("inboxRichEditId", "selectRichEditor") );
|
||||
$setting->set("inboxRichEditId", $form->process("inboxRichEditId", "selectRichEditor") );
|
||||
$setting->set("inboxCopySender", $form->process("inboxCopySender", "yesNo"));
|
||||
|
||||
#Inbox Notification Settings
|
||||
$setting->set("sendInboxNotificationsOnly", $form->process("sendInboxNotificationsOnly", "yesNo"));
|
||||
$setting->set("inboxNotificationsSubject", $form->process("inboxNotificationsSubject", "text"));
|
||||
$setting->set("inboxNotificationTemplateId", $form->process("inboxNotificationTemplateId","template"));
|
||||
$setting->set("inboxSmsNotificationTemplateId", $form->process("inboxSmsNotificationTemplateId","template"));
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -321,6 +336,19 @@ sub getInboxNotificationTemplateId {
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 getInboxSMSNotificationTemplateId ( )
|
||||
|
||||
This method returns the template ID for inbox SMS notifications.
|
||||
|
||||
=cut
|
||||
|
||||
sub getInboxSmsNotificationTemplateId {
|
||||
my $self = shift;
|
||||
return $self->session->setting->get("inboxSmsNotificationTemplateId") || "i9-G00ALhJOr0gMh-vHbKA";
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 getInvitationCount ( )
|
||||
|
||||
This method returns the total number of invitations in the invitation box.
|
||||
|
|
@ -1302,39 +1330,84 @@ sub www_sendMessageSave {
|
|||
#Let sendMessage deal with displaying errors
|
||||
return $self->www_sendMessage($errorMsg) if $hasError;
|
||||
|
||||
my $messageProperties = {
|
||||
message => $message,
|
||||
subject => $subject,
|
||||
status => 'unread',
|
||||
sentBy => $fromUser->userId
|
||||
};
|
||||
|
||||
if ($session->setting->get('sendInboxNotificationsOnly')) {
|
||||
my $template = WebGUI::Asset::Template->new($session, $self->getInboxNotificationTemplateId);
|
||||
if ($template) {
|
||||
##Create template variables
|
||||
my $var = {
|
||||
fromUsername => $fromUser->username,
|
||||
subject => $messageProperties->{subject},
|
||||
message => $messageProperties->{message},
|
||||
inboxLink => $session->url->append($session->url->getSiteURL, 'op=account;module=inbox'),
|
||||
};
|
||||
##Fill in template
|
||||
my $output = $template->process($var);
|
||||
##Evaluate macros by hand
|
||||
WebGUI::Macro::process($session, \$output);
|
||||
##Assign template output to $messageProperties->{emailMessage}
|
||||
$messageProperties->{emailMessage} = $output;
|
||||
}
|
||||
else {
|
||||
$session->log->warn(sprintf "Unable to instanciate notification template: ". $self->getInboxNotificationTemplateId);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
foreach my $uid (@toUsers) {
|
||||
my $messageProperties = {
|
||||
message => $message,
|
||||
subject => $subject,
|
||||
status => 'unread',
|
||||
sentBy => $fromUser->userId
|
||||
};
|
||||
my $messageOptions = {};
|
||||
|
||||
# Handle Email/SMS Notifications
|
||||
my $user = WebGUI::User->new($session, $uid);
|
||||
|
||||
# Sender only gets CCd on inbox message (not real email)
|
||||
my $isSender = $uid == $session->user->userId;
|
||||
$messageOptions->{no_email} = 1 if $isSender;
|
||||
|
||||
# Optionally set SMS notification details (excluding sender)
|
||||
my $smsAddress = $user->getInboxSmsNotificationAddress;
|
||||
if ( $smsAddress && !$isSender ) {
|
||||
my $smsNotificationTemplate
|
||||
= WebGUI::Asset::Template->new($session, $self->getInboxSmsNotificationTemplateId);
|
||||
if ($smsNotificationTemplate) {
|
||||
##Create template variables
|
||||
my $var = {
|
||||
fromUsername => $fromUser->username,
|
||||
subject => $messageProperties->{subject},
|
||||
message => $messageProperties->{message},
|
||||
inboxLink => $session->url->append($session->url->getSiteURL, 'op=account;module=inbox'),
|
||||
};
|
||||
##Fill in template
|
||||
my $output = $smsNotificationTemplate->process($var);
|
||||
##Evaluate macros by hand
|
||||
WebGUI::Macro::process($session, \$output);
|
||||
##Assign template output to $messageProperties->{emailMessage}
|
||||
$messageProperties->{smsMessage} = $output;
|
||||
$messageProperties->{smsAddress} = $smsAddress;
|
||||
$messageProperties->{smsSubject} = $self->session->setting->get('smsGatewaySubject');
|
||||
}
|
||||
else {
|
||||
$session->log->warn(sprintf "Unable to instanciate notification template: ". $self->getInboxSmsNotificationTemplateId);
|
||||
}
|
||||
}
|
||||
|
||||
# Optionally set email notification details (excluding sender)
|
||||
if ($session->setting->get('sendInboxNotificationsOnly') && !$isSender) {
|
||||
my $notificationAddresses = $user->getInboxNotificationAddresses;
|
||||
|
||||
# If user has turned off email notifications and admin has turned on sendInboxNotificationsOnly,
|
||||
# user gets no email at all - because email and email notification are mutually exclusive.
|
||||
# Note that they can still possibly get SMS notification above
|
||||
if (!$notificationAddresses) {
|
||||
$messageOptions->{no_email} = 1;
|
||||
} else {
|
||||
my $template = WebGUI::Asset::Template->new($session, $self->getInboxNotificationTemplateId);
|
||||
if ($template) {
|
||||
##Create template variables
|
||||
my $var = {
|
||||
fromUsername => $fromUser->username,
|
||||
subject => $messageProperties->{subject},
|
||||
message => $messageProperties->{message},
|
||||
inboxLink => $session->url->append($session->url->getSiteURL, 'op=account;module=inbox'),
|
||||
};
|
||||
##Fill in template
|
||||
my $output = $template->process($var);
|
||||
##Evaluate macros by hand
|
||||
WebGUI::Macro::process($session, \$output);
|
||||
##Assign template output to $messageProperties->{emailMessage}
|
||||
$messageProperties->{emailMessage} = $output;
|
||||
$messageProperties->{emailSubject} = $session->setting->get('inboxNotificationsSubject');
|
||||
}
|
||||
else {
|
||||
$session->log->warn(sprintf "Unable to instanciate notification template: ". $self->getInboxNotificationTemplateId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$messageProperties->{userId} = $uid;
|
||||
my $thisMessage = $inbox->addMessage($messageProperties);
|
||||
my $thisMessage = $inbox->addMessage($messageProperties, $messageOptions);
|
||||
if ($uid eq $session->user->userId) {
|
||||
$thisMessage->setRead;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue