start rewrite of notification system delivery backend

This commit is contained in:
friendica 2013-01-05 18:08:06 -08:00
parent 22ceb7c048
commit 529451a4e5
3 changed files with 82 additions and 46 deletions

View File

@ -6,10 +6,28 @@ function notification($params) {
$a = get_app();
if($params['from_xchan']) {
$x = q("select * from xchan where xchan_hash = '%s' limit 1",
dbesc($params['from_xchan'])
);
}
if($params['to_xchan']) {
$y = q("select channel.*, account.* from channel left join account on channel_account_id = account_id
where channel_hash = '%s' limit 1",
dbesc($params['to_xchan'])
);
}
if($x & $y) {
$sender = $x[0];
$recip = $y[0];
}
else
return;
// from here on everything is in the recipients language
push_lang($params['language']);
push_lang($recip['account_language']); // should probably have a channel language
$banner = t('Red Notification');
$product = FRIENDICA_PLATFORM;
@ -23,7 +41,9 @@ function notification($params) {
if(strpos($hostname,':'))
$hostname = substr($hostname,0,strpos($hostname,':'));
$sender_email = t('noreply') . '@' . $hostname;
// Do not translate 'noreply' as it must be a legal 7-bit email address
$sender_email = 'noreply' . '@' . $hostname;
$additional_mail_header = "";
if(array_key_exists('item',$params)) {
@ -41,8 +61,8 @@ function notification($params) {
$subject = sprintf( t('[Red:Notify] New mail received at %s'),$sitename);
$preamble = sprintf( t('%1$s sent you a new private message at %2$s.'),$params['source_name'],$sitename);
$epreamble = sprintf( t('%1$s sent you %2$s.'),'[url=' . $params['source_link'] . ']' . $params['source_name'] . '[/url]', '[url=$itemlink]' . t('a private message') . '[/url]');
$preamble = sprintf( t('%1$s sent you a new private message at %2$s.'),$sender['xchan_name'],$sitename);
$epreamble = sprintf( t('%1$s sent you %2$s.'),'[url=' . $sender['xchan_url'] . ']' . $sender['xchan_name'] . '[/url]', '[url=$itemlink]' . t('a private message') . '[/url]');
$sitelink = t('Please visit %s to view and/or reply to your private messages.');
$tsitelink = sprintf( $sitelink, $siteurl . '/message/' . $params['item']['id'] );
$hsitelink = sprintf( $sitelink, '<a href="' . $siteurl . '/message/' . $params['item']['id'] . '">' . $sitename . '</a>');
@ -256,9 +276,9 @@ function notification($params) {
$datarray = array();
$datarray['hash'] = $hash;
$datarray['name'] = $params['source_name'];
$datarray['url'] = $params['source_link'];
$datarray['photo'] = $params['source_photo'];
$datarray['name'] = $sender['xchan_name'];
$datarray['url'] = $sender['xchan_url'];
$datarray['photo'] = $sender['xchan_photo_s'];
$datarray['date'] = datetime_convert();
$datarray['uid'] = $params['uid'];
$datarray['link'] = $itemlink;
@ -309,7 +329,7 @@ function notification($params) {
// send email notification if notification preferences permit
require_once('bbcode.php');
if((intval($params['notify_flags']) & intval($params['type'])) || $params['type'] == NOTIFY_SYSTEM) {
if((intval($recip['channel_notifyflags']) & intval($params['type'])) || $params['type'] == NOTIFY_SYSTEM) {
logger('notification: sending notification email');
@ -361,11 +381,11 @@ intval($params['uid']), LOGGER_DEBUG);
$datarray['siteurl'] = $siteurl;
$datarray['type'] = $params['type'];
$datarray['parent'] = $params['parent'];
$datarray['source_name'] = $params['source_name'];
$datarray['source_link'] = $params['source_link'];
$datarray['source_photo'] = $params['source_photo'];
$datarray['source_name'] = $sender['xchan_name'];
$datarray['source_link'] = $sender['xchan_url'];
$datarray['source_photo'] = $sender['xchan_photo_s'];
$datarray['uid'] = $params['uid'];
$datarray['username'] = $params['to_name'];
$datarray['username'] = $recip['channel_name'];
$datarray['hsitelink'] = $hsitelink;
$datarray['tsitelink'] = $tsitelink;
$datarray['hitemlink'] = '<a href="' . $itemlink . '">' . $itemlink . '</a>';
@ -428,7 +448,7 @@ intval($params['uid']), LOGGER_DEBUG);
'fromName' => $sender_name,
'fromEmail' => $sender_email,
'replyTo' => $sender_email,
'toEmail' => $params['to_email'],
'toEmail' => $recip['account_email'],
'messageSubject' => $datarray['subject'],
'htmlVersion' => $email_html_body,
'textVersion' => $email_text_body,

View File

@ -1727,6 +1727,7 @@ function mail_store($arr) {
if($r) {
$current_post = $r[0]['id'];
logger('mail_store: created item ' . $current_post, LOGGER_DEBUG);
$arr['id'] = $current_post; // for notification
}
else {
logger('mail_store: could not locate created item');
@ -1740,6 +1741,20 @@ function mail_store($arr) {
intval($current_post)
);
}
else {
require_once('include/enotify.php');
$notif_params = array(
'from_xchan' => $arr['from_xchan'],
'to_xchan' => $arr['to_xchan'],
'type' => NOTIFY_MAIL,
'item' => $arr,
'verb' => ACTIVITY_POST,
'otype' => 'mail'
);
notification($notif_params);
}
call_hooks('post_mail_end',$arr);
return $current_post;

View File

@ -987,6 +987,7 @@ function process_mail_delivery($sender,$arr,$deliveries) {
$arr['account_id'] = $channel['channel_account_id'];
$arr['channel_id'] = $channel['channel_id'];
$item_id = mail_store($arr);
}
}
}